From 8513729674be20db6c3cd4f5fb45b004a6593e6a Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:16:07 -0700 Subject: [PATCH 1/3] Add config step for auto or manual setup --- .../solaredge_modbus_multi/config_flow.py | 65 ++++++++++++++++--- .../solaredge_modbus_multi/const.py | 5 ++ 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/config_flow.py b/custom_components/solaredge_modbus_multi/config_flow.py index 890a5ec7..d34c97f9 100644 --- a/custom_components/solaredge_modbus_multi/config_flow.py +++ b/custom_components/solaredge_modbus_multi/config_flow.py @@ -8,15 +8,18 @@ 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 HomeAssistant, callback -from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError from .const import ( DEFAULT_NAME, DOMAIN, + SETUP_MANUAL, + SETUP_SCAN, + SETUP_SCAN_FULL, + SETUP_TYPE, ConfDefaultFlag, ConfDefaultInt, ConfDefaultStr, @@ -48,8 +51,52 @@ 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.""" + 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.""" + 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: @@ -94,7 +141,7 @@ async def async_step_user( } return self.async_show_form( - step_id="user", + step_id="manual", data_schema=vol.Schema( { vol.Optional(CONF_NAME, default=user_input[CONF_NAME]): cv.string, @@ -113,7 +160,7 @@ async def async_step_user( 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( @@ -193,7 +240,7 @@ def __init__(self, config_entry: ConfigEntry): async def async_step_init( self, user_input: dict[str, Any] | None = None - ) -> FlowResult: + ) -> ConfigFlowResult: """Handle the initial options flow step.""" errors = {} @@ -282,7 +329,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 = {} @@ -339,7 +386,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 c4f5715c..418bd7e6 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" + # units missing in homeassistant core ENERGY_VOLT_AMPERE_HOUR: Final = "VAh" ENERGY_VOLT_AMPERE_REACTIVE_HOUR: Final = "varh" From aa041f9d1a41a9c1d3cd51ab2d6d5e6835497fd1 Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Sun, 28 Jul 2024 15:20:30 -0700 Subject: [PATCH 2/3] Update translations --- custom_components/solaredge_modbus_multi/strings.json | 6 ++++++ .../solaredge_modbus_multi/translations/de.json | 6 ++++++ .../solaredge_modbus_multi/translations/en.json | 6 ++++++ .../solaredge_modbus_multi/translations/fr.json | 6 ++++++ .../solaredge_modbus_multi/translations/it.json | 6 ++++++ .../solaredge_modbus_multi/translations/nb.json | 6 ++++++ .../solaredge_modbus_multi/translations/nl.json | 6 ++++++ .../solaredge_modbus_multi/translations/pl.json | 6 ++++++ 8 files changed, 48 insertions(+) diff --git a/custom_components/solaredge_modbus_multi/strings.json b/custom_components/solaredge_modbus_multi/strings.json index 1c737acb..b13a1c3b 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 7a8adeda..5d754b5b 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 1c737acb..b13a1c3b 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 d7cd2d6e..126154bf 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 444cc055..7b0bc985 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 a39f81c9..fe84b33b 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 21bbf9d2..53c9ffa2 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 8a36c8bd..1a6a332d 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", From c5cef61fa8c641b3360fed48ad729dafa4a5a16b Mon Sep 17 00:00:00 2001 From: WillCodeForCats <48533968+WillCodeForCats@users.noreply.github.com> Date: Mon, 29 Jul 2024 06:22:29 -0700 Subject: [PATCH 3/3] Update config_flow.py --- .../solaredge_modbus_multi/config_flow.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/custom_components/solaredge_modbus_multi/config_flow.py b/custom_components/solaredge_modbus_multi/config_flow.py index 5df9ba4c..c10dc2bd 100644 --- a/custom_components/solaredge_modbus_multi/config_flow.py +++ b/custom_components/solaredge_modbus_multi/config_flow.py @@ -80,7 +80,10 @@ async def async_step_user( async def async_step_scan( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: - """Handle the scan config flow step.""" + """ + Handle the scan config flow step. + Quick scan only scans the first 32 IDs (Scan IDs 1-32) + """ errors = {} raise HomeAssistantError("async_step_scan") @@ -88,7 +91,10 @@ async def 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.""" + """ + 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")