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

Fixed configuration failing #86

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions custom_components/goecharger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ async def async_setup_entry(hass, config):
_LOGGER.debug("async_Setup_entry")
_LOGGER.debug(repr(config.data))

config.async_on_unload(config.add_update_listener(update_listener))

name = config.data[CONF_NAME]
charger = GoeCharger(config.data[CONF_HOST])
hass.data[DOMAIN]["api"][name] = charger
Expand All @@ -74,6 +76,25 @@ async def async_setup_entry(hass, config):
)
return True

async def update_listener(hass, config):
"""Handle options update."""
_LOGGER.debug("update_listener")

name = config.data[CONF_NAME]
charger = GoeCharger(config.data[CONF_HOST])
hass.data[DOMAIN]["api"][name] = charger

await hass.data[DOMAIN]["coordinator"].async_refresh()

hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config, "sensor")
)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config, "switch")
)

return True


async def async_unload_entry(hass, entry):
_LOGGER.debug(f"Unloading charger '{entry.data[CONF_NAME]}")
Expand Down
41 changes: 40 additions & 1 deletion custom_components/goecharger/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from datetime import timedelta
from typing import Any
import voluptuous as vol

from homeassistant import config_entries
Expand All @@ -20,7 +21,8 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

@staticmethod
@callback
async def async_get_options_flow(config_entry):
def async_get_options_flow(config_entry: config_entries.ConfigEntry) -> config_entries.OptionsFlow:
"""Create the options flow."""
return OptionsFlowHandler(config_entry)

async def async_step_user(self, info):
Expand All @@ -42,3 +44,40 @@ async def async_step_user(self, info):
}
),
)

class OptionsFlowHandler(config_entries.OptionsFlow):
"""Options flow for the go-eCharger"""

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
""""Initialize options flow"""
self.config_entry = config_entry

async def async_step_init(self, user_input: dict[str, Any] | None = None) -> config_entries.FlowResult:
"""Manage options for the goe-Charger component"""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

# Gets current values from config entry. If no options are set, the values from the setup are used
if len(self.config_entry.options) == 0:
current_host = self.config_entry.data.get(CONF_HOST)
current_scan_interval = self.config_entry.data.get(CONF_SCAN_INTERVAL)
current_correction_factor = self.config_entry.data.get(CONF_CORRECTION_FACTOR)
else:
current_host = self.config_entry.options.get(CONF_HOST)
current_scan_interval = self.config_entry.options.get(CONF_SCAN_INTERVAL)
current_correction_factor = self.config_entry.options.get(CONF_CORRECTION_FACTOR)

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=current_host): str,
vol.Optional(
CONF_SCAN_INTERVAL, default=current_scan_interval if current_scan_interval else 20
): int,
vol.Required(
CONF_CORRECTION_FACTOR, default=current_correction_factor if current_correction_factor else "1.0"
): str,
}
)
)
18 changes: 17 additions & 1 deletion custom_components/goecharger/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"step": {
"user": {
"title": "go-eCharger Setup",
"description": "Ein Liste möglicher Konfigurationsparameter findest du hier : https://github.com/cathiele/homeassistant-goecharger",
"description": "Ein Liste möglicher Konfigurationsparameter findest du hier : https://github.com/cathiele/homeassistant-goecharger",
"data": {
"host": "Hostname oder IP-Address im lokalen Netzwerk",
"name": "Im Homeassistant eindeutiger Name des Chargers",
Expand All @@ -15,5 +15,21 @@
},
"abort": {
}
},
"options": {
"title": "go-eCharger konfigurieren",
"step": {
"init": {
"title": "go-eCharger Konfiguration",
"description": "Ein Liste möglicher Konfigurationsparameter findest du hier : https://github.com/cathiele/homeassistant-goecharger",
"data": {
"host": "Hostname oder IP-Address im lokalen Netzwerk",
"scan_interval": "Abfrageintervall in Sekunden",
"correction_factor": "Korrekturfaktor für ungenaue Spannungsmessung"
}
}
},
"abort": {
}
}
}
18 changes: 17 additions & 1 deletion custom_components/goecharger/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"step": {
"user": {
"title": "go-eCharger Setup",
"description": "If you need help with the configuration have a look here: https://github.com/cathiele/homeassistant-goecharger",
"description": "If you need help with the configuration have a look here: https://github.com/cathiele/homeassistant-goecharger",
"data": {
"host": "Hostname or IP-Address in the local network",
"name": "uniq name of the charger",
Expand All @@ -15,5 +15,21 @@
},
"abort": {
}
},
"options": {
"title": "Configure go-eCharger",
"step": {
"init": {
"title": "go-eCharger Configuration",
"description": "If you need help with the configuration have a look here: https://github.com/cathiele/homeassistant-goecharger",
"data": {
"host": "Hostname or IP-Address in the local network",
"scan_interval": "Pollinterval in seconds",
"correction_factor": "correction Factor for incorrect Voltage measurement"
}
}
},
"abort": {
}
}
}