diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index f3f6887570f..278f8a50ebc 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -917,7 +917,6 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator): async def force_data_refresh(self) -> None: """Force update of the addon info.""" - await self.hassio.refresh_updates() ( self.hass.data[DATA_INFO], self.hass.data[DATA_CORE_INFO], @@ -976,3 +975,18 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator): except HassioAPIError as err: _LOGGER.warning("Could not fetch info for %s: %s", slug, err) return (slug, None) + + async def _async_refresh( + self, + log_failures: bool = True, + raise_on_auth_failed: bool = False, + scheduled: bool = False, + ) -> None: + """Refresh data.""" + if not scheduled: + # Force refreshing updates for non-scheduled updates + try: + await self.hassio.refresh_updates() + except HassioAPIError as err: + _LOGGER.warning("Error on Supervisor API: %s", err) + await super()._async_refresh(log_failures, raise_on_auth_failed, scheduled) diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 2e7bea90f68..6f4b9a39a9f 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -646,7 +646,8 @@ async def test_device_registry_calls(hass): async def test_coordinator_updates(hass, caplog): - """Test coordinator.""" + """Test coordinator updates.""" + await async_setup_component(hass, "homeassistant", {}) with patch.dict(os.environ, MOCK_ENVIRON), patch( "homeassistant.components.hassio.HassIO.refresh_updates" ) as refresh_updates_mock: @@ -656,14 +657,47 @@ async def test_coordinator_updates(hass, caplog): await hass.async_block_till_done() assert refresh_updates_mock.call_count == 1 + with patch( + "homeassistant.components.hassio.HassIO.refresh_updates", + ) as refresh_updates_mock: + async_fire_time_changed(hass, dt_util.now() + timedelta(minutes=20)) + await hass.async_block_till_done() + assert refresh_updates_mock.call_count == 0 + + with patch( + "homeassistant.components.hassio.HassIO.refresh_updates", + ) as refresh_updates_mock: + await hass.services.async_call( + "homeassistant", + "update_entity", + { + "entity_id": [ + "update.home_assistant_core_update", + "update.home_assistant_supervisor_update", + ] + }, + blocking=True, + ) + assert refresh_updates_mock.call_count == 1 + + # There is a 10s cooldown on the debouncer + async_fire_time_changed(hass, dt_util.now() + timedelta(seconds=10)) + await hass.async_block_till_done() + with patch( "homeassistant.components.hassio.HassIO.refresh_updates", side_effect=HassioAPIError("Unknown"), ) as refresh_updates_mock: - async_fire_time_changed(hass, dt_util.now() + timedelta(minutes=5)) - await hass.async_block_till_done() - assert refresh_updates_mock.call_count == 1 - assert ( - "Error fetching hassio data: Error on Supervisor API: Unknown" - in caplog.text + await hass.services.async_call( + "homeassistant", + "update_entity", + { + "entity_id": [ + "update.home_assistant_core_update", + "update.home_assistant_supervisor_update", + ] + }, + blocking=True, ) + assert refresh_updates_mock.call_count == 1 + assert "Error on Supervisor API: Unknown" in caplog.text