aiohomematic 2025.8.6__py3-none-any.whl
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/__init__.py +47 -0
- aiohomematic/async_support.py +146 -0
- aiohomematic/caches/__init__.py +10 -0
- aiohomematic/caches/dynamic.py +554 -0
- aiohomematic/caches/persistent.py +459 -0
- aiohomematic/caches/visibility.py +774 -0
- aiohomematic/central/__init__.py +2034 -0
- aiohomematic/central/decorators.py +110 -0
- aiohomematic/central/xml_rpc_server.py +267 -0
- aiohomematic/client/__init__.py +1746 -0
- aiohomematic/client/json_rpc.py +1193 -0
- aiohomematic/client/xml_rpc.py +222 -0
- aiohomematic/const.py +795 -0
- aiohomematic/context.py +8 -0
- aiohomematic/converter.py +82 -0
- aiohomematic/decorators.py +188 -0
- aiohomematic/exceptions.py +145 -0
- aiohomematic/hmcli.py +159 -0
- aiohomematic/model/__init__.py +137 -0
- aiohomematic/model/calculated/__init__.py +65 -0
- aiohomematic/model/calculated/climate.py +230 -0
- aiohomematic/model/calculated/data_point.py +319 -0
- aiohomematic/model/calculated/operating_voltage_level.py +311 -0
- aiohomematic/model/calculated/support.py +174 -0
- aiohomematic/model/custom/__init__.py +175 -0
- aiohomematic/model/custom/climate.py +1334 -0
- aiohomematic/model/custom/const.py +146 -0
- aiohomematic/model/custom/cover.py +741 -0
- aiohomematic/model/custom/data_point.py +318 -0
- aiohomematic/model/custom/definition.py +861 -0
- aiohomematic/model/custom/light.py +1092 -0
- aiohomematic/model/custom/lock.py +389 -0
- aiohomematic/model/custom/siren.py +268 -0
- aiohomematic/model/custom/support.py +40 -0
- aiohomematic/model/custom/switch.py +172 -0
- aiohomematic/model/custom/valve.py +112 -0
- aiohomematic/model/data_point.py +1109 -0
- aiohomematic/model/decorators.py +173 -0
- aiohomematic/model/device.py +1347 -0
- aiohomematic/model/event.py +210 -0
- aiohomematic/model/generic/__init__.py +211 -0
- aiohomematic/model/generic/action.py +32 -0
- aiohomematic/model/generic/binary_sensor.py +28 -0
- aiohomematic/model/generic/button.py +25 -0
- aiohomematic/model/generic/data_point.py +162 -0
- aiohomematic/model/generic/number.py +73 -0
- aiohomematic/model/generic/select.py +36 -0
- aiohomematic/model/generic/sensor.py +72 -0
- aiohomematic/model/generic/switch.py +52 -0
- aiohomematic/model/generic/text.py +27 -0
- aiohomematic/model/hub/__init__.py +334 -0
- aiohomematic/model/hub/binary_sensor.py +22 -0
- aiohomematic/model/hub/button.py +26 -0
- aiohomematic/model/hub/data_point.py +332 -0
- aiohomematic/model/hub/number.py +37 -0
- aiohomematic/model/hub/select.py +47 -0
- aiohomematic/model/hub/sensor.py +35 -0
- aiohomematic/model/hub/switch.py +42 -0
- aiohomematic/model/hub/text.py +28 -0
- aiohomematic/model/support.py +599 -0
- aiohomematic/model/update.py +136 -0
- aiohomematic/py.typed +0 -0
- aiohomematic/rega_scripts/fetch_all_device_data.fn +75 -0
- aiohomematic/rega_scripts/get_program_descriptions.fn +30 -0
- aiohomematic/rega_scripts/get_serial.fn +44 -0
- aiohomematic/rega_scripts/get_system_variable_descriptions.fn +30 -0
- aiohomematic/rega_scripts/set_program_state.fn +12 -0
- aiohomematic/rega_scripts/set_system_variable.fn +15 -0
- aiohomematic/support.py +482 -0
- aiohomematic/validator.py +65 -0
- aiohomematic-2025.8.6.dist-info/METADATA +69 -0
- aiohomematic-2025.8.6.dist-info/RECORD +77 -0
- aiohomematic-2025.8.6.dist-info/WHEEL +5 -0
- aiohomematic-2025.8.6.dist-info/licenses/LICENSE +21 -0
- aiohomematic-2025.8.6.dist-info/top_level.txt +2 -0
- aiohomematic_support/__init__.py +1 -0
- aiohomematic_support/client_local.py +349 -0
aiohomematic/__init__.py
ADDED
|
@@ -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
|