Fix uom/device class mismatches in tests (#84372)
This commit is contained in:
parent
92beab82e2
commit
2e92fefc0a
6 changed files with 23 additions and 8 deletions
|
@ -21,9 +21,11 @@ from homeassistant.components.sensor import (
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
@ -263,6 +265,7 @@ async def test_setup(recorder_mock, hass):
|
||||||
{
|
{
|
||||||
"icon": "mdi:test",
|
"icon": "mdi:test",
|
||||||
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
|
||||||
ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
|
ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
TIME_HOURS,
|
TIME_HOURS,
|
||||||
TIME_SECONDS,
|
TIME_SECONDS,
|
||||||
|
UnitOfPower,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, State
|
from homeassistant.core import HomeAssistant, State
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -422,16 +423,26 @@ async def test_device_class(hass):
|
||||||
# include states of None and Unknown
|
# include states of None and Unknown
|
||||||
hass.states.async_set(entity_id, STATE_UNKNOWN, {})
|
hass.states.async_set(entity_id, STATE_UNKNOWN, {})
|
||||||
await hass.async_block_till_done()
|
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()
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("sensor.integration")
|
state = hass.states.get("sensor.integration")
|
||||||
assert "device_class" not in state.attributes
|
assert "device_class" not in state.attributes
|
||||||
|
|
||||||
hass.states.async_set(
|
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()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
|
@ -902,7 +902,7 @@ async def test_entity_config(hass: HomeAssistant) -> None:
|
||||||
"name": "{{'REST' + ' ' + 'Sensor'}}",
|
"name": "{{'REST' + ' ' + 'Sensor'}}",
|
||||||
"state_class": "measurement",
|
"state_class": "measurement",
|
||||||
"unique_id": "very_unique",
|
"unique_id": "very_unique",
|
||||||
"unit_of_measurement": "beardsecond",
|
"unit_of_measurement": "°C",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,5 +921,5 @@ async def test_entity_config(hass: HomeAssistant) -> None:
|
||||||
"friendly_name": "REST Sensor",
|
"friendly_name": "REST Sensor",
|
||||||
"icon": "mdi:one_two_three",
|
"icon": "mdi:one_two_three",
|
||||||
"state_class": "measurement",
|
"state_class": "measurement",
|
||||||
"unit_of_measurement": "beardsecond",
|
"unit_of_measurement": "°C",
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ async def test_entity_config(hass: HomeAssistant) -> None:
|
||||||
"name": "{{'SNMP' + ' ' + 'Sensor'}}",
|
"name": "{{'SNMP' + ' ' + 'Sensor'}}",
|
||||||
"state_class": "measurement",
|
"state_class": "measurement",
|
||||||
"unique_id": "very_unique",
|
"unique_id": "very_unique",
|
||||||
"unit_of_measurement": "beardsecond",
|
"unit_of_measurement": "°C",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,5 +78,5 @@ async def test_entity_config(hass: HomeAssistant) -> None:
|
||||||
"friendly_name": "SNMP Sensor",
|
"friendly_name": "SNMP Sensor",
|
||||||
"icon": "mdi:one_two_three",
|
"icon": "mdi:one_two_three",
|
||||||
"state_class": "measurement",
|
"state_class": "measurement",
|
||||||
"unit_of_measurement": "beardsecond",
|
"unit_of_measurement": "°C",
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,6 +292,7 @@ async def test_template_attribute_missing(hass, start_ha):
|
||||||
"sensors": {
|
"sensors": {
|
||||||
"test1": {
|
"test1": {
|
||||||
"value_template": "{{ states.sensor.test_sensor.state }}",
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
||||||
|
"unit_of_measurement": "°C",
|
||||||
"device_class": "temperature",
|
"device_class": "temperature",
|
||||||
},
|
},
|
||||||
"test2": {
|
"test2": {
|
||||||
|
|
|
@ -70,7 +70,7 @@ def init(empty=False):
|
||||||
name=f"{device_class} sensor",
|
name=f"{device_class} sensor",
|
||||||
unique_id=f"unique_{device_class}",
|
unique_id=f"unique_{device_class}",
|
||||||
device_class=device_class,
|
device_class=device_class,
|
||||||
unit_of_measurement=UNITS_OF_MEASUREMENT.get(device_class),
|
native_unit_of_measurement=UNITS_OF_MEASUREMENT.get(device_class),
|
||||||
)
|
)
|
||||||
for device_class in DEVICE_CLASSES
|
for device_class in DEVICE_CLASSES
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue