]> git.basschouten.com Git - openhab-addons.git/commitdiff
[fineoffsetweatherstation] Add channel for the sensors battery voltage (#13284)
authorAndreas Berger <Andy2003@users.noreply.github.com>
Thu, 18 Aug 2022 10:14:21 +0000 (12:14 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Aug 2022 10:14:21 +0000 (12:14 +0200)
* [fineoffsetweatherstation] add channel for the sensors battery voltage

Signed-off-by: Andreas Berger <andreas@berger-freelancer.com>
bundles/org.openhab.binding.fineoffsetweatherstation/README.md
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/handler/FineOffsetSensorHandler.java
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml
bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/sensor.xml

index d55b9474cff11ec9ac5ab89c4ec55ffa6547d9b9..1c47635ff467fbbdb4011ed3afedb907841d231f 100644 (file)
@@ -257,11 +257,12 @@ Valid sensors:
 
 ### `sensor` Channels
 
-| Channel      | Type   | Read/Write | Description                 |
-|--------------|--------|------------|-----------------------------|
-| signal       | Number | R          | The sensors signal strenght |
-| batteryLevel | Number | R          | The sensors battery level   |
-| lowBattery   | Switch | R          | The sensors battery status  |
+| Channel        | Type                     | Read/Write | Description                 |
+|----------------|--------------------------|------------|-----------------------------|
+| signal         | Number                   | R          | The sensors signal strength |
+| batteryLevel   | Number                   | R          | The sensors battery level   |
+| batteryVoltage | Number:ElectricPotential | R          | The sensors battery voltage |
+| lowBattery     | Switch                   | R          | The sensors battery status  |
 
 ## Full Example
 
index 6c5950667dd3cb42d59645bf1a99e6ea7051c9b9..a939a07d63ccd45fa16af4b7ddfd337bd428085d 100644 (file)
@@ -58,5 +58,7 @@ public class FineOffsetWeatherStationBindingConstants {
 
     public static final String SENSOR_CHANNEL_SIGNAL = "signal";
     public static final String SENSOR_CHANNEL_BATTERY_LEVEL = "batteryLevel";
+
+    public static final String SENSOR_CHANNEL_BATTERY_VOLTAGE = "batteryVoltage";
     public static final String SENSOR_CHANNEL_LOW_BATTERY = "lowBattery";
 }
index df0433361f48f2f3e4606e1a726a92ee2ac062ed..88506094bb640e1d7696495196b2155239c49a80 100644 (file)
@@ -17,9 +17,11 @@ import java.math.BigDecimal;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetWeatherStationBindingConstants;
+import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.BatteryStatus;
 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SensorDevice;
 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.thing.Channel;
 import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
@@ -29,6 +31,8 @@ import org.openhab.core.thing.binding.BaseThingHandler;
 import org.openhab.core.types.Command;
 import org.openhab.core.types.UnDefType;
 
+import tech.units.indriya.unit.Units;
+
 /**
  * The {@link FineOffsetSensorHandler} keeps track of the signal and battery of the sensor attached to the gateway.
  *
@@ -75,9 +79,11 @@ public class FineOffsetSensorHandler extends BaseThingHandler {
         }
         updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_SIGNAL,
                 new DecimalType(sensorDevice.getSignal()));
+        BatteryStatus batteryStatus = sensorDevice.getBatteryStatus();
+
         updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_LOW_BATTERY,
-                sensorDevice.getBatteryStatus().isLow() ? OnOffType.ON : OnOffType.OFF);
-        Integer percentage = sensorDevice.getBatteryStatus().getPercentage();
+                batteryStatus.isLow() ? OnOffType.ON : OnOffType.OFF);
+        Integer percentage = batteryStatus.getPercentage();
         if (percentage != null) {
             updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_LEVEL,
                     new DecimalType(new BigDecimal(percentage)));
@@ -88,5 +94,16 @@ public class FineOffsetSensorHandler extends BaseThingHandler {
                 updateThing(editThing().withoutChannels(channel).build());
             }
         }
+        Double voltage = batteryStatus.getVoltage();
+        if (voltage != null) {
+            updateState(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_VOLTAGE,
+                    new QuantityType<>(voltage, Units.VOLT));
+        } else {
+            @Nullable
+            Channel channel = thing.getChannel(FineOffsetWeatherStationBindingConstants.SENSOR_CHANNEL_BATTERY_VOLTAGE);
+            if (channel != null) {
+                updateThing(editThing().withoutChannels(channel).build());
+            }
+        }
     }
 }
index 1eda2bb2ae789efea4f9919b1482e5f3eba8910e..81e8310c6191cd207f0ded6683f54f83b630776f 100644 (file)
@@ -26,8 +26,10 @@ thing-type.config.fineoffsetweatherstation.sensor.sensor.label = Sensor
 
 # channel types
 
+channel-type.fineoffsetweatherstation.battery-voltage.label = Battery Voltage
+channel-type.fineoffsetweatherstation.battery-voltage.description = The voltage of the battery
 channel-type.fineoffsetweatherstation.co2.label = CO₂
-channel-type.fineoffsetweatherstation.co2.description = Air quality indicator
+channel-type.fineoffsetweatherstation.co2.description = Air Quality Indicator
 channel-type.fineoffsetweatherstation.humidity.label = Humidity
 channel-type.fineoffsetweatherstation.illumination.label = Illumination
 channel-type.fineoffsetweatherstation.lightning-counter.label = Lightning Counter
@@ -45,6 +47,8 @@ channel-type.fineoffsetweatherstation.uv-index.label = UV-Index
 channel-type.fineoffsetweatherstation.uv-radiation.label = UV-Irradiation
 channel-type.fineoffsetweatherstation.water-leak-detection.label = Water Leak Detection
 
+# channel types
+
 channel = Channel
 thing.gateway.label = Weather Station
 thing.sensor.WH24.label = Weather Station - Outdoor Unit
@@ -187,3 +191,4 @@ thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-5.label
 thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-6.label = Leaf Moisture Channel 6
 thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-7.label = Leaf Moisture Channel 7
 thing-type.fineoffsetweatherstation.gateway.channel.leaf-wetness-channel-8.label = Leaf Moisture Channel 8
+thing-type.fineoffsetweatherstation.sensor.channel.batteryVoltage.label = Battery Voltage
index 062a62401a04b806718ed92ff9f68674cc1d2625..be64e06ca0d438b42980e0ed5cacb41f065c5845 100644 (file)
        <channel-type id="co2">
                <item-type>Number:Dimensionless</item-type>
                <label>CO₂</label>
-               <description>Air quality indicator</description>
+               <description>Air Quality Indicator</description>
                <category>CarbonDioxide</category>
                <tags>
                        <tag>Measurement</tag>
index 3ea78110086ffd9e3af3bff4729501524fb48317..7581fc571d0c9826850f1be5ffdc3ebee29f503b 100644 (file)
@@ -4,6 +4,18 @@
        xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
        xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
+       <channel-type id="battery-voltage">
+               <item-type>Number:ElectricPotential</item-type>
+               <label>Battery Voltage</label>
+               <description>The voltage of the battery</description>
+               <category>Energy</category>
+               <tags>
+                       <tag>Measurement</tag>
+                       <tag>Voltage</tag>
+               </tags>
+               <state pattern="%.1f %unit%" readOnly="true"/>
+       </channel-type>
+
        <thing-type id="sensor" listed="false">
                <supported-bridge-type-refs>
                        <bridge-type-ref id="gateway"/>
@@ -16,6 +28,7 @@
                <channels>
                        <channel id="signal" typeId="system.signal-strength"/>
                        <channel id="batteryLevel" typeId="system.battery-level"/>
+                       <channel id="batteryVoltage" typeId="battery-voltage"/>
                        <channel id="lowBattery" typeId="system.low-battery"/>
                </channels>