Skip to content

Commit

Permalink
[avmfritz] Fixed channel update for DECT440 rocker (#9753)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp authored Jan 13, 2021
1 parent 7e28fbb commit 43b5e79
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public HumidityModel getHumidity() {
return humidity;
}

public void setTemperature(HumidityModel humidityModel) {
public void setHumidity(HumidityModel humidityModel) {
this.humidity = humidityModel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 43b5e79

Please sign in to comment.