From 36a0c49ceebdb3c8d8896dc1fd5bc038e8751717 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sat, 8 Feb 2025 13:15:13 +0100 Subject: [PATCH] Explicitly pass in the config_entry in gree coordinator (#137844) explicitly pass in the config_entry in coordinator --- homeassistant/components/gree/__init__.py | 2 +- homeassistant/components/gree/coordinator.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/gree/__init__.py b/homeassistant/components/gree/__init__.py index c385ce45262..7cb4f0f0921 100644 --- a/homeassistant/components/gree/__init__.py +++ b/homeassistant/components/gree/__init__.py @@ -26,7 +26,7 @@ PLATFORMS = [Platform.CLIMATE, Platform.SWITCH] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Gree Climate from a config entry.""" hass.data.setdefault(DOMAIN, {}) - gree_discovery = DiscoveryService(hass) + gree_discovery = DiscoveryService(hass, entry) hass.data[DATA_DISCOVERY_SERVICE] = gree_discovery async def _async_scan_update(_=None): diff --git a/homeassistant/components/gree/coordinator.py b/homeassistant/components/gree/coordinator.py index 42d6734a6b2..0d1aa60deaa 100644 --- a/homeassistant/components/gree/coordinator.py +++ b/homeassistant/components/gree/coordinator.py @@ -11,6 +11,7 @@ from greeclimate.discovery import Discovery, Listener from greeclimate.exceptions import DeviceNotBoundError, DeviceTimeoutError from greeclimate.network import Response +from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.json import json_dumps @@ -32,12 +33,16 @@ _LOGGER = logging.getLogger(__name__) class DeviceDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): """Manages polling for state changes from the device.""" - def __init__(self, hass: HomeAssistant, device: Device) -> None: + config_entry: ConfigEntry + + def __init__( + self, hass: HomeAssistant, config_entry: ConfigEntry, device: Device + ) -> None: """Initialize the data update coordinator.""" - DataUpdateCoordinator.__init__( - self, + super().__init__( hass, _LOGGER, + config_entry=config_entry, name=f"{DOMAIN}-{device.device_info.name}", update_interval=timedelta(seconds=UPDATE_INTERVAL), always_update=False, @@ -117,10 +122,11 @@ class DeviceDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): class DiscoveryService(Listener): """Discovery event handler for gree devices.""" - def __init__(self, hass: HomeAssistant) -> None: + def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None: """Initialize discovery service.""" super().__init__() self.hass = hass + self.entry = entry self.discovery = Discovery(DISCOVERY_TIMEOUT) self.discovery.add_listener(self) @@ -144,7 +150,7 @@ class DiscoveryService(Listener): device.device_info.ip, device.device_info.port, ) - coordo = DeviceDataUpdateCoordinator(self.hass, device) + coordo = DeviceDataUpdateCoordinator(self.hass, self.entry, device) self.hass.data[DOMAIN][COORDINATORS].append(coordo) await coordo.async_refresh()