Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions homeassistant/components/rfxtrx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
CONF_DEVICES,
CONF_HOST,
CONF_PORT,
ELECTRICAL_CURRENT_AMPERE,
ENERGY_KILO_WATT_HOUR,
EVENT_HOMEASSISTANT_STOP,
PERCENTAGE,
POWER_WATT,
PRESSURE_HPA,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
UV_INDEX,
VOLT,
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -52,30 +57,28 @@
("Temperature", TEMP_CELSIUS),
("Temperature2", TEMP_CELSIUS),
("Humidity", PERCENTAGE),
("Barometer", ""),
("Barometer", PRESSURE_HPA),
("Wind direction", ""),
("Rain rate", ""),
("Rain rate", "mm/h"),
Comment thread
elupus marked this conversation as resolved.
Outdated
("Energy usage", POWER_WATT),
("Total usage", POWER_WATT),
("Total usage", ENERGY_KILO_WATT_HOUR),
("Sound", ""),
Comment thread
elupus marked this conversation as resolved.
Outdated
("Sensor Status", ""),
("Counter value", ""),
("UV", UV_INDEX),
("Humidity status", ""),
("Forecast", ""),
("Forecast numeric", ""),
("Rain total", ""),
("Wind average speed", ""),
("Wind gust", ""),
("Chill", ""),
("Total usage", ""),
("Rain total", "mm"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LENGTH_MILLIMETERS

("Wind average speed", SPEED_METERS_PER_SECOND),
("Wind gust", SPEED_METERS_PER_SECOND),
("Chill", TEMP_CELSIUS),
("Count", ""),
("Current Ch. 1", ""),
("Current Ch. 2", ""),
("Current Ch. 3", ""),
("Energy usage", ""),
("Voltage", ""),
("Current", ""),
("Current Ch. 1", ELECTRICAL_CURRENT_AMPERE),
("Current Ch. 2", ELECTRICAL_CURRENT_AMPERE),
("Current Ch. 3", ELECTRICAL_CURRENT_AMPERE),
("Voltage", VOLT),
("Current", ELECTRICAL_CURRENT_AMPERE),
("Battery numeric", PERCENTAGE),
("Rssi numeric", "dBm"),
]
Expand Down
20 changes: 17 additions & 3 deletions homeassistant/components/rfxtrx/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
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 (
Expand All @@ -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):
Expand All @@ -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,
}


Expand Down
6 changes: 3 additions & 3 deletions tests/components/rfxtrx/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def test_discover_sensor(hass, rfxtrx_automatic):

state = hass.states.get(f"{base_id}_battery_numeric")
assert state
assert state.state == "90"
assert state.state == "100"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE

# 2
Expand Down Expand Up @@ -207,7 +207,7 @@ async def test_discover_sensor(hass, rfxtrx_automatic):

state = hass.states.get(f"{base_id}_battery_numeric")
assert state
assert state.state == "90"
assert state.state == "100"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE

# 1 Update
Expand Down Expand Up @@ -236,7 +236,7 @@ async def test_discover_sensor(hass, rfxtrx_automatic):

state = hass.states.get(f"{base_id}_battery_numeric")
assert state
assert state.state == "90"
assert state.state == "100"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE

assert len(hass.states.async_all()) == 10
Expand Down