From bf96efadaa145f100c4a5bfab53902af8c4927e8 Mon Sep 17 00:00:00 2001 From: SukramJ Date: Wed, 8 Jan 2025 09:24:02 +0100 Subject: [PATCH] Fix issue with programs/sysvars on backend restart (#1968) --- .pre-commit-config.yaml | 2 +- changelog.md | 4 ++++ hahomematic/central/__init__.py | 4 ++++ hahomematic/client/__init__.py | 18 +++++++++--------- hahomematic/const.py | 2 +- hahomematic/model/hub/__init__.py | 10 ++++++---- requirements_test.txt | 4 ++-- requirements_test_pre_commit.txt | 2 +- 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e2fc052c..a3c7214d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.8.5 + rev: v0.8.6 hooks: - id: ruff args: diff --git a/changelog.md b/changelog.md index 66b32dda..51e7f0fa 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# Version 2025.1.3 (2025-01-08) + +- Fix issue with programs/sysvars on backend restart + # Version 2025.1.2 (2025-01-06) - Add legacy name for hub entities diff --git a/hahomematic/central/__init__.py b/hahomematic/central/__init__.py index 089e3baa..6cbb05d8 100644 --- a/hahomematic/central/__init__.py +++ b/hahomematic/central/__init__.py @@ -1517,6 +1517,10 @@ def stop(self) -> None: async def _run_scheduler_tasks(self) -> None: """Run all tasks.""" while self._active: + if not self._central.started: + _LOGGER.debug("SCHEDULER: Waiting till central %s is started", self._central.name) + await asyncio.sleep(5) + continue for job in self._scheduler_jobs: if not self._active or not job.ready: continue diff --git a/hahomematic/client/__init__.py b/hahomematic/client/__init__.py index 0322deb2..44646c52 100644 --- a/hahomematic/client/__init__.py +++ b/hahomematic/client/__init__.py @@ -377,11 +377,11 @@ async def get_system_variable(self, name: str) -> Any: @abstractmethod async def get_all_system_variables( self, markers: tuple[DescriptionMarker | str, ...] - ) -> tuple[SystemVariableData, ...]: + ) -> tuple[SystemVariableData, ...] | None: """Get all system variables from CCU / Homegear.""" @abstractmethod - async def get_all_programs(self, markers: tuple[DescriptionMarker | str, ...]) -> tuple[ProgramData, ...]: + async def get_all_programs(self, markers: tuple[DescriptionMarker | str, ...]) -> tuple[ProgramData, ...] | None: """Get all programs, if available.""" @abstractmethod @@ -1082,14 +1082,14 @@ async def get_system_variable(self, name: str) -> Any: """Get single system variable from CCU / Homegear.""" return await self._json_rpc_client.get_system_variable(name=name) - @service(re_raise=False, no_raise_return=()) + @service(re_raise=False) async def get_all_system_variables( self, markers: tuple[DescriptionMarker | str, ...] - ) -> tuple[SystemVariableData, ...]: + ) -> tuple[SystemVariableData, ...] | None: """Get all system variables from CCU.""" return await self._json_rpc_client.get_all_system_variables(markers=markers) - @service(re_raise=False, no_raise_return=()) + @service(re_raise=False) async def get_all_programs(self, markers: tuple[DescriptionMarker | str, ...]) -> tuple[ProgramData, ...]: """Get all programs, if available.""" return await self._json_rpc_client.get_all_programs(markers=markers) @@ -1407,10 +1407,10 @@ async def get_system_variable(self, name: str) -> Any: """Get single system variable from CCU / Homegear.""" return await self._proxy.getSystemVariable(name) - @service(re_raise=False, no_raise_return=()) + @service(re_raise=False) async def get_all_system_variables( self, markers: tuple[DescriptionMarker | str, ...] - ) -> tuple[SystemVariableData, ...]: + ) -> tuple[SystemVariableData, ...] | None: """Get all system variables from Homegear.""" variables: list[SystemVariableData] = [] if hg_variables := await self._proxy.getAllSystemVariables(): @@ -1418,8 +1418,8 @@ async def get_all_system_variables( variables.append(SystemVariableData(vid=name, legacy_name=name, value=value)) return tuple(variables) - @service(re_raise=False, no_raise_return=()) - async def get_all_programs(self, markers: tuple[DescriptionMarker | str, ...]) -> tuple[ProgramData, ...]: + @service(re_raise=False) + async def get_all_programs(self, markers: tuple[DescriptionMarker | str, ...]) -> tuple[ProgramData, ...] | None: """Get all programs, if available.""" return () diff --git a/hahomematic/const.py b/hahomematic/const.py index 2905e59e..ac8a25b2 100644 --- a/hahomematic/const.py +++ b/hahomematic/const.py @@ -9,7 +9,7 @@ import re from typing import Any, Final, NamedTuple, Required, TypedDict -VERSION: Final = "2025.1.2" +VERSION: Final = "2025.1.3" # default DEFAULT_CUSTOM_ID: Final = "custom_id" diff --git a/hahomematic/model/hub/__init__.py b/hahomematic/model/hub/__init__.py index bd1928a7..476950b9 100644 --- a/hahomematic/model/hub/__init__.py +++ b/hahomematic/model/hub/__init__.py @@ -96,10 +96,11 @@ async def fetch_program_data(self, scheduled: bool) -> None: async def _update_program_data_points(self) -> None: """Retrieve all program data and update program values.""" - programs: tuple[ProgramData, ...] = () if not (client := self._central.primary_client): return - programs = await client.get_all_programs(markers=self._config.program_markers) + if (programs := await client.get_all_programs(markers=self._config.program_markers)) is None: + _LOGGER.debug("UPDATE_PROGRAM_DATA_POINTS: Unable to retrieve programs for %s", self._central.name) + return _LOGGER.debug( "UPDATE_PROGRAM_DATA_POINTS: %i programs received for %s", @@ -129,10 +130,11 @@ async def _update_program_data_points(self) -> None: async def _update_sysvar_data_points(self) -> None: """Retrieve all variable data and update hmvariable values.""" - variables: tuple[SystemVariableData, ...] = () if not (client := self._central.primary_client): return - variables = await client.get_all_system_variables(markers=self._config.sysvar_markers) + if (variables := await client.get_all_system_variables(markers=self._config.sysvar_markers)) is None: + _LOGGER.debug("UPDATE_SYSVAR_DATA_POINTS: Unable to retrieve sysvars for %s", self._central.name) + return _LOGGER.debug( "UPDATE_SYSVAR_DATA_POINTS: %i sysvars received for %s", diff --git a/requirements_test.txt b/requirements_test.txt index e4fd0dcd..64c265db 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -12,11 +12,11 @@ pylint-per-file-ignores==1.3.2 pylint-strict-informational==0.1 pylint==3.3.3 pytest-aiohttp==1.0.5 -pytest-asyncio==0.25.1 +pytest-asyncio==0.25.2 pytest-cov==6.0.0 pytest-rerunfailures==15.0 pytest-socket==0.7.0 pytest-timeout==2.3.1 pytest==8.3.4 types-python-slugify==8.0.2.20240310 -uv==0.5.14 +uv==0.5.15 diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 82f8b218..8c9a6fd2 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -2,5 +2,5 @@ bandit==1.8.0 codespell==2.3.0 pre-commit-hooks==v5.0.0 python-typing-update==v0.7.0 -ruff==0.8.5 +ruff==0.8.6 yamllint==1.35.1