mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Ensure wemo discovery is run in a background task (#112665)
This commit is contained in:
parent
e13d8200cc
commit
5e2edb6819
@ -119,7 +119,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a wemo config entry."""
|
||||
wemo_data = async_wemo_data(hass)
|
||||
dispatcher = WemoDispatcher(entry)
|
||||
discovery = WemoDiscovery(hass, dispatcher, wemo_data.static_config)
|
||||
discovery = WemoDiscovery(hass, dispatcher, wemo_data.static_config, entry)
|
||||
wemo_data.config_entry_data = WemoConfigEntryData(
|
||||
device_coordinators={},
|
||||
discovery=discovery,
|
||||
@ -246,6 +246,7 @@ class WemoDiscovery:
|
||||
hass: HomeAssistant,
|
||||
wemo_dispatcher: WemoDispatcher,
|
||||
static_config: Sequence[HostPortTuple],
|
||||
entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the WemoDiscovery."""
|
||||
self._hass = hass
|
||||
@ -253,7 +254,8 @@ class WemoDiscovery:
|
||||
self._stop: CALLBACK_TYPE | None = None
|
||||
self._scan_delay = 0
|
||||
self._static_config = static_config
|
||||
self._discover_job: HassJob[[datetime], Coroutine[Any, Any, None]] | None = None
|
||||
self._discover_job: HassJob[[datetime], None] | None = None
|
||||
self._entry = entry
|
||||
|
||||
async def async_discover_and_schedule(
|
||||
self, event_time: datetime | None = None
|
||||
@ -274,13 +276,23 @@ class WemoDiscovery:
|
||||
self.MAX_SECONDS_BETWEEN_SCANS,
|
||||
)
|
||||
if not self._discover_job:
|
||||
self._discover_job = HassJob(self.async_discover_and_schedule)
|
||||
self._discover_job = HassJob(self._async_discover_and_schedule_callback)
|
||||
self._stop = async_call_later(
|
||||
self._hass,
|
||||
self._scan_delay,
|
||||
self._discover_job,
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_discover_and_schedule_callback(self, event_time: datetime) -> None:
|
||||
"""Run the periodic background scanning."""
|
||||
self._entry.async_create_background_task(
|
||||
self._hass,
|
||||
self.async_discover_and_schedule(),
|
||||
name="wemo_discovery",
|
||||
eager_start=True,
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_stop_discovery(self) -> None:
|
||||
"""Stop the periodic background scanning."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user