diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/README.md b/bundles/org.openhab.binding.fineoffsetweatherstation/README.md index d55b9474cff11..1c47635ff467f 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/README.md +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/README.md @@ -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 diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java index 6c5950667dd3c..a939a07d63ccd 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/FineOffsetWeatherStationBindingConstants.java @@ -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"; } diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/handler/FineOffsetSensorHandler.java b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/handler/FineOffsetSensorHandler.java index df0433361f48f..88506094bb640 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/handler/FineOffsetSensorHandler.java +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/java/org/openhab/binding/fineoffsetweatherstation/internal/handler/FineOffsetSensorHandler.java @@ -17,9 +17,11 @@ 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.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 void updateSensorState(@Nullable SensorDevice sensorDevice) { } 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 void updateSensorState(@Nullable SensorDevice sensorDevice) { 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()); + } + } } } diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties index 1eda2bb2ae789..81e8310c6191c 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/i18n/fineoffsetweatherstation.properties @@ -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 diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml index 062a62401a04b..be64e06ca0d43 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/gateway.xml @@ -143,7 +143,7 @@ Number:Dimensionless - Air quality indicator + Air Quality Indicator CarbonDioxide Measurement diff --git a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/sensor.xml b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/sensor.xml index 3ea78110086ff..7581fc571d0c9 100644 --- a/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/sensor.xml +++ b/bundles/org.openhab.binding.fineoffsetweatherstation/src/main/resources/OH-INF/thing/sensor.xml @@ -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"> + + Number:ElectricPotential + + The voltage of the battery + Energy + + Measurement + Voltage + + + + @@ -16,6 +28,7 @@ +