From 6167a3a536fd43d03b370d4669ae7e739c381ba7 Mon Sep 17 00:00:00 2001 From: SchiZzA Date: Sun, 21 Jun 2026 12:51:25 +0200 Subject: [PATCH] fix(coordinator): pass config_entry to DataUpdateCoordinator Pass config_entry explicitly to super().__init__() in both WeatherDataUpdateCoordinator and HealthCoordinator instead of relying on the implicit ContextVar (deprecated, breaks in HA 2026.8 for core and was breaking async_config_entry_first_refresh outside the setup context). Also resolve each discovered sensor's display name once in received_data (the previous comprehension awaited translations() twice per key). Co-Authored-By: Claude Opus 4.8 (1M context) --- custom_components/sws12500/coordinator.py | 41 +++++++------------ .../sws12500/health_coordinator.py | 1 + 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/custom_components/sws12500/coordinator.py b/custom_components/sws12500/coordinator.py index 2235071..1dbed5f 100644 --- a/custom_components/sws12500/coordinator.py +++ b/custom_components/sws12500/coordinator.py @@ -83,7 +83,7 @@ class WeatherDataUpdateCoordinator(DataUpdateCoordinator): self.pocasi: PocasiPush = PocasiPush(hass, config) self.ecowitt_bridge: EcowittBridge = EcowittBridge(hass, config) - super().__init__(hass, _LOGGER, name=DOMAIN) + super().__init__(hass, _LOGGER, config_entry=config, name=DOMAIN) def _health_coordinator(self) -> HealthCoordinator | None: """Return the health coordinator for this config entry.""" @@ -260,32 +260,21 @@ class WeatherDataUpdateCoordinator(DataUpdateCoordinator): remaped_items: dict[str, str] = remap_wslink_items(data) if _wslink else remap_items(data) if sensors := check_disabled(remaped_items, self.config): - if ( - translate_sensors := checked( - [ - await translations( - self.hass, - DOMAIN, - f"sensor.{t_key}", - key="name", - category="entity", - ) - for t_key in sensors - if await translations( - self.hass, - DOMAIN, - f"sensor.{t_key}", - key="name", - category="entity", - ) - is not None - ], - list[str], + # Resolve each sensor's display name once (the previous comprehension + # awaited translations() twice per key). + translated_sensors: list[str] = [] + for t_key in sensors: + name = await translations( + self.hass, + DOMAIN, + f"sensor.{t_key}", + key="name", + category="entity", ) - ) is not None: - human_readable: str = "\n".join(translate_sensors) - else: - human_readable = "" + if name is not None: + translated_sensors.append(name) + + human_readable = "\n".join(translated_sensors) await translated_notification( self.hass, diff --git a/custom_components/sws12500/health_coordinator.py b/custom_components/sws12500/health_coordinator.py index dcb926b..5f9fd44 100644 --- a/custom_components/sws12500/health_coordinator.py +++ b/custom_components/sws12500/health_coordinator.py @@ -144,6 +144,7 @@ class HealthCoordinator(DataUpdateCoordinator): super().__init__( hass, logger=_LOGGER, + config_entry=config, name=f"{DOMAIN}_health", update_interval=timedelta(minutes=1), )