Fix unknown/unavailable source sensor in Filter entities (#92241)
This commit is contained in:
parent
1028841690
commit
37723792c7
2 changed files with 15 additions and 2 deletions
|
@ -236,11 +236,18 @@ class SensorFilter(SensorEntity):
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
return
|
return
|
||||||
|
|
||||||
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
if new_state.state == STATE_UNKNOWN:
|
||||||
self._state = new_state.state
|
self._state = None
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
return
|
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)
|
temp_state = _State(new_state.last_updated, new_state.state)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -308,6 +308,12 @@ async def test_invalid_state(recorder_mock: Recorder, hass: HomeAssistant) -> No
|
||||||
assert await async_setup_component(hass, "sensor", config)
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
await hass.async_block_till_done()
|
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)
|
hass.states.async_set("sensor.test_monitored", STATE_UNAVAILABLE)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue