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 bd6e0ff commit 6315757
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
56 changes: 50 additions & 6 deletions custom_components/solvis_control/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
Expand Down Expand Up @@ -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)
),
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand Down
27 changes: 22 additions & 5 deletions custom_components/solvis_control/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand All @@ -42,22 +45,36 @@
"data":{
"host":"IP-Adresse oder Hostname",
"port":"Port"
}
},
"description_placeholders": {
"choose_host_port": "<h2>Hostkonfiguration</h2>"
}
},
"features":{
"data":{
"hkr2":"HKR 2",
"hkr3":"HKR 3",
"solar collector":"Solar Kollektoren",
"heat pump":"Wärmepumpe"
}
},
"description_placeholders": {
"choose_device_version": "<h2>Geräteversion & Sonstiges</h2>"
}
},
"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": "<h2>Gerätefunktionen</h2>"
}
}
},
"error":{
Expand Down
27 changes: 22 additions & 5 deletions custom_components/solvis_control/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand All @@ -42,22 +45,36 @@
"data":{
"host":"IP-Adresse oder Hostname",
"port":"Port"
}
},
"description_placeholders": {
"choose_host_port": "<h2>Hostkonfiguration</h2>"
}
},
"features":{
"data":{
"hkr2":"HKR 2",
"hkr3":"HKR 3",
"solar collector":"Solar Kollektoren",
"heat pump":"Wärmepumpe"
}
},
"description_placeholders": {
"choose_device_version": "<h2>Geräteversion & Sonstiges</h2>"
}
},
"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": "<h2>Gerätefunktionen</h2>"
}
}
},
"error":{
Expand Down

0 comments on commit 6315757

Please sign in to comment.