-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_flow.py
60 lines (48 loc) · 2.68 KB
/
config_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
from .const import DOMAIN, CONF_HOST, CONF_PORT, CONF_UNIT_ID, CONF_POLLING_INTERVAL, CONF_NAME
DATA_SCHEMA = vol.Schema({
vol.Required(CONF_NAME, default="Powerbox", description="Device name"): str,
vol.Required(CONF_HOST, default="powerbox.local", description="Powerbox hostname or IP address"): str,
vol.Required(CONF_PORT, default=502, description="Modbus TCP port of the powerbox"): int,
vol.Required(CONF_UNIT_ID, default=10, description="Modbus Unit ID of the powerbox"): int,
vol.Required(CONF_POLLING_INTERVAL, default=5, description="Modbus polling interval"): int,
})
@config_entries.HANDLERS.register(DOMAIN)
class PowerboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for Modbus Integration."""
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
return self.async_create_entry(title=f"{user_input[CONF_NAME]}", data=user_input)
# placeholders = {
# "host": self.hass.config.components["homeassistant"].translations["en"]["config"]["step"]["user"]["host"],
# "port": self.hass.config.components["homeassistant"].translations["en"]["config"]["step"]["user"]["port"],
# }
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA, errors=errors)
# @staticmethod
# @callback
# def async_get_options_flow(config_entry):
# """Return the options flow."""
# return OptionsFlow(config_entry)
# class OptionsFlow(config_entries.OptionsFlow):
# """Options flow for Modbus Integration."""
# def __init__(self, config_entry):
# self.config_entry = config_entry
# async def async_step_init(self, user_input=None):
# if user_input is not None:
# return self.async_create_entry(title="", data=user_input)
# data_schema = vol.Schema(DATA_SCHEMA)
# self.add_suggested_values_to_schema
# current_options = self.config_entry.options
# # vol.Schema({
# # vol.Required(CONF_HOST, default=current_options.get(CONF_HOST, "powerbox.local")): str,
# # vol.Required(CONF_PORT, default=current_options.get(CONF_PORT, 502)): int,
# # vol.Required(CONF_UNIT_ID, default=current_options.get(CONF_UNIT_ID, 10)): int,
# # vol.Required(CONF_POLLING_INTERVAL, default=current_options.get(CONF_POLLING_INTERVAL, 5)): int,
# # })
# return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)