Use HA constants for Rfxtrx units (#40562)
* Add more units and device classes * Battery level is a value beteen 0 and 9 where 9 indicate full Actual 0 battery can't occur since since then we would get to signal * Adjust tests * Add wind direction and adjust rain rate * Adjust data types to be None rather than empty string * Set counter values to count unit * Forgotten unit
This commit is contained in:
1 parent
b6aa29012e
commit
0fbeb3bf7b
3 files changed
+53
-33
No files matched your search
@@ -9,7 +9,14 @@ from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICES
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICES,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import (
|
||||
@@ -30,7 +37,7 @@ def _battery_convert(value):
|
||||
"""Battery is given as a value between 0 and 9."""
|
||||
if value is None:
|
||||
return None
|
||||
return value * 10
|
||||
return (value + 1) * 10
|
||||
|
||||
|
||||
def _rssi_convert(value):
|
||||
@@ -41,10 +48,17 @@ def _rssi_convert(value):
|
||||
|
||||
|
||||
DEVICE_CLASSES = {
|
||||
"Barometer": DEVICE_CLASS_PRESSURE,
|
||||
"Battery numeric": DEVICE_CLASS_BATTERY,
|
||||
"Rssi numeric": DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
"Current Ch. 1": DEVICE_CLASS_CURRENT,
|
||||
"Current Ch. 2": DEVICE_CLASS_CURRENT,
|
||||
"Current Ch. 3": DEVICE_CLASS_CURRENT,
|
||||
"Energy usage": DEVICE_CLASS_POWER,
|
||||
"Humidity": DEVICE_CLASS_HUMIDITY,
|
||||
"Rssi numeric": DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
"Temperature": DEVICE_CLASS_TEMPERATURE,
|
||||
"Total usage": DEVICE_CLASS_ENERGY,
|
||||
"Voltage": DEVICE_CLASS_VOLTAGE,
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +138,7 @@ class RfxtrxSensor(RfxtrxEntity):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(device, device_id, event=event)
|
||||
self.data_type = data_type
|
||||
self._unit_of_measurement = DATA_TYPES.get(data_type, "")
|
||||
self._unit_of_measurement = DATA_TYPES.get(data_type)
|
||||
self._name = f"{device.type_string} {device.id_string} {data_type}"
|
||||
self._unique_id = "_".join(x for x in (*self._device_id, data_type))
|
||||
|
||||
|
||||
Reference in new issue
Block a user