Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[homekit] Make min/max values for Color Temperature configurable #11717

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion bundles/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ or using UI
| | | Hue | Dimmer, Color | Hue |
| | | Saturation | Dimmer, Color | Saturation in % (1-100) |
| | | Brightness | Dimmer, Color | Brightness in % (1-100). See "Usage of dimmer modes" for configuration details. |
| | | ColorTemperature | Number | NOT WORKING on iOS 14.x. Color temperature which is represented in reciprocal megaKelvin, values - 50 to 400. should not be used in combination with hue, saturation and brightness |
| | | ColorTemperature | Number | Color temperature which is represented in reciprocal megaKelvin, default value range - 50 to 400. should not be used in combination with hue, saturation and brightness. supported configuration: minValue, maxValue |
yfre marked this conversation as resolved.
Show resolved Hide resolved
| Fan | | | | Fan |
| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
| | | CurrentFanState | Number | current fan state. values: 0=INACTIVE, 1=IDLE, 2=BLOWING AIR |
Expand Down Expand Up @@ -745,6 +745,13 @@ openhab> log:set TRACE io.github.hapjava
openhab> log:tail io.github.hapjava
```

In to enable detailed logs of openHAB homekit binding
yfre marked this conversation as resolved.
Show resolved Hide resolved

```
openhab> log:set TRACE org.openhab.io.homekit.internal
openhab> log:tail org.openhab.io.homekit.internal
```

## Console commands

`openhab:homekit list` - list all HomeKit accessories currently advertised to the HomeKit clients.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ public boolean isInverted() {
return invertedConfig.equalsIgnoreCase("yes") || invertedConfig.equalsIgnoreCase("true");
}

/**
* return configuration as int if exists otherwise return defaultValue
*
* @param key configuration key
* @param defaultValue default value
* @return value
*/
public int getConfigurationAsInt(String key, int defaultValue) {
return getConfiguration(key, BigDecimal.valueOf(defaultValue)).intValue();
}

/**
* return configuration as double if exists otherwise return defaultValue
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,16 @@ private static void setValueFromEnum(HomekitTaggedItem taggedItem, Characteristi
}
}

private static int getIntFromItem(HomekitTaggedItem taggedItem) {
int value = 0;
private static int getIntFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
int value = defaultValue;
final State state = taggedItem.getItem().getState();
if (state instanceof PercentType) {
value = ((PercentType) state).intValue();
} else if (state instanceof DecimalType) {
value = ((DecimalType) state).intValue();
} else if (state instanceof UnDefType) {
logger.debug("Item state {} is UNDEF {}.", state, taggedItem.getName());
logger.debug("Item state {} is UNDEF {}. Returning default value {}", state, taggedItem.getName(),
defaultValue);
} else {
logger.warn(
"Item state {} is not supported for {}. Only PercentType and DecimalType (0/100) are supported.",
Expand All @@ -227,23 +228,24 @@ private static int getIntFromItem(HomekitTaggedItem taggedItem) {
}

/** special method for tilts. it converts percentage to angle */
private static int getAngleFromItem(HomekitTaggedItem taggedItem) {
int value = 0;
private static int getAngleFromItem(HomekitTaggedItem taggedItem, int defaultValue) {
int value = defaultValue;
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);
value = getIntFromItem(taggedItem, defaultValue);
}
return value;
}

private static Supplier<CompletableFuture<Integer>> getAngleSupplier(HomekitTaggedItem taggedItem) {
return () -> CompletableFuture.completedFuture(getAngleFromItem(taggedItem));
private static Supplier<CompletableFuture<Integer>> getAngleSupplier(HomekitTaggedItem taggedItem,
int defaultValue) {
return () -> CompletableFuture.completedFuture(getAngleFromItem(taggedItem, defaultValue));
}

private static Supplier<CompletableFuture<Integer>> getIntSupplier(HomekitTaggedItem taggedItem) {
return () -> CompletableFuture.completedFuture(getIntFromItem(taggedItem));
private static Supplier<CompletableFuture<Integer>> getIntSupplier(HomekitTaggedItem taggedItem, int defaultValue) {
return () -> CompletableFuture.completedFuture(getIntFromItem(taggedItem, defaultValue));
}

private static ExceptionalConsumer<Integer> setIntConsumer(HomekitTaggedItem taggedItem) {
Expand Down Expand Up @@ -399,28 +401,28 @@ private static CarbonDioxidePeakLevelCharacteristic createCarbonDioxidePeakLevel

private static CurrentHorizontalTiltAngleCharacteristic createCurrentHorizontalTiltAngleCharacteristic(
HomekitTaggedItem taggedItem, HomekitAccessoryUpdater updater) {
return new CurrentHorizontalTiltAngleCharacteristic(getAngleSupplier(taggedItem),
return new CurrentHorizontalTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0),
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(getAngleSupplier(taggedItem),
return new CurrentVerticalTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0),
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(getAngleSupplier(taggedItem), setAngleConsumer(taggedItem),
getSubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater),
return new TargetHorizontalTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0),
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(getAngleSupplier(taggedItem), setAngleConsumer(taggedItem),
return new TargetVerticalTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0), setAngleConsumer(taggedItem),
getSubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater),
getUnsubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater));
}
Expand Down Expand Up @@ -490,7 +492,12 @@ private static SaturationCharacteristic createSaturationCharacteristic(HomekitTa

private static ColorTemperatureCharacteristic createColorTemperatureCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
return new ColorTemperatureCharacteristic(getIntSupplier(taggedItem), setIntConsumer(taggedItem),
int minValue = taggedItem.getConfigurationAsInt(HomekitTaggedItem.MIN_VALUE,
ColorTemperatureCharacteristic.DEFAULT_MIN_VALUE);
return new ColorTemperatureCharacteristic(minValue,
taggedItem.getConfigurationAsInt(HomekitTaggedItem.MAX_VALUE,
ColorTemperatureCharacteristic.DEFAULT_MAX_VALUE),
getIntSupplier(taggedItem, minValue), setIntConsumer(taggedItem),
getSubscriber(taggedItem, COLOR_TEMPERATURE, updater),
getUnsubscriber(taggedItem, COLOR_TEMPERATURE, updater));
}
Expand Down Expand Up @@ -565,14 +572,14 @@ private static LockPhysicalControlsCharacteristic createLockPhysicalControlsChar

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

private static SetDurationCharacteristic createDurationCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
return new SetDurationCharacteristic(() -> {
int value = getIntFromItem(taggedItem);
int value = getIntFromItem(taggedItem, 0);
final @Nullable Map<String, Object> itemConfiguration = taggedItem.getConfiguration();
if ((value == 0) && (itemConfiguration != null)) { // check for default duration
final Object duration = itemConfiguration.get(HomekitValveImpl.CONFIG_DEFAULT_DURATION);
Expand All @@ -590,14 +597,14 @@ private static SetDurationCharacteristic createDurationCharacteristic(HomekitTag

private static RemainingDurationCharacteristic createRemainingDurationCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
return new RemainingDurationCharacteristic(getIntSupplier(taggedItem),
return new RemainingDurationCharacteristic(getIntSupplier(taggedItem, 0),
getSubscriber(taggedItem, REMAINING_DURATION, updater),
getUnsubscriber(taggedItem, REMAINING_DURATION, updater));
}

private static VolumeCharacteristic createVolumeCharacteristic(HomekitTaggedItem taggedItem,
HomekitAccessoryUpdater updater) {
return new VolumeCharacteristic(getIntSupplier(taggedItem),
return new VolumeCharacteristic(getIntSupplier(taggedItem, 0),
(volume) -> ((NumberItem) taggedItem.getItem()).send(new DecimalType(volume)),
getSubscriber(taggedItem, DURATION, updater), getUnsubscriber(taggedItem, DURATION, updater));
}
Expand Down