Compare commits
1 Commits
732ff47036
...
f789b754f0
| Author | SHA1 | Date |
|---|---|---|
|
|
f789b754f0 |
|
|
@ -52,7 +52,6 @@ class WeatherDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
"""Init global updater."""
|
||||
self.hass = hass
|
||||
self.config = config
|
||||
self.config_entry = config
|
||||
self.windy = WindyPush(hass, config)
|
||||
self.pocasi: PocasiPush = PocasiPush(hass, config)
|
||||
super().__init__(hass, _LOGGER, name=DOMAIN)
|
||||
|
|
|
|||
|
|
@ -40,10 +40,9 @@ class InvalidAuth(HomeAssistantError):
|
|||
class ConfigOptionsFlowHandler(OptionsFlow):
|
||||
"""Handle WeatherStation ConfigFlow."""
|
||||
|
||||
def __init__(self, config_entry) -> None:
|
||||
def __init__(self) -> None:
|
||||
"""Initialize flow."""
|
||||
super().__init__()
|
||||
self.config_entry = config_entry
|
||||
|
||||
self.windy_data: dict[str, Any] = {}
|
||||
self.windy_data_schema = {}
|
||||
|
|
@ -54,15 +53,18 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
self.pocasi_cz: dict[str, Any] = {}
|
||||
self.pocasi_cz_schema = {}
|
||||
|
||||
@property
|
||||
def config_entry(self):
|
||||
return self.hass.config_entries.async_get_entry(self.handler)
|
||||
|
||||
async def _get_entry_data(self):
|
||||
"""Get entry data."""
|
||||
entry_data = {**self.config_entry.data, **self.config_entry.options}
|
||||
|
||||
self.user_data = {
|
||||
API_ID: entry_data.get(API_ID),
|
||||
API_KEY: entry_data.get(API_KEY),
|
||||
WSLINK: entry_data.get(WSLINK, False),
|
||||
DEV_DBG: entry_data.get(DEV_DBG, False),
|
||||
API_ID: self.config_entry.options.get(API_ID),
|
||||
API_KEY: self.config_entry.options.get(API_KEY),
|
||||
WSLINK: self.config_entry.options.get(WSLINK, False),
|
||||
DEV_DBG: self.config_entry.options.get(DEV_DBG, False),
|
||||
}
|
||||
|
||||
self.user_data_schema = {
|
||||
|
|
@ -74,17 +76,19 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
|
||||
self.sensors = {
|
||||
SENSORS_TO_LOAD: (
|
||||
entry_data.get(SENSORS_TO_LOAD)
|
||||
if isinstance(entry_data.get(SENSORS_TO_LOAD), list)
|
||||
self.config_entry.options.get(SENSORS_TO_LOAD)
|
||||
if isinstance(self.config_entry.options.get(SENSORS_TO_LOAD), list)
|
||||
else []
|
||||
)
|
||||
}
|
||||
|
||||
self.windy_data = {
|
||||
WINDY_STATION_ID: entry_data.get(WINDY_STATION_ID),
|
||||
WINDY_STATION_PW: entry_data.get(WINDY_STATION_PW),
|
||||
WINDY_ENABLED: entry_data.get(WINDY_ENABLED, False),
|
||||
WINDY_LOGGER_ENABLED: entry_data.get(WINDY_LOGGER_ENABLED, False),
|
||||
WINDY_STATION_ID: self.config_entry.options.get(WINDY_STATION_ID),
|
||||
WINDY_STATION_PW: self.config_entry.options.get(WINDY_STATION_PW),
|
||||
WINDY_ENABLED: self.config_entry.options.get(WINDY_ENABLED, False),
|
||||
WINDY_LOGGER_ENABLED: self.config_entry.options.get(
|
||||
WINDY_LOGGER_ENABLED, False
|
||||
),
|
||||
}
|
||||
|
||||
self.windy_data_schema = {
|
||||
|
|
@ -103,11 +107,15 @@ class ConfigOptionsFlowHandler(OptionsFlow):
|
|||
}
|
||||
|
||||
self.pocasi_cz = {
|
||||
POCASI_CZ_API_ID: entry_data.get(POCASI_CZ_API_ID, ""),
|
||||
POCASI_CZ_API_KEY: entry_data.get(POCASI_CZ_API_KEY, ""),
|
||||
POCASI_CZ_ENABLED: entry_data.get(POCASI_CZ_ENABLED, False),
|
||||
POCASI_CZ_LOGGER_ENABLED: entry_data.get(POCASI_CZ_LOGGER_ENABLED, False),
|
||||
POCASI_CZ_SEND_INTERVAL: entry_data.get(POCASI_CZ_SEND_INTERVAL, 30),
|
||||
POCASI_CZ_API_ID: self.config_entry.options.get(POCASI_CZ_API_ID, ""),
|
||||
POCASI_CZ_API_KEY: self.config_entry.options.get(POCASI_CZ_API_KEY, ""),
|
||||
POCASI_CZ_ENABLED: self.config_entry.options.get(POCASI_CZ_ENABLED, False),
|
||||
POCASI_CZ_LOGGER_ENABLED: self.config_entry.options.get(
|
||||
POCASI_CZ_LOGGER_ENABLED, False
|
||||
),
|
||||
POCASI_CZ_SEND_INTERVAL: self.config_entry.options.get(
|
||||
POCASI_CZ_SEND_INTERVAL, 30
|
||||
),
|
||||
}
|
||||
|
||||
self.pocasi_cz_schema = {
|
||||
|
|
@ -302,4 +310,4 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
@callback
|
||||
def async_get_options_flow(config_entry) -> ConfigOptionsFlowHandler:
|
||||
"""Get the options flow for this handler."""
|
||||
return ConfigOptionsFlowHandler(config_entry)
|
||||
return ConfigOptionsFlowHandler()
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@
|
|||
"issue_tracker": "https://github.com/schizza/SWS-12500-custom-component/issues",
|
||||
"requirements": [],
|
||||
"ssdp": [],
|
||||
"version": "1.8.3",
|
||||
"version": "1.8.1",
|
||||
"zeroconf": []
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ class Routes:
|
|||
def switch_route(self, coordinator: Callable, url_path: str):
|
||||
"""Switch route."""
|
||||
|
||||
for route in self.routes.values():
|
||||
if route.url_path == url_path:
|
||||
for url, route in self.routes.items():
|
||||
if url == url_path:
|
||||
_LOGGER.info("New coordinator to route: %s", route.url_path)
|
||||
route.enabled = True
|
||||
route.handler = coordinator
|
||||
|
|
@ -52,20 +52,18 @@ class Routes:
|
|||
enabled: bool = False,
|
||||
):
|
||||
"""Add route."""
|
||||
key = f"{route.method}:{url_path}"
|
||||
self.routes[key] = Route(url_path, route, handler, enabled)
|
||||
self.routes[url_path] = Route(url_path, route, handler, enabled)
|
||||
|
||||
def get_route(self, url_path: str) -> Route | None:
|
||||
def get_route(self, url_path: str) -> Route:
|
||||
"""Get route."""
|
||||
for route in self.routes.values():
|
||||
if route.url_path == url_path:
|
||||
return route
|
||||
return None
|
||||
return self.routes.get(url_path, Route)
|
||||
|
||||
def get_enabled(self) -> str:
|
||||
"""Get enabled routes."""
|
||||
enabled_routes = {route.url_path for route in self.routes.values() if route.enabled}
|
||||
return ", ".join(sorted(enabled_routes)) if enabled_routes else "None"
|
||||
enabled_routes = [
|
||||
route.url_path for route in self.routes.values() if route.enabled
|
||||
]
|
||||
return "".join(enabled_routes) if enabled_routes else "None"
|
||||
|
||||
def __str__(self):
|
||||
"""Return string representation."""
|
||||
|
|
|
|||
|
|
@ -139,12 +139,10 @@ class WindyPush:
|
|||
if "t1solrad" in purged_data:
|
||||
purged_data["solarradiation"] = purged_data.pop("t1solrad")
|
||||
|
||||
windy_station_id = (self.config.options.get(WINDY_STATION_ID) or "").strip()
|
||||
windy_station_pw = (self.config.options.get(WINDY_STATION_PW) or "").strip()
|
||||
windy_station_id = self.config.options.get(WINDY_STATION_ID, "")
|
||||
windy_station_pw = self.config.options.get(WINDY_STATION_PW, "")
|
||||
|
||||
# Both values are required. Options can sometimes be None, so normalize to
|
||||
# empty string and strip whitespace before validating.
|
||||
if not windy_station_id or not 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!"
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue