[homekit] add support for dimmer item for slat accessories (#10019)
Signed-off-by: Eugen Freiter <freiter@gmx.de>
This commit is contained in:
parent
93fac19be8
commit
9f0ec10a7d
|
@ -562,10 +562,10 @@ Switch motionsensor_tampered "Motion Sensor Tampered"
|
|||
| | | 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. |
|
||||
| | | ObstructionStatus | Switch, Contact | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction |
|
||||
| | | CurrentHorizontalTiltAngle | Number | current angle of horizontal slats for accessories windows. 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. |
|
||||
| | | TargetHorizontalTiltAngle | Number | target angle of horizontal slats |
|
||||
| | | CurrentVerticalTiltAngle | Number | current angle of vertical slats |
|
||||
| | | TargetVerticalTiltAngle | Number | target angle of vertical slats |
|
||||
| | | 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%) |
|
||||
| Switchable | | | | An accessory that can be turned off and on. While similar to a lightbulb, this will be presented differently in the Siri grammar and iOS apps |
|
||||
| | OnState | | Switch | State of the switch - ON/OFF |
|
||||
| | | Name | String | Name of the switch |
|
||||
|
|
|
@ -214,6 +214,22 @@ public class HomekitCharacteristicFactory {
|
|||
return value;
|
||||
}
|
||||
|
||||
/** special method for tilts. it converts percentage to angle */
|
||||
private static int getAngleFromItem(HomekitTaggedItem taggedItem) {
|
||||
int value = 0;
|
||||
final State state = taggedItem.getItem().getState();
|
||||
if (state instanceof PercentType) {
|
||||
value = (int) ((((PercentType) state).intValue() * 90.0) / 50.0 - 90.0);
|
||||
} else {
|
||||
value = getIntFromItem(taggedItem);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Supplier<CompletableFuture<Integer>> getAngleSupplier(HomekitTaggedItem taggedItem) {
|
||||
return () -> CompletableFuture.completedFuture(getAngleFromItem(taggedItem));
|
||||
}
|
||||
|
||||
private static Supplier<CompletableFuture<Integer>> getIntSupplier(HomekitTaggedItem taggedItem) {
|
||||
return () -> CompletableFuture.completedFuture(getIntFromItem(taggedItem));
|
||||
}
|
||||
|
@ -242,6 +258,20 @@ public class HomekitCharacteristicFactory {
|
|||
};
|
||||
}
|
||||
|
||||
private static ExceptionalConsumer<Integer> setAngleConsumer(HomekitTaggedItem taggedItem) {
|
||||
return (value) -> {
|
||||
if (taggedItem.getItem() instanceof NumberItem) {
|
||||
((NumberItem) taggedItem.getItem()).send(new DecimalType(value));
|
||||
} else if (taggedItem.getItem() instanceof DimmerItem) {
|
||||
value = (int) (value * 50.0 / 90.0 + 50.0);
|
||||
((DimmerItem) taggedItem.getItem()).send(new PercentType(value));
|
||||
} else {
|
||||
logger.warn("Item type {} is not supported for {}. Only DimmerItem and NumberItem are supported.",
|
||||
taggedItem.getItem().getType(), taggedItem.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Supplier<CompletableFuture<Double>> getDoubleSupplier(HomekitTaggedItem taggedItem) {
|
||||
return () -> {
|
||||
final @Nullable DecimalType value = taggedItem.getItem().getStateAs(DecimalType.class);
|
||||
|
@ -357,28 +387,28 @@ public class HomekitCharacteristicFactory {
|
|||
|
||||
private static CurrentHorizontalTiltAngleCharacteristic createCurrentHorizontalTiltAngleCharacteristic(
|
||||
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
|
||||
return new CurrentHorizontalTiltAngleCharacteristic(getIntSupplier(taggedItem),
|
||||
return new CurrentHorizontalTiltAngleCharacteristic(getAngleSupplier(taggedItem),
|
||||
getSubscriber(taggedItem, CURRENT_HORIZONTAL_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, CURRENT_HORIZONTAL_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static CurrentVerticalTiltAngleCharacteristic createCurrentVerticalTiltAngleCharacteristic(
|
||||
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
|
||||
return new CurrentVerticalTiltAngleCharacteristic(getIntSupplier(taggedItem),
|
||||
return new CurrentVerticalTiltAngleCharacteristic(getAngleSupplier(taggedItem),
|
||||
getSubscriber(taggedItem, CURRENT_VERTICAL_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, CURRENT_VERTICAL_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static TargetHorizontalTiltAngleCharacteristic createTargetHorizontalTiltAngleCharacteristic(
|
||||
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
|
||||
return new TargetHorizontalTiltAngleCharacteristic(getIntSupplier(taggedItem), setIntConsumer(taggedItem),
|
||||
return new TargetHorizontalTiltAngleCharacteristic(getAngleSupplier(taggedItem), setAngleConsumer(taggedItem),
|
||||
getSubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static TargetVerticalTiltAngleCharacteristic createTargetVerticalTiltAngleCharacteristic(
|
||||
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
|
||||
return new TargetVerticalTiltAngleCharacteristic(getIntSupplier(taggedItem), setIntConsumer(taggedItem),
|
||||
return new TargetVerticalTiltAngleCharacteristic(getAngleSupplier(taggedItem), setAngleConsumer(taggedItem),
|
||||
getSubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue