From edd222f0ee0f6c8cf65c111c261462684b572778 Mon Sep 17 00:00:00 2001 From: Ted Jordan Date: Thu, 3 Sep 2020 22:40:27 -0500 Subject: [PATCH 1/8] Added absolute control mode to the Radio Thermostat binding. Signed-off-by: Ted Jordan --- .../README.md | 19 ++++++++++--------- .../RadioThermostatConfiguration.java | 1 + .../handler/RadioThermostatHandler.java | 13 +++++++++++-- .../resources/ESH-INF/thing/thing-types.xml | 5 +++++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.radiothermostat/README.md b/bundles/org.openhab.binding.radiothermostat/README.md index ab307b4cd4904..dcd9cab184cd2 100644 --- a/bundles/org.openhab.binding.radiothermostat/README.md +++ b/bundles/org.openhab.binding.radiothermostat/README.md @@ -32,13 +32,14 @@ The binding has no configuration options, all configuration is done at Thing lev The thing has a few configuration parameters: -| Parameter | Description | -|-----------------|-----------------------------------------------------------------------------------------------------------| -| hostName | The host name or IP address of the thermostat. Mandatory. | -| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | -| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | -| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | -| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | +| Parameter | Description | +|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| hostName | The host name or IP address of the thermostat. Mandatory. | +| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | +| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | +| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | +| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | +| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are perminant; the thermostat will ignore its program maintaining the given setpoint. | ## Channels @@ -113,8 +114,8 @@ NULL_over=- radiotherm.things: ```java -radiothermostat:rtherm:mytherm1 "My 1st floor thermostat" [ hostName="192.168.10.1", refresh=2, logRefresh=10, isCT80=false, disableLogs=false ] -radiothermostat:rtherm:mytherm2 "My 2nd floor thermostat" [ hostName="mythermhost2", refresh=1, logRefresh=20, isCT80=true, disableLogs=false ] +radiothermostat:rtherm:mytherm1 "My 1st floor thermostat" [ hostName="192.168.10.1", refresh=2, logRefresh=10, isCT80=false, disableLogs=false, absolute=false ] +radiothermostat:rtherm:mytherm2 "My 2nd floor thermostat" [ hostName="mythermhost2", refresh=1, logRefresh=20, isCT80=true, disableLogs=false, absolute=true ] ``` radiotherm.items: diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java index 18b8c4232f178..020ee7cef9427 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java @@ -28,4 +28,5 @@ public class RadioThermostatConfiguration { public @Nullable Integer logRefresh; public boolean isCT80 = false; public boolean disableLogs = false; + public boolean absolute = false; } diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java index dac91d9010e0e..4bc6b024374cb 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java @@ -189,6 +189,7 @@ public void handleRawCommand(@Nullable String rawCommand) { connector.sendCommand(null, null, rawCommand); } + @SuppressWarnings("null") @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { @@ -248,10 +249,18 @@ public void handleCommand(ChannelUID channelUID, Command command) { case SET_POINT: String cmdKey = null; if (rthermData.getThermostatData().getMode() == 1) { - cmdKey = "t_heat"; + if (config.absolute) { + cmdKey = "a_heat"; + } else { + cmdKey = "t_heat"; + } rthermData.getThermostatData().setHeatTarget(cmdInt); } else if (rthermData.getThermostatData().getMode() == 2) { - cmdKey = "t_cool"; + if (config.absolute) { + cmdKey = "a_cool"; + } else { + cmdKey = "t_cool"; + } rthermData.getThermostatData().setCoolTarget(cmdInt); } else { // don't do anything if we are not in heat or cool mode diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml index ecdadebcec0ad..91bc9a50fbb38 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml @@ -58,6 +58,11 @@ Optional Flag to Disable the Retrieval of Run-time Data from the Thermostat false + + + Optional Flag to run in absolute or temporary setpoint mode + false + From 13475ea8dd4533ab9a871a74ea24351c6fbbb750 Mon Sep 17 00:00:00 2001 From: Ted Jordan Date: Thu, 3 Sep 2020 22:44:10 -0500 Subject: [PATCH 2/8] Explained the absolute parameter is optional. Signed-off-by: Ted Jordan --- .../README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bundles/org.openhab.binding.radiothermostat/README.md b/bundles/org.openhab.binding.radiothermostat/README.md index dcd9cab184cd2..fb4d9cfe2a716 100644 --- a/bundles/org.openhab.binding.radiothermostat/README.md +++ b/bundles/org.openhab.binding.radiothermostat/README.md @@ -32,14 +32,14 @@ The binding has no configuration options, all configuration is done at Thing lev The thing has a few configuration parameters: -| Parameter | Description | -|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| hostName | The host name or IP address of the thermostat. Mandatory. | -| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | -| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | -| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | -| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | -| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are perminant; the thermostat will ignore its program maintaining the given setpoint. | +| Parameter | Description | +|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| hostName | The host name or IP address of the thermostat. Mandatory. | +| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | +| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | +| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | +| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | +| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are perminant; the thermostat will ignore its program maintaining the given setpoint. Optional, the default is false. | ## Channels From ed64593863d0fa8a86831c4c184566757a644d9c Mon Sep 17 00:00:00 2001 From: silverfunk Date: Mon, 7 Sep 2020 21:30:32 -0500 Subject: [PATCH 3/8] Update bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml Co-authored-by: cpmeister Signed-off-by: Ted Jordan --- .../src/main/resources/ESH-INF/thing/thing-types.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml index 91bc9a50fbb38..b9754f59bb88c 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml @@ -59,7 +59,7 @@ false - + Optional Flag to run in absolute or temporary setpoint mode false From a6c91b2b5bedae5e1b6ef0405e30ebcbee9e10e4 Mon Sep 17 00:00:00 2001 From: Ted Jordan Date: Mon, 7 Sep 2020 21:46:33 -0500 Subject: [PATCH 4/8] Fixed the spelling of permanent. Co-authored-by: mlobstein Signed-off-by: Ted Jordan --- bundles/org.openhab.binding.radiothermostat/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.radiothermostat/README.md b/bundles/org.openhab.binding.radiothermostat/README.md index fb4d9cfe2a716..495ee4902d161 100644 --- a/bundles/org.openhab.binding.radiothermostat/README.md +++ b/bundles/org.openhab.binding.radiothermostat/README.md @@ -39,7 +39,7 @@ The thing has a few configuration parameters: | logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | | isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | | disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | -| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are perminant; the thermostat will ignore its program maintaining the given setpoint. Optional, the default is false. | +| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are permanent; the thermostat will ignore its program maintaining the given setpoint. Optional, the default is false. | ## Channels From 507140fe848b57c9206c2cf6d2a28eb968135657 Mon Sep 17 00:00:00 2001 From: silverfunk Date: Tue, 8 Sep 2020 20:54:59 -0500 Subject: [PATCH 5/8] Refactored code to removed suppressed warnings. Changed the absolute parameter to setpointMode. Signed-off-by: silverfunk --- .../README.md | 20 ++-- .../RadioThermostatConfiguration.java | 2 +- ...dioThermostatStateDescriptionProvider.java | 44 +++------ .../handler/RadioThermostatHandler.java | 93 ++++++++++++------- .../resources/ESH-INF/thing/thing-types.xml | 12 ++- 5 files changed, 87 insertions(+), 84 deletions(-) diff --git a/bundles/org.openhab.binding.radiothermostat/README.md b/bundles/org.openhab.binding.radiothermostat/README.md index 495ee4902d161..74987466aae42 100644 --- a/bundles/org.openhab.binding.radiothermostat/README.md +++ b/bundles/org.openhab.binding.radiothermostat/README.md @@ -32,14 +32,14 @@ The binding has no configuration options, all configuration is done at Thing lev The thing has a few configuration parameters: -| Parameter | Description | -|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| hostName | The host name or IP address of the thermostat. Mandatory. | -| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | -| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | -| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | -| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | -| absolute | Controls temporary or absolute mode. When false setpoint changes are temporary; the thermostat will return to its program after a time. When true setpoint changes are permanent; the thermostat will ignore its program maintaining the given setpoint. Optional, the default is false. | +| Parameter | Description | +|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| hostName | The host name or IP address of the thermostat. Mandatory. | +| refresh | Overrides the refresh interval of the thermostat data. Optional, the default is 2 minutes. | +| logRefresh | Overrides the refresh interval of the run-time logs & humidity data. Optional, the default is 10 minutes. | +| isCT80 | Flag to enable additional features only available on the CT80 thermostat. Optional, the default is false. | +| disableLogs | Disable retrieval of run-time logs from the thermostat. Optional, the default is false. | +| setpointMode | Controls temporary or absolute setpoint mode. In "temporary" mode the thermostat will temporarily maintain the given setpoint, returning to its program after a time. In "absolute" mode the thermostat will ignore its program maintaining the given setpoint. | ## Channels @@ -114,8 +114,8 @@ NULL_over=- radiotherm.things: ```java -radiothermostat:rtherm:mytherm1 "My 1st floor thermostat" [ hostName="192.168.10.1", refresh=2, logRefresh=10, isCT80=false, disableLogs=false, absolute=false ] -radiothermostat:rtherm:mytherm2 "My 2nd floor thermostat" [ hostName="mythermhost2", refresh=1, logRefresh=20, isCT80=true, disableLogs=false, absolute=true ] +radiothermostat:rtherm:mytherm1 "My 1st floor thermostat" [ hostName="192.168.10.1", refresh=2, logRefresh=10, isCT80=false, disableLogs=false, setpointMode="temporary" ] +radiothermostat:rtherm:mytherm2 "My 2nd floor thermostat" [ hostName="mythermhost2", refresh=1, logRefresh=20, isCT80=true, disableLogs=false, setpointMode="absolute" ] ``` radiotherm.items: diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java index 020ee7cef9427..d509e25658244 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatConfiguration.java @@ -28,5 +28,5 @@ public class RadioThermostatConfiguration { public @Nullable Integer logRefresh; public boolean isCT80 = false; public boolean disableLogs = false; - public boolean absolute = false; + public String setpointMode = "temporary"; } diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java index b5a63acbac247..824e9fffec620 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java @@ -12,21 +12,12 @@ */ package org.openhab.binding.radiothermostat.internal; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.smarthome.core.thing.Channel; -import org.eclipse.smarthome.core.thing.ChannelUID; +import org.eclipse.smarthome.core.thing.binding.BaseDynamicStateDescriptionProvider; +import org.eclipse.smarthome.core.thing.i18n.ChannelTypeI18nLocalizationService; import org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider; -import org.eclipse.smarthome.core.types.StateDescription; -import org.eclipse.smarthome.core.types.StateDescriptionFragmentBuilder; -import org.eclipse.smarthome.core.types.StateOption; import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; /** * The {@link RadioThermostatStateDescriptionProvider} class is a dynamic provider of state options while leaving other @@ -37,28 +28,15 @@ */ @Component(service = { DynamicStateDescriptionProvider.class, RadioThermostatStateDescriptionProvider.class }) @NonNullByDefault -public class RadioThermostatStateDescriptionProvider implements DynamicStateDescriptionProvider { - private final Map> channelOptionsMap = new ConcurrentHashMap<>(); - - public void setStateOptions(ChannelUID channelUID, List options) { - channelOptionsMap.put(channelUID, options); - } - - @Override - public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original, - @Nullable Locale locale) { - List options = channelOptionsMap.get(channel.getUID()); - if (options == null) { - return null; - } - - StateDescriptionFragmentBuilder builder = (original == null) ? StateDescriptionFragmentBuilder.create() - : StateDescriptionFragmentBuilder.create(original); - return builder.withOptions(options).build().toStateDescription(); +public class RadioThermostatStateDescriptionProvider extends BaseDynamicStateDescriptionProvider { + @Reference + protected void setChannelTypeI18nLocalizationService( + final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService){ + this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService; } - @Deactivate - public void deactivate() { - channelOptionsMap.clear(); + protected void unsetChannelTypeI18nLocalizationService( + final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService){ + this.channelTypeI18nLocalizationService = null; } } diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java index 4bc6b024374cb..f044982fd4087 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java @@ -76,8 +76,7 @@ public class RadioThermostatHandler extends BaseThingHandler implements RadioThe private static final int DEFAULT_REFRESH_PERIOD = 2; private static final int DEFAULT_LOG_REFRESH_PERIOD = 10; - private @Nullable final RadioThermostatStateDescriptionProvider stateDescriptionProvider; - + private final RadioThermostatStateDescriptionProvider stateDescriptionProvider; private final Logger logger = LoggerFactory.getLogger(RadioThermostatHandler.class); private final Gson gson; @@ -87,37 +86,66 @@ public class RadioThermostatHandler extends BaseThingHandler implements RadioThe private @Nullable ScheduledFuture refreshJob; private @Nullable ScheduledFuture logRefreshJob; - private @Nullable RadioThermostatConfiguration config; + private int refreshPeriod = DEFAULT_REFRESH_PERIOD; + private int logRefreshPeriod = DEFAULT_LOG_REFRESH_PERIOD; + private boolean isCT80 = false; + private boolean disableLogs = false; + private String setpointCmdKeyPrefix = "t_"; - public RadioThermostatHandler(Thing thing, - @Nullable RadioThermostatStateDescriptionProvider stateDescriptionProvider, HttpClient httpClient) { + public RadioThermostatHandler(Thing thing, RadioThermostatStateDescriptionProvider stateDescriptionProvider, + HttpClient httpClient) { super(thing); this.stateDescriptionProvider = stateDescriptionProvider; gson = new Gson(); connector = new RadioThermostatConnector(httpClient); } - @SuppressWarnings("null") @Override public void initialize() { logger.debug("Initializing RadioThermostat handler."); - this.config = getConfigAs(RadioThermostatConfiguration.class); - connector.setThermostatHostName(config.hostName); + RadioThermostatConfiguration config = getConfigAs(RadioThermostatConfiguration.class); + + final String hostName = config.hostName; + final Integer refresh = config.refresh; + final Integer logRefresh = config.logRefresh; + this.isCT80 = config.isCT80; + this.disableLogs = config.disableLogs; + + if (hostName == null || hostName == "") { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "Thermostat Host Name must be specified"); + return; + } + + if (refresh != null) { + this.refreshPeriod = refresh; + } + + if (logRefresh != null) { + this.logRefreshPeriod = logRefresh; + } + + connector.setThermostatHostName(hostName); connector.addEventListener(this); + // The setpoint mode is controlled by the name of setpoint attribute sent to the thermostat. + // Temporary mode uses setpoint names prefixed with "t_" while absolute mode uses "a_" + if (config.setpointMode.equals("absolute")) { + this.setpointCmdKeyPrefix = "a_"; + } + // populate fan mode options based on thermostat model - List fanModeOptions = getFanModeOptions(config.isCT80); - stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), FAN_MODE), fanModeOptions); + stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), FAN_MODE), getFanModeOptions()); // if we are not a CT-80, remove the humidity & program mode channel - if (!config.isCT80) { + if (!this.isCT80) { List channels = new ArrayList<>(this.getThing().getChannels()); channels.removeIf(c -> (c.getUID().getId().equals(HUMIDITY))); channels.removeIf(c -> (c.getUID().getId().equals(PROGRAM_MODE))); updateThing(editThing().withChannels(channels).build()); } startAutomaticRefresh(); - if (!config.disableLogs || config.isCT80) { + if (!this.disableLogs || this.isCT80) { startAutomaticLogRefresh(); } @@ -132,56 +160,58 @@ public Collection> getServices() { /** * Start the job to periodically update data from the thermostat */ - @SuppressWarnings("null") private void startAutomaticRefresh() { + ScheduledFuture refreshJob = this.refreshJob; if (refreshJob == null || refreshJob.isCancelled()) { Runnable runnable = () -> { // send an async call to the thermostat to get the 'tstat' data connector.getAsyncThermostatData(DEFAULT_RESOURCE); }; - int delay = (config.refresh != null) ? config.refresh.intValue() : DEFAULT_REFRESH_PERIOD; - refreshJob = scheduler.scheduleWithFixedDelay(runnable, 0, delay, TimeUnit.MINUTES); + refreshJob = null; + this.refreshJob = scheduler.scheduleWithFixedDelay(runnable, 0, refreshPeriod, TimeUnit.MINUTES); } } /** * Start the job to periodically update humidity and runtime date from the thermostat */ - @SuppressWarnings("null") private void startAutomaticLogRefresh() { + ScheduledFuture logRefreshJob = this.logRefreshJob; if (logRefreshJob == null || logRefreshJob.isCancelled()) { Runnable runnable = () -> { // Request humidity data from the thermostat if we are a CT80 - if (config.isCT80) { + if (this.isCT80) { // send an async call to the thermostat to get the humidity data connector.getAsyncThermostatData(HUMIDITY_RESOURCE); } - if (!config.disableLogs) { + if (!this.disableLogs) { // send an async call to the thermostat to get the runtime data connector.getAsyncThermostatData(RUNTIME_RESOURCE); } }; - int delay = ((config.logRefresh != null) ? config.logRefresh.intValue() : DEFAULT_LOG_REFRESH_PERIOD) * 60; - logRefreshJob = scheduler.scheduleWithFixedDelay(runnable, 30, delay, TimeUnit.SECONDS); + logRefreshJob = null; + this.logRefreshJob = scheduler.scheduleWithFixedDelay(runnable, 1, logRefreshPeriod, TimeUnit.MINUTES); } } - @SuppressWarnings("null") @Override public void dispose() { logger.debug("Disposing the RadioThermostat handler."); connector.removeEventListener(this); + ScheduledFuture refreshJob = this.refreshJob; if (refreshJob != null) { refreshJob.cancel(true); - refreshJob = null; + this.refreshJob = null; } + + ScheduledFuture logRefreshJob = this.logRefreshJob; if (logRefreshJob != null) { logRefreshJob.cancel(true); - logRefreshJob = null; + this.logRefreshJob = null; } } @@ -189,7 +219,6 @@ public void handleRawCommand(@Nullable String rawCommand) { connector.sendCommand(null, null, rawCommand); } - @SuppressWarnings("null") @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { @@ -249,18 +278,10 @@ public void handleCommand(ChannelUID channelUID, Command command) { case SET_POINT: String cmdKey = null; if (rthermData.getThermostatData().getMode() == 1) { - if (config.absolute) { - cmdKey = "a_heat"; - } else { - cmdKey = "t_heat"; - } + cmdKey = this.setpointCmdKeyPrefix + "heat"; rthermData.getThermostatData().setHeatTarget(cmdInt); } else if (rthermData.getThermostatData().getMode() == 2) { - if (config.absolute) { - cmdKey = "a_cool"; - } else { - cmdKey = "t_cool"; - } + cmdKey = this.setpointCmdKeyPrefix + "cool"; rthermData.getThermostatData().setCoolTarget(cmdInt); } else { // don't do anything if we are not in heat or cool mode @@ -438,11 +459,11 @@ private void updateAllChannels() { * * @return list of state options for thermostat fan modes */ - private List getFanModeOptions(boolean isCT80) { + private List getFanModeOptions() { List fanModeOptions = new ArrayList<>(); fanModeOptions.add(new StateOption("0", "Auto")); - if (isCT80) { + if (this.isCT80) { fanModeOptions.add(new StateOption("1", "Auto/Circulate")); } fanModeOptions.add(new StateOption("2", "On")); diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml index b9754f59bb88c..557d36c560bbe 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.radiothermostat/src/main/resources/ESH-INF/thing/thing-types.xml @@ -58,10 +58,14 @@ Optional Flag to Disable the Retrieval of Run-time Data from the Thermostat false - - - Optional Flag to run in absolute or temporary setpoint mode - false + + + Run in absolute or temporary setpoint mode + temporary + + + + From d15ea1b5db280a26719c0d5a237c9ab7cf6ebf7e Mon Sep 17 00:00:00 2001 From: silverfunk Date: Tue, 8 Sep 2020 21:16:34 -0500 Subject: [PATCH 6/8] Fixed a few code style errors. Signed-off-by: silverfunk --- .../internal/RadioThermostatStateDescriptionProvider.java | 4 ++-- .../internal/handler/RadioThermostatHandler.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java index 824e9fffec620..a135ae9d7b813 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/RadioThermostatStateDescriptionProvider.java @@ -31,12 +31,12 @@ public class RadioThermostatStateDescriptionProvider extends BaseDynamicStateDescriptionProvider { @Reference protected void setChannelTypeI18nLocalizationService( - final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService){ + final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) { this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService; } protected void unsetChannelTypeI18nLocalizationService( - final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService){ + final ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) { this.channelTypeI18nLocalizationService = null; } } diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java index f044982fd4087..c347908dd3a45 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java @@ -113,7 +113,7 @@ public void initialize() { if (hostName == null || hostName == "") { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, - "Thermostat Host Name must be specified"); + "Thermostat Host Name must be specified"); return; } @@ -121,7 +121,7 @@ public void initialize() { this.refreshPeriod = refresh; } - if (logRefresh != null) { + if (logRefresh != null) { this.logRefreshPeriod = logRefresh; } From 802d7fbafdc069072a9af2f37d6daf75b70b7792 Mon Sep 17 00:00:00 2001 From: silverfunk Date: Tue, 8 Sep 2020 22:20:11 -0500 Subject: [PATCH 7/8] Changed a string comparison to use the equals() method. Signed-off-by: silverfunk --- .../internal/handler/RadioThermostatHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java index c347908dd3a45..31313b6e5defa 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java @@ -111,7 +111,7 @@ public void initialize() { this.isCT80 = config.isCT80; this.disableLogs = config.disableLogs; - if (hostName == null || hostName == "") { + if (hostName.equals("")) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Thermostat Host Name must be specified"); return; From 9f91747870e7d0b66bd5e82540632cf229e0733f Mon Sep 17 00:00:00 2001 From: silverfunk Date: Tue, 8 Sep 2020 22:32:16 -0500 Subject: [PATCH 8/8] Forgot to leave the check for null in place. Signed-off-by: silverfunk --- .../internal/handler/RadioThermostatHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java index 31313b6e5defa..635b20b84fe13 100644 --- a/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java +++ b/bundles/org.openhab.binding.radiothermostat/src/main/java/org/openhab/binding/radiothermostat/internal/handler/RadioThermostatHandler.java @@ -111,7 +111,7 @@ public void initialize() { this.isCT80 = config.isCT80; this.disableLogs = config.disableLogs; - if (hostName.equals("")) { + if (hostName == null || hostName.equals("")) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Thermostat Host Name must be specified"); return;