Skip to content

Commit

Permalink
[homekit] support DimmerItems for fan RotationSpeed characteristic (o…
Browse files Browse the repository at this point in the history
…penhab#7985)

i.e a zwave dimmer switch controlling a fan

Signed-off-by: Cody Cutrer <[email protected]>
Signed-off-by: MPH80 <[email protected]>
  • Loading branch information
ccutrer authored and MPH80 committed Aug 3, 2020
1 parent 26600e0 commit ace8f71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bundles/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ A full list of supported accessory types can be found in the table *below*.
| | | CurrentFanState | Number | current fan state. values: 0=INACTIVE, 1=IDLE, 2=BLOWING AIR |
| | | TargetFanState | Number | target fan state. values: 0=MANUAL, 1=AUTO |
| | | RotationDirection | Number,SwitchItem | rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE |
| | | RotationSpeed | Number | fan rotation speed in % (1-100) |
| | | RotationSpeed | Number,DimmerItem | fan rotation speed in % (1-100) |
| | | SwingMode | Number,SwitchItem | swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
| | | LockControl | Number,SwitchItem | status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED |
| Thermostat | | | | A thermostat requires all mandatory characteristics defined below |
Expand Down Expand Up @@ -506,4 +506,4 @@ openhab> log:tail io.github.hapjava
`smarthome:homekit list` - list all HomeKit accessories currently advertised to the HomeKit clients.

`smarthome:homekit show <accessory_id | name>` - print additional details of the accessories which partially match provided ID or name.


Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,20 @@ private static ExceptionalConsumer<Integer> setIntConsumer(final HomekitTaggedIt
if (taggedItem.getItem() instanceof NumberItem) {
((NumberItem) taggedItem.getItem()).send(new DecimalType(value));
} else {
logger.warn("Item type {} is not supported for {}. Only Number type is supported.",
logger.warn("Item type {} is not supported for {}. Only NumberItem is supported.",
taggedItem.getItem().getType(), taggedItem.getName());
}
};
}

private static ExceptionalConsumer<Integer> setPercentConsumer(final HomekitTaggedItem taggedItem) {
return (value) -> {
if (taggedItem.getItem() instanceof NumberItem) {
((NumberItem) taggedItem.getItem()).send(new DecimalType(value));
} else if (taggedItem.getItem() instanceof DimmerItem) {
((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());
}
};
Expand Down Expand Up @@ -501,7 +514,7 @@ private static LockPhysicalControlsCharacteristic createLockPhysicalControlsChar

private static RotationSpeedCharacteristic createRotationSpeedCharacteristic(final HomekitTaggedItem item,
HomekitAccessoryUpdater updater) {
return new RotationSpeedCharacteristic(getIntSupplier(item), setIntConsumer(item),
return new RotationSpeedCharacteristic(getIntSupplier(item), setPercentConsumer(item),
getSubscriber(item, ROTATION_SPEED, updater), getUnsubscriber(item, ROTATION_SPEED, updater));
}

Expand Down

0 comments on commit ace8f71

Please sign in to comment.