Improve calls to async_show_progress in snooz (#107793)

This commit is contained in:
Erik Montnemery 2024-01-14 11:00:10 +01:00 committed by GitHub
parent e12dcfc1b4
commit 1c9764bc44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,18 +134,20 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN):
self._pairing_task = self.hass.async_create_task( self._pairing_task = self.hass.async_create_task(
self._async_wait_for_pairing_mode() self._async_wait_for_pairing_mode()
) )
if not self._pairing_task.done():
return self.async_show_progress( return self.async_show_progress(
step_id="wait_for_pairing_mode", step_id="wait_for_pairing_mode",
progress_action="wait_for_pairing_mode", progress_action="wait_for_pairing_mode",
progress_task=self._pairing_task,
) )
try: try:
await self._pairing_task await self._pairing_task
except asyncio.TimeoutError: except asyncio.TimeoutError:
self._pairing_task = None
return self.async_show_progress_done(next_step_id="pairing_timeout") return self.async_show_progress_done(next_step_id="pairing_timeout")
finally:
self._pairing_task = None self._pairing_task = None
return self.async_show_progress_done(next_step_id="pairing_complete") return self.async_show_progress_done(next_step_id="pairing_complete")
@ -192,15 +194,10 @@ class SnoozConfigFlow(ConfigFlow, domain=DOMAIN):
) -> bool: ) -> bool:
return device.supported(service_info) and device.is_pairing return device.supported(service_info) and device.is_pairing
try: await async_process_advertisements(
await async_process_advertisements( self.hass,
self.hass, is_device_in_pairing_mode,
is_device_in_pairing_mode, {"address": self._discovery.info.address},
{"address": self._discovery.info.address}, BluetoothScanningMode.ACTIVE,
BluetoothScanningMode.ACTIVE, WAIT_FOR_PAIRING_TIMEOUT,
WAIT_FOR_PAIRING_TIMEOUT, )
)
finally:
self.hass.async_create_task(
self.hass.config_entries.flow.async_configure(flow_id=self.flow_id)
)