mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Migrate DSMR to new entity naming style (#75077)
This commit is contained in:
@@ -77,18 +77,18 @@ async def test_default_setup(hass, dsmr_connection_fixture):
|
||||
|
||||
registry = er.async_get(hass)
|
||||
|
||||
entry = registry.async_get("sensor.power_consumption")
|
||||
entry = registry.async_get("sensor.electricity_meter_power_consumption")
|
||||
assert entry
|
||||
assert entry.unique_id == "1234_current_electricity_usage"
|
||||
|
||||
entry = registry.async_get("sensor.gas_consumption")
|
||||
entry = registry.async_get("sensor.gas_meter_gas_consumption")
|
||||
assert entry
|
||||
assert entry.unique_id == "5678_gas_meter_reading"
|
||||
|
||||
telegram_callback = connection_factory.call_args_list[0][0][2]
|
||||
|
||||
# make sure entities have been created and return 'unknown' state
|
||||
power_consumption = hass.states.get("sensor.power_consumption")
|
||||
power_consumption = hass.states.get("sensor.electricity_meter_power_consumption")
|
||||
assert power_consumption.state == STATE_UNKNOWN
|
||||
assert (
|
||||
power_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.POWER
|
||||
@@ -107,22 +107,22 @@ async def test_default_setup(hass, dsmr_connection_fixture):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
# ensure entities have new state value after incoming telegram
|
||||
power_consumption = hass.states.get("sensor.power_consumption")
|
||||
power_consumption = hass.states.get("sensor.electricity_meter_power_consumption")
|
||||
assert power_consumption.state == "0.0"
|
||||
assert (
|
||||
power_consumption.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
)
|
||||
|
||||
# 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(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_active_tariff")
|
||||
assert active_tariff.state == "low"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
@@ -155,11 +155,11 @@ async def test_setup_only_energy(hass, dsmr_connection_fixture):
|
||||
|
||||
registry = er.async_get(hass)
|
||||
|
||||
entry = registry.async_get("sensor.power_consumption")
|
||||
entry = registry.async_get("sensor.electricity_meter_power_consumption")
|
||||
assert entry
|
||||
assert entry.unique_id == "1234_current_electricity_usage"
|
||||
|
||||
entry = registry.async_get("sensor.gas_consumption")
|
||||
entry = registry.async_get("sensor.gas_meter_gas_consumption")
|
||||
assert not entry
|
||||
|
||||
|
||||
@@ -213,15 +213,15 @@ async def test_v4_meter(hass, dsmr_connection_fixture):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
# 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(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_active_tariff")
|
||||
assert active_tariff.state == "low"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert gas_consumption.attributes.get("unit_of_measurement") == VOLUME_CUBIC_METERS
|
||||
@@ -284,15 +284,15 @@ async def test_v5_meter(hass, dsmr_connection_fixture):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
# 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(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_active_tariff")
|
||||
assert active_tariff.state == "low"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
@@ -359,24 +359,24 @@ async def test_luxembourg_meter(hass, dsmr_connection_fixture):
|
||||
# after receiving telegram entities need to have the chance to update
|
||||
await asyncio.sleep(0)
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_consumption_total")
|
||||
assert power_tariff.state == "123.456"
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert power_tariff.attributes.get(ATTR_ICON) is None
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_consumption_total")
|
||||
assert active_tariff.state == "123.456"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert active_tariff.attributes.get(ATTR_ICON) is None
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
active_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
active_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"
|
||||
assert power_tariff.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_production_total")
|
||||
assert active_tariff.state == "654.321"
|
||||
assert active_tariff.attributes.get("unit_of_measurement") == ENERGY_KILO_WATT_HOUR
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
@@ -438,15 +438,15 @@ async def test_belgian_meter(hass, dsmr_connection_fixture):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
# 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(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_active_tariff")
|
||||
assert active_tariff.state == "normal"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
# check if gas consumption is parsed correctly
|
||||
gas_consumption = hass.states.get("sensor.gas_consumption")
|
||||
gas_consumption = hass.states.get("sensor.gas_meter_gas_consumption")
|
||||
assert gas_consumption.state == "745.695"
|
||||
assert gas_consumption.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.GAS
|
||||
assert (
|
||||
@@ -497,12 +497,12 @@ async def test_belgian_meter_low(hass, dsmr_connection_fixture):
|
||||
await asyncio.sleep(0)
|
||||
|
||||
# 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(ATTR_DEVICE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert power_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_active_tariff")
|
||||
assert active_tariff.state == "low"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_ICON) == "mdi:flash"
|
||||
assert active_tariff.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ""
|
||||
|
||||
|
||||
async def test_swedish_meter(hass, dsmr_connection_fixture):
|
||||
@@ -553,26 +553,26 @@ async def test_swedish_meter(hass, dsmr_connection_fixture):
|
||||
# after receiving telegram entities need to have the chance to update
|
||||
await asyncio.sleep(0)
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_consumption_total")
|
||||
assert power_tariff.state == "123.456"
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert power_tariff.attributes.get(ATTR_ICON) is None
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_consumption_total")
|
||||
assert active_tariff.state == "123.456"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert active_tariff.attributes.get(ATTR_ICON) is None
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
active_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
active_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"
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_production_total")
|
||||
assert active_tariff.state == "654.321"
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
active_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
)
|
||||
|
||||
|
||||
@@ -627,26 +627,26 @@ async def test_easymeter(hass, dsmr_connection_fixture):
|
||||
# after receiving telegram entities need to have the chance to update
|
||||
await asyncio.sleep(0)
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_consumption_total")
|
||||
assert power_tariff.state == "54184.6316"
|
||||
assert power_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert power_tariff.attributes.get(ATTR_ICON) is None
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_consumption_total")
|
||||
assert active_tariff.state == "54184.6316"
|
||||
assert active_tariff.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENERGY
|
||||
assert active_tariff.attributes.get(ATTR_ICON) is None
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
active_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
)
|
||||
|
||||
power_tariff = hass.states.get("sensor.energy_production_total")
|
||||
assert power_tariff.state == "19981.1069"
|
||||
active_tariff = hass.states.get("sensor.electricity_meter_energy_production_total")
|
||||
assert active_tariff.state == "19981.1069"
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
active_tariff.attributes.get(ATTR_STATE_CLASS)
|
||||
== SensorStateClass.TOTAL_INCREASING
|
||||
)
|
||||
assert (
|
||||
power_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
active_tariff.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == ENERGY_KILO_WATT_HOUR
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user