diff --git a/custom_components/senec/__init__.py b/custom_components/senec/__init__.py index 3ff5f88..b3bb3c5 100644 --- a/custom_components/senec/__init__.py +++ b/custom_components/senec/__init__.py @@ -371,49 +371,62 @@ def __call__(self, evt: Event) -> bool: async def _async_is2408_or_later(self) -> bool: return await self.senec.is_2408_or_higher_async() - async def _async_update_data(self): + async def _async_update_data(self) -> dict: + _LOGGER.debug(f"_async_update_data called") try: await self.senec.update() - return self.senec + data = self.senec.dict_data(); + _LOGGER.debug(f"read: {util.mask_map(data)}") + return data except UpdateFailed as exception: + _LOGGER.warning(f"UpdateFailed: {exception}") raise UpdateFailed() from exception except Exception as fatal: + _LOGGER.warning(f"UpdateFailed (fatal): {fatal}") raise UpdateFailed() from fatal async def _async_switch_to_state(self, switch_key, state): try: await self.senec.switch(switch_key, state) - return self.senec + return self.senec.dict_data() except UpdateFailed as exception: + _LOGGER.warning(f"UpdateFailed: {exception}") raise UpdateFailed() from exception except Exception as fatal: + _LOGGER.warning(f"UpdateFailed (fatal): {fatal}") raise UpdateFailed() from fatal async def _async_switch_array_to_state(self, switch_array_key, array_pos, state): try: await self.senec.switch_array(switch_array_key, array_pos, state) - return self.senec + return self.senec.dict_data() except UpdateFailed as exception: + _LOGGER.warning(f"UpdateFailed: {exception}") raise UpdateFailed() from exception except Exception as fatal: + _LOGGER.warning(f"UpdateFailed (fatal): {fatal}") raise UpdateFailed() from fatal async def _async_set_string_value(self, set_str_key, value: str): try: await self.senec.set_string_value(set_str_key, value) - return self.senec + return self.senec.dict_data() except UpdateFailed as exception: + _LOGGER.warning(f"UpdateFailed: {exception}") raise UpdateFailed() from exception except Exception as fatal: + _LOGGER.warning(f"UpdateFailed (fatal): {fatal}") raise UpdateFailed() from fatal async def _async_trigger_button(self, trigger_key:str, payload: str): try: await self.senec._trigger_button(trigger_key, payload) - return self.senec + return self.senec.dict_data() except UpdateFailed as exception: + _LOGGER.warning(f"UpdateFailed: {exception}") raise UpdateFailed() from exception except Exception as fatal: + _LOGGER.warning(f"UpdateFailed (fatal): {fatal}") raise UpdateFailed() from fatal diff --git a/custom_components/senec/manifest.json b/custom_components/senec/manifest.json index 638af41..0a82e63 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.13.0", "packaging>=21.0", "python-dateutil>=2.8.0"], - "version": "2024.12.2" + "version": "2024.12.3" } diff --git a/custom_components/senec/pysenec_ha/__init__.py b/custom_components/senec/pysenec_ha/__init__.py index b889d1f..b6d4290 100644 --- a/custom_components/senec/pysenec_ha/__init__.py +++ b/custom_components/senec/pysenec_ha/__init__.py @@ -198,6 +198,12 @@ def __init__(self, host, use_https, web_session, lang: str = "en", options: dict except Exception as exc: _LOGGER.debug(f"Exception while try to call 'IntBridge.app_api.update': {exc}") + def dict_data(self) -> dict: + # will be called by the UpdateCoordinator (to get the current data) + # self._raw = None + # self._raw_version = None + return {"data": self._raw, "version": self._raw_version} + @property def device_id(self) -> str: return self._raw_version[SENEC_SECTION_FACTORY]["DEVICE_ID"] @@ -2264,6 +2270,14 @@ def __init__(self, host, web_session): self.url3 = f"http://{host}/versions.xml" self._version_infos = '' self._has_bdc = False + self._raw = None + self._raw_version = None + + def dict_data(self) -> dict: + # will be called by the UpdateCoordinator (to get the current data) + # self._raw = None + # self._raw_version = None + return {"data": self._raw, "version": self._raw_version} async def update_version(self): await self.read_inverter_version() @@ -2689,6 +2703,23 @@ def __init__(self, user, pwd, web_session, master_plant_number: int = 0, lang: s self._QUERY_WALLBOX = True _LOGGER.debug("APP-API: will query WALLBOX data (cause 'lala_cgi._QUERY_WALLBOX_APPAPI' is True)") + def dict_data(self) -> dict: + # will be called by the UpdateCoordinator (to get the current data) + # self._app_raw_now = None + # self._app_raw_today = None + # self._app_raw_total_v1_outdated = None + # self._app_raw_total_v2 = None + # self._app_raw_tech_data = None + # self._app_raw_wallbox = [None, None, None, None] + return { + "now": self._app_raw_now, + "today": self._app_raw_today, + "total": self._app_raw_total_v2, + "total_old": self._app_raw_total_v1_outdated, + "tech_data": self._app_raw_tech_data, + "wallbox": self._app_raw_wallbox + } + def check_cookie_jar_type(self): if _require_lib_patch(): if hasattr(self.web_session, "_cookie_jar"):