From 72ce0558101a894860fd2e3de51e72a37a7288b4 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 12 May 2025 11:21:49 +0200 Subject: [PATCH] Updated hochwasserportal integration --- .../hochwasserportal/config_flow.py | 27 +++++++++++++++++-- .../hochwasserportal/manifest.json | 4 +-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/custom_components/hochwasserportal/config_flow.py b/custom_components/hochwasserportal/config_flow.py index 94aef41..8b424b7 100644 --- a/custom_components/hochwasserportal/config_flow.py +++ b/custom_components/hochwasserportal/config_flow.py @@ -4,12 +4,18 @@ from __future__ import annotations from typing import Any -from lhpapi import HochwasserPortalAPI, LHPError +from lhpapi import HochwasserPortalAPI, LHPError, get_all_stations import voluptuous as vol from homeassistant.config_entries import ConfigFlow from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.selector import ( + SelectOptionDict, + SelectSelector, + SelectSelectorConfig, + SelectSelectorMode, +) from .const import CONF_ADD_UNAVAILABLE, CONF_PEGEL_IDENTIFIER, DOMAIN, LOGGER @@ -50,12 +56,29 @@ class HochwasserPortalConfigFlow(ConfigFlow, domain=DOMAIN): return self.async_create_entry(title=f"{api.name}", data=user_input) + stations_dict = await self.hass.async_add_executor_job(get_all_stations) + LOGGER.debug( + "%i stations found on Github", + len(stations_dict), + ) + stations = [SelectOptionDict(value="---", label="")] + stations.extend( + SelectOptionDict(value=k, label=f"{v} ({k})") + for k, v in stations_dict.items() + ) return self.async_show_form( step_id="user", errors=errors, data_schema=vol.Schema( { - vol.Required(CONF_PEGEL_IDENTIFIER): cv.string, + vol.Required(CONF_PEGEL_IDENTIFIER): SelectSelector( + SelectSelectorConfig( + options=stations, + mode=SelectSelectorMode.DROPDOWN, + sort=True, + custom_value=True, + ) + ), vol.Required(CONF_ADD_UNAVAILABLE, default=False): cv.boolean, } ), diff --git a/custom_components/hochwasserportal/manifest.json b/custom_components/hochwasserportal/manifest.json index d888608..6ac3c34 100644 --- a/custom_components/hochwasserportal/manifest.json +++ b/custom_components/hochwasserportal/manifest.json @@ -9,6 +9,6 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/stephan192/hochwasserportal/issues", "loggers": ["hochwasserportal"], - "requirements": ["lhpapi==1.0.3"], - "version": "1.0.1" + "requirements": ["lhpapi==1.0.4"], + "version": "1.0.2" } \ No newline at end of file