Reduce broadlink executor jobs at setup time (#49447)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
pull/49489/head
J. Nick Koston 2021-04-20 08:22:10 -10:00 committed by GitHub
parent df66f2a9da
commit f73d9fa572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -63,6 +63,13 @@ class BroadlinkDevice:
device_registry.async_update_device(device_entry.id, name=entry.title)
await hass.config_entries.async_reload(entry.entry_id)
def _auth_fetch_firmware(self):
"""Auth and fetch firmware."""
self.api.auth()
with suppress(BroadlinkException, OSError):
return self.api.get_fwversion()
return None
async def async_setup(self):
"""Set up the device and related entities."""
config = self.config
@ -77,7 +84,9 @@ class BroadlinkDevice:
self.api = api
try:
await self.hass.async_add_executor_job(api.auth)
self.fw_version = await self.hass.async_add_executor_job(
self._auth_fetch_firmware
)
except AuthenticationError:
await self._async_handle_auth_error()
@ -102,9 +111,6 @@ class BroadlinkDevice:
self.hass.data[DOMAIN].devices[config.entry_id] = self
self.reset_jobs.append(config.add_update_listener(self.async_update))
with suppress(BroadlinkException, OSError):
self.fw_version = await self.hass.async_add_executor_job(api.get_fwversion)
# Forward entry setup to related domains.
tasks = (
self.hass.config_entries.async_forward_entry_setup(config, domain)