From 21b31a9e8ddb83630af918a7e508727f29e73bc6 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Wed, 21 Dec 2022 21:44:31 -0700 Subject: [PATCH 1/2] [homekit] support Rollershutter items for HoldPosition just send STOP to them Signed-off-by: Cody Cutrer --- bundles/org.openhab.io.homekit/README.md | 8 ++++---- .../accessories/HomekitCharacteristicFactory.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 04225645410e5..14afde7952aec 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -698,28 +698,28 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | TargetPosition | | Rollershutter, Dimmer, Number | Target position of motorized door | | | PositionState | | Rollershutter, String | Position state. Supported states: DECREASING, INCREASING, STOPPED. Mapping can be redefined at item level, e.g. [DECREASING="Down", INCREASING="Up"]. If no state provided, "STOPPED" is used. | | | | Name | String | Name of the motorized door | -| | | HoldPosition | Switch | Motorized door should stop at its current position. A value of ON must hold the state of the accessory. A value of OFF should be ignored. | +| | | HoldPosition | Switch, Rollershutter | Motorized door should stop at its current position. ON is sent to Switch items. STOP is sent to Rollershutter items. Only supported by 3rd party Home apps (such as Elgato Eve) | | | | ObstructionStatus | Switch, Contact, Dimmer | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction | | Window | | | | Motorized window. One Rollershutter item covers all mandatory characteristics. see examples below. | | | CurrentPosition | | Rollershutter, Dimmer, Number | Current position of motorized window | | | TargetPosition | | Rollershutter, Dimmer, Number | Target position of motorized window | | | PositionState | | Rollershutter, String | Position state. Supported states: DECREASING, INCREASING, STOPPED. Mapping can be redefined at item level, e.g. [DECREASING="Down", INCREASING="Up"]. If no state provided, "STOPPED" is used. | | | | Name | String | Name of the motorized window | -| | | HoldPosition | Switch | Motorized door should stop at its current position. A value of ON must hold the state of the accessory. A value of OFF should be ignored. | +| | | HoldPosition | Switch, Rollershutter | Motorized door should stop at its current position. ON is sent to Switch items. STOP is sent to Rollershutter items. Only supported by 3rd party Home apps (such as Elgato Eve) | | | | ObstructionStatus | Switch, Contact, Dimmer | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction | | WindowCovering | | | | Window covering / blinds. One Rollershutter item covers all mandatory characteristics. see examples below. | | | CurrentPosition | | Rollershutter, Dimmer, Number | Current position of window covering | | | TargetPosition | | Rollershutter, Dimmer, Number | Target position of window covering | | | PositionState | | Rollershutter, String | Currently only "STOPPED" is supported. | | | | Name | String | Name of the windows covering | -| | | HoldPosition | Switch | Window covering should stop at its current position. A value of ON must hold the state of the accessory. A value of OFF should be ignored. | +| | | HoldPosition | Switch, Rollershutter | Motorized door should stop at its current position. ON is sent to Switch items. STOP is sent to Rollershutter items. Only supported by 3rd party Home apps (such as Elgato Eve) | | | | ObstructionStatus | Switch, Contact, Dimmer | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction | | | | CurrentHorizontalTiltAngle | Number, Dimmer | Number Item = current angle of horizontal slats. values -90 to 90. A value of 0 indicates that the slats are rotated to a fully open position. A value of -90 indicates that the slats are rotated all the way in a direction where the user-facing edge is higher than the window-facing edge. Dimmer Item = the percentage of openness (0%-100%) | | | | TargetHorizontalTiltAngle | Number, Dimmer | Number Item = target angle of horizontal slats (-90 to +90). Dimmer Item = the percentage of openness (0%-100%) | | | | CurrentVerticalTiltAngle | Number, Dimmer | Number Item = current angle of vertical slats (-90 to +90) . Dimmer Item = the percentage of openness (0%-100%) | | | | TargetVerticalTiltAngle | Number, Dimmer | Number Item = target angle of vertical slats. Dimmer Item = the percentage of openness (0%-100%) | | Slat | | | | Slat which tilts on a vertical or a horizontal axis. Configuration "type:horizontal" or "type:vertical" | -| | CurrentSlatState | | String | Current slat state. possible values (FIXED,SWINGING,JAMMED). Custom mapping can be defined at item level, e.g. [JAMMED="JAM", FIXED="FIX"] | +| | CurrentSlatState | | String | Current slat state. possible values (FIXED,SWINGING,JAMMED). Custom mapping can be defined at item level, e.g. [JAMMED="JAM", FIXED="FIX"] | | | | Name | String | Name of the slat | | | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED | | | | CurrentTiltAngle | Number, Dimmer | Number Item = current angle of slats. values -90 to 90. A value of 0 indicates that the slats are rotated to a fully open position. Dimmer Item = the percentage of openness (0%-100%) | diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java index c16a17cdd1045..5dc528bfd672a 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java @@ -29,9 +29,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.items.GenericItem; +import org.openhab.core.items.Item; import org.openhab.core.library.items.ColorItem; import org.openhab.core.library.items.DimmerItem; import org.openhab.core.library.items.NumberItem; +import org.openhab.core.library.items.RollershutterItem; import org.openhab.core.library.items.StringItem; import org.openhab.core.library.items.SwitchItem; import org.openhab.core.library.types.DecimalType; @@ -40,6 +42,7 @@ import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.QuantityType; +import org.openhab.core.library.types.StopMoveType; import org.openhab.core.library.types.StringType; import org.openhab.core.library.unit.ImperialUnits; import org.openhab.core.library.unit.SIUnits; @@ -471,7 +474,17 @@ private static NameCharacteristic createNameCharacteristic(HomekitTaggedItem tag private static HoldPositionCharacteristic createHoldPositionCharacteristic(HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { - return new HoldPositionCharacteristic(value -> ((SwitchItem) taggedItem.getItem()).send(OnOffType.from(value))); + return new HoldPositionCharacteristic(value -> { + if (!value) { + return; + } + Item item = taggedItem.getBaseItem(); + if (item instanceof SwitchItem) { + ((SwitchItem) item).send(OnOffType.ON); + } else if (item instanceof RollershutterItem) { + ((RollershutterItem) item).send(StopMoveType.STOP); + } + }); } private static CarbonMonoxideLevelCharacteristic createCarbonMonoxideLevelCharacteristic( From c267a49a816d7c363a3048af0bc71c06e4fba5f8 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Fri, 23 Dec 2022 07:54:00 -0700 Subject: [PATCH 2/2] [homekit] log a warning for incompatible HoldPosition items Signed-off-by: Cody Cutrer --- .../accessories/HomekitCharacteristicFactory.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java index 5dc528bfd672a..67a9ed1b55649 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitCharacteristicFactory.java @@ -474,11 +474,18 @@ private static NameCharacteristic createNameCharacteristic(HomekitTaggedItem tag private static HoldPositionCharacteristic createHoldPositionCharacteristic(HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) { + final Item item = taggedItem.getBaseItem(); + if (!(item instanceof SwitchItem || item instanceof RollershutterItem)) { + logger.warn( + "Item {} cannot be used for the HoldPosition characteristic; only SwitchItem and RollershutterItem are supported. Hold requests will be ignored.", + item.getName()); + } + return new HoldPositionCharacteristic(value -> { if (!value) { return; } - Item item = taggedItem.getBaseItem(); + if (item instanceof SwitchItem) { ((SwitchItem) item).send(OnOffType.ON); } else if (item instanceof RollershutterItem) {