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) <noreply@anthropic.com>
parent
e20c23a3af
commit
b72efa5985
|
|
@ -83,7 +83,7 @@ class WeatherDataUpdateCoordinator(DataUpdateCoordinator):
|
||||||
self.pocasi: PocasiPush = PocasiPush(hass, config)
|
self.pocasi: PocasiPush = PocasiPush(hass, config)
|
||||||
self.ecowitt_bridge: EcowittBridge = EcowittBridge(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:
|
def _health_coordinator(self) -> HealthCoordinator | None:
|
||||||
"""Return the health coordinator for this config entry."""
|
"""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)
|
remaped_items: dict[str, str] = remap_wslink_items(data) if _wslink else remap_items(data)
|
||||||
|
|
||||||
if sensors := check_disabled(remaped_items, self.config):
|
if sensors := check_disabled(remaped_items, self.config):
|
||||||
if (
|
# Resolve each sensor's display name once (the previous comprehension
|
||||||
translate_sensors := checked(
|
# awaited translations() twice per key).
|
||||||
[
|
translated_sensors: list[str] = []
|
||||||
await translations(
|
for t_key in sensors:
|
||||||
self.hass,
|
name = await translations(
|
||||||
DOMAIN,
|
self.hass,
|
||||||
f"sensor.{t_key}",
|
DOMAIN,
|
||||||
key="name",
|
f"sensor.{t_key}",
|
||||||
category="entity",
|
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],
|
|
||||||
)
|
)
|
||||||
) is not None:
|
if name is not None:
|
||||||
human_readable: str = "\n".join(translate_sensors)
|
translated_sensors.append(name)
|
||||||
else:
|
|
||||||
human_readable = ""
|
human_readable = "\n".join(translated_sensors)
|
||||||
|
|
||||||
await translated_notification(
|
await translated_notification(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,7 @@ class HealthCoordinator(DataUpdateCoordinator):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=_LOGGER,
|
logger=_LOGGER,
|
||||||
|
config_entry=config,
|
||||||
name=f"{DOMAIN}_health",
|
name=f"{DOMAIN}_health",
|
||||||
update_interval=timedelta(minutes=1),
|
update_interval=timedelta(minutes=1),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue