Fix unknown/unavailable source sensor in Filter entities (#92241)

This commit is contained in:
Franck Nijhof 2023-04-29 17:47:04 +02:00 committed by GitHub
parent 1028841690
commit 37723792c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -236,11 +236,18 @@ class SensorFilter(SensorEntity):
self.async_write_ha_state()
return
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
self._state = new_state.state
if new_state.state == STATE_UNKNOWN:
self._state = None
self.async_write_ha_state()
return
if new_state.state == STATE_UNAVAILABLE:
self._attr_available = False
self.async_write_ha_state()
return
self._attr_available = True
temp_state = _State(new_state.last_updated, new_state.state)
try:

View file

@ -308,6 +308,12 @@ async def test_invalid_state(recorder_mock: Recorder, hass: HomeAssistant) -> No
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
hass.states.async_set("sensor.test_monitored", "unknown")
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state.state == STATE_UNKNOWN
hass.states.async_set("sensor.test_monitored", STATE_UNAVAILABLE)
await hass.async_block_till_done()