diff --git a/custom_components/solvis_control/config_flow.py b/custom_components/solvis_control/config_flow.py index 7f8f037..3f9f672 100644 --- a/custom_components/solvis_control/config_flow.py +++ b/custom_components/solvis_control/config_flow.py @@ -1,5 +1,5 @@ import logging -from enum import Enum +from enum import IntEnum from pymodbus import ModbusException import pymodbus.client as ModbusClient @@ -10,6 +10,7 @@ from homeassistant import config_entries from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult +from homeassistant.helpers import selector from homeassistant.helpers.typing import ConfigType from homeassistant.helpers import config_validation as cv @@ -25,16 +26,23 @@ DEVICE_VERSION, POLL_RATE_DEFAULT, POLL_RATE_SLOW, + SolvisDeviceVersion, ) _LOGGER = logging.getLogger(__name__) - -class DeviceVersion(Enum): - """Enum for device versions.""" - - SC2 = 2 - SC3 = 1 +SolvisVersionSelect = selector.SelectSelector( + selector.SelectSelectorConfig( + options=[ + selector.SelectOptionDict(value=str(SolvisDeviceVersion.SC3), label="SC3"), + selector.SelectOptionDict( + value=str(SolvisDeviceVersion.SC2), + label="SC2", + ), + ], + mode=selector.SelectSelectorMode.DROPDOWN, + ) +) def validate_poll_rates(data): @@ -67,27 +75,9 @@ def get_solvis_modules(data: ConfigType) -> Schema: def get_solvis_devices(data: ConfigType) -> Schema: return vol.Schema( { - vol.Required(DEVICE_VERSION, default=DeviceVersion.SC3): vol.All( - vol.Coerce(DeviceVersion), - vol.In( - [ - vol.Schema( - { - vol.Required("value"): DeviceVersion.SC2, - vol.Required("title"): "2", - vol.Optional("description"): "sc2_description", - } - ), - vol.Schema( - { - vol.Required("value"): DeviceVersion.SC3, - vol.Required("title"): "1", - vol.Optional("description"): "sc3_description", - } - ), - ] - ), - ), + vol.Required( + DEVICE_VERSION, default=str(SolvisDeviceVersion.SC3) + ): SolvisVersionSelect, vol.Required(POLL_RATE_DEFAULT, default=30): vol.All( vol.Coerce(int), vol.Range(min=30) ), @@ -122,27 +112,9 @@ def get_solvis_modules_options(data: ConfigType) -> Schema: def get_solvis_devices_options(data: ConfigType) -> Schema: return vol.Schema( { - vol.Required(DEVICE_VERSION, default=DeviceVersion.SC3): vol.All( - vol.Coerce(DeviceVersion), - vol.In( - [ - vol.Schema( - { - vol.Required("value"): DeviceVersion.SC2, - vol.Required("title"): "2", - vol.Optional("description"): "sc2_description", - } - ), - vol.Schema( - { - vol.Required("value"): DeviceVersion.SC3, - vol.Required("title"): "1", - vol.Optional("description"): "sc3_description", - } - ), - ] - ), - ), + vol.Required( + DEVICE_VERSION, default=str(SolvisDeviceVersion.SC3) + ): SolvisVersionSelect, vol.Required(POLL_RATE_DEFAULT, default=30): vol.All( vol.Coerce(int), vol.Range(min=30) ), diff --git a/custom_components/solvis_control/const.py b/custom_components/solvis_control/const.py index 6957cae..2ebc3dd 100644 --- a/custom_components/solvis_control/const.py +++ b/custom_components/solvis_control/const.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from enum import IntEnum DOMAIN = "solvis_control" @@ -20,6 +21,13 @@ MANUFACTURER = "Solvis" +class SolvisDeviceVersion(IntEnum): + """Enum for device versions.""" + + SC2 = 2 + SC3 = 1 + + @dataclass class ModbusFieldConfig: name: str diff --git a/custom_components/solvis_control/strings.json b/custom_components/solvis_control/strings.json index e0f6558..25de78c 100644 --- a/custom_components/solvis_control/strings.json +++ b/custom_components/solvis_control/strings.json @@ -2,25 +2,24 @@ "config":{ "flow_title":"Solvis Setup", "step":{ - "user":{ + "init":{ + "description": "Solvis Control\n**Grundeinrichtung-Init**", "data":{ "name":"Anlagenname (frei)", "host":"IP-Adresse oder Hostname", "port":"Port" - }, - "description_placeholders": { - "choose_host_port": "

Hostkonfiguration

" - + } }, - "init":{ + "user":{ + "description": "Solvis Control\n**Grundeinrichtung**", "data":{ + "name":"Anlagenname (frei)", "host":"IP-Adresse oder Hostname", "port":"Port" - }, - "description_placeholders": { - "choose_device_version": "

Geräteversion & Sonstiges

" + } }, "features":{ + "description": "Solvis Control\n**Auswahl der Gerätefunktionen**", "data":{ "hkr2":"HKR 2", "hkr3":"HKR 3", @@ -29,6 +28,7 @@ } }, "device":{ + "description": "Solvis Control\n**Geräteversion & Sonstiges**", "data":{ "device_version": { "2": "SC2", @@ -36,10 +36,7 @@ }, "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 1a57a99..25de78c 100644 --- a/custom_components/solvis_control/translations/de.json +++ b/custom_components/solvis_control/translations/de.json @@ -2,20 +2,24 @@ "config":{ "flow_title":"Solvis Setup", "step":{ - "user":{ + "init":{ + "description": "Solvis Control\n**Grundeinrichtung-Init**", "data":{ "name":"Anlagenname (frei)", "host":"IP-Adresse oder Hostname", "port":"Port" } }, - "init":{ + "user":{ + "description": "Solvis Control\n**Grundeinrichtung**", "data":{ + "name":"Anlagenname (frei)", "host":"IP-Adresse oder Hostname", "port":"Port" } }, "features":{ + "description": "Solvis Control\n**Auswahl der Gerätefunktionen**", "data":{ "hkr2":"HKR 2", "hkr3":"HKR 3", @@ -24,6 +28,7 @@ } }, "device":{ + "description": "Solvis Control\n**Geräteversion & Sonstiges**", "data":{ "device_version": { "2": "SC2", @@ -79,7 +84,8 @@ } }, "error":{ - "cannot_connect":"Ein Fehler bei der Verbindung ist aufgetreten." + "cannot_connect":"Ein Fehler bei der Verbindung ist aufgetreten.", + "poll_rate_invalid": "POLL_RATE_SLOW muss ein Vielfaches von POLL_RATE_DEFAULT sein." } }, "entity":{ @@ -409,4 +415,4 @@ } } } -} \ No newline at end of file +}