Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.openhab.io.homekit.internal.HomekitCommandType.*;
import static org.openhab.io.homekit.internal.HomekitDimmerMode.*;
import static org.openhab.io.homekit.internal.HomekitTaggedItem.HOMEKIT_SOURCE;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -110,9 +111,9 @@ private void sendCommand() {
&& ((brightness == null) || (brightness.intValue() == 100)))) {
logger.trace("send OnOff command for item {} with value {}", item, on);
if (item instanceof GroupItem groupItem) {
groupItem.send(on);
groupItem.send(on, HOMEKIT_SOURCE);
} else {
((DimmerItem) item).send(on);
((DimmerItem) item).send(on, HOMEKIT_SOURCE);
}
}
}
Expand All @@ -134,9 +135,9 @@ private void sendCommand() {
if (item instanceof ColorItem colorItem) {
sendHSBCommand(colorItem, hue, saturation, brightness);
} else if (item instanceof GroupItem groupItem) {
groupItem.send(brightness);
groupItem.send(brightness, HOMEKIT_SOURCE);
} else {
((DimmerItem) item).send(brightness);
((DimmerItem) item).send(brightness, HOMEKIT_SOURCE);
}
}
}
Expand All @@ -152,9 +153,9 @@ private void sendHSBCommand(Item item, @Nullable DecimalType hue, @Nullable Perc
final PercentType targetBrightness = brightness != null ? brightness : currentState.getBrightness();
final HSBType command = new HSBType(targetHue, targetSaturation, targetBrightness);
if (item instanceof GroupItem groupItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
} else {
((ColorItem) item).send(command);
((ColorItem) item).send(command, HOMEKIT_SOURCE);
}
logger.trace("send HSB command for item {} with following values hue={} saturation={} brightness={}", item,
targetHue, targetSaturation, targetBrightness);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class HomekitTaggedItem {
public static final String EMULATE_STOP_SAME_DIRECTION = "stopSameDirection";
public static final String SEND_UP_DOWN_FOR_EXTENTS = "sendUpDownForExtents";

// The "source" sent with command events so rules can identify them as coming from HomeKit
public static final String HOMEKIT_SOURCE = "org.openhab.io.homekit";

private static final Map<Integer, String> CREATED_ACCESSORY_IDS = new ConcurrentHashMap<>();

// proxy item used to group commands for complex item types like Color or Dimmer
Expand Down Expand Up @@ -181,10 +184,10 @@ public HomekitOHItemProxy getProxyItem() {
*/
public void send(DecimalType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof NumberItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof NumberItem numberItem) {
numberItem.send(command);
numberItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received DecimalType command for item {} that doesn't support it. This is probably a bug.",
Expand All @@ -198,10 +201,10 @@ public void send(DecimalType command) {
*/
public void send(QuantityType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof NumberItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof NumberItem numberItem) {
numberItem.send(command);
numberItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received QuantityType command for item {} that doesn't support it. This is probably a bug.",
Expand All @@ -215,10 +218,10 @@ public void send(QuantityType command) {
*/
public void send(OnOffType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof SwitchItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof SwitchItem switchItem) {
switchItem.send(command);
switchItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received OnOffType command for item {} that doesn't support it. This is probably a bug.",
Expand All @@ -230,10 +233,10 @@ public void send(OnOffType command) {
*/
public void send(IncreaseDecreaseType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof DimmerItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof DimmerItem dimmerItem) {
dimmerItem.send(command);
dimmerItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn(
Expand All @@ -249,13 +252,13 @@ public void send(IncreaseDecreaseType command) {
public void send(PercentType command) {
if (getItem() instanceof GroupItem groupItem
&& (getBaseItem() instanceof DimmerItem || getBaseItem() instanceof RollershutterItem)) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof DimmerItem dimmerItem) {
dimmerItem.send(command);
dimmerItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof RollershutterItem rollerShutterItem) {
rollerShutterItem.send(command);
rollerShutterItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received PercentType command for item {} that doesn't support it. This is probably a bug.",
Expand All @@ -269,10 +272,10 @@ public void send(PercentType command) {
*/
public void send(StringType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof StringItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof StringItem stringItem) {
stringItem.send(command);
stringItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received StringType command for item {} that doesn't support it. This is probably a bug.",
Expand All @@ -284,10 +287,10 @@ public void send(StringType command) {
*/
public void send(UpDownType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof RollershutterItem) {
groupItem.send(command);
groupItem.send(command, HOMEKIT_SOURCE);
return;
} else if (getItem() instanceof RollershutterItem rollershutterItem) {
rollershutterItem.send(command);
rollershutterItem.send(command, HOMEKIT_SOURCE);
return;
}
logger.warn("Received UpDownType command for item {} that doesn't support it. This is probably a bug.",
Expand Down