Skip to content

Commit

Permalink
Limit Supervisor refresh updates (home-assistant#70075)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored and frenck committed Apr 16, 2022
1 parent 0a61822 commit 410e0f5
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
16 changes: 15 additions & 1 deletion homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,6 @@ async def force_info_update_supervisor(self) -> None:

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],
Expand Down Expand Up @@ -976,3 +975,18 @@ async def _update_addon_info(self, slug):
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)
46 changes: 40 additions & 6 deletions tests/components/hassio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -658,12 +659,45 @@ async def test_coordinator_updates(hass, caplog):

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))
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
assert (
"Error fetching hassio data: Error on Supervisor API: Unknown"
in caplog.text

# 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:
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

0 comments on commit 410e0f5

Please sign in to comment.