Skip to content

Commit 71692e7

Browse files
authored
Add item overloads for providing source (openhab#5040)
* Add item overloads for providing source Signed-off-by: Cody Cutrer <cody@cutrer.us>
1 parent 1517cc3 commit 71692e7

11 files changed

Lines changed: 298 additions & 22 deletions

File tree

bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ public void setItemStateConverter(@Nullable ItemStateConverter itemStateConverte
211211
this.itemStateConverter = itemStateConverter;
212212
}
213213

214-
protected void internalSend(Command command) {
214+
protected void internalSend(Command command, @Nullable String source) {
215215
// try to send the command to the bus
216216
if (eventPublisher instanceof EventPublisher publisher) {
217-
publisher.post(ItemEventFactory.createCommandEvent(this.getName(), command));
217+
publisher.post(ItemEventFactory.createCommandEvent(this.getName(), command, source));
218218
}
219219
}
220220

@@ -338,8 +338,22 @@ private void sendStateChangedEvent(State newState, State oldState, @Nullable Zon
338338
}
339339
}
340340

341+
/**
342+
* Send a REFRESH command to the item.
343+
*/
341344
public void send(RefreshType command) {
342-
internalSend(command);
345+
internalSend(command, null);
346+
}
347+
348+
/**
349+
* Send a REFRESH command to the item.
350+
*
351+
* @param command the command to be sent
352+
* @param source the source of the command. See
353+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
354+
*/
355+
public void send(RefreshType command, @Nullable String source) {
356+
internalSend(command, source);
343357
}
344358

345359
protected void notifyListeners(final State oldState, final State newState) {

bundles/org.openhab.core/src/main/java/org/openhab/core/items/GroupItem.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,37 @@ public List<Class<? extends Command>> getAcceptedCommandTypes() {
278278
}
279279
}
280280

281+
/**
282+
* Send a command to the each member of the group.
283+
*
284+
* @param command the command to be sent
285+
*/
281286
public void send(Command command) {
287+
send(command, null);
288+
}
289+
290+
/**
291+
* Send a command to the each member of the group.
292+
*
293+
* @param command the command to be sent
294+
* @param source the source of the command. See
295+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
296+
*/
297+
public void send(Command command, @Nullable String source) {
282298
if (getAcceptedCommandTypes().contains(command.getClass())) {
283-
internalSend(command);
299+
internalSend(command, source);
284300
} else {
285301
logger.warn("Command '{}' has been ignored for group '{}' as it is not accepted.", command, getName());
286302
}
287303
}
288304

289305
@Override
290-
protected void internalSend(Command command) {
306+
protected void internalSend(Command command, @Nullable String source) {
291307
EventPublisher eventPublisher = this.eventPublisher;
292308
if (eventPublisher != null) {
293309
for (Item member : members) {
294310
// try to send the command to the bus
295-
eventPublisher.post(ItemEventFactory.createCommandEvent(member.getName(), command));
311+
eventPublisher.post(ItemEventFactory.createCommandEvent(member.getName(), command, source));
296312
}
297313
}
298314
}

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/ColorItem.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.eclipse.jdt.annotation.NonNullByDefault;
19+
import org.eclipse.jdt.annotation.Nullable;
1920
import org.openhab.core.library.CoreItemFactory;
2021
import org.openhab.core.library.types.DecimalType;
2122
import org.openhab.core.library.types.HSBType;
@@ -45,8 +46,24 @@ public ColorItem(String name) {
4546
super(CoreItemFactory.COLOR, name);
4647
}
4748

49+
/**
50+
* Send an HSBType command to the item.
51+
*
52+
* @param command the command to be sent
53+
*/
4854
public void send(HSBType command) {
49-
internalSend(command);
55+
internalSend(command, null);
56+
}
57+
58+
/**
59+
* Send an HSBType command to the item.
60+
*
61+
* @param command the command to be sent
62+
* @param source the source of the command. See
63+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
64+
*/
65+
public void send(HSBType command, @Nullable String source) {
66+
internalSend(command, source);
5067
}
5168

5269
@Override

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/DateTimeItem.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616

1717
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.eclipse.jdt.annotation.Nullable;
1819
import org.openhab.core.items.GenericItem;
1920
import org.openhab.core.library.CoreItemFactory;
2021
import org.openhab.core.library.types.DateTimeType;
@@ -52,8 +53,24 @@ public List<Class<? extends Command>> getAcceptedCommandTypes() {
5253
return ACCEPTED_COMMAND_TYPES;
5354
}
5455

56+
/**
57+
* Send a DateTimeType command to the item.
58+
*
59+
* @param command the command to be sent
60+
*/
5561
public void send(DateTimeType command) {
56-
internalSend(command);
62+
internalSend(command, null);
63+
}
64+
65+
/**
66+
* Send a DateTimeType command to the item.
67+
*
68+
* @param command the command to be sent
69+
* @param source the source of the command. See
70+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
71+
*/
72+
public void send(DateTimeType command, @Nullable String source) {
73+
internalSend(command, source);
5774
}
5875

5976
@Override

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/DimmerItem.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616

1717
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.eclipse.jdt.annotation.Nullable;
1819
import org.openhab.core.library.CoreItemFactory;
1920
import org.openhab.core.library.types.IncreaseDecreaseType;
2021
import org.openhab.core.library.types.OnOffType;
@@ -48,12 +49,44 @@ public DimmerItem(String name) {
4849
super(type, name);
4950
}
5051

52+
/**
53+
* Send a PercentType command to the item.
54+
*
55+
* @param command the command to be sent
56+
*/
5157
public void send(PercentType command) {
52-
internalSend(command);
58+
internalSend(command, null);
5359
}
5460

61+
/**
62+
* Send a PercentType command to the item.
63+
*
64+
* @param command the command to be sent
65+
* @param source the source of the command. See
66+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
67+
*/
68+
public void send(PercentType command, @Nullable String source) {
69+
internalSend(command, source);
70+
}
71+
72+
/**
73+
* Send an INCREASE/DECREASE command to the item.
74+
*
75+
* @param command the command to be sent
76+
*/
5577
public void send(IncreaseDecreaseType command) {
56-
internalSend(command);
78+
internalSend(command, null);
79+
}
80+
81+
/**
82+
* Send an INCREASE/DECREASE command to the item.
83+
*
84+
* @param command the command to be sent
85+
* @param source the source of the command. See
86+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
87+
*/
88+
public void send(IncreaseDecreaseType command, @Nullable String source) {
89+
internalSend(command, source);
5790
}
5891

5992
@Override

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/LocationItem.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,24 @@ public LocationItem(String name) {
4343
super(CoreItemFactory.LOCATION, name);
4444
}
4545

46+
/**
47+
* Send a PointType command to the item.
48+
*
49+
* @param command the command to be sent
50+
*/
4651
public void send(PointType command) {
47-
internalSend(command);
52+
internalSend(command, null);
53+
}
54+
55+
/**
56+
* Send a PointType command to the item.
57+
*
58+
* @param command the command to be sent
59+
* @param source the source of the command. See
60+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
61+
*/
62+
public void send(PointType command, @Nullable String source) {
63+
internalSend(command, source);
4864
}
4965

5066
@Override

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/NumberItem.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,48 @@ public List<Class<? extends Command>> getAcceptedCommandTypes() {
9898
return ACCEPTED_COMMAND_TYPES;
9999
}
100100

101+
/**
102+
* Send a DecimalType command to the item.
103+
*
104+
* @param command the command to be sent
105+
*/
101106
public void send(DecimalType command) {
102-
internalSend(command);
107+
internalSend(command, null);
108+
}
109+
110+
/**
111+
* Send a DecimalType command to the item.
112+
*
113+
* @param command the command to be sent
114+
* @param source the source of the command. See
115+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
116+
*/
117+
public void send(DecimalType command, @Nullable String source) {
118+
internalSend(command, source);
103119
}
104120

121+
/**
122+
* Send a QuantityType command to the item.
123+
*
124+
* @param command the command to be sent
125+
*/
105126
public void send(QuantityType<?> command) {
127+
send(command, null);
128+
}
129+
130+
/**
131+
* Send a QuantityType command to the item.
132+
*
133+
* @param command the command to be sent
134+
* @param source the source of the command. See
135+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
136+
*/
137+
public void send(QuantityType<?> command, @Nullable String source) {
106138
if (dimension == null) {
107139
DecimalType strippedCommand = new DecimalType(command);
108-
internalSend(strippedCommand);
140+
internalSend(strippedCommand, source);
109141
} else if (command.getUnit().isCompatible(unit) || command.getUnit().inverse().isCompatible(unit)) {
110-
internalSend(command);
142+
internalSend(command, source);
111143
} else {
112144
logger.warn("Command '{}' to item '{}' was rejected because it is incompatible with the item unit '{}'",
113145
command, name, unit);

bundles/org.openhab.core/src/main/java/org/openhab/core/library/items/PlayerItem.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616

1717
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.eclipse.jdt.annotation.Nullable;
1819
import org.openhab.core.items.GenericItem;
1920
import org.openhab.core.library.CoreItemFactory;
2021
import org.openhab.core.library.types.NextPreviousType;
@@ -57,16 +58,64 @@ public List<Class<? extends Command>> getAcceptedCommandTypes() {
5758
return ACCEPTED_COMMAND_TYPES;
5859
}
5960

61+
/**
62+
* Send a PLAY/PAUSE command to the item.
63+
*
64+
* @param command the command to be sent
65+
*/
6066
public void send(PlayPauseType command) {
61-
internalSend(command);
67+
internalSend(command, null);
6268
}
6369

70+
/**
71+
* Send a PLAY/PAUSE command to the item.
72+
*
73+
* @param command the command to be sent
74+
* @param source the source of the command. See
75+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
76+
*/
77+
public void send(PlayPauseType command, @Nullable String source) {
78+
internalSend(command, source);
79+
}
80+
81+
/**
82+
* Send a REWIND/FASTFORWARD command to the item.
83+
*
84+
* @param command the command to be sent
85+
*/
6486
public void send(RewindFastforwardType command) {
65-
internalSend(command);
87+
internalSend(command, null);
88+
}
89+
90+
/**
91+
* Send a REWIND/FASTFORWARD command to the item.
92+
*
93+
* @param command the command to be sent
94+
* @param source the source of the command. See
95+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
96+
*/
97+
public void send(RewindFastforwardType command, @Nullable String source) {
98+
internalSend(command, source);
6699
}
67100

101+
/**
102+
* Send a NEXT/PREVIOUS command to the item.
103+
*
104+
* @param command the command to be sent
105+
*/
68106
public void send(NextPreviousType command) {
69-
internalSend(command);
107+
internalSend(command, null);
108+
}
109+
110+
/**
111+
* Send a NEXT/PREVIOUS command to the item.
112+
*
113+
* @param command the command to be sent
114+
* @param source the source of the command. See
115+
* https://www.openhab.org/docs/developer/utils/events.html#the-core-events
116+
*/
117+
public void send(NextPreviousType command, @Nullable String source) {
118+
internalSend(command, source);
70119
}
71120

72121
@Override

0 commit comments

Comments
 (0)