diff --git a/homeassistant/components/canary/sensor.py b/homeassistant/components/canary/sensor.py index 5c92f0089f2..acb885055a3 100644 --- a/homeassistant/components/canary/sensor.py +++ b/homeassistant/components/canary/sensor.py @@ -113,7 +113,6 @@ class CanarySensor(CoordinatorEntity, SensorEntity): canary_sensor_type = SensorType.BATTERY self._canary_type = canary_sensor_type - self._attr_state = self.reading self._attr_unique_id = f"{device.device_id}_{sensor_type[0]}" self._attr_device_info = { "identifiers": {(DOMAIN, str(device.device_id))}, @@ -144,6 +143,11 @@ class CanarySensor(CoordinatorEntity, SensorEntity): return None + @property + def state(self) -> float | None: + """Return the state of the sensor.""" + return self.reading + @property def extra_state_attributes(self) -> dict[str, str] | None: """Return the state attributes.""" diff --git a/tests/components/canary/test_sensor.py b/tests/components/canary/test_sensor.py index 6419f81a62e..67d4a724584 100644 --- a/tests/components/canary/test_sensor.py +++ b/tests/components/canary/test_sensor.py @@ -118,9 +118,10 @@ async def test_sensors_attributes_pro(hass, canary) -> None: await hass.async_block_till_done() entity_id = "sensor.home_dining_room_air_quality" - state = hass.states.get(entity_id) - assert state - assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_ABNORMAL + state1 = hass.states.get(entity_id) + assert state1 + assert state1.state == "0.59" + assert state1.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_ABNORMAL instance.get_latest_readings.return_value = [ mock_reading("temperature", "21.12"), @@ -133,9 +134,10 @@ async def test_sensors_attributes_pro(hass, canary) -> None: await hass.helpers.entity_component.async_update_entity(entity_id) await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state - assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_VERY_ABNORMAL + state2 = hass.states.get(entity_id) + assert state2 + assert state2.state == "0.4" + assert state2.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_VERY_ABNORMAL instance.get_latest_readings.return_value = [ mock_reading("temperature", "21.12"), @@ -148,9 +150,10 @@ async def test_sensors_attributes_pro(hass, canary) -> None: await hass.helpers.entity_component.async_update_entity(entity_id) await hass.async_block_till_done() - state = hass.states.get(entity_id) - assert state - assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_NORMAL + state3 = hass.states.get(entity_id) + assert state3 + assert state3.state == "1.0" + assert state3.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_NORMAL async def test_sensors_flex(hass, canary) -> None: