Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay start of scheduler until devices are created #1998

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .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.9.0
rev: v0.9.2
hooks:
- id: ruff
args:
Expand All @@ -18,7 +18,7 @@ repos:
exclude_types: [csv, json]
exclude: ^tests/fixtures/|hahomematic/rega_scripts
- repo: https://github.com/PyCQA/bandit
rev: 1.8.0
rev: 1.8.2
hooks:
- id: bandit
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.11 (2025-01-20)

- Delay start of scheduler until devices are created

# Version 2025.1.10 (2025-01-17)

- Return regular dict from list_devices
Expand Down
13 changes: 11 additions & 2 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,9 @@ def __init__(self, central: CentralUnit) -> None:
"""Init the connection checker."""
threading.Thread.__init__(self, name=f"ConnectionChecker for {central.name}")
self._central: Final = central
self._unregister_callback = self._central.register_backend_system_callback(cb=self._backend_system_callback)
self._active = True
self._devices_created = False
self._scheduler_jobs = [
_SchedulerJob(task=self._check_connection, run_interval=CONNECTION_CHECKER_INTERVAL),
_SchedulerJob(
Expand All @@ -1498,6 +1500,11 @@ def __init__(self, central: CentralUnit) -> None:
),
]

def _backend_system_callback(self, system_event: BackendSystemEvent, **kwargs: Any) -> None:
"""Handle event of new device creation, to delay the start of the sysvar scan."""
if system_event == BackendSystemEvent.DEVICES_CREATED:
self._devices_created = True

def run(self) -> None:
"""Run the scheduler thread."""
_LOGGER.debug(
Expand All @@ -1512,14 +1519,16 @@ def run(self) -> None:

def stop(self) -> None:
"""To stop the ConnectionChecker."""
if self._unregister_callback is not None:
self._unregister_callback()
self._active = False

async def _run_scheduler_tasks(self) -> None:
"""Run all tasks."""
while self._active:
if not self._central.started:
if not self._central.started or not self._devices_created:
_LOGGER.debug("SCHEDULER: Waiting till central %s is started", self._central.name)
await asyncio.sleep(5)
await asyncio.sleep(10)
continue
for job in self._scheduler_jobs:
if not self._active or not job.ready:
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.10"
VERSION: Final = "2025.1.11"

# default
DEFAULT_CUSTOM_ID: Final = "custom_id"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp>=3.11.11
orjson>=3.10.14
orjson>=3.10.15
python-slugify>=8.0.4
voluptuous>=0.15.2
6 changes: 3 additions & 3 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ coverage==7.6.10
freezegun==1.5.1
mypy-dev==1.15.0a1
pip==24.3.1
pre-commit==4.0.1
pre-commit==4.1.0
pur==7.3.3
pydevccu==0.1.9
pylint-per-file-ignores==1.3.2
pylint-per-file-ignores==1.4.0
pylint-strict-informational==0.1
pylint==3.3.3
pytest-aiohttp==1.0.5
Expand All @@ -19,4 +19,4 @@ pytest-socket==0.7.0
pytest-timeout==2.3.1
pytest==8.3.4
types-python-slugify==8.0.2.20240310
uv==0.5.16
uv==0.5.21
4 changes: 2 additions & 2 deletions requirements_test_pre_commit.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bandit==1.8.0
bandit==1.8.2
codespell==2.3.0
pre-commit-hooks==v5.0.0
python-typing-update==v0.7.0
ruff==0.9.0
ruff==0.9.2
yamllint==1.35.1
Loading