From d00934a8f8f63bf13ebe53dc98ab62344982abf5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Oct 2023 22:42:15 -1000 Subject: [PATCH] Refactor automation trigger attachment to avoid creating a closure (#102288) --- homeassistant/components/automation/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index df388e52a7f..84f7f3aca52 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -733,14 +733,14 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity): self.async_write_ha_state() + def _log_callback(self, level: int, msg: str, **kwargs: Any) -> None: + """Log helper callback.""" + self._logger.log(level, "%s %s", msg, self.name, **kwargs) + async def _async_attach_triggers( self, home_assistant_start: bool ) -> Callable[[], None] | None: """Set up the triggers.""" - - def log_cb(level: int, msg: str, **kwargs: Any) -> None: - self._logger.log(level, "%s %s", msg, self.name, **kwargs) - this = None self.async_write_ha_state() if state := self.hass.states.get(self.entity_id): @@ -763,7 +763,7 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity): self.async_trigger, DOMAIN, str(self.name), - log_cb, + self._log_callback, home_assistant_start, variables, )