diff --git a/custom_components/solvis_control/config_flow.py b/custom_components/solvis_control/config_flow.py index 401ee0f..a2dbdbf 100644 --- a/custom_components/solvis_control/config_flow.py +++ b/custom_components/solvis_control/config_flow.py @@ -45,15 +45,6 @@ def __init__(self) -> None: self.data: ConfigType = {} self.client = None - # @staticmethod - # @callback - # def async_get_options_flow( - # entry: config_entries.ConfigEntry, - # ) -> config_entries.OptionsFlow: - # """Get the options flow for this handler.""" - # _LOGGER.debug(f'config_flow.py:ConfigFlow.async_get_options_flow: {entry}') - # return SolvisOptionsFlow(entry) - async def async_step_user( self, user_input: dict[str, str, int] | None = None ) -> FlowResult: @@ -66,11 +57,13 @@ async def async_step_user( await self.async_set_unique_id(self.data[CONF_HOST], raise_on_progress=False) self._abort_if_unique_id_configured() - return self.async_create_entry( - title=self.data[CONF_NAME], data=self.data) + return self.async_create_entry(title=self.data[CONF_NAME], data=self.data) + @staticmethod @callback - def async_get_options_flow(config_entry: config_entries.ConfigEntry,) -> config_entries.OptionsFlow: + def async_get_options_flow( + config_entry: config_entries.ConfigEntry, + ) -> config_entries.OptionsFlow: """Create the options flow.""" return SolvisOptionsFlow(config_entry) @@ -90,7 +83,7 @@ def async_get_options_flow(config_entry: config_entries.ConfigEntry,) -> config_ # _LOGGER.debug(f"Received ModbusException({exc}) from library") # else: # await self.client.close() - + # errors["base"] = "cannot_connect" # return self.async_show_form( @@ -98,7 +91,7 @@ def async_get_options_flow(config_entry: config_entries.ConfigEntry,) -> config_ # ) -class SolvisOptionsFlow(config_entries.OptionsFlow, domain=DOMAIN): +class SolvisOptionsFlow(config_entries.OptionsFlow): # The schema version of the entries that it creates # Home Assistant will call your migrate method if the version changes VERSION = 1 @@ -106,7 +99,8 @@ class SolvisOptionsFlow(config_entries.OptionsFlow, domain=DOMAIN): def __init__(self, config) -> None: """Init the ConfigFlow.""" - self.data: ConfigType = config + self.config: ConfigType = config + self.data = dict(config.data) self.client = None async def async_step_init( @@ -115,29 +109,10 @@ async def async_step_init( """Handle the initial step.""" if user_input is None: return self.async_show_form( - step_id="user", data_schema=get_host_schema_options(self.data) + step_id="init", + data_schema=get_host_schema_options(self.data), ) self.data = user_input return self.async_create_entry( - title=self.data[CONF_NAME], data=self.data - ) - # errors = {} - # try: - # self.client = ModbusClient.AsyncModbusTcpClient( - # user_input[CONF_HOST], user_input[CONF_PORT] - # ) - # await self.client.connect() - # except ConnectionException: - # errors["base"] = "Es konnte keine Verbinung aufgebaut werden" - # else: - # try: - # rr = await self.client.read_coils(32770, 3, slave=1) - # except ModbusException as exc: - # print(f"Received ModbusException({exc}) from library") - # finally: - # await self.client.close() - # errors["base"] = "cannot_connect" - - # return self.async_show_form( - # step_id="init", data_schema=self.data_schema, errors=errors - # ) + title=self.config_entry.get(CONF_NAME), data=self.data + ) diff --git a/custom_components/solvis_control/strings.json b/custom_components/solvis_control/strings.json index 3d62abf..945559f 100644 --- a/custom_components/solvis_control/strings.json +++ b/custom_components/solvis_control/strings.json @@ -8,7 +8,13 @@ "host": "host", "port": "port" } - } + }, + "init": { + "data": { + "host": "host", + "port": "port" + } + } }, "abort": { "already_configured": "Device is already configured" diff --git a/custom_components/solvis_control/translations/de.json b/custom_components/solvis_control/translations/de.json index 3d62abf..76c040e 100644 --- a/custom_components/solvis_control/translations/de.json +++ b/custom_components/solvis_control/translations/de.json @@ -1,14 +1,20 @@ { "config": { - "flow_title": "Solvis Setup", + "flow_title": "Solvis Einrichtung", "step": { "user": { "data": { - "name": "name", - "host": "host", - "port": "port" + "name": "Gerätename", + "host": "Host", + "port": "Port" } - } + }, + "init": { + "data": { + "host": "Host", + "port": "Port" + } + } }, "abort": { "already_configured": "Device is already configured" diff --git a/custom_components/solvis_control/translations/en.json b/custom_components/solvis_control/translations/en.json index d2a3324..f78b643 100644 --- a/custom_components/solvis_control/translations/en.json +++ b/custom_components/solvis_control/translations/en.json @@ -1,22 +1,28 @@ { - "config": { - "flow_title": "Solvis Setup", - "step": { - "user": { - "data": { - "name": "name", - "host": "host", - "port": "port" - } - } - }, - "abort": { - "already_configured": "Device is already configured" + "config": { + "flow_title": "Solvis Setup", + "step": { + "user": { + "data": { + "name": "Name", + "host": "Host", + "port": "Port" + } }, - "error": { - "cannot_connect": "Failed to connect", - "invalid_auth": "Invalid authentication", - "unknown": "Unexpected error" - } + "init": { + "data": { + "host": "Host", + "port": "Port" } + } + }, + "abort": { + "already_configured": "Device is already configured" + }, + "error": { + "cannot_connect": "Failed to connect", + "invalid_auth": "Invalid authentication", + "unknown": "Unexpected error" + } } + }