mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
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
This commit is contained in:
parent
59872f1914
commit
3be3226aaa
@ -159,8 +159,16 @@ class TasmotaDiscoveryUpdate(TasmotaEntity):
|
|||||||
self._removed_from_hass = False
|
self._removed_from_hass = False
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
async def discovery_callback(config: TasmotaEntityConfig) -> None:
|
@callback
|
||||||
"""Handle discovery update."""
|
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(
|
_LOGGER.debug(
|
||||||
"Got update for entity with hash: %s '%s'",
|
"Got update for entity with hash: %s '%s'",
|
||||||
self._discovery_hash,
|
self._discovery_hash,
|
||||||
@ -169,7 +177,7 @@ class TasmotaDiscoveryUpdate(TasmotaEntity):
|
|||||||
if not self._tasmota_entity.config_same(config):
|
if not self._tasmota_entity.config_same(config):
|
||||||
# Changed payload: Notify component
|
# Changed payload: Notify component
|
||||||
_LOGGER.debug("Updating component: %s", self.entity_id)
|
_LOGGER.debug("Updating component: %s", self.entity_id)
|
||||||
await self.discovery_update(config)
|
self.hass.async_create_task(self.discovery_update(config))
|
||||||
else:
|
else:
|
||||||
# Unchanged payload: Ignore to avoid changing states
|
# Unchanged payload: Ignore to avoid changing states
|
||||||
_LOGGER.debug("Ignoring unchanged update for: %s", self.entity_id)
|
_LOGGER.debug("Ignoring unchanged update for: %s", self.entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user