diff --git a/homeassistant/components/vizio/__init__.py b/homeassistant/components/vizio/__init__.py index fb3a399327d..7c1ed7e8fa7 100644 --- a/homeassistant/components/vizio/__init__.py +++ b/homeassistant/components/vizio/__init__.py @@ -113,6 +113,9 @@ class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator): """Update data via library.""" data = await gen_apps_list_from_url(session=async_get_clientsession(self.hass)) if not data: + # For every failure, increase the fail count until we reach the threshold. + # We then log a warning, increase the threshold, and reset the fail count. + # This is here to prevent silent failures but to reduce repeat logs. if self.fail_count == self.fail_threshold: _LOGGER.warning( ( @@ -126,6 +129,7 @@ class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator): else: self.fail_count += 1 return self.data + # Reset the fail count and threshold when the data is successfully retrieved self.fail_count = 0 self.fail_threshold = 10 return sorted(data, key=lambda app: app["name"]) diff --git a/tests/components/vizio/test_init.py b/tests/components/vizio/test_init.py index c3e8afe49e6..ccda9253ec7 100644 --- a/tests/components/vizio/test_init.py +++ b/tests/components/vizio/test_init.py @@ -94,14 +94,11 @@ async def test_coordinator_update_failure( assert len(hass.states.async_entity_ids(MP_DOMAIN)) == 1 assert DOMAIN in hass.data - for days in range(1, 10): + # Failing 25 days in a row should result in a single log message + # (first one after 10 days, next one would be at 30 days) + for days in range(1, 25): async_fire_time_changed(hass, now + timedelta(days=days)) await hass.async_block_till_done() - assert ( - "Unable to retrieve the apps list from the external server" - not in caplog.text - ) - async_fire_time_changed(hass, now + timedelta(days=10)) - await hass.async_block_till_done() - assert "Unable to retrieve the apps list from the external server" in caplog.text + err_msg = "Unable to retrieve the apps list from the external server" + assert len([record for record in caplog.records if err_msg in record.msg]) == 1