From a03056d30abb37192001320c6c9cd644ca7c1bb2 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Tue, 20 Aug 2024 07:30:47 -0600 Subject: [PATCH] [homekit] Make Thermostat.CurrentHeatingCoolingMode optional (#17191) Just default it to OFF if it's not linked. The experience in Home app is still decent - it says "Cool to X", "Heat to X", or "Set to X", instead of "Cooling to X", "Heating to X" if it was actually running. I thought about defaulting it to "HEAT" or "COOL" depending on the current target mode, but if it's set to "AUTO", that's not a valid state for the current mode. Signed-off-by: Cody Cutrer --- bundles/org.openhab.io.homekit/README.md | 2 +- .../accessories/HomekitAccessoryFactory.java | 3 +-- .../accessories/HomekitThermostatImpl.java | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 66cd5141159..9d420b9e4db 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -952,9 +952,9 @@ All accessories also support the following optional characteristic that can be l | | | FaultStatus | Contact, Number, String, Switch | Fault status | inverted (false) | NO_FAULT (0, OFF, CLOSED), GENERAL_FAULT (1, ON, OPEN) | | | | TamperedStatus | Contact, Number, String, Switch | Tampered status | inverted (false) | NOT_TAMPERED (0, OFF, CLOSED), TAMPERED (1, ON, OPEN) | | Thermostat | | | | A thermostat requires at least one of TargetTemperature, CoolingThresholdTemperature, or HeatingThresholdTemperature must be provided. | | | -| | CurrentHeatingCoolingMode | | Number, String, Switch | Current heating cooling mode | | OFF (0, OFF), HEAT (1, ON), COOL (2) | | | CurrentTemperature | | Number | Current temperature. | minValue (0), maxValue (100), step (0.1) | | | | TargetHeatingCoolingMode | | Number, String, Switch | Target heating cooling mode | | OFF (0, OFF), HEAT (1, ON), COOL (2), AUTO (3) [*](#customizable-enum) | +| | | CurrentHeatingCoolingMode | Number, String, Switch | Current heating cooling mode | | OFF (0, OFF), HEAT (1, ON), COOL (2) | | | | TargetTemperature | Number | Target temperature. If CoolingThresholdTemperature and HeatingThresholdTemperature are also provided, this characteristic is used when the thermostat is in HEAT or COOL mode. In AUTO mode, this characteristic receives the average of the two thresholds. | minValue (10), maxValue (38), step (0.1) | | | | | CoolingThresholdTemperature | Number | Maximum temperature that must be reached before cooling is turned on. If TargetTemperature is not provided, this characteristic will also be used in COOL mode. | minValue (10), maxValue (35), step (0.1) | | | | | HeatingThresholdTemperature | Number | Minimum temperature that must be reached before heating is turned on. If TargetTemperature is not provided, this characteristic will also be used in HEAT mode. | minValue (0), maxValue (25), step (0.1) | | diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java index f019eeb821e..74462e7adeb 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java @@ -104,8 +104,7 @@ public class HomekitAccessoryFactory { put(TELEVISION, new HomekitCharacteristicType[] { ACTIVE }); put(TELEVISION_SPEAKER, new HomekitCharacteristicType[] { MUTE }); put(TEMPERATURE_SENSOR, new HomekitCharacteristicType[] { CURRENT_TEMPERATURE }); - put(THERMOSTAT, new HomekitCharacteristicType[] { CURRENT_HEATING_COOLING_STATE, - TARGET_HEATING_COOLING_STATE, CURRENT_TEMPERATURE }); + put(THERMOSTAT, new HomekitCharacteristicType[] { TARGET_HEATING_COOLING_STATE, CURRENT_TEMPERATURE }); put(VALVE, new HomekitCharacteristicType[] { ACTIVE_STATUS, INUSE_STATUS }); put(WINDOW, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE }); put(WINDOW_COVERING, new HomekitCharacteristicType[] { TARGET_POSITION, CURRENT_POSITION, POSITION_STATE }); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java index fbbe9401c42..94f6bfae8b0 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java @@ -34,6 +34,7 @@ import io.github.hapjava.characteristics.Characteristic; import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; import io.github.hapjava.characteristics.impl.thermostat.CoolingThresholdTemperatureCharacteristic; import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateCharacteristic; +import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateEnum; import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic; import io.github.hapjava.characteristics.impl.thermostat.HeatingThresholdTemperatureCharacteristic; import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateCharacteristic; @@ -186,14 +187,22 @@ class HomekitThermostatImpl extends AbstractHomekitAccessoryImpl { })); } - // This characteristic is technically mandatory, but we provide a default if it's not provided + // These characteristics are technically mandatory, but we provide defaults if they're not provided + var currentHeatingCoolingStateCharacteristic = getCharacteristic(CurrentHeatingCoolingStateCharacteristic.class) + .orElseGet(() -> new CurrentHeatingCoolingStateCharacteristic( + new CurrentHeatingCoolingStateEnum[] { CurrentHeatingCoolingStateEnum.OFF }, + () -> CompletableFuture.completedFuture(CurrentHeatingCoolingStateEnum.OFF), (cb) -> { + }, () -> { + }) + + ); var displayUnitCharacteristic = getCharacteristic(TemperatureDisplayUnitCharacteristic.class) .orElseGet(() -> HomekitCharacteristicFactory.createSystemTemperatureDisplayUnitCharacteristic()); - addService(new ThermostatService(getCharacteristic(CurrentHeatingCoolingStateCharacteristic.class).get(), - targetHeatingCoolingStateCharacteristic, - getCharacteristic(CurrentTemperatureCharacteristic.class).get(), targetTemperatureCharacteristic.get(), - displayUnitCharacteristic)); + addService( + new ThermostatService(currentHeatingCoolingStateCharacteristic, targetHeatingCoolingStateCharacteristic, + getCharacteristic(CurrentTemperatureCharacteristic.class).get(), + targetTemperatureCharacteristic.get(), displayUnitCharacteristic)); } private void thresholdTemperatureChanged() {