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>
This commit is contained in:
parent
df66f2a9da
commit
f73d9fa572
1 changed files with 10 additions and 4 deletions
|
@ -63,6 +63,13 @@ class BroadlinkDevice:
|
||||||
device_registry.async_update_device(device_entry.id, name=entry.title)
|
device_registry.async_update_device(device_entry.id, name=entry.title)
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
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):
|
async def async_setup(self):
|
||||||
"""Set up the device and related entities."""
|
"""Set up the device and related entities."""
|
||||||
config = self.config
|
config = self.config
|
||||||
|
@ -77,7 +84,9 @@ class BroadlinkDevice:
|
||||||
self.api = api
|
self.api = api
|
||||||
|
|
||||||
try:
|
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:
|
except AuthenticationError:
|
||||||
await self._async_handle_auth_error()
|
await self._async_handle_auth_error()
|
||||||
|
@ -102,9 +111,6 @@ class BroadlinkDevice:
|
||||||
self.hass.data[DOMAIN].devices[config.entry_id] = self
|
self.hass.data[DOMAIN].devices[config.entry_id] = self
|
||||||
self.reset_jobs.append(config.add_update_listener(self.async_update))
|
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.
|
# Forward entry setup to related domains.
|
||||||
tasks = (
|
tasks = (
|
||||||
self.hass.config_entries.async_forward_entry_setup(config, domain)
|
self.hass.config_entries.async_forward_entry_setup(config, domain)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue