Skip to content

Commit

Permalink
Anpassungen für den config_flow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsK1 committed Nov 28, 2024
1 parent 6315757 commit 14065ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
30 changes: 20 additions & 10 deletions custom_components/solvis_control/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from enum import Enum

from pymodbus import ModbusException
import pymodbus.client as ModbusClient
Expand Down Expand Up @@ -29,9 +30,16 @@
_LOGGER = logging.getLogger(__name__)


class DeviceVersion(Enum):
"""Enum for device versions."""

SC2 = 2
SC3 = 1


def validate_poll_rates(data):
if data[POLL_RATE_SLOW] % data[POLL_RATE_DEFAULT] != 0:
raise vol.Invalid("POLL_RATE_SLOW must be a multiple of POLL_RATE_DEFAULT")
raise vol.Invalid(cv.string("poll_rate_invalid"))
return data


Expand Down Expand Up @@ -59,20 +67,20 @@ def get_solvis_modules(data: ConfigType) -> Schema:
def get_solvis_devices(data: ConfigType) -> Schema:
return vol.Schema(
{
vol.Required(DEVICE_VERSION, default="SC3"): vol.All(
vol.Coerce(lambda x: {o["value"]: o["title"] for o in x}),
vol.Required(DEVICE_VERSION, default=DeviceVersion.SC3): vol.All(
vol.Coerce(DeviceVersion),
vol.In(
[
vol.Schema(
{
vol.Required("value"): 2,
vol.Required("value"): DeviceVersion.SC2,
vol.Required("title"): "2",
vol.Optional("description"): "sc2_description",
}
),
vol.Schema(
{
vol.Required("value"): 1,
vol.Required("value"): DeviceVersion.SC3,
vol.Required("title"): "1",
vol.Optional("description"): "sc3_description",
}
Expand All @@ -86,7 +94,9 @@ def get_solvis_devices(data: ConfigType) -> Schema:
vol.Required(POLL_RATE_SLOW, default=300): vol.All(
vol.Coerce(int), vol.Range(min=60)
),
}
},
extra=vol.ALLOW_EXTRA,
validator=validate_poll_rates,
)


Expand All @@ -112,20 +122,20 @@ def get_solvis_modules_options(data: ConfigType) -> Schema:
def get_solvis_devices_options(data: ConfigType) -> Schema:
return vol.Schema(
{
vol.Required(DEVICE_VERSION, default="SC3"): vol.All(
vol.Coerce(lambda x: {o["value"]: o["title"] for o in x}),
vol.Required(DEVICE_VERSION, default=DeviceVersion.SC3): vol.All(
vol.Coerce(DeviceVersion),
vol.In(
[
vol.Schema(
{
vol.Required("value"): 2,
vol.Required("value"): DeviceVersion.SC2,
vol.Required("title"): "2",
vol.Optional("description"): "sc2_description",
}
),
vol.Schema(
{
vol.Required("value"): 1,
vol.Required("value"): DeviceVersion.SC3,
vol.Required("title"): "1",
vol.Optional("description"): "sc3_description",
}
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solvis_control/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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":{
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solvis_control/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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."
}
},
"options":{
Expand Down

0 comments on commit 14065ec

Please sign in to comment.