]> git.basschouten.com Git - openhab-addons.git/commitdiff
Venstar: split away and schedule settings calls (#13046)
authordae1804 <github@daveeberhart.com>
Fri, 22 Jul 2022 19:44:43 +0000 (15:44 -0400)
committerGitHub <noreply@github.com>
Fri, 22 Jul 2022 19:44:43 +0000 (21:44 +0200)
Separate Venstar thermostat API calls to change the away mode or
schedule-enabled mode so that the POST to the thermostat's REST
API settings endpoint contains only one of these two params.

Newer ColorTouch thermostat firmwares will reject any POSTs to the
settings endpoint that include the 'schedule' parameter when the
thermostat is currently in AWAY mode, regardless of the value
passed for 'schedule'.  This had the effect of preventing the
OpenHab binding from un-setting away mode.

Signed-off-by: David Eberhart <git@daveeberhart.com>
bundles/org.openhab.binding.venstarthermostat/src/main/java/org/openhab/binding/venstarthermostat/internal/handler/VenstarThermostatHandler.java

index 4b0e50ddc6752adb48be8d33987e8dbda7da32a6..a5f23710586e349c6fcee4a49cc4e59aacc95811 100644 (file)
@@ -382,13 +382,42 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
     }
 
     private void setAwayMode(VenstarAwayMode away) {
-        VenstarScheduleMode schedule = infoData.getScheduleMode();
-        updateSettings(away, schedule);
+        // This function updates the away mode via a POST to the thermostat's local API's /settings endpoint.
+        //
+        // The /settings endpoint supports a number of additional parameters (tempunits, de/humedifier
+        // setpoints, etc). However, newer Venstar firmwares will reject any POST to /settings that
+        // contains a `schedule` parameter when the thermostat is currently in away mode.
+        //
+        // Separating the updates to change `schedule` and `away` ensures that the thermostat will not
+        // reject attempts to un-set away mode due to the presence of the `schedule` parameter.
+        Map<String, String> params = new HashMap<>();
+        params.put("away", String.valueOf(away.mode()));
+        VenstarResponse res = updateThermostat("/settings", params);
+        if (res != null) {
+            log.debug("Updated thermostat");
+            // update our local copy until the next refresh occurs
+            infoData.setAwayMode(away);
+        }
     }
 
     private void setScheduleMode(VenstarScheduleMode schedule) {
-        VenstarAwayMode away = infoData.getAwayMode();
-        updateSettings(away, schedule);
+        // This function updates the schedule mode via a POST to the thermostat's local API's /settings endpoint.
+        //
+        // The /settings endpoint supports a number of additional parameters (tempunits, de/humedifier
+        // setpoints, etc). However, newer Venstar firmwares will reject any POST to /settings that
+        // contains a `schedule` parameter when the thermostat is currently in away mode.
+        //
+        // Separating the updates to change `schedule` and `away` ensures that the thermostat will not
+        // reject attempts to un-set away mode due to the presence of the `schedule` parameter.
+        Map<String, String> params = new HashMap<>();
+        params.put("schedule", String.valueOf(schedule.mode()));
+        VenstarResponse res = updateThermostat("/settings", params);
+        if (res != null) {
+            log.debug("Updated thermostat");
+            // update our local copy until the next refresh occurs
+            infoData.setScheduleMode(schedule);
+            // add other parameters here in the same way
+        }
     }
 
     private QuantityType<Temperature> getCoolingSetpoint() {
@@ -407,23 +436,7 @@ public class VenstarThermostatHandler extends ConfigStatusThingHandler {
         return z;
     }
 
-    private void updateSettings(VenstarAwayMode away, VenstarScheduleMode schedule) {
-        // this function corresponds to the thermostat local API POST /settings instruction
-        // the function can be expanded with other parameters which are changed via POST /settings
-        // settings that can be included are tempunits, away mode, schedule mode, humidifier setpoint, dehumidifier
-        // setpoint
-        // (hum/dehum are the only ones missing)
-        Map<String, String> params = new HashMap<>();
-        params.put("away", String.valueOf(away.mode()));
-        params.put("schedule", String.valueOf(schedule.mode()));
-        VenstarResponse res = updateThermostat("/settings", params);
-        if (res != null) {
-            log.debug("Updated thermostat");
-            // update our local copy until the next refresh occurs
-            infoData.setAwayMode(away);
-            infoData.setScheduleMode(schedule);
-            // add other parameters here in the same way
-        }
+    private void updateScheduleMode(VenstarScheduleMode schedule) {
     }
 
     private void updateControls(double heat, double cool, VenstarSystemMode mode, VenstarFanMode fanmode) {