From 5094b1d69c6d996f1981f62b8d9a2741e3a56042 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Tue, 27 Dec 2022 03:55:12 -0700 Subject: [PATCH] [homekit] support Rollershutter items for HoldPosition (#14045) * [homekit] support Rollershutter items for HoldPosition just send STOP to them * [homekit] log a warning for incompatible HoldPosition items Signed-off-by: Cody Cutrer --- bundles/org.openhab.io.homekit/README.md | 8 +++---- .../HomekitCharacteristicFactory.java | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index daab5feb067c3..1d146f88b4bf7 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -704,28 +704,28 @@ or using UI | | 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..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 @@ -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,24 @@ 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))); + 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; + } + + if (item instanceof SwitchItem) { + ((SwitchItem) item).send(OnOffType.ON); + } else if (item instanceof RollershutterItem) { + ((RollershutterItem) item).send(StopMoveType.STOP); + } + }); } private static CarbonMonoxideLevelCharacteristic createCarbonMonoxideLevelCharacteristic(