diff --git a/tests/components/filter/test_sensor.py b/tests/components/filter/test_sensor.py index b440ac7889b..bb01b5b4c5c 100644 --- a/tests/components/filter/test_sensor.py +++ b/tests/components/filter/test_sensor.py @@ -21,9 +21,11 @@ from homeassistant.components.sensor import ( ) from homeassistant.const import ( ATTR_DEVICE_CLASS, + ATTR_UNIT_OF_MEASUREMENT, SERVICE_RELOAD, STATE_UNAVAILABLE, STATE_UNKNOWN, + UnitOfTemperature, ) import homeassistant.core as ha from homeassistant.helpers import entity_registry as er @@ -263,6 +265,7 @@ async def test_setup(recorder_mock, hass): { "icon": "mdi:test", ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE, + ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS, ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING, }, ) diff --git a/tests/components/integration/test_sensor.py b/tests/components/integration/test_sensor.py index 8999c1f8d04..9cc1bbb2692 100644 --- a/tests/components/integration/test_sensor.py +++ b/tests/components/integration/test_sensor.py @@ -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() diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index 50c8c6677b5..db55df4ff16 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -902,7 +902,7 @@ async def test_entity_config(hass: HomeAssistant) -> None: "name": "{{'REST' + ' ' + 'Sensor'}}", "state_class": "measurement", "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", "icon": "mdi:one_two_three", "state_class": "measurement", - "unit_of_measurement": "beardsecond", + "unit_of_measurement": "°C", } diff --git a/tests/components/snmp/test_sensor.py b/tests/components/snmp/test_sensor.py index e34c2a1baaf..965bc0d3ae9 100644 --- a/tests/components/snmp/test_sensor.py +++ b/tests/components/snmp/test_sensor.py @@ -60,7 +60,7 @@ async def test_entity_config(hass: HomeAssistant) -> None: "name": "{{'SNMP' + ' ' + 'Sensor'}}", "state_class": "measurement", "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", "icon": "mdi:one_two_three", "state_class": "measurement", - "unit_of_measurement": "beardsecond", + "unit_of_measurement": "°C", } diff --git a/tests/components/template/test_sensor.py b/tests/components/template/test_sensor.py index 44fa96cfc6a..19d43f08d2b 100644 --- a/tests/components/template/test_sensor.py +++ b/tests/components/template/test_sensor.py @@ -292,6 +292,7 @@ async def test_template_attribute_missing(hass, start_ha): "sensors": { "test1": { "value_template": "{{ states.sensor.test_sensor.state }}", + "unit_of_measurement": "°C", "device_class": "temperature", }, "test2": { diff --git a/tests/testing_config/custom_components/test/sensor.py b/tests/testing_config/custom_components/test/sensor.py index c7ca9a76005..9ec56ad23f6 100644 --- a/tests/testing_config/custom_components/test/sensor.py +++ b/tests/testing_config/custom_components/test/sensor.py @@ -70,7 +70,7 @@ def init(empty=False): name=f"{device_class} sensor", unique_id=f"unique_{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 }