]> git.basschouten.com Git - openhab-addons.git/commitdiff
[avmfritz] Fixed channel update for DECT440 rocker (#9753)
authorChristoph Weitkamp <github@christophweitkamp.de>
Wed, 13 Jan 2021 22:58:03 +0000 (23:58 +0100)
committerGitHub <noreply@github.com>
Wed, 13 Jan 2021 22:58:03 +0000 (14:58 -0800)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java
bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/dto/DeviceModel.java
bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java
bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java

index b59d09f755bdd675a65d8a2262ccdeb71e1456da..05b60fc34c3bed2a9c8e557abb35bd3101470f02 100644 (file)
@@ -90,6 +90,7 @@ public class AVMFritzBindingConstants {
     public static final String PRODUCT_NAME = "productName";
 
     // List of all channel groups
+    public static final String CHANNEL_GROUP_DEVICE = "device";
     public static final String CHANNEL_GROUP_SENSORS = "sensors";
     public static final String CHANNEL_GROUP_TOP_LEFT = "top-left";
     public static final String CHANNEL_GROUP_BOTTOM_LEFT = "bottom-left";
index ba5d88e097d873fdac5008e88d9b4ec4e239cc22..9fbb401eb2788452b456c4f5e331ccdd35342118 100644 (file)
@@ -50,7 +50,7 @@ public class DeviceModel extends AVMFritzBaseModel {
         return humidity;
     }
 
-    public void setTemperature(HumidityModel humidityModel) {
+    public void setHumidity(HumidityModel humidityModel) {
         this.humidity = humidityModel;
     }
 
index 967d43ebb50e9b2e5b7a2914d8c9ca0d6995a5cc..aed952d2442f5213fef7c74a1c9f57094863bd88 100644 (file)
@@ -156,7 +156,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
         }
     }
 
-    private void updateTemperatureSensor(@Nullable TemperatureModel temperatureModel) {
+    protected void updateTemperatureSensor(@Nullable TemperatureModel temperatureModel) {
         if (temperatureModel != null) {
             updateThingChannelState(CHANNEL_TEMPERATURE,
                     new QuantityType<>(temperatureModel.getCelsius(), SIUnits.CELSIUS));
@@ -301,7 +301,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
      * @param configId ID of the configuration to be updated.
      * @param value Value to be set.
      */
-    private void updateThingChannelConfiguration(String channelId, String configId, Object value) {
+    protected void updateThingChannelConfiguration(String channelId, String configId, Object value) {
         Channel channel = thing.getChannel(channelId);
         if (channel != null) {
             Configuration editConfig = channel.getConfiguration();
index 34b0e992a44ff0c87d5d5f2428d0904aa9817b82..850bb35f00d723b7e42200974001693867c360a9 100644 (file)
@@ -14,6 +14,7 @@ package org.openhab.binding.avmfritz.internal.handler;
 
 import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
 
+import java.math.BigDecimal;
 import java.time.Instant;
 import java.time.ZoneId;
 import java.time.ZonedDateTime;
@@ -23,11 +24,16 @@ import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.avmfritz.internal.dto.AVMFritzBaseModel;
+import org.openhab.binding.avmfritz.internal.dto.BatteryModel;
 import org.openhab.binding.avmfritz.internal.dto.ButtonModel;
 import org.openhab.binding.avmfritz.internal.dto.DeviceModel;
 import org.openhab.binding.avmfritz.internal.dto.HumidityModel;
+import org.openhab.binding.avmfritz.internal.dto.TemperatureModel;
 import org.openhab.core.library.types.DateTimeType;
+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.library.unit.SIUnits;
 import org.openhab.core.library.unit.Units;
 import org.openhab.core.thing.Channel;
 import org.openhab.core.thing.ChannelUID;
@@ -89,11 +95,44 @@ public class AVMFritzButtonHandler extends DeviceHandler {
         }
     }
 
+    @Override
+    protected void updateTemperatureSensor(@Nullable TemperatureModel temperatureModel) {
+        if (temperatureModel != null) {
+            String channelId = (DECT440_THING_TYPE.equals(thing.getThingTypeUID())
+                    ? CHANNEL_GROUP_SENSORS + ChannelUID.CHANNEL_GROUP_SEPARATOR
+                    : "") + CHANNEL_TEMPERATURE;
+            updateThingChannelState(channelId, new QuantityType<>(temperatureModel.getCelsius(), SIUnits.CELSIUS));
+            updateThingChannelConfiguration(channelId, CONFIG_CHANNEL_TEMP_OFFSET, temperatureModel.getOffset());
+        }
+    }
+
     @Override
     protected void updateHumiditySensor(@Nullable HumidityModel humidityModel) {
         if (humidityModel != null) {
-            updateThingChannelState(CHANNEL_GROUP_SENSORS + ChannelUID.CHANNEL_GROUP_SEPARATOR + CHANNEL_HUMIDITY,
-                    new QuantityType<>(humidityModel.getRelativeHumidity(), Units.PERCENT));
+            String channelId = (DECT440_THING_TYPE.equals(thing.getThingTypeUID())
+                    ? CHANNEL_GROUP_SENSORS + ChannelUID.CHANNEL_GROUP_SEPARATOR
+                    : "") + CHANNEL_HUMIDITY;
+            updateThingChannelState(channelId, new QuantityType<>(humidityModel.getRelativeHumidity(), Units.PERCENT));
+        }
+    }
+
+    @Override
+    protected void updateBattery(BatteryModel batteryModel) {
+        String batteryLevelChannelId = (DECT440_THING_TYPE.equals(thing.getThingTypeUID())
+                ? CHANNEL_GROUP_DEVICE + ChannelUID.CHANNEL_GROUP_SEPARATOR
+                : "") + CHANNEL_BATTERY;
+        BigDecimal batteryLevel = batteryModel.getBattery();
+        updateThingChannelState(batteryLevelChannelId,
+                batteryLevel == null ? UnDefType.UNDEF : new DecimalType(batteryLevel));
+        String lowBatteryChannelId = (DECT440_THING_TYPE.equals(thing.getThingTypeUID())
+                ? CHANNEL_GROUP_DEVICE + ChannelUID.CHANNEL_GROUP_SEPARATOR
+                : "") + CHANNEL_BATTERY_LOW;
+        BigDecimal lowBattery = batteryModel.getBatterylow();
+        if (lowBattery == null) {
+            updateThingChannelState(lowBatteryChannelId, UnDefType.UNDEF);
+        } else {
+            updateThingChannelState(lowBatteryChannelId,
+                    BatteryModel.BATTERY_ON.equals(lowBattery) ? OnOffType.ON : OnOffType.OFF);
         }
     }