From 18545d77a7bad249690084fe7c86c8c43efaf295 Mon Sep 17 00:00:00 2001 From: marq24 Date: Fri, 8 Mar 2024 18:28:41 +0100 Subject: [PATCH] web_client TEST will use also new API (and make sure that auto-detect is working) --- custom_components/senec/__init__.py | 4 ++-- custom_components/senec/config_flow.py | 23 +++++++------------ custom_components/senec/manifest.json | 2 +- .../senec/pysenec_ha/__init__.py | 4 +++- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/custom_components/senec/__init__.py b/custom_components/senec/__init__.py index 36a8d3b..275fcdc 100644 --- a/custom_components/senec/__init__.py +++ b/custom_components/senec/__init__.py @@ -12,7 +12,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity import EntityDescription, Entity from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from homeassistant.helpers import entity_registry, event +from homeassistant.helpers import config_validation as config_val, entity_registry, event from homeassistant.util import slugify from custom_components.senec.pysenec_ha import Senec, Inverter, MySenecWebPortal @@ -77,7 +77,7 @@ SCAN_INTERVAL = timedelta(seconds=60) PLATFORMS = ["sensor", "binary_sensor", "select", "switch", "number"] - +CONFIG_SCHEMA = config_val.removed(DOMAIN, raise_if_present=False) async def async_setup(hass: HomeAssistant, config: dict): """Set up the senec component.""" diff --git a/custom_components/senec/config_flow.py b/custom_components/senec/config_flow.py index be82ca0..ca814c8 100644 --- a/custom_components/senec/config_flow.py +++ b/custom_components/senec/config_flow.py @@ -186,27 +186,20 @@ async def _test_connection_webapi(self, user: str, pwd: str, master_plant: int): try: senec_web_client = MySenecWebPortal(user=user, pwd=pwd, web_session=web_session, master_plant_number=master_plant) - await senec_web_client.web_authenticate(do_update=False, throw401=True) - if senec_web_client._is_authenticated: - await senec_web_client.update_context() + await senec_web_client.app_authenticate(retry=False, do_update=False) + if senec_web_client._app_is_authenticated: + await senec_web_client.app_update_context() self._device_master_plant_number = senec_web_client.masterPlantNumber + await senec_web_client.app_update_tech_data() # these values will also read with every restart... self._device_type = SYSTYPE_NAME_WEBAPI self._device_model = senec_web_client.product_name + ' | SENEC.Num: ' + senec_web_client.senec_num self._device_serial = senec_web_client.serial_number - self._device_version = None # senec_web_client.firmwareVersion - - if not senec_web_client._app_is_authenticated: - await senec_web_client.app_authenticate(retry=False, do_update=False) - - if senec_web_client._app_is_authenticated: - self._app_token = senec_web_client._app_token - self._app_master_plant_id = senec_web_client._app_master_plant_id - self._app_wallbox_num_max = senec_web_client._app_wallbox_num_max - - await senec_web_client.app_update_tech_data() - self._device_version = senec_web_client.versions + self._app_token = senec_web_client._app_token + self._app_master_plant_id = senec_web_client._app_master_plant_id + self._app_wallbox_num_max = senec_web_client._app_wallbox_num_max + self._device_version = senec_web_client.versions _LOGGER.info(f"Successfully connect to mein-senec.de and APP-API with '{user}'") return True diff --git a/custom_components/senec/manifest.json b/custom_components/senec/manifest.json index 06e6500..ef91f44 100644 --- a/custom_components/senec/manifest.json +++ b/custom_components/senec/manifest.json @@ -13,5 +13,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/marq24/ha-senec-v3/issues", "requirements": ["xmltodict>=0.12.0", "packaging>=21.0", "python-dateutil>=2.8.0"], - "version": "2024.2.1" + "version": "2024.3.0" } diff --git a/custom_components/senec/pysenec_ha/__init__.py b/custom_components/senec/pysenec_ha/__init__.py index bb48b55..ded7ed7 100644 --- a/custom_components/senec/pysenec_ha/__init__.py +++ b/custom_components/senec/pysenec_ha/__init__.py @@ -2509,8 +2509,10 @@ async def app_get_master_plant_id(self, retry: bool = True): data = None try: data = await res.json(); + if self._master_plant_number == -1: + self._master_plant_number = 0 idx = int(self._master_plant_number) - if int(len(data)) >= idx: + if len(data) > idx: if "id" in data[idx]: self._app_master_plant_id = data[idx]["id"] _LOGGER.debug(f"APP-API set _app_master_plant_id to {self._app_master_plant_id}")