1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix uom/device class mismatches in tests (#84372)

This commit is contained in:
Franck Nijhof
2022-12-21 22:47:59 +01:00
committed by GitHub
parent 92beab82e2
commit 2e92fefc0a
6 changed files with 23 additions and 8 deletions

View File

@@ -15,6 +15,7 @@ from homeassistant.const import (
STATE_UNKNOWN,
TIME_HOURS,
TIME_SECONDS,
UnitOfPower,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.setup import async_setup_component
@@ -422,16 +423,26 @@ async def test_device_class(hass):
# include states of None and Unknown
hass.states.async_set(entity_id, STATE_UNKNOWN, {})
await hass.async_block_till_done()
hass.states.async_set(entity_id, 100, {"device_class": None})
hass.states.async_set(
entity_id, 100, {"device_class": None, "unit_of_measurement": None}
)
await hass.async_block_till_done()
hass.states.async_set(entity_id, 200, {"device_class": None})
hass.states.async_set(
entity_id, 200, {"device_class": None, "unit_of_measurement": None}
)
await hass.async_block_till_done()
state = hass.states.get("sensor.integration")
assert "device_class" not in state.attributes
hass.states.async_set(
entity_id, 300, {"device_class": SensorDeviceClass.POWER}, force_update=True
entity_id,
300,
{
"device_class": SensorDeviceClass.POWER,
"unit_of_measurement": UnitOfPower.WATT,
},
force_update=True,
)
await hass.async_block_till_done()