diff --git a/README.md b/README.md index 6480fd7c..e1d80643 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ After rebooting Home Assistant, this integration can be configured through the i [WillCodeForCats/solaredge-modbus-multi/wiki](https://github.com/WillCodeForCats/solaredge-modbus-multi/wiki) ### Required Versions -* Home Assistant 2024.3.2 or newer +* Home Assistant 2024.4.0 or newer * Python 3.11 or newer * pymodbus 3.6.6 or newer diff --git a/custom_components/solaredge_modbus_multi/config_flow.py b/custom_components/solaredge_modbus_multi/config_flow.py index dc03f6b2..97248f7b 100644 --- a/custom_components/solaredge_modbus_multi/config_flow.py +++ b/custom_components/solaredge_modbus_multi/config_flow.py @@ -2,6 +2,8 @@ from __future__ import annotations +from typing import Any + import homeassistant.helpers.config_validation as cv import voluptuous as vol from homeassistant import config_entries @@ -35,7 +37,9 @@ def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow: """Create the options flow for SolarEdge Modbus Multi.""" return SolaredgeModbusMultiOptionsFlowHandler(config_entry) - async def async_step_user(self, user_input=None) -> FlowResult: + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle the initial config flow step.""" errors = {} @@ -99,6 +103,78 @@ async def async_step_user(self, user_input=None) -> FlowResult: errors=errors, ) + async def async_step_reconfigure( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: + """Handle the reconfigure flow step.""" + errors = {} + config_entry = self.hass.config_entries.async_get_entry( + self.context["entry_id"] + ) + assert config_entry + unique_id = config_entry.unique_id + + if user_input is not None: + user_input[CONF_HOST] = user_input[CONF_HOST].lower() + + if not host_valid(user_input[CONF_HOST]): + errors[CONF_HOST] = "invalid_host" + elif user_input[CONF_PORT] < 1: + errors[CONF_PORT] = "invalid_tcp_port" + elif user_input[CONF_PORT] > 65535: + errors[CONF_PORT] = "invalid_tcp_port" + elif user_input[ConfName.DEVICE_ID] > 247: + errors[ConfName.DEVICE_ID] = "max_device_id" + elif user_input[ConfName.DEVICE_ID] < 1: + errors[ConfName.DEVICE_ID] = "min_device_id" + elif user_input[ConfName.NUMBER_INVERTERS] > 32: + errors[ConfName.NUMBER_INVERTERS] = "max_inverters" + elif user_input[ConfName.NUMBER_INVERTERS] < 1: + errors[ConfName.NUMBER_INVERTERS] = "min_inverters" + elif ( + user_input[ConfName.NUMBER_INVERTERS] + user_input[ConfName.DEVICE_ID] + > 247 + ): + errors[ConfName.NUMBER_INVERTERS] = "too_many_inverters" + else: + return self.async_update_reload_and_abort( + config_entry, + unique_id=unique_id, + data={**config_entry.data, **user_input}, + reason="reconfigure_successful", + ) + else: + user_input = { + CONF_HOST: config_entry.data.get(CONF_HOST), + CONF_PORT: config_entry.data.get(CONF_PORT, ConfDefaultInt.PORT), + ConfName.NUMBER_INVERTERS: config_entry.data.get( + ConfName.NUMBER_INVERTERS, ConfDefaultInt.NUMBER_INVERTERS + ), + ConfName.DEVICE_ID: config_entry.data.get( + ConfName.DEVICE_ID, ConfDefaultInt.DEVICE_ID + ), + } + + return self.async_show_form( + step_id="reconfigure", + data_schema=vol.Schema( + { + 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.NUMBER_INVERTERS}", + default=user_input[ConfName.NUMBER_INVERTERS], + ): vol.Coerce(int), + vol.Required( + f"{ConfName.DEVICE_ID}", default=user_input[ConfName.DEVICE_ID] + ): vol.Coerce(int), + }, + ), + errors=errors, + ) + class SolaredgeModbusMultiOptionsFlowHandler(OptionsFlow): """Handle an options flow for SolarEdge Modbus Multi.""" @@ -107,7 +183,9 @@ def __init__(self, config_entry: ConfigEntry): """Initialize options flow.""" self.config_entry = config_entry - async def async_step_init(self, user_input=None) -> FlowResult: + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle the initial options flow step.""" errors = {} @@ -194,7 +272,9 @@ async def async_step_init(self, user_input=None) -> FlowResult: errors=errors, ) - async def async_step_battery_options(self, user_input=None) -> FlowResult: + async def async_step_battery_options( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Battery Options""" errors = {} @@ -249,7 +329,9 @@ async def async_step_battery_options(self, user_input=None) -> FlowResult: errors=errors, ) - async def async_step_adv_pwr_ctl(self, user_input=None) -> FlowResult: + async def async_step_adv_pwr_ctl( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Power Control Options""" errors = {} diff --git a/custom_components/solaredge_modbus_multi/strings.json b/custom_components/solaredge_modbus_multi/strings.json index af880f79..af7221d5 100644 --- a/custom_components/solaredge_modbus_multi/strings.json +++ b/custom_components/solaredge_modbus_multi/strings.json @@ -10,6 +10,15 @@ "device_id": "Inverter Modbus Address (Device ID)", "number_of_inverters": "Number of Inverters" } + }, + "reconfigure": { + "title": "SolarEdge Modbus Configuration", + "data": { + "host": "Inverter IP Address", + "port": "Modbus/TCP Port", + "device_id": "Inverter Modbus Address (Device ID)", + "number_of_inverters": "Number of Inverters" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Valid port range is 1 to 65535." }, "abort": { - "already_configured": "Device is already configured!" + "already_configured": "Device is already configured", + "reconfigure_successful": "Re-configuration was successful" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/de.json b/custom_components/solaredge_modbus_multi/translations/de.json index ec955e8f..b3dd3fc9 100644 --- a/custom_components/solaredge_modbus_multi/translations/de.json +++ b/custom_components/solaredge_modbus_multi/translations/de.json @@ -10,6 +10,15 @@ "device_id": "Wechselrichter-Modbus-Adresse (Geräte-ID)", "number_of_inverters": "Anzahl Wechselrichter" } + }, + "reconfigure": { + "title": "SolarEdge Modbus-Konfiguration", + "data": { + "host": "Wechselrichter-IP-Adresse", + "port": "Modbus/TCP-Port", + "device_id": "Wechselrichter-Modbus-Adresse (Geräte-ID)", + "number_of_inverters": "Anzahl Wechselrichter" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Der gültige Portbereich ist 1 bis 65535." }, "abort": { - "already_configured": "Der Wechselrichter ist bereits konfiguriert." + "already_configured": "Gerät ist bereits konfiguriert", + "reconfigure_successful": "Die Neukonfiguration war erfolgreich" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/en.json b/custom_components/solaredge_modbus_multi/translations/en.json index af880f79..af7221d5 100644 --- a/custom_components/solaredge_modbus_multi/translations/en.json +++ b/custom_components/solaredge_modbus_multi/translations/en.json @@ -10,6 +10,15 @@ "device_id": "Inverter Modbus Address (Device ID)", "number_of_inverters": "Number of Inverters" } + }, + "reconfigure": { + "title": "SolarEdge Modbus Configuration", + "data": { + "host": "Inverter IP Address", + "port": "Modbus/TCP Port", + "device_id": "Inverter Modbus Address (Device ID)", + "number_of_inverters": "Number of Inverters" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Valid port range is 1 to 65535." }, "abort": { - "already_configured": "Device is already configured!" + "already_configured": "Device is already configured", + "reconfigure_successful": "Re-configuration was successful" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/fr.json b/custom_components/solaredge_modbus_multi/translations/fr.json index 0f3d9d7d..af1c0d93 100644 --- a/custom_components/solaredge_modbus_multi/translations/fr.json +++ b/custom_components/solaredge_modbus_multi/translations/fr.json @@ -10,6 +10,15 @@ "device_id": "L'adresse Modbus de l'onduleur (Device ID)", "number_of_inverters": "Nombre d'onduleurs" } + }, + "reconfigure": { + "title": "Configuration SolarEdge Modbus", + "data": { + "host": "Adresse IP de l'onduleur", + "port": "Port Modbus/TCP", + "device_id": "L'adresse Modbus de l'onduleur (Device ID)", + "number_of_inverters": "Nombre d'onduleurs" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "La plage de ports valide est comprise entre 1 et 65535." }, "abort": { - "already_configured": "L'appareil est déjà configuré!" + "already_configured": "L'appareil est déjà configuré", + "reconfigure_successful": "La reconfiguration a réussi" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/it.json b/custom_components/solaredge_modbus_multi/translations/it.json index 6342e5c5..956b3ade 100644 --- a/custom_components/solaredge_modbus_multi/translations/it.json +++ b/custom_components/solaredge_modbus_multi/translations/it.json @@ -10,6 +10,15 @@ "device_id": "Indirizzo Modbus dell'inverter (ID dispositivo)", "number_of_inverters": "Numero di inverter" } + }, + "reconfigure": { + "title": "Configurazione Modbus SolarEdge", + "data": { + "host": "Indirizzo IP dell'inverter", + "port": "Porta Modbus/TCP", + "device_id": "Indirizzo Modbus dell'inverter (ID dispositivo)", + "number_of_inverters": "Numero di inverter" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "L'intervallo di porte valido è compreso tra 1 e 65535." }, "abort": { - "already_configured": "Il dispositivo è già configurato!" + "already_configured": "Il dispositivo è già configurato", + "reconfigure_successful": "La riconfigurazione ha avuto successo" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/nb.json b/custom_components/solaredge_modbus_multi/translations/nb.json index 689b06b1..a81a3be6 100644 --- a/custom_components/solaredge_modbus_multi/translations/nb.json +++ b/custom_components/solaredge_modbus_multi/translations/nb.json @@ -10,6 +10,15 @@ "device_id": "Inverter Modbus-adresse (enhets-ID)", "number_of_inverters": "Antall omformere koblet sammen" } + }, + "reconfigure": { + "title": "SolarEdge Modbus-konfigurasjon", + "data": { + "host": "IP-adres van omvormer", + "port": "Modbus/TCP-poort", + "device_id": "Inverter Modbus-adresse (enhets-ID)", + "number_of_inverters": "Antall omformere koblet sammen" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Gyldig portområde er 1 til 65535." }, "abort": { - "already_configured": "Enheten er allerede konfigurert" + "already_configured": "Enheten er allerede konfigurert", + "reconfigure_successful": "Omkonfigureringen var vellykket" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/nl.json b/custom_components/solaredge_modbus_multi/translations/nl.json index 5455664f..07f30d13 100644 --- a/custom_components/solaredge_modbus_multi/translations/nl.json +++ b/custom_components/solaredge_modbus_multi/translations/nl.json @@ -10,6 +10,15 @@ "device_id": "Omvormer Modbus-adres (apparaat-ID)", "number_of_inverters": "Aantal aangesloten omvormers" } + }, + "reconfigure": { + "title": "SolarEdge Modbus-configuratie", + "data": { + "host": "omvormer IP-adres", + "port": "Modbus/TCP Port", + "device_id": "Omvormer Modbus-adres (apparaat-ID)", + "number_of_inverters": "Aantal aangesloten omvormers" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Geldig poortbereik is 1 tot 65535." }, "abort": { - "already_configured": "Apparaat is al geconfigureerd" + "already_configured": "Apparaat is al geconfigureerd", + "reconfigure_successful": "De herconfiguratie was succesvol" } }, "options": { diff --git a/custom_components/solaredge_modbus_multi/translations/pl.json b/custom_components/solaredge_modbus_multi/translations/pl.json index 7580c62b..2647a938 100644 --- a/custom_components/solaredge_modbus_multi/translations/pl.json +++ b/custom_components/solaredge_modbus_multi/translations/pl.json @@ -10,6 +10,15 @@ "device_id": "Adres Modbus Inwertera (Device ID)", "number_of_inverters": "Ilość inwerterów" } + }, + "reconfigure": { + "title": "Konfiguracja SolarEdge Modbus", + "data": { + "host": "Adres IP inwertera", + "port": "Modbus/TCP Port", + "device_id": "Adres Modbus Inwertera (Device ID)", + "number_of_inverters": "Ilość inwerterów" + } } }, "error": { @@ -23,7 +32,8 @@ "invalid_tcp_port": "Dozwolony zakres portów to od 1 do 65535." }, "abort": { - "already_configured": "Urządzenie jest już skonfigurowane!" + "already_configured": "Urządzenie jest już skonfigurowane", + "reconfigure_successful": "Ponowna konfiguracja przebiegła pomyślnie" } }, "options": { diff --git a/hacs.json b/hacs.json index 4e37af59..9c206f7b 100644 --- a/hacs.json +++ b/hacs.json @@ -1,6 +1,6 @@ { "name": "SolarEdge Modbus Multi", "content_in_root": false, - "homeassistant": "2024.3.2", + "homeassistant": "2024.4.0", "render_readme": false } diff --git a/info.md b/info.md index f6fa4359..edd7e6be 100644 --- a/info.md +++ b/info.md @@ -22,4 +22,4 @@ Read more on the wiki: [WillCodeForCats/solaredge-modbus-multi/wiki](https://git * Supports status and error reporting sensors. * User friendly configuration through Config Flow. -Requires Home Assistant 2024.3.2 and newer with pymodbus 3.6.6 and newer. +Requires Home Assistant 2024.4.0 and newer with pymodbus 3.6.6 and newer.