Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsK1 committed Nov 29, 2024
1 parent 6a61698 commit 36005bf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 66 deletions.
70 changes: 21 additions & 49 deletions custom_components/solvis_control/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from enum import Enum
from enum import IntEnum

from pymodbus import ModbusException
import pymodbus.client as ModbusClient
Expand All @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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)
),
Expand Down Expand Up @@ -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)
),
Expand Down
8 changes: 8 additions & 0 deletions custom_components/solvis_control/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from enum import IntEnum

DOMAIN = "solvis_control"

Expand All @@ -20,6 +21,13 @@
MANUFACTURER = "Solvis"


class SolvisDeviceVersion(IntEnum):
"""Enum for device versions."""

SC2 = 2
SC3 = 1


@dataclass
class ModbusFieldConfig:
name: str
Expand Down
23 changes: 10 additions & 13 deletions custom_components/solvis_control/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<h2>Hostkonfiguration</h2>"

}
},
"init":{
"user":{
"description": "Solvis Control\n**Grundeinrichtung**",
"data":{
"name":"Anlagenname (frei)",
"host":"IP-Adresse oder Hostname",
"port":"Port"
},
"description_placeholders": {
"choose_device_version": "<h2>Geräteversion & Sonstiges</h2>"
}
},
"features":{
"description": "Solvis Control\n**Auswahl der Gerätefunktionen**",
"data":{
"hkr2":"HKR 2",
"hkr3":"HKR 3",
Expand All @@ -29,17 +28,15 @@
}
},
"device":{
"description": "Solvis Control\n**Geräteversion & Sonstiges**",
"data":{
"device_version": {
"2": "SC2",
"1": "SC3"
},
"poll_rate_default": "Standard Pollrate (in s)",
"poll_rate_slow": "Langsame Pollrate (in s)"
},
"description_placeholders": {
"choose_device_features": "<h2>Gerätefunktionen</h2>"
}
}
}
},
"error":{
Expand Down
14 changes: 10 additions & 4 deletions custom_components/solvis_control/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -24,6 +28,7 @@
}
},
"device":{
"description": "Solvis Control\n**Geräteversion & Sonstiges**",
"data":{
"device_version": {
"2": "SC2",
Expand Down Expand Up @@ -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":{
Expand Down Expand Up @@ -409,4 +415,4 @@
}
}
}
}
}

0 comments on commit 36005bf

Please sign in to comment.