Skip to content

Commit c2da561

Browse files
authored
Update config_flow.py
1 parent 760c5ce commit c2da561

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

custom_components/apsystems_ecu_proxy/config_flow.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
_LOGGER = logging.getLogger(__name__)
1010

11+
1112
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
1213
"""First start of integration settings."""
1314
VERSION = 1
@@ -17,12 +18,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
1718
@callback
1819
def async_get_options_flow(config_entry):
1920
"""Get stored configuration data to present in async_step_init."""
20-
_LOGGER.warning("async_get_options_flow called: %s", config_entry)
21+
_LOGGER.debug("async_get_options_flow called: %s", config_entry)
2122
return OptionsFlowHandler(config_entry)
2223

2324
async def async_step_user(self, user_input=None):
2425
"""First step: Initial set-up of integration options."""
25-
_LOGGER.warning("async_step_user")
26+
_LOGGER.debug("async_step_user")
2627
schema = vol.Schema({
2728
vol.Required("ema_host", default="3.67.1.32"): str,
2829
vol.Required("message_ignore_age", default="1800"): str,
@@ -32,9 +33,8 @@ async def async_step_user(self, user_input=None):
3233
})
3334

3435
if user_input is not None:
35-
ema_host = user_input["ema_host"]
36-
if await OptionsFlowHandler.validate_ip(ema_host):
37-
return self.async_create_entry(title="", data=user_input)
36+
if await OptionsFlowHandler.validate_ip(user_input["ema_host"]):
37+
return self.async_create_entry(title="APsystems ECU proxy", data=user_input)
3838
else:
3939
return self.async_show_form(
4040
step_id="user",
@@ -44,7 +44,6 @@ async def async_step_user(self, user_input=None):
4444
return self.async_show_form(step_id="user", data_schema=schema)
4545

4646

47-
4847
class OptionsFlowHandler(config_entries.OptionsFlow):
4948
"""Regular change of integration options."""
5049
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
@@ -57,14 +56,18 @@ async def async_step_init(self, user_input=None):
5756
if not self.config_entry.options
5857
else self.config_entry.options
5958
)
60-
_LOGGER.warning("async_step_init with options: %s", current_options)
59+
_LOGGER.debug("async_step_init with options: %s", current_options)
6160

61+
keys = [
62+
"ema_host",
63+
"message_ignore_age",
64+
"max_stub_interval",
65+
"no_update_timeout",
66+
"send_to_ema"
67+
]
6268
schema = vol.Schema({
63-
vol.Required("ema_host", default=current_options.get("ema_host")): str,
64-
vol.Required("message_ignore_age", default=current_options.get("message_ignore_age")): str,
65-
vol.Required("max_stub_interval", default=current_options.get("max_stub_interval")): str,
66-
vol.Required("no_update_timeout", default=current_options.get("no_update_timeout")): str,
67-
vol.Required("send_to_ema", default=current_options.get("send_to_ema")): bool,
69+
vol.Required(key, default=current_options.get(key)): str if key != "send_to_ema" else bool
70+
for key in keys
6871
})
6972

7073
if user_input is not None:
@@ -88,6 +91,3 @@ async def validate_ip(ip_address: str) -> bool:
8891
return True
8992
except (OSError, asyncio.TimeoutError):
9093
return False
91-
92-
class CannotConnect(exceptions.HomeAssistantError):
93-
"""Error to indicate we cannot connect."""

0 commit comments

Comments
 (0)