Set directv unavailable state when errors returned for longer then a minute (#19014)
* Fix unavailable Change setting to unavailable when getting request exceptions only after 1 minute has past since 1st occurrence. * Put common code in _check_state_available Put common code to determine if available should be set to False in method _check_state_available
This commit is contained in:
1 parent
ce736e7ba1
commit
8a62bc9237
2 files changed
+57
-7
No files matched your search
@@ -515,7 +515,7 @@ async def test_available(hass, platforms, main_dtv, mock_now):
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Make update fail (i.e. DVR offline)
|
||||
# Make update fail 1st time
|
||||
next_update = next_update + timedelta(minutes=5)
|
||||
with patch.object(
|
||||
main_dtv, 'get_standby', side_effect=requests.RequestException), \
|
||||
@@ -523,6 +523,28 @@ async def test_available(hass, platforms, main_dtv, mock_now):
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Make update fail 2nd time within 1 minute
|
||||
next_update = next_update + timedelta(seconds=30)
|
||||
with patch.object(
|
||||
main_dtv, 'get_standby', side_effect=requests.RequestException), \
|
||||
patch('homeassistant.util.dt.utcnow', return_value=next_update):
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
# Make update fail 3rd time more then a minute after 1st failure
|
||||
next_update = next_update + timedelta(minutes=1)
|
||||
with patch.object(
|
||||
main_dtv, 'get_standby', side_effect=requests.RequestException), \
|
||||
patch('homeassistant.util.dt.utcnow', return_value=next_update):
|
||||
async_fire_time_changed(hass, next_update)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(MAIN_ENTITY_ID)
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
Reference in new issue
Block a user