aiohomematic 2025.8.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of aiohomematic might be problematic. Click here for more details.
- aiohomematic-2025.8.6/LICENSE +21 -0
- aiohomematic-2025.8.6/PKG-INFO +69 -0
- aiohomematic-2025.8.6/README.md +41 -0
- aiohomematic-2025.8.6/aiohomematic/__init__.py +47 -0
- aiohomematic-2025.8.6/aiohomematic/async_support.py +146 -0
- aiohomematic-2025.8.6/aiohomematic/caches/__init__.py +10 -0
- aiohomematic-2025.8.6/aiohomematic/caches/dynamic.py +554 -0
- aiohomematic-2025.8.6/aiohomematic/caches/persistent.py +459 -0
- aiohomematic-2025.8.6/aiohomematic/caches/visibility.py +774 -0
- aiohomematic-2025.8.6/aiohomematic/central/__init__.py +2034 -0
- aiohomematic-2025.8.6/aiohomematic/central/decorators.py +110 -0
- aiohomematic-2025.8.6/aiohomematic/central/xml_rpc_server.py +267 -0
- aiohomematic-2025.8.6/aiohomematic/client/__init__.py +1746 -0
- aiohomematic-2025.8.6/aiohomematic/client/json_rpc.py +1193 -0
- aiohomematic-2025.8.6/aiohomematic/client/xml_rpc.py +222 -0
- aiohomematic-2025.8.6/aiohomematic/const.py +795 -0
- aiohomematic-2025.8.6/aiohomematic/context.py +8 -0
- aiohomematic-2025.8.6/aiohomematic/converter.py +82 -0
- aiohomematic-2025.8.6/aiohomematic/decorators.py +188 -0
- aiohomematic-2025.8.6/aiohomematic/exceptions.py +145 -0
- aiohomematic-2025.8.6/aiohomematic/hmcli.py +159 -0
- aiohomematic-2025.8.6/aiohomematic/model/__init__.py +137 -0
- aiohomematic-2025.8.6/aiohomematic/model/calculated/__init__.py +65 -0
- aiohomematic-2025.8.6/aiohomematic/model/calculated/climate.py +230 -0
- aiohomematic-2025.8.6/aiohomematic/model/calculated/data_point.py +319 -0
- aiohomematic-2025.8.6/aiohomematic/model/calculated/operating_voltage_level.py +311 -0
- aiohomematic-2025.8.6/aiohomematic/model/calculated/support.py +174 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/__init__.py +175 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/climate.py +1334 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/const.py +146 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/cover.py +741 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/data_point.py +318 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/definition.py +861 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/light.py +1092 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/lock.py +389 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/siren.py +268 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/support.py +40 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/switch.py +172 -0
- aiohomematic-2025.8.6/aiohomematic/model/custom/valve.py +112 -0
- aiohomematic-2025.8.6/aiohomematic/model/data_point.py +1109 -0
- aiohomematic-2025.8.6/aiohomematic/model/decorators.py +173 -0
- aiohomematic-2025.8.6/aiohomematic/model/device.py +1347 -0
- aiohomematic-2025.8.6/aiohomematic/model/event.py +210 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/__init__.py +211 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/action.py +32 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/binary_sensor.py +28 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/button.py +25 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/data_point.py +162 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/number.py +73 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/select.py +36 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/sensor.py +72 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/switch.py +52 -0
- aiohomematic-2025.8.6/aiohomematic/model/generic/text.py +27 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/__init__.py +334 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/binary_sensor.py +22 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/button.py +26 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/data_point.py +332 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/number.py +37 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/select.py +47 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/sensor.py +35 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/switch.py +42 -0
- aiohomematic-2025.8.6/aiohomematic/model/hub/text.py +28 -0
- aiohomematic-2025.8.6/aiohomematic/model/support.py +599 -0
- aiohomematic-2025.8.6/aiohomematic/model/update.py +136 -0
- aiohomematic-2025.8.6/aiohomematic/py.typed +0 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/fetch_all_device_data.fn +75 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/get_program_descriptions.fn +30 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/get_serial.fn +44 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/get_system_variable_descriptions.fn +30 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/set_program_state.fn +12 -0
- aiohomematic-2025.8.6/aiohomematic/rega_scripts/set_system_variable.fn +15 -0
- aiohomematic-2025.8.6/aiohomematic/support.py +482 -0
- aiohomematic-2025.8.6/aiohomematic/validator.py +65 -0
- aiohomematic-2025.8.6/aiohomematic.egg-info/PKG-INFO +69 -0
- aiohomematic-2025.8.6/aiohomematic.egg-info/SOURCES.txt +104 -0
- aiohomematic-2025.8.6/aiohomematic.egg-info/dependency_links.txt +1 -0
- aiohomematic-2025.8.6/aiohomematic.egg-info/requires.txt +4 -0
- aiohomematic-2025.8.6/aiohomematic.egg-info/top_level.txt +3 -0
- aiohomematic-2025.8.6/aiohomematic_support/__init__.py +1 -0
- aiohomematic-2025.8.6/aiohomematic_support/client_local.py +349 -0
- aiohomematic-2025.8.6/pyproject.toml +586 -0
- aiohomematic-2025.8.6/setup.cfg +7 -0
- aiohomematic-2025.8.6/tests/test_action.py +69 -0
- aiohomematic-2025.8.6/tests/test_binary_sensor.py +95 -0
- aiohomematic-2025.8.6/tests/test_button.py +110 -0
- aiohomematic-2025.8.6/tests/test_calculated_support.py +129 -0
- aiohomematic-2025.8.6/tests/test_central.py +1016 -0
- aiohomematic-2025.8.6/tests/test_central_pydevccu.py +180 -0
- aiohomematic-2025.8.6/tests/test_climate.py +1011 -0
- aiohomematic-2025.8.6/tests/test_cover.py +967 -0
- aiohomematic-2025.8.6/tests/test_decorator.py +75 -0
- aiohomematic-2025.8.6/tests/test_device.py +134 -0
- aiohomematic-2025.8.6/tests/test_entity.py +216 -0
- aiohomematic-2025.8.6/tests/test_event.py +133 -0
- aiohomematic-2025.8.6/tests/test_json_rpc.py +53 -0
- aiohomematic-2025.8.6/tests/test_light.py +1210 -0
- aiohomematic-2025.8.6/tests/test_lock.py +171 -0
- aiohomematic-2025.8.6/tests/test_number.py +219 -0
- aiohomematic-2025.8.6/tests/test_select.py +115 -0
- aiohomematic-2025.8.6/tests/test_sensor.py +145 -0
- aiohomematic-2025.8.6/tests/test_siren.py +179 -0
- aiohomematic-2025.8.6/tests/test_support.py +617 -0
- aiohomematic-2025.8.6/tests/test_switch.py +202 -0
- aiohomematic-2025.8.6/tests/test_text.py +71 -0
- aiohomematic-2025.8.6/tests/test_valve.py +97 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Daniel Perna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aiohomematic
|
|
3
|
+
Version: 2025.8.6
|
|
4
|
+
Summary: Homematic interface for Home Assistant running on Python 3.
|
|
5
|
+
Home-page: https://github.com/sukramj/aiohomematic
|
|
6
|
+
Author-email: SukramJ <sukramj@icloud.com>, Daniel Perna <danielperna84@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
Project-URL: Source Code, https://github.com/sukramj/aiohomematic
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/sukramj/aiohomematic/issues
|
|
10
|
+
Project-URL: Docs: Dev, https://github.com/sukramj/aiohomematic
|
|
11
|
+
Project-URL: Forum, https://github.com/sukramj/aiohomematic/discussions
|
|
12
|
+
Keywords: home,automation,homematic
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Home Automation
|
|
20
|
+
Requires-Python: >=3.13.0
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: aiohttp>=3.10.0
|
|
24
|
+
Requires-Dist: orjson>=3.10.0
|
|
25
|
+
Requires-Dist: python-slugify>=8.0.0
|
|
26
|
+
Requires-Dist: voluptuous>=0.14.0
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# AIO Homematic (hahomematic)
|
|
30
|
+
|
|
31
|
+
A lightweight Python 3 library that powers Home Assistant integrations for controlling and monitoring [HomeMatic](https://www.eq-3.com/products/homematic.html) and [HomematicIP](https://www.homematic-ip.com/en/start.html) devices. Some third‑party devices/gateways (e.g., Bosch, Intertechno) may be supported as well.
|
|
32
|
+
|
|
33
|
+
This project is the modern successor to [pyhomematic](https://github.com/danielperna84/pyhomematic), focusing on automatic entity creation, fewer manual device definitions, and faster startups.
|
|
34
|
+
|
|
35
|
+
## How it works
|
|
36
|
+
|
|
37
|
+
Unlike pyhomematic, which required manual device mappings, aiohomematic automatically creates entities for each relevant parameter on every device channel (unless blacklisted). To achieve this it:
|
|
38
|
+
|
|
39
|
+
- Fetches and caches device paramsets (VALUES) for fast successive startups.
|
|
40
|
+
- Provides hooks for custom entity classes where complex behavior is needed (e.g., thermostats, lights, covers, climate, locks, sirens).
|
|
41
|
+
- Includes helpers for robust operation, such as automatic reconnection after CCU restarts.
|
|
42
|
+
|
|
43
|
+
## Key features
|
|
44
|
+
|
|
45
|
+
- Automatic entity discovery from device/channel parameters.
|
|
46
|
+
- Extensible via custom entity classes for complex devices.
|
|
47
|
+
- Caching of paramsets to speed up restarts.
|
|
48
|
+
- Designed to integrate with Home Assistant.
|
|
49
|
+
|
|
50
|
+
## Installation (with Home Assistant)
|
|
51
|
+
|
|
52
|
+
Install via the custom component: [custom_homematic](https://github.com/sukramj/custom_homematic).
|
|
53
|
+
|
|
54
|
+
Follow the installation guide: https://github.com/sukramj/custom_homematic/wiki/Installation
|
|
55
|
+
|
|
56
|
+
## Requirements
|
|
57
|
+
|
|
58
|
+
Due to a bug in earlier CCU2/CCU3 firmware, aiohomematic requires at least the following versions when used with HomematicIP devices:
|
|
59
|
+
|
|
60
|
+
- CCU2: 2.53.27
|
|
61
|
+
- CCU3: 3.53.26
|
|
62
|
+
|
|
63
|
+
See details here: https://github.com/jens-maus/RaspberryMatic/issues/843. Other CCU‑like platforms using the buggy HmIPServer version are not supported.
|
|
64
|
+
|
|
65
|
+
## Useful links
|
|
66
|
+
|
|
67
|
+
- Examples: see example.py in this repository.
|
|
68
|
+
- Changelog: see changelog.md.
|
|
69
|
+
- Source code and documentation: this repository (docs/ directory may contain additional information).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# AIO Homematic (hahomematic)
|
|
2
|
+
|
|
3
|
+
A lightweight Python 3 library that powers Home Assistant integrations for controlling and monitoring [HomeMatic](https://www.eq-3.com/products/homematic.html) and [HomematicIP](https://www.homematic-ip.com/en/start.html) devices. Some third‑party devices/gateways (e.g., Bosch, Intertechno) may be supported as well.
|
|
4
|
+
|
|
5
|
+
This project is the modern successor to [pyhomematic](https://github.com/danielperna84/pyhomematic), focusing on automatic entity creation, fewer manual device definitions, and faster startups.
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
Unlike pyhomematic, which required manual device mappings, aiohomematic automatically creates entities for each relevant parameter on every device channel (unless blacklisted). To achieve this it:
|
|
10
|
+
|
|
11
|
+
- Fetches and caches device paramsets (VALUES) for fast successive startups.
|
|
12
|
+
- Provides hooks for custom entity classes where complex behavior is needed (e.g., thermostats, lights, covers, climate, locks, sirens).
|
|
13
|
+
- Includes helpers for robust operation, such as automatic reconnection after CCU restarts.
|
|
14
|
+
|
|
15
|
+
## Key features
|
|
16
|
+
|
|
17
|
+
- Automatic entity discovery from device/channel parameters.
|
|
18
|
+
- Extensible via custom entity classes for complex devices.
|
|
19
|
+
- Caching of paramsets to speed up restarts.
|
|
20
|
+
- Designed to integrate with Home Assistant.
|
|
21
|
+
|
|
22
|
+
## Installation (with Home Assistant)
|
|
23
|
+
|
|
24
|
+
Install via the custom component: [custom_homematic](https://github.com/sukramj/custom_homematic).
|
|
25
|
+
|
|
26
|
+
Follow the installation guide: https://github.com/sukramj/custom_homematic/wiki/Installation
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
Due to a bug in earlier CCU2/CCU3 firmware, aiohomematic requires at least the following versions when used with HomematicIP devices:
|
|
31
|
+
|
|
32
|
+
- CCU2: 2.53.27
|
|
33
|
+
- CCU3: 3.53.26
|
|
34
|
+
|
|
35
|
+
See details here: https://github.com/jens-maus/RaspberryMatic/issues/843. Other CCU‑like platforms using the buggy HmIPServer version are not supported.
|
|
36
|
+
|
|
37
|
+
## Useful links
|
|
38
|
+
|
|
39
|
+
- Examples: see example.py in this repository.
|
|
40
|
+
- Changelog: see changelog.md.
|
|
41
|
+
- Source code and documentation: this repository (docs/ directory may contain additional information).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AioHomematic: a Python 3 library to interact with HomeMatic and HomematicIP backends.
|
|
3
|
+
|
|
4
|
+
This package provides a high-level API to discover devices and channels, read and write
|
|
5
|
+
parameters (data points), receive events, and manage programs and system variables.
|
|
6
|
+
|
|
7
|
+
Key layers and responsibilities:
|
|
8
|
+
- aiohomematic.central: Orchestrates clients, caches, device creation and events.
|
|
9
|
+
- aiohomematic.client: Interface-specific clients (JSON-RPC/XML-RPC, Homegear) handling IO.
|
|
10
|
+
- aiohomematic.model: Data point abstraction for generic, hub, and calculated entities.
|
|
11
|
+
- aiohomematic.caches: Persistent and runtime caches for descriptions, values, and metadata.
|
|
12
|
+
|
|
13
|
+
Typical usage is to construct a CentralConfig, create a CentralUnit and start it, then
|
|
14
|
+
consume data points and events or issue write commands via the exposed API.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import asyncio
|
|
20
|
+
import logging
|
|
21
|
+
import signal
|
|
22
|
+
import sys
|
|
23
|
+
import threading
|
|
24
|
+
from typing import Final
|
|
25
|
+
|
|
26
|
+
from aiohomematic import central as hmcu
|
|
27
|
+
from aiohomematic.const import VERSION
|
|
28
|
+
|
|
29
|
+
if sys.stdout.isatty():
|
|
30
|
+
logging.basicConfig(level=logging.INFO)
|
|
31
|
+
|
|
32
|
+
__version__: Final = VERSION
|
|
33
|
+
_LOGGER: Final = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# pylint: disable=unused-argument
|
|
37
|
+
# noinspection PyUnusedLocal
|
|
38
|
+
def signal_handler(sig, frame): # type: ignore[no-untyped-def]
|
|
39
|
+
"""Handle signal to shut down central."""
|
|
40
|
+
_LOGGER.info("Got signal: %s. Shutting down central", str(sig))
|
|
41
|
+
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
42
|
+
for central in hmcu.CENTRAL_INSTANCES.values():
|
|
43
|
+
asyncio.run_coroutine_threadsafe(central.stop(), asyncio.get_running_loop())
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
if threading.current_thread() is threading.main_thread() and sys.stdout.isatty():
|
|
47
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Module with support for loop interaction."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Callable, Collection, Coroutine
|
|
7
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
8
|
+
from concurrent.futures._base import CancelledError
|
|
9
|
+
from functools import wraps
|
|
10
|
+
import logging
|
|
11
|
+
from time import monotonic
|
|
12
|
+
from typing import Any, Final, cast
|
|
13
|
+
|
|
14
|
+
from aiohomematic.const import BLOCK_LOG_TIMEOUT
|
|
15
|
+
from aiohomematic.exceptions import AioHomematicException
|
|
16
|
+
from aiohomematic.support import debug_enabled, extract_exc_args
|
|
17
|
+
|
|
18
|
+
_LOGGER: Final = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Looper:
|
|
22
|
+
"""Helper class for event loop support."""
|
|
23
|
+
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
"""Init the loop helper."""
|
|
26
|
+
self._tasks: Final[set[asyncio.Future[Any]]] = set()
|
|
27
|
+
self._loop = asyncio.get_event_loop()
|
|
28
|
+
|
|
29
|
+
async def block_till_done(self) -> None:
|
|
30
|
+
"""Block until all pending work is done."""
|
|
31
|
+
# To flush out any call_soon_threadsafe
|
|
32
|
+
await asyncio.sleep(0)
|
|
33
|
+
start_time: float | None = None
|
|
34
|
+
current_task = asyncio.current_task()
|
|
35
|
+
while tasks := [task for task in self._tasks if task is not current_task and not cancelling(task)]:
|
|
36
|
+
await self._await_and_log_pending(tasks)
|
|
37
|
+
|
|
38
|
+
if start_time is None:
|
|
39
|
+
# Avoid calling monotonic() until we know
|
|
40
|
+
# we may need to start logging blocked tasks.
|
|
41
|
+
start_time = 0
|
|
42
|
+
elif start_time == 0:
|
|
43
|
+
# If we have waited twice then we set the start
|
|
44
|
+
# time
|
|
45
|
+
start_time = monotonic()
|
|
46
|
+
elif monotonic() - start_time > BLOCK_LOG_TIMEOUT:
|
|
47
|
+
# We have waited at least three loops and new tasks
|
|
48
|
+
# continue to block. At this point we start
|
|
49
|
+
# logging all waiting tasks.
|
|
50
|
+
for task in tasks:
|
|
51
|
+
_LOGGER.debug("Waiting for task: %s", task)
|
|
52
|
+
|
|
53
|
+
async def _await_and_log_pending(self, pending: Collection[asyncio.Future[Any]]) -> None:
|
|
54
|
+
"""Await and log tasks that take a long time."""
|
|
55
|
+
wait_time = 0
|
|
56
|
+
while pending:
|
|
57
|
+
_, pending = await asyncio.wait(pending, timeout=BLOCK_LOG_TIMEOUT)
|
|
58
|
+
if not pending:
|
|
59
|
+
return
|
|
60
|
+
wait_time += BLOCK_LOG_TIMEOUT
|
|
61
|
+
for task in pending:
|
|
62
|
+
_LOGGER.debug("Waited %s seconds for task: %s", wait_time, task)
|
|
63
|
+
|
|
64
|
+
def create_task(self, target: Coroutine[Any, Any, Any], name: str) -> None:
|
|
65
|
+
"""Add task to the executor pool."""
|
|
66
|
+
try:
|
|
67
|
+
self._loop.call_soon_threadsafe(self._async_create_task, target, name)
|
|
68
|
+
except CancelledError:
|
|
69
|
+
_LOGGER.debug(
|
|
70
|
+
"create_task: task cancelled for %s",
|
|
71
|
+
name,
|
|
72
|
+
)
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
def _async_create_task[R](self, target: Coroutine[Any, Any, R], name: str) -> asyncio.Task[R]:
|
|
76
|
+
"""Create a task from within the event_loop. This method must be run in the event_loop."""
|
|
77
|
+
task = self._loop.create_task(target, name=name)
|
|
78
|
+
self._tasks.add(task)
|
|
79
|
+
task.add_done_callback(self._tasks.remove)
|
|
80
|
+
return task
|
|
81
|
+
|
|
82
|
+
def run_coroutine(self, coro: Coroutine, name: str) -> Any:
|
|
83
|
+
"""Call coroutine from sync."""
|
|
84
|
+
try:
|
|
85
|
+
return asyncio.run_coroutine_threadsafe(coro, self._loop).result()
|
|
86
|
+
except CancelledError: # pragma: no cover
|
|
87
|
+
_LOGGER.debug(
|
|
88
|
+
"run_coroutine: coroutine interrupted for %s",
|
|
89
|
+
name,
|
|
90
|
+
)
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def async_add_executor_job[T](
|
|
94
|
+
self,
|
|
95
|
+
target: Callable[..., T],
|
|
96
|
+
*args: Any,
|
|
97
|
+
name: str,
|
|
98
|
+
executor: ThreadPoolExecutor | None = None,
|
|
99
|
+
) -> asyncio.Future[T]:
|
|
100
|
+
"""Add an executor job from within the event_loop."""
|
|
101
|
+
try:
|
|
102
|
+
task = self._loop.run_in_executor(executor, target, *args)
|
|
103
|
+
self._tasks.add(task)
|
|
104
|
+
task.add_done_callback(self._tasks.remove)
|
|
105
|
+
except (TimeoutError, CancelledError) as err: # pragma: no cover
|
|
106
|
+
message = f"async_add_executor_job: task cancelled for {name} [{extract_exc_args(exc=err)}]"
|
|
107
|
+
_LOGGER.debug(message)
|
|
108
|
+
raise AioHomematicException(message) from err
|
|
109
|
+
return task
|
|
110
|
+
|
|
111
|
+
def cancel_tasks(self) -> None:
|
|
112
|
+
"""Cancel running tasks."""
|
|
113
|
+
for task in self._tasks.copy():
|
|
114
|
+
if not task.cancelled():
|
|
115
|
+
task.cancel()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def cancelling(task: asyncio.Future[Any]) -> bool:
|
|
119
|
+
"""Return True if task is cancelling."""
|
|
120
|
+
return bool((cancelling_ := getattr(task, "cancelling", None)) and cancelling_())
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def loop_check[**P, R](func: Callable[P, R]) -> Callable[P, R]:
|
|
124
|
+
"""Annotation to mark method that must be run within the event loop."""
|
|
125
|
+
|
|
126
|
+
_with_loop: set = set()
|
|
127
|
+
|
|
128
|
+
@wraps(func)
|
|
129
|
+
def wrapper_loop_check(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
130
|
+
"""Wrap loop check."""
|
|
131
|
+
return_value = func(*args, **kwargs)
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
asyncio.get_running_loop()
|
|
135
|
+
loop_running = True
|
|
136
|
+
except Exception:
|
|
137
|
+
loop_running = False
|
|
138
|
+
|
|
139
|
+
if not loop_running and func not in _with_loop:
|
|
140
|
+
_with_loop.add(func)
|
|
141
|
+
_LOGGER.warning("Method %s must run in the event_loop. No loop detected.", func.__name__)
|
|
142
|
+
|
|
143
|
+
return return_value
|
|
144
|
+
|
|
145
|
+
setattr(func, "_loop_check", True)
|
|
146
|
+
return cast(Callable[P, R], wrapper_loop_check) if debug_enabled() else func
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Cache packages for AioHomematic.
|
|
3
|
+
|
|
4
|
+
This package groups cache implementations used throughout the library:
|
|
5
|
+
- persistent: Long-lived on-disk caches for device and paramset descriptions.
|
|
6
|
+
- dynamic: Short-lived in-memory caches for runtime values and connection health.
|
|
7
|
+
- visibility: Parameter visibility rules to decide which parameters are relevant.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|