From f73d9fa572096d88cfcc2fae368068b5bc9d1011 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 20 Apr 2021 08:22:10 -1000 Subject: [PATCH] Reduce broadlink executor jobs at setup time (#49447) Co-authored-by: Martin Hjelmare Co-authored-by: Paulus Schoutsen --- homeassistant/components/broadlink/device.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/broadlink/device.py b/homeassistant/components/broadlink/device.py index 5b42205993c..fd9c6dcd9d3 100644 --- a/homeassistant/components/broadlink/device.py +++ b/homeassistant/components/broadlink/device.py @@ -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)