[homekit] make min/max values for Color Temperature configurable (#11717)
* make min/max values for ColorTemprature configurable Signed-off-by: Eugen Freiter <freiter@gmx.de>
This commit is contained in:
parent
46971554e3
commit
b89ae048e2
|
@ -587,7 +587,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 represented in reciprocal megaKelvin. The default value range is from 50 to 400. Color temperature should not be used in combination with hue, saturation and brightness. It supports following configuration parameters: minValue, maxValue |
|
||||
| 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 |
|
||||
|
@ -747,6 +747,13 @@ openhab> log:set TRACE io.github.hapjava
|
|||
openhab> log:tail io.github.hapjava
|
||||
```
|
||||
|
||||
In order to enable detailed logs of openHAB HomeKit binding
|
||||
|
||||
```
|
||||
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.
|
||||
|
|
|
@ -220,6 +220,17 @@ public class HomekitTaggedItem {
|
|||
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
|
||||
*
|
||||
|
|
|
@ -209,15 +209,16 @@ public class HomekitCharacteristicFactory {
|
|||
}
|
||||
}
|
||||
|
||||
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.",
|
||||
|
@ -227,23 +228,24 @@ public class HomekitCharacteristicFactory {
|
|||
}
|
||||
|
||||
/** 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) {
|
||||
|
@ -399,28 +401,28 @@ public class HomekitCharacteristicFactory {
|
|||
|
||||
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));
|
||||
}
|
||||
|
@ -490,7 +492,12 @@ public class HomekitCharacteristicFactory {
|
|||
|
||||
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));
|
||||
}
|
||||
|
@ -565,14 +572,14 @@ public class HomekitCharacteristicFactory {
|
|||
|
||||
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);
|
||||
|
@ -590,14 +597,14 @@ public class HomekitCharacteristicFactory {
|
|||
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue