From 5ca0d65cd6d8e42f4b0528d2603c0e732c1233d7 Mon Sep 17 00:00:00 2001 From: Lukas Svoboda Date: Mon, 23 Feb 2026 18:31:25 +0100 Subject: [PATCH] Fixing error when Windy was not set correctly. (#95) * Fixing error when Windy was not set correctly. Fixed an issue when integration fails to send data to Windy and crashed, so no data was accepted from station. Windy resend is disabled on misconfiguration detect. * Fixed WSLink bool in resend function. --- custom_components/sws12500/__init__.py | 2 +- custom_components/sws12500/config_flow.py | 20 ++++++++++++------- .../sws12500/translations/cs.json | 3 ++- .../sws12500/translations/en.json | 3 ++- custom_components/sws12500/windy_func.py | 19 ++++++++++++++++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/custom_components/sws12500/__init__.py b/custom_components/sws12500/__init__.py index b00b97d..991cd36 100644 --- a/custom_components/sws12500/__init__.py +++ b/custom_components/sws12500/__init__.py @@ -86,7 +86,7 @@ class WeatherDataUpdateCoordinator(DataUpdateCoordinator): raise HTTPUnauthorized if self.config_entry.options.get(WINDY_ENABLED): - response = await self.windy.push_data_to_windy(data, _wslink) + _ = await self.windy.push_data_to_windy(data, _wslink) if self.config.options.get(POCASI_CZ_ENABLED): await self.pocasi.push_data_to_server(data, "WSLINK" if _wslink else "WU") diff --git a/custom_components/sws12500/config_flow.py b/custom_components/sws12500/config_flow.py index d8b8261..b58aad0 100644 --- a/custom_components/sws12500/config_flow.py +++ b/custom_components/sws12500/config_flow.py @@ -197,13 +197,19 @@ class ConfigOptionsFlowHandler(OptionsFlow): errors=errors, ) - if (user_input[WINDY_ENABLED] is True) and ((user_input[WINDY_STATION_ID] == "") or (user_input[WINDY_STATION_PW] == "")): - errors[WINDY_STATION_ID] = "windy_key_required" - return self.async_show_form( - step_id="windy", - data_schema=vol.Schema(self.windy_data_schema), - errors=errors, - ) + station_id = (user_input.get(WINDY_STATION_ID) or "").strip() + station_pw = (user_input.get(WINDY_STATION_PW) or "").strip() + if user_input.get(WINDY_ENABLED): + if not station_id: + errors[WINDY_STATION_ID] = "windy_id_required" + if not station_pw: + errors[WINDY_STATION_PW] = "windy_pw_required" + if errors: + return self.async_show_form( + step_id="windy", + data_schema=vol.Schema(self.windy_data_schema), + errors=errors, + ) # retain user_data user_input.update(self.user_data) diff --git a/custom_components/sws12500/translations/cs.json b/custom_components/sws12500/translations/cs.json index 1c0cffb..bcd43bc 100644 --- a/custom_components/sws12500/translations/cs.json +++ b/custom_components/sws12500/translations/cs.json @@ -29,7 +29,8 @@ "valid_credentials_api": "Vyplňte platné API ID", "valid_credentials_key": "Vyplňte platný API KEY", "valid_credentials_match": "API ID a API KEY nesmějí být stejné!", - "windy_key_required": "Je vyžadován Windy API key, pokud chcete aktivovat přeposílání dat na Windy", + "windy_id_required": "Je vyžadováno Windy ID, pokud chcete aktivovat přeposílání dat na Windy", + "windy_pw_required": "Je vyžadován Windy KEY, pokud chcete aktivovat přeposílání dat na Windy", "pocasi_id_required": "Je vyžadován Počasí ID, pokud chcete aktivovat přeposílání dat na Počasí Meteo CZ", "pocasi_key_required": "Klíč k účtu Počasí Meteo je povinný.", "pocasi_send_minimum": "Minimální interval pro přeposílání je 12 sekund." diff --git a/custom_components/sws12500/translations/en.json b/custom_components/sws12500/translations/en.json index 139ab25..9abdac8 100644 --- a/custom_components/sws12500/translations/en.json +++ b/custom_components/sws12500/translations/en.json @@ -29,7 +29,8 @@ "valid_credentials_api": "Provide valid API ID.", "valid_credentials_key": "Provide valid API KEY.", "valid_credentials_match": "API ID and API KEY should not be the same.", - "windy_key_required": "Windy API key is required if you want to enable this function." + "windy_id_required": "Windy API key is required if you want to enable this function.", + "windy_pw_required": "Windy API password is required if you want to enable this function." }, "step": { "init": { diff --git a/custom_components/sws12500/windy_func.py b/custom_components/sws12500/windy_func.py index 02d6e05..63ceb1d 100644 --- a/custom_components/sws12500/windy_func.py +++ b/custom_components/sws12500/windy_func.py @@ -5,6 +5,7 @@ import logging from aiohttp.client_exceptions import ClientError +from homeassistant.components import persistent_notification from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -138,8 +139,22 @@ class WindyPush: if "t1solrad" in purged_data: purged_data["solarradiation"] = purged_data.pop("t1solrad") - windy_station_id = self.config.options.get(WINDY_STATION_ID) - windy_station_pw = self.config.options.get(WINDY_STATION_PW) + windy_station_id = self.config.options.get(WINDY_STATION_ID, "") + windy_station_pw = self.config.options.get(WINDY_STATION_PW, "") + + if windy_station_id == "" or windy_station_pw == "": + _LOGGER.error( + "Windy ID or PASSWORD is not set correctly. Please reconfigure your WINDY resend credentials. Disabling WINDY resend for now!" + ) + + persistent_notification.async_create( + self.hass, + "Your Windy credentials are not set correctly. Disabling Windy resending for now. Update Windy options and enable reseding.", + "Windy resending disabled.", + ) + + await update_options(self.hass, self.config, WINDY_ENABLED, False) + return False request_url = f"{WINDY_URL}"