]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] Make Thermostat.CurrentHeatingCoolingMode optional (#17191)
authorCody Cutrer <cody@cutrer.us>
Tue, 20 Aug 2024 13:30:47 +0000 (07:30 -0600)
committerGitHub <noreply@github.com>
Tue, 20 Aug 2024 13:30:47 +0000 (15:30 +0200)
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 <cody@cutrer.us>
bundles/org.openhab.io.homekit/README.md
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitThermostatImpl.java

index 66cd514115972db95dfcefdeed8be0bf8acf7135..9d420b9e4db6821b2a4aeec175cd5f703e512ab0 100644 (file)
@@ -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)                               |                                                                                                             |
index f019eeb821e85cdef67707ab5e0a7cb5957f5fbb..74462e7adeb5a04169a603b789e3b410a6dd063c 100644 (file)
@@ -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 });
index fbbe9401c4258df1ce1e8278888ad6f09edb58f4..94f6bfae8b0a3302529845d6370a1d36f72ca3db 100644 (file)
@@ -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() {