From 3be3226aaa0d775e642ea079ce2f876d6482ce63 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 8 Apr 2023 17:13:22 -1000 Subject: [PATCH] Convert tasmota discovery callback function to a normal function (#90865) * Convert tasmota discovery callback function to a normal function Nothing was being awaited when the payload had not changed. This allows us to avoid creating a task. see #90801 * comment --- homeassistant/components/tasmota/mixins.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tasmota/mixins.py b/homeassistant/components/tasmota/mixins.py index d9f417b2c8d..bfa6d01032b 100644 --- a/homeassistant/components/tasmota/mixins.py +++ b/homeassistant/components/tasmota/mixins.py @@ -159,8 +159,16 @@ class TasmotaDiscoveryUpdate(TasmotaEntity): self._removed_from_hass = False await super().async_added_to_hass() - async def discovery_callback(config: TasmotaEntityConfig) -> None: - """Handle discovery update.""" + @callback + def discovery_callback(config: TasmotaEntityConfig) -> None: + """Handle discovery update. + + If the config has changed we will create a task to + do the discovery update. + + As this callback can fire when nothing has changed, this + is a normal function to avoid task creation until it is needed. + """ _LOGGER.debug( "Got update for entity with hash: %s '%s'", self._discovery_hash, @@ -169,7 +177,7 @@ class TasmotaDiscoveryUpdate(TasmotaEntity): if not self._tasmota_entity.config_same(config): # Changed payload: Notify component _LOGGER.debug("Updating component: %s", self.entity_id) - await self.discovery_update(config) + self.hass.async_create_task(self.discovery_update(config)) else: # Unchanged payload: Ignore to avoid changing states _LOGGER.debug("Ignoring unchanged update for: %s", self.entity_id)