[homekit] allow linking GarageDoorOpener directly to a Rollershutter (#17150)

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer 2024-08-01 01:31:43 -06:00 committed by GitHub
parent 57ca70861c
commit 213a0b7d51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 280 additions and 238 deletions

View File

@ -738,7 +738,7 @@ All accessories also support the following optional characteristic that can be l
* Identify (receives `ON` command when the user wishes to identify the accessory)
| Accessory Tag | Mandatory Characteristics | Optional Characteristics | Supported openHAB item types | Description | Configuration Options | Valid Enum Values |
|-----------------------------|-----------------------------|-----------------------------|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
|-----------------------------|-----------------------------|-----------------------------|------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| AirQualitySensor | | | | Air Quality Sensor which can measure different parameters | | |
| | AirQuality | | Number, String, Switch | Air quality state | | UNKNOWN (0, OFF), EXCELLENT (1, ON), GOOD (2), FAIR (3), INFERIOR (4), POOR (5) |
| | | ActiveStatus | Contact, Switch | Working status | | |
@ -803,8 +803,8 @@ All accessories also support the following optional characteristic that can be l
| | | FilterLifeLevel | Number | Current filter life level. 0% to 100% | | |
| | | FilterResetIndication | Switch | Send "filter reset" action triggered by user in iOS Home app to openHAB ("ON" = reset requested by user). | | |
| GarageDoorOpener | | | | A garage door opener. | | |
| | CurrentDoorState | | Contact, Switch, Number, String | Current door state. | inverted (false) | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED), OPENING (2), CLOSING (3), STOPPED (4) |
| | TargetDoorState | | Contact, Switch, Number, String | Target door state. | inverted (false) | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED) |
| | CurrentDoorState | | Contact, Number, Rollershutter, String, Switch | Current door state. | inverted (false) | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED), OPENING (2), CLOSING (3), STOPPED (4) |
| | TargetDoorState | | Contact, Number, Rollershutter, String, Switch | Target door state. | inverted (false) | OPEN (0, ON, OPEN), CLOSED (1, OFF, CLOSED) |
| | | LockCurrentState | Contact, Number, String, Switch | Current state of lock mechanism | inverted (false) | UNSECURED (0, OFF, CLOSED), SECURED (1, ON, OPEN), JAMMED (2), UNKNOWN (3) |
| | | LockTargetState | Number, String, Switch | Target state of lock mechanism | inverted (false) | UNSECURED (0, OFF), SECURED (1, ON) |
| | | ObstructionStatus | Contact, Switch | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction | inverted (false) | |

View File

@ -35,6 +35,7 @@ import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.types.UpDownType;
import org.openhab.core.types.State;
import org.openhab.core.types.StateDescription;
import org.slf4j.Logger;
@ -277,6 +278,21 @@ public class HomekitTaggedItem {
getName());
}
/**
* Send UpDownType command to a RollshutterItem (or a Group:Rollershutter)
*/
public void send(UpDownType command) {
if (getItem() instanceof GroupItem groupItem && getBaseItem() instanceof RollershutterItem) {
groupItem.send(command);
return;
} else if (getItem() instanceof RollershutterItem rollershutterItem) {
rollershutterItem.send(command);
return;
}
logger.warn("Received UpDownType command for item {} that doesn't support it. This is probably a bug.",
getName());
}
/**
* send openHAB item command via proxy item, which allows to group commands.
* e.g. sendCommandProxy(hue), sendCommandProxy(brightness) would lead to one openHAB command that updates hue and

View File

@ -50,6 +50,7 @@ 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.types.UpDownType;
import org.openhab.core.library.unit.ImperialUnits;
import org.openhab.core.library.unit.SIUnits;
import org.openhab.core.library.unit.Units;
@ -855,12 +856,24 @@ public class HomekitCharacteristicFactory {
private static CurrentDoorStateCharacteristic createCurrentDoorStateCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
if (taggedItem.getBaseItem() instanceof RollershutterItem) {
return new CurrentDoorStateCharacteristic(() -> {
if (taggedItem.getItem().getState() instanceof PercentType percentType
&& percentType.equals(PercentType.HUNDRED)) {
return CompletableFuture.completedFuture(CurrentDoorStateEnum.CLOSED);
}
return CompletableFuture.completedFuture(CurrentDoorStateEnum.OPEN);
}, getSubscriber(taggedItem, CURRENT_DOOR_STATE, updater),
getUnsubscriber(taggedItem, CURRENT_DOOR_STATE, updater));
} else {
List<CurrentDoorStateEnum> validValues = new ArrayList<>();
var map = createMapping(taggedItem, CurrentDoorStateEnum.class, validValues, true);
return new CurrentDoorStateCharacteristic(() -> getEnumFromItem(taggedItem, map, CurrentDoorStateEnum.CLOSED),
return new CurrentDoorStateCharacteristic(
() -> getEnumFromItem(taggedItem, map, CurrentDoorStateEnum.CLOSED),
getSubscriber(taggedItem, CURRENT_DOOR_STATE, updater),
getUnsubscriber(taggedItem, CURRENT_DOOR_STATE, updater));
}
}
private static CurrentHeatingCoolingStateCharacteristic createCurrentHeatingCoolingStateCharacteristic(
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
@ -1426,6 +1439,18 @@ public class HomekitCharacteristicFactory {
private static TargetDoorStateCharacteristic createTargetDoorStateCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
if (taggedItem.getBaseItem() instanceof RollershutterItem) {
return new TargetDoorStateCharacteristic(() -> {
if (taggedItem.getItem().getState() instanceof PercentType percentType
&& percentType.equals(PercentType.HUNDRED)) {
return CompletableFuture.completedFuture(TargetDoorStateEnum.CLOSED);
}
return CompletableFuture.completedFuture(TargetDoorStateEnum.OPEN);
}, (targetState) -> taggedItem
.send(targetState.equals(TargetDoorStateEnum.OPEN) ? UpDownType.UP : UpDownType.DOWN),
getSubscriber(taggedItem, TARGET_DOOR_STATE, updater),
getUnsubscriber(taggedItem, TARGET_DOOR_STATE, updater));
} else {
List<TargetDoorStateEnum> validValues = new ArrayList<>();
var map = createMapping(taggedItem, TargetDoorStateEnum.class, validValues, true);
return new TargetDoorStateCharacteristic(() -> getEnumFromItem(taggedItem, map, TargetDoorStateEnum.CLOSED),
@ -1433,6 +1458,7 @@ public class HomekitCharacteristicFactory {
getSubscriber(taggedItem, TARGET_DOOR_STATE, updater),
getUnsubscriber(taggedItem, TARGET_DOOR_STATE, updater));
}
}
private static TargetFanStateCharacteristic createTargetFanStateCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {