Added humidity channel, minor fixes (#9467)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2020-12-22 20:55:08 +01:00
committed by GitHub
parent 54ca612630
commit 2c6e15bb02
10 changed files with 144 additions and 22 deletions

View File

@@ -89,6 +89,7 @@ public class AVMFritzBindingConstants {
public static final String PROPERTY_MEMBERS = "members";
// List of all channel groups
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";
public static final String CHANNEL_GROUP_TOP_RIGHT = "top-right";
@@ -105,6 +106,7 @@ public class AVMFritzBindingConstants {
public static final String CHANNEL_DEVICE_LOCKED = "device_locked";
public static final String CHANNEL_APPLY_TEMPLATE = "apply_template";
public static final String CHANNEL_TEMPERATURE = "temperature";
public static final String CHANNEL_HUMIDITY = "humidity";
public static final String CHANNEL_ENERGY = "energy";
public static final String CHANNEL_POWER = "power";
public static final String CHANNEL_VOLTAGE = "voltage";

View File

@@ -47,11 +47,12 @@ public abstract class AVMFritzBaseModel implements BatteryModel {
protected static final int BUTTON_BIT = 1 << 5; // Bit 5
protected static final int HEATING_THERMOSTAT_BIT = 1 << 6; // Bit 6
protected static final int POWERMETER_BIT = 1 << 7; // Bit 7
protected static final int TEMPSENSOR_BIT = 1 << 8; // Bit 8
protected static final int TEMPERATURE_SENSOR_BIT = 1 << 8; // Bit 8
protected static final int OUTLET_BIT = 1 << 9; // Bit 9
protected static final int DECT_REPEATER_BIT = 1 << 10; // Bit 10
protected static final int MICROPHONE_BIT = 1 << 11; // Bit 11
protected static final int HAN_FUN_UNIT_BIT = 1 << 13; // Bit 13
protected static final int HUMIDITY_SENSOR_BIT = 1 << 20; // Bit 20 - undocumented
@XmlAttribute(name = "identifier")
private String ident;
@@ -149,7 +150,11 @@ public abstract class AVMFritzBaseModel implements BatteryModel {
}
public boolean isTempSensor() {
return (bitmask & TEMPSENSOR_BIT) > 0;
return (bitmask & TEMPERATURE_SENSOR_BIT) > 0;
}
public boolean isHumiditySensor() {
return (bitmask & HUMIDITY_SENSOR_BIT) > 0;
}
public boolean isPowermeter() {
@@ -208,13 +213,14 @@ public abstract class AVMFritzBaseModel implements BatteryModel {
.append(",isHANFUNDevice=").append(isHANFUNDevice()).append(",isHANFUNButton=").append(isHANFUNButton())
.append(",isHANFUNAlarmSensor=").append(isHANFUNAlarmSensor()).append(",isButton=").append(isButton())
.append(",isSwitchableOutlet=").append(isSwitchableOutlet()).append(",isTempSensor=")
.append(isTempSensor()).append(",isPowermeter=").append(isPowermeter()).append(",isDectRepeater=")
.append(isDectRepeater()).append(",isHeatingThermostat=").append(isHeatingThermostat())
.append(",isMicrophone=").append(isMicrophone()).append(",isHANFUNUnit=").append(isHANFUNUnit())
.append(",id=").append(deviceId).append(",manufacturer=").append(deviceManufacturer)
.append(",productname=").append(productName).append(",fwversion=").append(firmwareVersion)
.append(",present=").append(present).append(",name=").append(name).append(",battery=")
.append(getBattery()).append(",batterylow=").append(getBatterylow()).append(",").append(getSwitch())
.append(",").append(getPowermeter()).append(",").append(getHkr()).append(",").toString();
.append(isTempSensor()).append(",isHumiditySensor=").append(isHumiditySensor()).append(",isPowermeter=")
.append(isPowermeter()).append(",isDectRepeater=").append(isDectRepeater())
.append(",isHeatingThermostat=").append(isHeatingThermostat()).append(",isMicrophone=")
.append(isMicrophone()).append(",isHANFUNUnit=").append(isHANFUNUnit()).append(",id=").append(deviceId)
.append(",manufacturer=").append(deviceManufacturer).append(",productname=").append(productName)
.append(",fwversion=").append(firmwareVersion).append(",present=").append(present).append(",name=")
.append(name).append(",battery=").append(getBattery()).append(",batterylow=").append(getBatterylow())
.append(",").append(getSwitch()).append(",").append(getPowermeter()).append(",").append(getHkr())
.append(",").toString();
}
}

View File

@@ -12,7 +12,6 @@
*/
package org.openhab.binding.avmfritz.internal.dto;
import java.util.Collections;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
@@ -31,6 +30,7 @@ import javax.xml.bind.annotation.XmlType;
public class DeviceModel extends AVMFritzBaseModel {
private TemperatureModel temperature;
private HumidityModel humidity;
private AlertModel alert;
@XmlElement(name = "button", type = ButtonModel.class)
@@ -46,6 +46,14 @@ public class DeviceModel extends AVMFritzBaseModel {
this.temperature = temperatureModel;
}
public HumidityModel getHumidity() {
return humidity;
}
public void setTemperature(HumidityModel humidityModel) {
this.humidity = humidityModel;
}
public AlertModel getAlert() {
return alert;
}
@@ -55,10 +63,7 @@ public class DeviceModel extends AVMFritzBaseModel {
}
public List<ButtonModel> getButtons() {
if (buttons == null) {
return Collections.emptyList();
}
return buttons;
return buttons == null ? List.of() : buttons;
}
public void setButtons(List<ButtonModel> buttons) {
@@ -75,8 +80,8 @@ public class DeviceModel extends AVMFritzBaseModel {
@Override
public String toString() {
return new StringBuilder().append(super.toString()).append(temperature).append(",").append(alert).append(",")
.append(getButtons()).append(",").append(etsiunitinfo).append("]").toString();
return new StringBuilder().append(super.toString()).append(temperature).append(",").append(humidity).append(",")
.append(alert).append(",").append(getButtons()).append(",").append(etsiunitinfo).append("]").toString();
}
@XmlAccessorType(XmlAccessType.FIELD)

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2010-2020 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.avmfritz.internal.dto;
import java.math.BigDecimal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* See {@link DeviceListModel}.
*
* @author Christoph Weitkamp - Initial contribution
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "humidity")
public class HumidityModel {
@XmlElement(name = "rel_humidity")
private BigDecimal relativeHumidity;
public BigDecimal getRelativeHumidity() {
return relativeHumidity != null ? relativeHumidity : BigDecimal.ZERO;
}
public void setRelativeHumidity(BigDecimal relativeHumidity) {
this.relativeHumidity = relativeHumidity;
}
@Override
public String toString() {
return new StringBuilder().append("[rel_humidity=").append(getRelativeHumidity()).append("]").toString();
}
}

View File

@@ -32,6 +32,7 @@ import org.openhab.binding.avmfritz.internal.dto.BatteryModel;
import org.openhab.binding.avmfritz.internal.dto.DeviceModel;
import org.openhab.binding.avmfritz.internal.dto.HeatingModel;
import org.openhab.binding.avmfritz.internal.dto.HeatingModel.NextChangeModel;
import org.openhab.binding.avmfritz.internal.dto.HumidityModel;
import org.openhab.binding.avmfritz.internal.dto.PowerMeterModel;
import org.openhab.binding.avmfritz.internal.dto.SwitchModel;
import org.openhab.binding.avmfritz.internal.dto.TemperatureModel;
@@ -138,6 +139,9 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
if (deviceModel.isTempSensor()) {
updateTemperatureSensor(deviceModel.getTemperature());
}
if (deviceModel.isHumiditySensor()) {
updateHumiditySensor(deviceModel.getHumidity());
}
if (deviceModel.isHANFUNAlarmSensor()) {
updateHANFUNAlarmSensor(deviceModel.getAlert());
}
@@ -161,6 +165,13 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
}
protected void updateHumiditySensor(@Nullable HumidityModel humidityModel) {
if (humidityModel != null) {
updateThingChannelState(CHANNEL_HUMIDITY,
new QuantityType<>(humidityModel.getRelativeHumidity(), Units.PERCENT));
}
}
private void updateHeatingThermostat(@Nullable HeatingModel heatingModel) {
if (heatingModel != null) {
updateThingChannelState(CHANNEL_MODE, new StringType(heatingModel.getMode()));
@@ -255,6 +266,19 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
}
/**
* Creates a {@link ChannelTypeUID} from the given channel id.
*
* @param channelId ID of the channel type UID to be created.
* @return the channel type UID
*/
private ChannelTypeUID createChannelTypeUID(String channelId) {
int pos = channelId.indexOf(ChannelUID.CHANNEL_GROUP_SEPARATOR);
String id = pos > -1 ? channelId.substring(pos + 1) : channelId;
return CHANNEL_BATTERY.equals(id) ? DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_BATTERY_LEVEL.getUID()
: new ChannelTypeUID(BINDING_ID, id);
}
/**
* Creates new channels for the thing.
*
@@ -264,9 +288,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
ThingHandlerCallback callback = getCallback();
if (callback != null) {
ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);
ChannelTypeUID channelTypeUID = CHANNEL_BATTERY.equals(channelId)
? DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_BATTERY_LEVEL.getUID()
: new ChannelTypeUID(BINDING_ID, channelId);
ChannelTypeUID channelTypeUID = createChannelTypeUID(channelId);
Channel channel = callback.createChannelBuilder(channelUID, channelTypeUID).build();
updateThing(editThing().withoutChannel(channelUID).withChannel(channel).build());
}
@@ -317,6 +339,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
case CHANNEL_LOCKED:
case CHANNEL_DEVICE_LOCKED:
case CHANNEL_TEMPERATURE:
case CHANNEL_HUMIDITY:
case CHANNEL_ENERGY:
case CHANNEL_POWER:
case CHANNEL_VOLTAGE:

View File

@@ -25,7 +25,10 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.avmfritz.internal.dto.AVMFritzBaseModel;
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.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.unit.Units;
import org.openhab.core.thing.Channel;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.CommonTriggerEvents;
@@ -86,6 +89,14 @@ public class AVMFritzButtonHandler extends DeviceHandler {
}
}
@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));
}
}
private void updateShortLongPressButton(List<ButtonModel> buttons) {
ButtonModel shortPressButton = buttons.size() > 0 ? buttons.get(0) : null;
ButtonModel longPressButton = buttons.size() > 1 ? buttons.get(1) : null;

View File

@@ -159,6 +159,9 @@ channel-type.avmfritz.apply_template.description = Erm
channel-type.avmfritz.temperature.label = Temperatur
channel-type.avmfritz.temperature.description = Zeigt die aktuelle Temperatur an.
channel-type.avmfritz.humidity.label = Luftfeuchtigkeit
channel-type.avmfritz.humidity.description = Zeigt die aktuelle Luftfeuchtigkeit an.
channel-type.avmfritz.energy.label = Gesamtverbrauch
channel-type.avmfritz.energy.description = Zeigt den akkumulierten Gesamtverbrauch an.

View File

@@ -97,6 +97,7 @@
<label>Sensor Data</label>
<channels>
<channel id="temperature" typeId="temperature"/>
<channel id="humidity" typeId="humidity"/>
</channels>
</channel-group-type>
@@ -111,6 +112,14 @@
<config-description-ref uri="channel-type:avmfritz:temperature"/>
</channel-type>
<channel-type id="humidity">
<item-type>Number:Dimensionless</item-type>
<label>Current Humidity</label>
<description>Current measured humidity.</description>
<category>Humidity</category>
<state pattern="%.0f %unit%" readOnly="true"/>
</channel-type>
<channel-type id="energy">
<item-type>Number:Energy</item-type>
<label>Energy Consumption</label>