From 63157570eee40ad3953c24424cc611ae41b7ff00 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Thu, 28 Nov 2024 20:56:03 +0100 Subject: [PATCH] =?UTF-8?q?Anpassungen=20f=C3=BCr=20den=20config=5Fflow.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solvis_control/config_flow.py | 56 +++++++++++++++++-- custom_components/solvis_control/strings.json | 27 +++++++-- .../solvis_control/translations/de.json | 27 +++++++-- 3 files changed, 94 insertions(+), 16 deletions(-) diff --git a/custom_components/solvis_control/config_flow.py b/custom_components/solvis_control/config_flow.py index 1920a68..62b87d8 100644 --- a/custom_components/solvis_control/config_flow.py +++ b/custom_components/solvis_control/config_flow.py @@ -59,7 +59,27 @@ def get_solvis_modules(data: ConfigType) -> Schema: def get_solvis_devices(data: ConfigType) -> Schema: return vol.Schema( { - vol.Required(DEVICE_VERSION, default="SC3"): vol.In({"SC2": 2, "SC3": 1}), + vol.Required(DEVICE_VERSION, default="SC3"): vol.All( + vol.Coerce(lambda x: {o["value"]: o["title"] for o in x}), + vol.In( + [ + vol.Schema( + { + vol.Required("value"): 2, + vol.Required("title"): "2", + vol.Optional("description"): "sc2_description", + } + ), + vol.Schema( + { + vol.Required("value"): 1, + vol.Required("title"): "1", + vol.Optional("description"): "sc3_description", + } + ), + ] + ), + ), vol.Required(POLL_RATE_DEFAULT, default=30): vol.All( vol.Coerce(int), vol.Range(min=30) ), @@ -92,9 +112,27 @@ def get_solvis_modules_options(data: ConfigType) -> Schema: def get_solvis_devices_options(data: ConfigType) -> Schema: return vol.Schema( { - vol.Required( - DEVICE_VERSION, default=data.get(DEVICE_VERSION, "SC3") - ): vol.In({"SC2": 2, "SC3": 1}), + vol.Required(DEVICE_VERSION, default="SC3"): vol.All( + vol.Coerce(lambda x: {o["value"]: o["title"] for o in x}), + vol.In( + [ + vol.Schema( + { + vol.Required("value"): 2, + vol.Required("title"): "2", + vol.Optional("description"): "sc2_description", + } + ), + vol.Schema( + { + vol.Required("value"): 1, + vol.Required("title"): "1", + vol.Optional("description"): "sc3_description", + } + ), + ] + ), + ), vol.Required(POLL_RATE_DEFAULT, default=30): vol.All( vol.Coerce(int), vol.Range(min=30) ), @@ -135,7 +173,10 @@ async def async_step_user(self, user_input: ConfigType | None = None) -> FlowRes return await self.async_step_device() return self.async_show_form( - step_id="user", data_schema=get_host_schema_config(self.data), errors=errors + step_id="user", + data_schema=get_host_schema_config(self.data), + errors=errors, + description_placeholders={"heading": "choose_host_port"}, ) async def async_step_device( @@ -154,6 +195,7 @@ async def async_step_device( step_id="device", data_schema=get_solvis_devices(self.data), errors=errors, + description_placeholders={"heading": "choose_device_version"}, ) async def async_step_features( @@ -162,7 +204,9 @@ async def async_step_features( """Handle the feature step.""" if user_input is None: return self.async_show_form( - step_id="features", data_schema=get_solvis_modules(self.data) + step_id="features", + data_schema=get_solvis_modules(self.data), + description_placeholders={"heading": "choose_device_features"}, ) self.data.update(user_input) return self.async_create_entry(title=self.data[CONF_NAME], data=self.data) diff --git a/custom_components/solvis_control/strings.json b/custom_components/solvis_control/strings.json index 8c1c2f0..795f384 100644 --- a/custom_components/solvis_control/strings.json +++ b/custom_components/solvis_control/strings.json @@ -25,7 +25,10 @@ }, "device":{ "data":{ - "device_version":"Geräteversion", + "device_version": { + "2": "SC2", + "1": "SC3" + }, "poll_rate_default": "Standard Pollrate (in s)", "poll_rate_slow": "Langsame Pollrate (in s)" } @@ -42,7 +45,10 @@ "data":{ "host":"IP-Adresse oder Hostname", "port":"Port" - } + }, + "description_placeholders": { + "choose_host_port": "

Hostkonfiguration

" + } }, "features":{ "data":{ @@ -50,14 +56,25 @@ "hkr3":"HKR 3", "solar collector":"Solar Kollektoren", "heat pump":"Wärmepumpe" - } + }, + "description_placeholders": { + "choose_device_version": "

Geräteversion & Sonstiges

" + } }, "device":{ "data":{ - "device_version":"Geräteversion", + "device_version": { + "2": "SC2", + "1": "SC3", + "sc2_description": "Hinweistext für SC2", + "sc3_description": "Hinweistext für SC3" + }, "poll_rate_default": "Standard Pollrate (in s)", "poll_rate_slow": "Langsame Pollrate (in s)" - } + }, + "description_placeholders": { + "choose_device_features": "

Gerätefunktionen

" + } } }, "error":{ diff --git a/custom_components/solvis_control/translations/de.json b/custom_components/solvis_control/translations/de.json index bfc669b..795f384 100644 --- a/custom_components/solvis_control/translations/de.json +++ b/custom_components/solvis_control/translations/de.json @@ -25,7 +25,10 @@ }, "device":{ "data":{ - "device_version": "Geräteversion", + "device_version": { + "2": "SC2", + "1": "SC3" + }, "poll_rate_default": "Standard Pollrate (in s)", "poll_rate_slow": "Langsame Pollrate (in s)" } @@ -42,7 +45,10 @@ "data":{ "host":"IP-Adresse oder Hostname", "port":"Port" - } + }, + "description_placeholders": { + "choose_host_port": "

Hostkonfiguration

" + } }, "features":{ "data":{ @@ -50,14 +56,25 @@ "hkr3":"HKR 3", "solar collector":"Solar Kollektoren", "heat pump":"Wärmepumpe" - } + }, + "description_placeholders": { + "choose_device_version": "

Geräteversion & Sonstiges

" + } }, "device":{ "data":{ - "device_version":"Geräteversion", + "device_version": { + "2": "SC2", + "1": "SC3", + "sc2_description": "Hinweistext für SC2", + "sc3_description": "Hinweistext für SC3" + }, "poll_rate_default": "Standard Pollrate (in s)", "poll_rate_slow": "Langsame Pollrate (in s)" - } + }, + "description_placeholders": { + "choose_device_features": "

Gerätefunktionen

" + } } }, "error":{