Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config data changeable in the options dialog #188

Merged
merged 32 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b18e0b8
added host, username and password to config options: #178, #184
raymanP Apr 9, 2023
77086c9
Added host, username, password option strings
raymanP Apr 9, 2023
fd28afa
added options config by source type
raymanP Apr 9, 2023
8a08a0f
fixed typo
raymanP Apr 9, 2023
556d1f1
fixed conf type
raymanP Apr 9, 2023
496caa2
options added validate host
raymanP Apr 10, 2023
4804a35
try fix config
raymanP Apr 10, 2023
b0cf0d9
more options changes
raymanP Apr 10, 2023
6b22e66
added tcp options
raymanP Apr 10, 2023
62824c6
updated options DE
raymanP Apr 10, 2023
c2a5a4c
Updated options EN
raymanP Apr 10, 2023
301810e
Updated options NL
raymanP Apr 10, 2023
3d5bb61
fixed config update
raymanP Apr 10, 2023
6b0b4a5
fixed integration don't update title
raymanP Apr 10, 2023
31d1f48
added errors to options
raymanP Apr 10, 2023
3d277d0
removed unneeded entry in options
raymanP Apr 10, 2023
c5ccb43
added name config in options
raymanP Apr 10, 2023
e1103fd
fixed options
raymanP Apr 10, 2023
a5c4a9a
fixed config options typo
raymanP Apr 10, 2023
810f021
updated DE
raymanP Apr 10, 2023
dee01d4
Updated EN
raymanP Apr 10, 2023
5a50458
Updated NL
raymanP Apr 10, 2023
071bb80
Updated strings (added name)
raymanP Apr 10, 2023
73415c9
change name only if specified
raymanP Apr 10, 2023
b1925b0
Updated DE
raymanP Apr 10, 2023
e9cc982
Updated EN
raymanP Apr 10, 2023
cf0bd1e
Updated NL
raymanP Apr 10, 2023
389b700
fixed empty name in options
raymanP Apr 10, 2023
a8141a9
Fixed setting empty name
raymanP Apr 10, 2023
a11b14f
added default name in options
Apr 10, 2023
89ebea6
fixed black code formating
raymanP Apr 11, 2023
a7f2e5b
Remove trailing white space
robbinjanssen Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 72 additions & 12 deletions custom_components/omnik_inverter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
)
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.selector import (
TextSelector,
TextSelectorConfig,
TextSelectorType,
)
from omnikinverter import OmnikInverter, OmnikInverterError

from .const import (
Expand Down Expand Up @@ -274,6 +279,7 @@ def __init__(self, config_entry: ConfigEntry) -> None:
config_entry: The ConfigEntry instance.
"""
self.config_entry = config_entry
self.source_type = config_entry.data[CONF_SOURCE_TYPE]

async def async_step_init(
self, user_input: dict[str, Any] | None = None
Expand All @@ -287,20 +293,74 @@ async def async_step_init(
Returns:
The created config entry.
"""
errors = {}

if user_input is not None:
return self.async_create_entry(title="", data=user_input)
try:
await validate_input(user_input)
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
except Exception as error: # pylint: disable=broad-except
errors["base"] = str(error)
else:
updated_config = {CONF_SOURCE_TYPE: self.source_type}
for key in (CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_SERIAL):
if key in user_input:
updated_config[key] = user_input[key]

self.hass.config_entries.async_update_entry(
self.config_entry,
data=updated_config,
title=user_input.get(CONF_NAME),
)

options = {}
for key in (CONF_SCAN_INTERVAL, CONF_USE_CACHE):
options[key] = user_input[key]
return self.async_create_entry(title="", data=options)

fields = {
vol.Optional(
CONF_NAME,
default=self.config_entry.title,
): str,
vol.Required(
CONF_HOST,
default=self.config_entry.data.get(CONF_HOST),
): str,
}

if self.source_type == "html":
fields[
vol.Required(
CONF_USERNAME, default=self.config_entry.data.get(CONF_USERNAME)
)
] = str
fields[
vol.Required(
CONF_PASSWORD, default=self.config_entry.data.get(CONF_PASSWORD)
)
] = TextSelector(TextSelectorConfig(type=TextSelectorType.PASSWORD))
elif self.source_type == "tcp":
fields[
vol.Required(
CONF_SERIAL, default=self.config_entry.data.get(CONF_SERIAL)
)
] = str

fields[
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
)
] = vol.All(vol.Coerce(int), vol.Range(min=1))
fields[vol.Optional(CONF_USE_CACHE, default=False)] = bool

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
): vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Optional(CONF_USE_CACHE, default=False): bool,
}
),
data_schema=vol.Schema(fields),
errors=errors,
)
4 changes: 4 additions & 0 deletions custom_components/omnik_inverter/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
"init": {
"description": "Change the way the integration fetches your Omnik Inverter.",
"data": {
"name": "[%key:common::config_flow::data::name%]",
"host": "[%key:common::config_flow::data::host%]",
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]",
"scan_interval": "Minimum time between entity updates [m]",
"use_cache": "Cache the total power of today"
}
Expand Down
5 changes: 5 additions & 0 deletions custom_components/omnik_inverter/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"step": {
"init": {
"data": {
"name": "Name",
"host": "Host",
"username": "Benutzername",
"password": "Passwort",
"serial": "Seriennummer",
"scan_interval": "Aktualisierungsintervall der Daten (Minuten)",
"use_cache": "Den gesamten Tagesumsatz zwischenspeichern"
},
Expand Down
5 changes: 5 additions & 0 deletions custom_components/omnik_inverter/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"step": {
"init": {
"data": {
"name": "Name",
"host": "Host",
"username": "Username",
"password": "Password",
"serial": "Serial Number",
"scan_interval": "Minimum time between entity updates [m]",
"use_cache": "Cache the total power of today"
},
Expand Down
5 changes: 5 additions & 0 deletions custom_components/omnik_inverter/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"step": {
"init": {
"data": {
"name": "Naam",
"host": "Host",
"username": "Gebruikersnaam",
"password": "Wachtwoord",
"serial": "Serienummer",
"scan_interval": "Minimale tijd tussen entiteitsupdates [m]",
"use_cache": "Cache de dagopbrengst"
},
Expand Down