From d133959abf9839d5b583dcae49eb31269f123d51 Mon Sep 17 00:00:00 2001 From: Andrew Schofield Date: Sat, 2 Jan 2021 19:58:16 +0000 Subject: [PATCH] [draytonwiser] Add comfort mode option to boiler controller (#9649) Signed-off-by: Andrew Schofield --- bundles/org.openhab.binding.draytonwiser/README.md | 9 +++++---- .../internal/DraytonWiserBindingConstants.java | 1 + .../draytonwiser/internal/api/DraytonWiserApi.java | 5 +++++ .../internal/handler/ControllerHandler.java | 12 ++++++++++++ .../draytonwiser/internal/model/SystemDTO.java | 9 +++++++++ .../src/main/resources/OH-INF/thing/thing-types.xml | 7 +++++++ 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.draytonwiser/README.md b/bundles/org.openhab.binding.draytonwiser/README.md index ef5591114..6a05d3b5c 100644 --- a/bundles/org.openhab.binding.draytonwiser/README.md +++ b/bundles/org.openhab.binding.draytonwiser/README.md @@ -121,10 +121,11 @@ The `awaySetPoint` defines the temperature in degrees Celsius that will be sent #### Boiler Controller -| Channel | Item Type | Description | -|-----------------|-----------|----------------------------| -| `awayModeState` | Switch | Has away mode been enabled | -| `ecoModeState` | Switch | Has eco mode been enabled | +| Channel | Item Type | Description | +|--------------------|-----------|-------------------------------| +| `awayModeState` | Switch | Has away mode been enabled | +| `ecoModeState` | Switch | Has eco mode been enabled | +| `comfortModeState` | Switch | Has comfort mode been enabled | #### Hot Water diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java index 370cae880..524536173 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/DraytonWiserBindingConstants.java @@ -104,6 +104,7 @@ public class DraytonWiserBindingConstants { public static final String CHANNEL_DEVICE_LOCKED = "deviceLocked"; public static final String CHANNEL_SMARTPLUG_OUTPUT_STATE = "plugOutputState"; public static final String CHANNEL_SMARTPLUG_AWAY_ACTION = "plugAwayAction"; + public static final String CHANNEL_COMFORT_MODE_STATE = "comfortModeState"; public static final Set SUPPORTED_THING_TYPES_UIDS = Collections .unmodifiableSet(new HashSet<>(Arrays.asList(THING_TYPE_CONTROLLER, THING_TYPE_ROOM, THING_TYPE_ROOMSTAT, diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/api/DraytonWiserApi.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/api/DraytonWiserApi.java index 8c03af39f..457194a4a 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/api/DraytonWiserApi.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/api/DraytonWiserApi.java @@ -171,6 +171,11 @@ public class DraytonWiserApi { sendMessageToHeatHub(SMARTPLUG_ENDPOINT + id, "PATCH", payload); } + public void setComfortMode(final boolean comfortMode) throws DraytonWiserApiException { + final String payload = "{\"ComfortModeEnabled\":" + comfortMode + "}"; + sendMessageToHeatHub(SYSTEM_ENDPOINT, "PATCH", payload); + } + private synchronized @Nullable ContentResponse sendMessageToHeatHub(final String path, final HttpMethod method) throws DraytonWiserApiException { return sendMessageToHeatHub(path, method.asString(), ""); diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/ControllerHandler.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/ControllerHandler.java index a15779fa0..4b6958085 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/ControllerHandler.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/handler/ControllerHandler.java @@ -60,6 +60,8 @@ public class ControllerHandler extends DraytonWiserThingHandler setAwayMode(onOffState); } else if (CHANNEL_ECO_MODE_STATE.equals(channelId)) { setEcoMode(onOffState); + } else if (CHANNEL_COMFORT_MODE_STATE.equals(channelId)) { + setComfortMode(onOffState); } } } @@ -76,6 +78,7 @@ public class ControllerHandler extends DraytonWiserThingHandler updateState(CHANNEL_HEATCHANNEL_2_DEMAND_STATE, this::getHeatChannel2DemandState); updateState(CHANNEL_AWAY_MODE_STATE, this::getAwayModeState); updateState(CHANNEL_ECO_MODE_STATE, this::getEcoModeState); + updateState(CHANNEL_COMFORT_MODE_STATE, this::getComfortModeState); } @Override @@ -139,6 +142,11 @@ public class ControllerHandler extends DraytonWiserThingHandler return OnOffType.from(getData().system.getEcoModeEnabled() != null && getData().system.getEcoModeEnabled()); } + private State getComfortModeState() { + return OnOffType + .from(getData().system.getComfortModeEnabled() != null && getData().system.getComfortModeEnabled()); + } + private void setAwayMode(final Boolean awayMode) throws DraytonWiserApiException { getApi().setAwayMode(awayMode); } @@ -147,6 +155,10 @@ public class ControllerHandler extends DraytonWiserThingHandler getApi().setEcoMode(ecoMode); } + private void setComfortMode(final Boolean comfortMode) throws DraytonWiserApiException { + getApi().setComfortMode(comfortMode); + } + static class ControllerData { public final DeviceDTO device; public final SystemDTO system; diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/model/SystemDTO.java b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/model/SystemDTO.java index bf2557b92..780713885 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/model/SystemDTO.java +++ b/bundles/org.openhab.binding.draytonwiser/src/main/java/org/openhab/binding/draytonwiser/internal/model/SystemDTO.java @@ -26,6 +26,7 @@ public class SystemDTO { private Boolean fotaEnabled; private Boolean valveProtectionEnabled; private Boolean ecoModeEnabled; + private Boolean comfortModeEnabled; private BoilerSettingsDTO boilerSettings; private Long unixTime; private String cloudConnectionStatus; @@ -162,4 +163,12 @@ public class SystemDTO { public void setHotWaterButtonOverrideState(final String hotWaterButtonOverrideState) { this.hotWaterButtonOverrideState = hotWaterButtonOverrideState; } + + public Boolean getComfortModeEnabled() { + return comfortModeEnabled; + } + + public void setComfortModeEnabled(final Boolean comfortModeEnabled) { + this.comfortModeEnabled = comfortModeEnabled; + } } diff --git a/bundles/org.openhab.binding.draytonwiser/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.draytonwiser/src/main/resources/OH-INF/thing/thing-types.xml index faf2196e3..6fd046ace 100644 --- a/bundles/org.openhab.binding.draytonwiser/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.draytonwiser/src/main/resources/OH-INF/thing/thing-types.xml @@ -62,6 +62,7 @@ + id @@ -422,4 +423,10 @@ Should the smart plug switch off when in away mode + + Switch + + Should the room pre-heat to achieve the desired temperature + +