diff --git a/custom_components/solaredge_modbus_multi/config_flow.py b/custom_components/solaredge_modbus_multi/config_flow.py index 2c4bd854..9507bea6 100644 --- a/custom_components/solaredge_modbus_multi/config_flow.py +++ b/custom_components/solaredge_modbus_multi/config_flow.py @@ -8,7 +8,7 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol from homeassistant import config_entries -from homeassistant.config_entries import ConfigEntry, OptionsFlow +from homeassistant.config_entries import ConfigEntry, ConfigFlowResult, OptionsFlow from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_SCAN_INTERVAL from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult @@ -17,6 +17,10 @@ from .const import ( DEFAULT_NAME, DOMAIN, + SETUP_MANUAL, + SETUP_SCAN, + SETUP_SCAN_FULL, + SETUP_TYPE, ConfDefaultFlag, ConfDefaultInt, ConfDefaultStr, @@ -59,8 +63,58 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow: async def async_step_user( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: - """Handle the initial config flow step.""" + ) -> ConfigFlowResult: + """Handle the initial step.""" + data_schema = vol.Schema( + { + vol.Required(SETUP_TYPE, default=SETUP_SCAN): vol.In( + ( + SETUP_SCAN, + SETUP_SCAN_FULL, + SETUP_MANUAL, + ) + ) + } + ) + + if user_input is None: + return self.async_show_form( + step_id="user", + data_schema=data_schema, + ) + + if user_input[SETUP_TYPE] == SETUP_MANUAL: + return await self.async_step_manual() + if user_input[SETUP_TYPE] == SETUP_SCAN_FULL: + return await self.async_step_scan_full() + return await self.async_step_scan() + + async def async_step_scan( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """ + Handle the scan config flow step. + Quick scan only scans the first 32 IDs (Scan IDs 1-32) + """ + errors = {} + + raise HomeAssistantError("async_step_scan") + + async def async_step_scan_full( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """ + Handle the full scan config flow step. + Full scan will scan all possible IDs (Scan IDs 1-247) + """ + errors = {} + + raise HomeAssistantError("async_step_scan_full") + + async def async_step_manual( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Handle the manual config flow step.""" errors = {} if user_input is not None: @@ -105,14 +159,27 @@ async def async_step_user( } return self.async_show_form( - step_id="user", - data_schema=generate_config_schema("user", user_input), + step_id="manual", + data_schema=vol.Schema( + { + vol.Optional(CONF_NAME, default=user_input[CONF_NAME]): cv.string, + vol.Required(CONF_HOST, default=user_input[CONF_HOST]): cv.string, + vol.Required(CONF_PORT, default=user_input[CONF_PORT]): vol.Coerce( + int + ), + vol.Required( + f"{ConfName.DEVICE_LIST}", + default=user_input[ConfName.DEVICE_LIST], + ): cv.string, + }, + ), + errors=errors, ) async def async_step_reconfigure( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Handle the reconfigure flow step.""" errors = {} config_entry = self.hass.config_entries.async_get_entry( @@ -185,7 +252,7 @@ class SolaredgeModbusMultiOptionsFlowHandler(OptionsFlow): async def async_step_init( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Handle the initial options flow step.""" errors = {} @@ -274,7 +341,7 @@ async def async_step_init( async def async_step_battery_options( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Battery Options""" errors = {} @@ -331,7 +398,7 @@ async def async_step_battery_options( async def async_step_adv_pwr_ctl( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Power Control Options""" errors = {} diff --git a/custom_components/solaredge_modbus_multi/const.py b/custom_components/solaredge_modbus_multi/const.py index 194c92b0..7d3bd1e0 100644 --- a/custom_components/solaredge_modbus_multi/const.py +++ b/custom_components/solaredge_modbus_multi/const.py @@ -9,6 +9,11 @@ DOMAIN = "solaredge_modbus_multi" DEFAULT_NAME = "SolarEdge" +SETUP_TYPE = "setup_type" +SETUP_SCAN = "Scanning Setup" # Scan IDs 1-32 +SETUP_SCAN_FULL = "Scanning Setup (Full)" # Scan IDs 1-247 +SETUP_MANUAL = "Manual Setup" + # raise a startup exception if pymodbus version is less than this PYMODBUS_REQUIRED_VERSION = "3.8.3" diff --git a/custom_components/solaredge_modbus_multi/strings.json b/custom_components/solaredge_modbus_multi/strings.json index 04885772..f3c3f1c6 100644 --- a/custom_components/solaredge_modbus_multi/strings.json +++ b/custom_components/solaredge_modbus_multi/strings.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "SolarEdge Modbus Configuration", + "data": { + "setup_type": "Choose a Setup Method" + } + }, + "manual": { + "title": "Manual Modbus Configuration", "data": { "name": "Sensor Prefix", "host": "Inverter IP Address", diff --git a/custom_components/solaredge_modbus_multi/translations/de.json b/custom_components/solaredge_modbus_multi/translations/de.json index 151fa867..56db418c 100644 --- a/custom_components/solaredge_modbus_multi/translations/de.json +++ b/custom_components/solaredge_modbus_multi/translations/de.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "SolarEdge Modbus-Konfiguration", + "data": { + "setup_type": "Wählen Sie eine Einrichtungsmethode" + } + }, + "manual": { + "title": "Manuelle Modbus-Konfiguration", "data": { "name": "Sensorpräfix", "host": "Wechselrichter-IP-Adresse", diff --git a/custom_components/solaredge_modbus_multi/translations/en.json b/custom_components/solaredge_modbus_multi/translations/en.json index 04885772..f3c3f1c6 100644 --- a/custom_components/solaredge_modbus_multi/translations/en.json +++ b/custom_components/solaredge_modbus_multi/translations/en.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "SolarEdge Modbus Configuration", + "data": { + "setup_type": "Choose a Setup Method" + } + }, + "manual": { + "title": "Manual Modbus Configuration", "data": { "name": "Sensor Prefix", "host": "Inverter IP Address", diff --git a/custom_components/solaredge_modbus_multi/translations/fr.json b/custom_components/solaredge_modbus_multi/translations/fr.json index 082628dd..140df429 100644 --- a/custom_components/solaredge_modbus_multi/translations/fr.json +++ b/custom_components/solaredge_modbus_multi/translations/fr.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "Configuration SolarEdge Modbus", + "data": { + "setup_type": "Choisissez une méthode de configuration" + } + }, + "manual": { + "title": "Configuration Modbus manuelle", "data": { "name": "Prefix du capteur", "host": "Adresse IP de l'onduleur", diff --git a/custom_components/solaredge_modbus_multi/translations/it.json b/custom_components/solaredge_modbus_multi/translations/it.json index 8fe0bc79..17401bab 100644 --- a/custom_components/solaredge_modbus_multi/translations/it.json +++ b/custom_components/solaredge_modbus_multi/translations/it.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "Configurazione Modbus SolarEdge", + "data": { + "setup_type": "Scegli un metodo di configurazione" + } + }, + "manual": { + "title": "Configurazione Modbus manuale", "data": { "name": "Prefisso sensore", "host": "Indirizzo IP dell'inverter", diff --git a/custom_components/solaredge_modbus_multi/translations/nb.json b/custom_components/solaredge_modbus_multi/translations/nb.json index d7ad81c5..79ee8931 100644 --- a/custom_components/solaredge_modbus_multi/translations/nb.json +++ b/custom_components/solaredge_modbus_multi/translations/nb.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "SolarEdge Modbus-konfigurasjon", + "data": { + "setup_type": "Velg en oppsettmetode" + } + }, + "manual": { + "title": "Manuell Modbus-konfigurasjon", "data": { "name": "Sensorvoorvoegsel", "host": "IP-adres van omvormer", diff --git a/custom_components/solaredge_modbus_multi/translations/nl.json b/custom_components/solaredge_modbus_multi/translations/nl.json index 70a86d6f..6d5aa19a 100644 --- a/custom_components/solaredge_modbus_multi/translations/nl.json +++ b/custom_components/solaredge_modbus_multi/translations/nl.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "SolarEdge Modbus-configuratie", + "data": { + "setup_type": "Kies een installatiemethode" + } + }, + "manual": { + "title": "Handmatige Modbus-configuratie", "data": { "name": "Sensor prefix", "host": "omvormer IP-adres", diff --git a/custom_components/solaredge_modbus_multi/translations/pl.json b/custom_components/solaredge_modbus_multi/translations/pl.json index 47c0bb5a..f72f7801 100644 --- a/custom_components/solaredge_modbus_multi/translations/pl.json +++ b/custom_components/solaredge_modbus_multi/translations/pl.json @@ -3,6 +3,12 @@ "step": { "user": { "title": "Konfiguracja SolarEdge Modbus", + "data": { + "setup_type": "Wybierz metodę konfiguracji" + } + }, + "manual": { + "title": "Ręczna konfiguracja Modbus", "data": { "name": "Prefix sensora", "host": "Adres IP inwertera",