Skip to content

Commit

Permalink
Fix issue with programs/sysvars on backend restart (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Jan 8, 2025
1 parent 30ff320 commit bf96efa
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions hahomematic/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1407,19 +1407,19 @@ 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():
for name, value in hg_variables.items():
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 ()

Expand Down
2 changes: 1 addition & 1 deletion hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions hahomematic/model/hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bf96efa

Please sign in to comment.