mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix Canary sensor state (#54380)
This commit is contained in:
parent
934662cd54
commit
8cb3a485e0
@ -113,7 +113,6 @@ class CanarySensor(CoordinatorEntity, SensorEntity):
|
|||||||
canary_sensor_type = SensorType.BATTERY
|
canary_sensor_type = SensorType.BATTERY
|
||||||
|
|
||||||
self._canary_type = canary_sensor_type
|
self._canary_type = canary_sensor_type
|
||||||
self._attr_state = self.reading
|
|
||||||
self._attr_unique_id = f"{device.device_id}_{sensor_type[0]}"
|
self._attr_unique_id = f"{device.device_id}_{sensor_type[0]}"
|
||||||
self._attr_device_info = {
|
self._attr_device_info = {
|
||||||
"identifiers": {(DOMAIN, str(device.device_id))},
|
"identifiers": {(DOMAIN, str(device.device_id))},
|
||||||
@ -144,6 +143,11 @@ class CanarySensor(CoordinatorEntity, SensorEntity):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self) -> float | None:
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self.reading
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, str] | None:
|
def extra_state_attributes(self) -> dict[str, str] | None:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
@ -118,9 +118,10 @@ async def test_sensors_attributes_pro(hass, canary) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
entity_id = "sensor.home_dining_room_air_quality"
|
entity_id = "sensor.home_dining_room_air_quality"
|
||||||
state = hass.states.get(entity_id)
|
state1 = hass.states.get(entity_id)
|
||||||
assert state
|
assert state1
|
||||||
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_ABNORMAL
|
assert state1.state == "0.59"
|
||||||
|
assert state1.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_ABNORMAL
|
||||||
|
|
||||||
instance.get_latest_readings.return_value = [
|
instance.get_latest_readings.return_value = [
|
||||||
mock_reading("temperature", "21.12"),
|
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.helpers.entity_component.async_update_entity(entity_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state2 = hass.states.get(entity_id)
|
||||||
assert state
|
assert state2
|
||||||
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_VERY_ABNORMAL
|
assert state2.state == "0.4"
|
||||||
|
assert state2.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_VERY_ABNORMAL
|
||||||
|
|
||||||
instance.get_latest_readings.return_value = [
|
instance.get_latest_readings.return_value = [
|
||||||
mock_reading("temperature", "21.12"),
|
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.helpers.entity_component.async_update_entity(entity_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state3 = hass.states.get(entity_id)
|
||||||
assert state
|
assert state3
|
||||||
assert state.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_NORMAL
|
assert state3.state == "1.0"
|
||||||
|
assert state3.attributes[ATTR_AIR_QUALITY] == STATE_AIR_QUALITY_NORMAL
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors_flex(hass, canary) -> None:
|
async def test_sensors_flex(hass, canary) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user