From c66de7c65fb540b6a5e1a22988d702bb8aa2a0bd Mon Sep 17 00:00:00 2001 From: Valdis Rigdon Date: Fri, 6 Dec 2024 16:37:32 -0500 Subject: [PATCH] fixup! fixup! [intellicenter2] feat: adds IntelliCenter2 binding for Pentair --- .../handler/IntelliCenter2BridgeHandler.java | 12 +++++++++++ .../handler/IntelliCenter2PoolHandler.java | 20 +++++++++++++----- .../internal/model/SystemInfo.java | 4 ++++ .../OH-INF/i18n/intellicenter2_xx.properties | 21 ------------------- .../resources/OH-INF/thing/thing-types.xml | 6 +++--- 5 files changed, 34 insertions(+), 29 deletions(-) delete mode 100644 bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/i18n/intellicenter2_xx.properties diff --git a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2BridgeHandler.java b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2BridgeHandler.java index df27662525c..6ff97b08757 100644 --- a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2BridgeHandler.java +++ b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2BridgeHandler.java @@ -17,12 +17,17 @@ import java.net.UnknownHostException; import java.util.Collection; import java.util.Collections; +import javax.measure.Unit; +import javax.measure.quantity.Temperature; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.intellicenter2.internal.IntelliCenter2Configuration; import org.openhab.binding.intellicenter2.internal.discovery.IntelliCenter2DiscoveryService; import org.openhab.binding.intellicenter2.internal.model.SystemInfo; import org.openhab.binding.intellicenter2.internal.protocol.ICProtocol; +import org.openhab.core.library.unit.ImperialUnits; +import org.openhab.core.library.unit.SIUnits; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; @@ -113,6 +118,13 @@ public class IntelliCenter2BridgeHandler extends BaseBridgeHandler { return Futures.getUnchecked(protocolFuture); } + public Unit getTemperatureUnits() { + if (systemInfo != null) { + return systemInfo.isMetricSystem() ? SIUnits.CELSIUS : ImperialUnits.FAHRENHEIT; + } + throw new IllegalStateException("systemInfo was not set yet."); + } + @Override public void dispose() { scheduler.execute(() -> { diff --git a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2PoolHandler.java b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2PoolHandler.java index 8e84a3ec799..cc9cb187d66 100644 --- a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2PoolHandler.java +++ b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/handler/IntelliCenter2PoolHandler.java @@ -27,8 +27,8 @@ import org.openhab.binding.intellicenter2.internal.protocol.ICProtocol; import org.openhab.binding.intellicenter2.internal.protocol.ICRequest; import org.openhab.binding.intellicenter2.internal.protocol.ICResponse; import org.openhab.binding.intellicenter2.internal.protocol.ResponseObject; -import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.QuantityType; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.Thing; import org.slf4j.Logger; @@ -52,9 +52,15 @@ public class IntelliCenter2PoolHandler extends IntelliCenter2ThingHandler @Override protected void updateState(Body pool) { + final IntelliCenter2BridgeHandler bh = getBridgeHandler(); + if (bh == null) { + return; + } updateState(CHANNEL_HEATER_STATUS, OnOffType.from(pool.isHeating())); - updateState(CHANNEL_CURRENT_TEMPERATURE, new DecimalType(pool.getCurrentTemperature())); - updateState(CHANNEL_TARGET_TEMPERATURE, new DecimalType(pool.getTargetTemperature())); + updateState(CHANNEL_CURRENT_TEMPERATURE, + new QuantityType<>(pool.getCurrentTemperature(), bh.getTemperatureUnits())); + updateState(CHANNEL_TARGET_TEMPERATURE, + new QuantityType<>(pool.getTargetTemperature(), bh.getTemperatureUnits())); } @Override @@ -72,12 +78,16 @@ public class IntelliCenter2PoolHandler extends IntelliCenter2ThingHandler @Override protected void updateState(ChannelUID channelUID, Body pool) { + final IntelliCenter2BridgeHandler bh = getBridgeHandler(); + if (bh == null) { + return; + } switch (channelUID.getId()) { case CHANNEL_CURRENT_TEMPERATURE: - updateState(channelUID, new DecimalType(pool.getCurrentTemperature())); + updateState(channelUID, new QuantityType<>(pool.getCurrentTemperature(), bh.getTemperatureUnits())); break; case CHANNEL_TARGET_TEMPERATURE: - updateState(channelUID, new DecimalType(pool.getTargetTemperature())); + updateState(channelUID, new QuantityType<>(pool.getTargetTemperature(), bh.getTemperatureUnits())); break; case CHANNEL_HEATER_STATUS: updateState(channelUID, OnOffType.from(pool.isHeating())); diff --git a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/model/SystemInfo.java b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/model/SystemInfo.java index 7386fd95c66..9e5b1188e9b 100644 --- a/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/model/SystemInfo.java +++ b/bundles/org.openhab.binding.intellicenter2/src/main/java/org/openhab/binding/intellicenter2/internal/model/SystemInfo.java @@ -51,6 +51,10 @@ public class SystemInfo extends ResponseModel { return getValueAsString(MODE); } + public boolean isMetricSystem() { + return "METRIC".equals(getMode()); + } + public String getVersion() { return getValueAsString(VER); } diff --git a/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/i18n/intellicenter2_xx.properties b/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/i18n/intellicenter2_xx.properties deleted file mode 100644 index 23e66e6b519..00000000000 --- a/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/i18n/intellicenter2_xx.properties +++ /dev/null @@ -1,21 +0,0 @@ -# FIXME: please substitute the xx with a proper locale, ie. de -# FIXME: please do not add the file to the repo if you add or change no content -# binding -binding.intellicenter2.name = -binding.intellicenter2.description = - -# thing types -thing-type.intellicenter2.sample.label = -thing-type.intellicenter2.sample.description = - -# thing type config description -thing-type.config.intellicenter2.sample.hostname.label = -thing-type.config.intellicenter2.sample.hostname.description = -thing-type.config.intellicenter2.sample.password.label = -thing-type.config.intellicenter2.sample.password.description = -thing-type.config.intellicenter2.sample.refreshInterval.label = -thing-type.config.intellicenter2.sample.refreshInterval.description = - -# channel types -channel-type.intellicenter2.sample-channel.label = -channel-type.intellicenter2.sample-channel.description = diff --git a/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/thing/thing-types.xml index 6be3ca55616..e7743626664 100644 --- a/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.intellicenter2/src/main/resources/OH-INF/thing/thing-types.xml @@ -127,21 +127,21 @@ Number:Temperature The temperature value. - + Number:Temperature The current temperature value. - + Number:Temperature The target temperature value. - +