From 91d46dcb6cbb8f2d6ab1d365b79786cf3496907a Mon Sep 17 00:00:00 2001 From: Jules Dejaeghere Date: Sun, 29 Dec 2024 18:04:24 +0100 Subject: [PATCH 1/3] Put config entry in coordinator --- custom_components/irm_kmi/coordinator.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/custom_components/irm_kmi/coordinator.py b/custom_components/irm_kmi/coordinator.py index ba9eb55..5127b0d 100644 --- a/custom_components/irm_kmi/coordinator.py +++ b/custom_components/irm_kmi/coordinator.py @@ -43,6 +43,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry): super().__init__( hass, _LOGGER, + config_entry=entry, # Name of the data. For logging purposes. name="IRM KMI weather", # Polling interval. Will only be polled if there are subscribers. @@ -52,11 +53,10 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry): self._zone = get_config_value(entry, CONF_ZONE) self._dark_mode = get_config_value(entry, CONF_DARK_MODE) self._style = get_config_value(entry, CONF_STYLE) - self._config_entry = entry self.shared_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, identifiers={(DOMAIN, entry.entry_id)}, - manufacturer=IRM_KMI_NAME.get(preferred_language(self.hass, self._config_entry)), + manufacturer=IRM_KMI_NAME.get(preferred_language(self.hass, self.config_entry)), name=f"{entry.title}" ) @@ -92,7 +92,7 @@ async def _async_update_data(self) -> ProcessedCoordinatorData: _LOGGER.error(f"The zone {self._zone} is now out of Benelux and forecast is only available in Benelux." f"Associated device is now disabled. Move the zone back in Benelux and re-enable to fix " f"this") - disable_from_config(self.hass, self._config_entry) + disable_from_config(self.hass, self.config_entry) issue_registry.async_create_issue( self.hass, @@ -101,7 +101,7 @@ async def _async_update_data(self) -> ProcessedCoordinatorData: is_fixable=True, severity=issue_registry.IssueSeverity.ERROR, translation_key='zone_moved', - data={'config_entry_id': self._config_entry.entry_id, 'zone': self._zone}, + data={'config_entry_id': self.config_entry.entry_id, 'zone': self._zone}, translation_placeholders={'zone': self._zone} ) return ProcessedCoordinatorData() @@ -131,7 +131,7 @@ async def _async_animation_data(self, api_data: dict) -> RadarAnimationData: localisation = images_from_api[0] images_from_api = images_from_api[1:] - lang = preferred_language(self.hass, self._config_entry) + lang = preferred_language(self.hass, self.config_entry) radar_animation = RadarAnimationData( hint=api_data.get('animation', {}).get('sequenceHint', {}).get(lang), unit=api_data.get('animation', {}).get('unit', {}).get(lang), @@ -367,7 +367,7 @@ async def daily_list_to_forecast(self, data: List[dict] | None) -> List[IrmKmiFo return None forecasts = list() - lang = preferred_language(self.hass, self._config_entry) + lang = preferred_language(self.hass, self.config_entry) tz = await dt.async_get_time_zone('Europe/Brussels') forecast_day = dt.now(tz) @@ -502,7 +502,7 @@ def warnings_from_data(self, warning_data: list | None) -> List[WarningData]: if warning_data is None or not isinstance(warning_data, list) or len(warning_data) == 0: return [] - lang = preferred_language(self.hass, self._config_entry) + lang = preferred_language(self.hass, self.config_entry) result = list() for data in warning_data: try: From 1254ae71570b6be4936bca8b80f4932b4e2513fc Mon Sep 17 00:00:00 2001 From: Jules Dejaeghere Date: Sun, 29 Dec 2024 18:04:56 +0100 Subject: [PATCH 2/3] Use hass.config_entries.async_reload to reload config entry --- custom_components/irm_kmi/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/irm_kmi/__init__.py b/custom_components/irm_kmi/__init__.py index f7bb08a..14c05e2 100644 --- a/custom_components/irm_kmi/__init__.py +++ b/custom_components/irm_kmi/__init__.py @@ -45,8 +45,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: """Reload config entry.""" - await async_unload_entry(hass, entry) - await async_setup_entry(hass, entry) + await hass.config_entries.async_reload(entry.entry_id) async def async_migrate_entry(hass, config_entry: ConfigEntry): From 4978a923859f12dc738a903a17047ca3419460ec Mon Sep 17 00:00:00 2001 From: Jules Dejaeghere Date: Sun, 29 Dec 2024 18:17:17 +0100 Subject: [PATCH 3/3] Fix typo --- custom_components/irm_kmi/coordinator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/irm_kmi/coordinator.py b/custom_components/irm_kmi/coordinator.py index 5127b0d..3c83ff2 100644 --- a/custom_components/irm_kmi/coordinator.py +++ b/custom_components/irm_kmi/coordinator.py @@ -89,7 +89,7 @@ async def _async_update_data(self) -> ProcessedCoordinatorData: f"Last success time is: {self.last_update_success_time}") if api_data.get('cityName', None) in OUT_OF_BENELUX: - _LOGGER.error(f"The zone {self._zone} is now out of Benelux and forecast is only available in Benelux." + _LOGGER.error(f"The zone {self._zone} is now out of Benelux and forecast is only available in Benelux. " f"Associated device is now disabled. Move the zone back in Benelux and re-enable to fix " f"this") disable_from_config(self.hass, self.config_entry)