diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java index b59d09f755bdd..05b60fc34c3be 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/AVMFritzBindingConstants.java @@ -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"; diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/dto/DeviceModel.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/dto/DeviceModel.java index ba5d88e097d87..9fbb401eb2788 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/dto/DeviceModel.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/dto/DeviceModel.java @@ -50,7 +50,7 @@ public HumidityModel getHumidity() { return humidity; } - public void setTemperature(HumidityModel humidityModel) { + public void setHumidity(HumidityModel humidityModel) { this.humidity = humidityModel; } diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java index 967d43ebb50e9..aed952d2442f5 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzBaseThingHandler.java @@ -156,7 +156,7 @@ private void updateHANFUNAlarmSensor(@Nullable AlertModel alertModel) { } } - 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 @@ private void createChannel(String channelId) { * @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(); diff --git a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java index 34b0e992a44ff..850bb35f00d72 100644 --- a/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java +++ b/bundles/org.openhab.binding.avmfritz/src/main/java/org/openhab/binding/avmfritz/internal/handler/AVMFritzButtonHandler.java @@ -14,6 +14,7 @@ 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 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 void onDeviceUpdated(ThingUID thingUID, AVMFritzBaseModel device) { } } + @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); } }