From bfff3d453fa32bca7200f5471f2500c1ca022fb7 Mon Sep 17 00:00:00 2001 From: Jan Gustafsson Date: Tue, 17 Mar 2020 17:57:38 +0100 Subject: [PATCH] [tellstick] Fix auto-detect handling for Rain and Wind devices (#7172) * Fixes #7171. Updated humidity and rain channels to use measurement units, changed state to use %unit%. Updated README with correct measurement units. Signed-off-by: Jan Gustafsson --- .../org.openhab.binding.tellstick/README.md | 40 +++++----- .../internal/TellstickBindingConstants.java | 25 ++++++ .../discovery/TellstickDiscoveryService.java | 17 ++-- .../handler/TelldusDevicesHandler.java | 64 +++++++++------ .../internal/live/xml/LiveDataType.java | 2 +- .../main/resources/ESH-INF/config/config.xml | 13 --- .../main/resources/ESH-INF/thing/devices.xml | 2 + .../main/resources/ESH-INF/thing/sensor.xml | 80 ++++++++++--------- 8 files changed, 142 insertions(+), 101 deletions(-) diff --git a/bundles/org.openhab.binding.tellstick/README.md b/bundles/org.openhab.binding.tellstick/README.md index 8f96752a1ea1..9e524d4e7f37 100644 --- a/bundles/org.openhab.binding.tellstick/README.md +++ b/bundles/org.openhab.binding.tellstick/README.md @@ -123,39 +123,39 @@ Actuators (dimmer/switch) support the following channels: Sensors (sensor) support the following channels: -| Channel Type ID | Item Type | Description | -|-----------------|-----------|-------------------------------------------------------------| -| humidity | Number | This channel reports the current humidity in percentage. | -| temperature | Number | This channel reports the current temperature in celsius. | -| timestamp | DateTime | This channel reports the last time this sensor was updates. | +| Channel Type ID | Item Type | Description | +|-----------------|---------------------|-------------------------------------------------------------| +| humidity | Number:Dimensionless| This channel reports the current humidity in percentage. | +| temperature | Number:Temperature | This channel reports the current temperature. | +| timestamp | DateTime | This channel reports the last time this sensor was updates. | PowerSensors ([powersensor]) support the following channels: -| Channel Type ID | Item Type | Description | -|-----------------|-----------|-------------------------------------------------------------| -| watt | Number | This channel reports the current watt. | -| ampere | Number | This channel reports the current ampere. | -| timestamp | DateTime | This channel reports the last time this sensor was updates. | +| Channel Type ID | Item Type | Description | +|-----------------|------------------------|-------------------------------------------------------------| +| watt | Number:Power | This channel reports the current watt. | +| ampere | Number:ElectricCurrent | This channel reports the current ampere. | +| timestamp | DateTime | This channel reports the last time this sensor was updates. | WindSensors ([windsensor]) support the following channels: -| Channel Type ID | Item Type | Description | -|-----------------|-----------|------------------------------| -| windgust | Number | This current peak wind gust. | -| winddirection | Number | The current wind direction. | -| windaverage | DateTime | The current wind avarage. | +| Channel Type ID | Item Type | Description | +|-----------------|--------------|------------------------------| +| windgust | Number:Speed | The current peak wind gust. | +| winddirection | Number:Angle | The current wind direction. | +| windaverage | Number:Speed | The current wind average. | RainSensors ([rainsensor]) support the following channels: -| Channel Type ID | Item Type | Description | -|-----------------|-----------|----------------------------| -| rainrate | Number | This current rate of rain. | -| raintotal | Number | The total rain. | +| Channel Type ID | Item Type | Description | +|-----------------|---------------|----------------------------| +| rainrate | Number:Length | This current rate of rain. | +| raintotal | Number:Length | The total rain. | ### Switchbased sensor workaround All switchbased sensors are binary and the goal is to represent them as a `contact` item in openHAB. Eg. a door is open or closed and can't be altered by sending a radio signal. -To achive that we will create a proxy item which is updated by a rule. +To achieve that we will create a proxy item which is updated by a rule. First create another proxy item for every sensor: diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickBindingConstants.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickBindingConstants.java index 7e71fc62a3e6..545a6949762d 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickBindingConstants.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/TellstickBindingConstants.java @@ -12,12 +12,27 @@ */ package org.openhab.binding.tellstick.internal; +import static org.eclipse.smarthome.core.library.unit.MetricPrefix.*; + import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.measure.Unit; +import javax.measure.quantity.Angle; +import javax.measure.quantity.Dimensionless; +import javax.measure.quantity.ElectricCurrent; +import javax.measure.quantity.Illuminance; +import javax.measure.quantity.Length; +import javax.measure.quantity.Power; +import javax.measure.quantity.Pressure; +import javax.measure.quantity.Speed; +import javax.measure.quantity.Temperature; + import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.smarthome.core.library.unit.SIUnits; +import org.eclipse.smarthome.core.library.unit.SmartHomeUnits; import org.eclipse.smarthome.core.thing.ThingTypeUID; /** @@ -31,6 +46,16 @@ public class TellstickBindingConstants { public static final String BINDING_ID = "tellstick"; + public static final Unit HUMIDITY_UNIT = SmartHomeUnits.PERCENT; + public static final Unit TEMPERATURE_UNIT = SIUnits.CELSIUS; + public static final Unit PRESSURE_UNIT = HECTO(SIUnits.PASCAL); + public static final Unit WIND_SPEED_UNIT_MS = SmartHomeUnits.METRE_PER_SECOND; + public static final Unit WIND_DIRECTION_UNIT = SmartHomeUnits.DEGREE_ANGLE; + public static final Unit RAIN_UNIT = MILLI(SIUnits.METRE); + public static final Unit LUX_UNIT = SmartHomeUnits.LUX; + public static final Unit ELECTRIC_UNIT = SmartHomeUnits.AMPERE; + public static final Unit POWER_UNIT = KILO(SmartHomeUnits.WATT); + public static final String CONFIGPATH_ID = "location"; public static final String DEVICE_ID = "deviceId"; public static final String DEVICE_PROTOCOL = "protocol"; diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java index c9a00d78f504..cb6689cea31b 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/discovery/TellstickDiscoveryService.java @@ -80,9 +80,10 @@ public Set getSupportedThingTypes() { @Override public void onDeviceAdded(Bridge bridge, Device device) { - logger.debug("Adding new TellstickDevice! {} with id '{}' to smarthome inbox", device.getDeviceType(), - device.getId()); + logger.debug("Adding new TellstickDevice! '{}' with id '{}' and type '{}' to smarthome inbox", device, + device.getId(), device.getDeviceType()); ThingUID thingUID = getThingUID(bridge, device); + logger.debug("Detected thingUID: {}", thingUID); if (thingUID != null) { DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withTTL(DEFAULT_TTL) .withProperty(TellstickBindingConstants.DEVICE_ID, device.getUUId()) @@ -149,21 +150,25 @@ private ThingUID getThingUID(Bridge bridge, Device device) { } private ThingTypeUID findSensorType(Device device) { + logger.debug("Device: {}", device); ThingTypeUID sensorThingId; if (device instanceof TellstickSensor) { TellstickSensor sensor = (TellstickSensor) device; - if (sensor.getData(DataType.WINDAVERAGE) != null) { + logger.debug("Sensor: {}", device); + if (sensor.getData(DataType.WINDAVERAGE) != null || sensor.getData(DataType.WINDGUST) != null + || sensor.getData(DataType.WINDDIRECTION) != null) { sensorThingId = TellstickBindingConstants.WINDSENSOR_THING_TYPE; - } else if (sensor.getData(DataType.RAINTOTAL) != null) { + } else if (sensor.getData(DataType.RAINTOTAL) != null || sensor.getData(DataType.RAINRATE) != null) { sensorThingId = TellstickBindingConstants.RAINSENSOR_THING_TYPE; } else { sensorThingId = TellstickBindingConstants.SENSOR_THING_TYPE; } } else { TellstickNetSensor sensor = (TellstickNetSensor) device; - if (sensor.isSensorOfType(LiveDataType.WINDAVERAGE)) { + if (sensor.isSensorOfType(LiveDataType.WINDAVERAGE) || sensor.isSensorOfType(LiveDataType.WINDDIRECTION) + || sensor.isSensorOfType(LiveDataType.WINDGUST)) { sensorThingId = TellstickBindingConstants.WINDSENSOR_THING_TYPE; - } else if (sensor.isSensorOfType(LiveDataType.RAINRATE)) { + } else if (sensor.isSensorOfType(LiveDataType.RAINRATE) || sensor.isSensorOfType(LiveDataType.RAINTOTAL)) { sensorThingId = TellstickBindingConstants.RAINSENSOR_THING_TYPE; } else if (sensor.isSensorOfType(LiveDataType.WATT)) { sensorThingId = TellstickBindingConstants.POWERSENSOR_THING_TYPE; diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java index 590589977cab..51455fda7f38 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java @@ -17,11 +17,21 @@ import java.math.BigDecimal; import java.util.Calendar; +import javax.measure.quantity.Angle; +import javax.measure.quantity.Dimensionless; +import javax.measure.quantity.ElectricCurrent; +import javax.measure.quantity.Illuminance; +import javax.measure.quantity.Length; +import javax.measure.quantity.Power; +import javax.measure.quantity.Speed; +import javax.measure.quantity.Temperature; + import org.eclipse.smarthome.config.core.Configuration; import org.eclipse.smarthome.core.library.types.DateTimeType; import org.eclipse.smarthome.core.library.types.DecimalType; import org.eclipse.smarthome.core.library.types.PercentType; -import org.eclipse.smarthome.core.library.types.StringType; +import org.eclipse.smarthome.core.library.types.QuantityType; +import org.eclipse.smarthome.core.library.unit.SIUnits; import org.eclipse.smarthome.core.thing.Bridge; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; @@ -205,11 +215,13 @@ public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) { private Device getDevice(TelldusBridgeHandler tellHandler, String deviceId) { Device dev = null; - if (deviceId != null && isSensor()) { - dev = tellHandler.getSensor(deviceId); - } else if (deviceId != null) { - dev = tellHandler.getDevice(deviceId); - updateDeviceState(dev); + if (deviceId != null) { + if (isSensor()) { + dev = tellHandler.getSensor(deviceId); + } else { + dev = tellHandler.getDevice(deviceId); + updateDeviceState(dev); + } } return dev; } @@ -271,25 +283,25 @@ public void onDeviceStateChanged(Bridge bridge, Device device, TellstickEvent ev private void updateSensorDataState(DataType dataType, String data) { switch (dataType) { case HUMIDITY: - updateState(humidityChannel, new DecimalType(data)); + updateState(humidityChannel, new QuantityType(new BigDecimal(data), HUMIDITY_UNIT)); break; case TEMPERATURE: - updateState(tempChannel, new DecimalType(data)); + updateState(tempChannel, new QuantityType(new BigDecimal(data), SIUnits.CELSIUS)); break; case RAINRATE: - updateState(rainRateChannel, new DecimalType(data)); + updateState(rainRateChannel, new QuantityType(new BigDecimal(data), RAIN_UNIT)); break; case RAINTOTAL: - updateState(raintTotChannel, new DecimalType(data)); + updateState(raintTotChannel, new QuantityType(new BigDecimal(data), RAIN_UNIT)); break; case WINDAVERAGE: - updateState(windAverageChannel, new DecimalType(data)); + updateState(windAverageChannel, new QuantityType(new BigDecimal(data), WIND_SPEED_UNIT_MS)); break; case WINDDIRECTION: - updateState(windDirectionChannel, new StringType(data)); + updateState(windDirectionChannel, new QuantityType(new BigDecimal(data), WIND_DIRECTION_UNIT)); break; case WINDGUST: - updateState(windGuestChannel, new DecimalType(data)); + updateState(windGuestChannel, new QuantityType(new BigDecimal(data), WIND_SPEED_UNIT_MS)); break; default: } @@ -298,35 +310,41 @@ private void updateSensorDataState(DataType dataType, String data) { private void updateSensorDataState(DataTypeValue dataType) { switch (dataType.getName()) { case HUMIDITY: - updateState(humidityChannel, new DecimalType(dataType.getValue())); + updateState(humidityChannel, + new QuantityType(new BigDecimal(dataType.getValue()), HUMIDITY_UNIT)); break; case TEMPERATURE: - updateState(tempChannel, new DecimalType(dataType.getValue())); + updateState(tempChannel, + new QuantityType(new BigDecimal(dataType.getValue()), SIUnits.CELSIUS)); break; case RAINRATE: - updateState(rainRateChannel, new DecimalType(dataType.getValue())); + updateState(rainRateChannel, new QuantityType(new BigDecimal(dataType.getValue()), RAIN_UNIT)); break; case RAINTOTAL: - updateState(raintTotChannel, new DecimalType(dataType.getValue())); + updateState(raintTotChannel, new QuantityType(new BigDecimal(dataType.getValue()), RAIN_UNIT)); break; case WINDAVERAGE: - updateState(windAverageChannel, new DecimalType(dataType.getValue())); + updateState(windAverageChannel, + new QuantityType(new BigDecimal(dataType.getValue()), WIND_SPEED_UNIT_MS)); break; case WINDDIRECTION: - updateState(windDirectionChannel, new StringType(dataType.getValue())); + updateState(windDirectionChannel, + new QuantityType(new BigDecimal(dataType.getValue()), WIND_DIRECTION_UNIT)); break; case WINDGUST: - updateState(windGuestChannel, new DecimalType(dataType.getValue())); + updateState(windGuestChannel, + new QuantityType(new BigDecimal(dataType.getValue()), WIND_SPEED_UNIT_MS)); break; case WATT: if (dataType.getUnit() != null && dataType.getUnit().equals("A")) { - updateState(ampereChannel, new DecimalType(dataType.getValue())); + updateState(ampereChannel, + new QuantityType(new BigDecimal(dataType.getValue()), ELECTRIC_UNIT)); } else { - updateState(wattChannel, new DecimalType(dataType.getValue())); + updateState(wattChannel, new QuantityType(new BigDecimal(dataType.getValue()), POWER_UNIT)); } break; case LUMINATION: - updateState(luxChannel, new DecimalType(dataType.getValue())); + updateState(luxChannel, new QuantityType(new DecimalType(dataType.getValue()), LUX_UNIT)); break; default: } diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/xml/LiveDataType.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/xml/LiveDataType.java index 10e7fa615635..3cd75cef8104 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/xml/LiveDataType.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/live/xml/LiveDataType.java @@ -22,7 +22,7 @@ public enum LiveDataType { TEMPERATURE("temp"), WINDAVERAGE("windaverage"), WINDDIRECTION("winddirection"), - WINDGUST("temp"), + WINDGUST("windgust"), RAINRATE("rainrate"), RAINTOTAL("rainttotal"), WATT("watt"), diff --git a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/config/config.xml b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/config/config.xml index 22b1cdd5db59..585983fb89eb 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/config/config.xml +++ b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/config/config.xml @@ -4,19 +4,6 @@ xsi:schemaLocation="https://openhab.org/schemas/config-description/v1.0.0 https://openhab.org/schemas/config-description-1.0.0.xsd"> - - - - Refresh interval for positional data calculation in seconds. - 300 - - - - The model used by a specific device. - false - - - diff --git a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/devices.xml b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/devices.xml index ec7e4eb21f5b..c76f9b42704c 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/devices.xml +++ b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/devices.xml @@ -49,6 +49,7 @@ + @@ -93,6 +94,7 @@ + Dimmer diff --git a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/sensor.xml b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/sensor.xml index 142e9c05a6f3..f1c6df811258 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/sensor.xml +++ b/bundles/org.openhab.binding.tellstick/src/main/resources/ESH-INF/thing/sensor.xml @@ -20,6 +20,7 @@ + @@ -35,6 +36,7 @@ + @@ -49,14 +51,15 @@ + - - This Thing defines a Rain Sensor + + This Thing defines a Wind Sensor @@ -65,81 +68,82 @@ + - Number - + Number:Temperature + Actual measured room temperature Temperature - + - + - Number - + Number:Dimensionless + Actual measured room Humidity Humidity - + - Number + Number:Length The current rain rate - + - Number + Number:Length Total rain - + - Number + Number:Speed Current wind gust - - + + + + + Number:Speed + + Current average wind + + + + + Number:Angle + + Current wind direction + Wind + - Number + Number:Power Current kWatt - + + - Number + Number:Illuminance Current lumination - - + + - Number + Number:ElectricCurrent Current ampere - - - - - Number - - Current wind average - - - - - - String - - Current wind directoin - +