Prevent new discovery flows from being created when stopping (#88743)
parent
7b61d3763b
commit
57360a7528
|
@ -44,7 +44,9 @@ def _async_init_flow(
|
|||
# as ones in progress as it may cause additional device probing
|
||||
# which can overload devices since zeroconf/ssdp updates can happen
|
||||
# multiple times in the same minute
|
||||
if hass.config_entries.flow.async_has_matching_flow(domain, context, data):
|
||||
if hass.is_stopping or hass.config_entries.flow.async_has_matching_flow(
|
||||
domain, context, data
|
||||
):
|
||||
return None
|
||||
|
||||
return hass.config_entries.flow.async_init(domain, context=context, data=data)
|
||||
|
|
|
@ -96,3 +96,20 @@ async def test_async_create_flow_checks_existing_flows_before_startup(
|
|||
data={"properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
async def test_async_create_flow_does_nothing_after_stop(
|
||||
hass: HomeAssistant, mock_flow_init
|
||||
) -> None:
|
||||
"""Test we no longer create flows when hass is stopping."""
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||
await hass.async_block_till_done()
|
||||
hass.state = CoreState.stopping
|
||||
mock_flow_init.reset_mock()
|
||||
discovery_flow.async_create_flow(
|
||||
hass,
|
||||
"hue",
|
||||
{"source": config_entries.SOURCE_HOMEKIT},
|
||||
{"properties": {"id": "aa:bb:cc:dd:ee:ff"}},
|
||||
)
|
||||
assert len(mock_flow_init.mock_calls) == 0
|
||||
|
|
Loading…
Reference in New Issue