Skip to content

Commit bb12d2e

Browse files
authored
Avoid creating tasks in homeassistant_alerts when the debouncer will not fire (home-assistant#113580)
1 parent 4174d88 commit bb12d2e

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

homeassistant/components/homeassistant_alerts/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ async def initial_refresh(hass: HomeAssistant) -> None:
9898
function=coordinator.async_refresh,
9999
)
100100

101-
async def _component_loaded(_: Event) -> None:
102-
await refresh_debouncer.async_call()
101+
@callback
102+
def _component_loaded(_: Event) -> None:
103+
refresh_debouncer.async_schedule_call()
103104

104105
await coordinator.async_refresh()
105-
hass.bus.async_listen(EVENT_COMPONENT_LOADED, _component_loaded)
106+
hass.bus.async_listen(
107+
EVENT_COMPONENT_LOADED, _component_loaded, run_immediately=True
108+
)
106109

107110
async_at_start(hass, initial_refresh)
108111

tests/components/homeassistant_alerts/test_init.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,33 @@ async def test_alerts_refreshed_on_component_load(
323323
):
324324
assert await async_setup_component(hass, DOMAIN, {})
325325

326-
client = await hass_ws_client(hass)
327-
328-
await client.send_json({"id": 1, "type": "repairs/list_issues"})
329-
msg = await client.receive_json()
330-
assert msg["success"]
331-
assert msg["result"] == {
332-
"issues": [
333-
{
334-
"breaks_in_ha_version": None,
335-
"created": ANY,
336-
"dismissed_version": None,
337-
"domain": "homeassistant_alerts",
338-
"ignored": False,
339-
"is_fixable": False,
340-
"issue_id": f"{alert}.markdown_{integration}",
341-
"issue_domain": integration,
342-
"learn_more_url": None,
343-
"severity": "warning",
344-
"translation_key": "alert",
345-
"translation_placeholders": {
346-
"title": f"Title for {alert}",
347-
"description": f"Content for {alert}",
348-
},
349-
}
350-
for alert, integration in initial_alerts
351-
]
352-
}
326+
client = await hass_ws_client(hass)
327+
328+
await client.send_json({"id": 1, "type": "repairs/list_issues"})
329+
msg = await client.receive_json()
330+
assert msg["success"]
331+
assert msg["result"] == {
332+
"issues": [
333+
{
334+
"breaks_in_ha_version": None,
335+
"created": ANY,
336+
"dismissed_version": None,
337+
"domain": "homeassistant_alerts",
338+
"ignored": False,
339+
"is_fixable": False,
340+
"issue_id": f"{alert}.markdown_{integration}",
341+
"issue_domain": integration,
342+
"learn_more_url": None,
343+
"severity": "warning",
344+
"translation_key": "alert",
345+
"translation_placeholders": {
346+
"title": f"Title for {alert}",
347+
"description": f"Content for {alert}",
348+
},
349+
}
350+
for alert, integration in initial_alerts
351+
]
352+
}
353353

354354
with patch(
355355
"homeassistant.components.homeassistant_alerts.__version__",
@@ -368,33 +368,33 @@ async def test_alerts_refreshed_on_component_load(
368368
freezer.tick(COMPONENT_LOADED_COOLDOWN + 1)
369369
await hass.async_block_till_done()
370370

371-
client = await hass_ws_client(hass)
372-
373-
await client.send_json({"id": 2, "type": "repairs/list_issues"})
374-
msg = await client.receive_json()
375-
assert msg["success"]
376-
assert msg["result"] == {
377-
"issues": [
378-
{
379-
"breaks_in_ha_version": None,
380-
"created": ANY,
381-
"dismissed_version": None,
382-
"domain": "homeassistant_alerts",
383-
"ignored": False,
384-
"is_fixable": False,
385-
"issue_id": f"{alert}.markdown_{integration}",
386-
"issue_domain": integration,
387-
"learn_more_url": None,
388-
"severity": "warning",
389-
"translation_key": "alert",
390-
"translation_placeholders": {
391-
"title": f"Title for {alert}",
392-
"description": f"Content for {alert}",
393-
},
394-
}
395-
for alert, integration in late_alerts
396-
]
397-
}
371+
client = await hass_ws_client(hass)
372+
373+
await client.send_json({"id": 2, "type": "repairs/list_issues"})
374+
msg = await client.receive_json()
375+
assert msg["success"]
376+
assert msg["result"] == {
377+
"issues": [
378+
{
379+
"breaks_in_ha_version": None,
380+
"created": ANY,
381+
"dismissed_version": None,
382+
"domain": "homeassistant_alerts",
383+
"ignored": False,
384+
"is_fixable": False,
385+
"issue_id": f"{alert}.markdown_{integration}",
386+
"issue_domain": integration,
387+
"learn_more_url": None,
388+
"severity": "warning",
389+
"translation_key": "alert",
390+
"translation_placeholders": {
391+
"title": f"Title for {alert}",
392+
"description": f"Content for {alert}",
393+
},
394+
}
395+
for alert, integration in late_alerts
396+
]
397+
}
398398

399399

400400
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)