mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
DSMR: Device/state classes, icons, less common disabled by default (#52159)
This commit is contained in:
@@ -13,8 +13,22 @@ from unittest.mock import DEFAULT, MagicMock
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.dsmr.const import DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLUME_CUBIC_METERS
|
||||
from homeassistant.components.sensor import (
|
||||
ATTR_LAST_RESET,
|
||||
ATTR_STATE_CLASS,
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
STATE_UNKNOWN,
|
||||
VOLUME_CUBIC_METERS,
|
||||
)
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
@@ -118,8 +132,12 @@ async def test_default_setup(hass, dsmr_connection_fixture):
|
||||
|
||||
# make sure entities have been created and return 'unknown' state
|
||||
power_consumption = hass.states.get("sensor.power_consumption")
|
||||
assert power_consumption.state == "unknown"
|
||||
assert power_consumption.attributes.get("unit_of_measurement") is None
|
||||
assert power_consumption.state == STATE_UNKNOWN
|
||||
assert power_consumption.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
|
||||
assert power_consumption.attributes.get(ATTR_ICON) is None
|
||||
assert power_consumption.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert power_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||
|
||||
# simulate a telegram pushed from the smartmeter and parsed by dsmr_parser
|
||||
telegram_callback(telegram)
|
||||
@@ -137,12 +155,22 @@ async def test_default_setup(hass, dsmr_connection_fixture):
|
||||
# tariff should be translated in human readable and have no unit
|
||||
power_tariff = hass.states.get("sensor.power_tariff")
|
||||
assert power_tariff.state == "low"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ""
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
|
||||
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
|
||||
)
|
||||
|
||||
|
||||
async def test_setup_only_energy(hass, dsmr_connection_fixture):
|
||||
@@ -226,12 +254,23 @@ async def test_v4_meter(hass, dsmr_connection_fixture):
|
||||
# tariff should be translated in human readable and have no unit
|
||||
power_tariff = hass.states.get("sensor.power_tariff")
|
||||
assert power_tariff.state == "low"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ""
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
|
||||
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
|
||||
)
|
||||
|
||||
|
||||
async def test_v5_meter(hass, dsmr_connection_fixture):
|
||||
@@ -286,12 +325,22 @@ async def test_v5_meter(hass, dsmr_connection_fixture):
|
||||
# tariff should be translated in human readable and have no unit
|
||||
power_tariff = hass.states.get("sensor.power_tariff")
|
||||
assert power_tariff.state == "low"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ""
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
|
||||
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
|
||||
)
|
||||
|
||||
|
||||
async def test_luxembourg_meter(hass, dsmr_connection_fixture):
|
||||
@@ -351,7 +400,13 @@ async def test_luxembourg_meter(hass, dsmr_connection_fixture):
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_consumption_total")
|
||||
assert power_tariff.state == "123.456"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_ENERGY
|
||||
assert power_tariff.attributes.get(ATTR_ICON) is None
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
)
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_production_total")
|
||||
assert power_tariff.state == "654.321"
|
||||
@@ -360,7 +415,13 @@ async def test_luxembourg_meter(hass, dsmr_connection_fixture):
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
|
||||
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
|
||||
)
|
||||
|
||||
|
||||
async def test_belgian_meter(hass, dsmr_connection_fixture):
|
||||
@@ -415,12 +476,22 @@ async def test_belgian_meter(hass, dsmr_connection_fixture):
|
||||
# tariff should be translated in human readable and have no unit
|
||||
power_tariff = hass.states.get("sensor.power_tariff")
|
||||
assert power_tariff.state == "normal"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ""
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert gas_consumption.attributes.get(ATTR_ICON) == "mdi:fire"
|
||||
assert gas_consumption.attributes.get(ATTR_LAST_RESET) is not None
|
||||
assert gas_consumption.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
gas_consumption.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == VOLUME_CUBIC_METERS
|
||||
)
|
||||
|
||||
|
||||
async def test_belgian_meter_low(hass, dsmr_connection_fixture):
|
||||
@@ -464,7 +535,11 @@ async def test_belgian_meter_low(hass, dsmr_connection_fixture):
|
||||
# tariff should be translated in human readable and have no unit
|
||||
power_tariff = hass.states.get("sensor.power_tariff")
|
||||
assert power_tariff.state == "low"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ""
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_LAST_RESET) is None
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
|
||||
async def test_tcp(hass, dsmr_connection_fixture):
|
||||
|
||||
Reference in New Issue
Block a user