aiohomematic 2025.11.3__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.

Files changed (77) hide show
  1. aiohomematic/__init__.py +61 -0
  2. aiohomematic/async_support.py +212 -0
  3. aiohomematic/central/__init__.py +2309 -0
  4. aiohomematic/central/decorators.py +155 -0
  5. aiohomematic/central/rpc_server.py +295 -0
  6. aiohomematic/client/__init__.py +1848 -0
  7. aiohomematic/client/_rpc_errors.py +81 -0
  8. aiohomematic/client/json_rpc.py +1326 -0
  9. aiohomematic/client/rpc_proxy.py +311 -0
  10. aiohomematic/const.py +1127 -0
  11. aiohomematic/context.py +18 -0
  12. aiohomematic/converter.py +108 -0
  13. aiohomematic/decorators.py +302 -0
  14. aiohomematic/exceptions.py +164 -0
  15. aiohomematic/hmcli.py +186 -0
  16. aiohomematic/model/__init__.py +140 -0
  17. aiohomematic/model/calculated/__init__.py +84 -0
  18. aiohomematic/model/calculated/climate.py +290 -0
  19. aiohomematic/model/calculated/data_point.py +327 -0
  20. aiohomematic/model/calculated/operating_voltage_level.py +299 -0
  21. aiohomematic/model/calculated/support.py +234 -0
  22. aiohomematic/model/custom/__init__.py +177 -0
  23. aiohomematic/model/custom/climate.py +1532 -0
  24. aiohomematic/model/custom/cover.py +792 -0
  25. aiohomematic/model/custom/data_point.py +334 -0
  26. aiohomematic/model/custom/definition.py +871 -0
  27. aiohomematic/model/custom/light.py +1128 -0
  28. aiohomematic/model/custom/lock.py +394 -0
  29. aiohomematic/model/custom/siren.py +275 -0
  30. aiohomematic/model/custom/support.py +41 -0
  31. aiohomematic/model/custom/switch.py +175 -0
  32. aiohomematic/model/custom/valve.py +114 -0
  33. aiohomematic/model/data_point.py +1123 -0
  34. aiohomematic/model/device.py +1445 -0
  35. aiohomematic/model/event.py +208 -0
  36. aiohomematic/model/generic/__init__.py +217 -0
  37. aiohomematic/model/generic/action.py +34 -0
  38. aiohomematic/model/generic/binary_sensor.py +30 -0
  39. aiohomematic/model/generic/button.py +27 -0
  40. aiohomematic/model/generic/data_point.py +171 -0
  41. aiohomematic/model/generic/dummy.py +147 -0
  42. aiohomematic/model/generic/number.py +76 -0
  43. aiohomematic/model/generic/select.py +39 -0
  44. aiohomematic/model/generic/sensor.py +74 -0
  45. aiohomematic/model/generic/switch.py +54 -0
  46. aiohomematic/model/generic/text.py +29 -0
  47. aiohomematic/model/hub/__init__.py +333 -0
  48. aiohomematic/model/hub/binary_sensor.py +24 -0
  49. aiohomematic/model/hub/button.py +28 -0
  50. aiohomematic/model/hub/data_point.py +340 -0
  51. aiohomematic/model/hub/number.py +39 -0
  52. aiohomematic/model/hub/select.py +49 -0
  53. aiohomematic/model/hub/sensor.py +37 -0
  54. aiohomematic/model/hub/switch.py +44 -0
  55. aiohomematic/model/hub/text.py +30 -0
  56. aiohomematic/model/support.py +586 -0
  57. aiohomematic/model/update.py +143 -0
  58. aiohomematic/property_decorators.py +496 -0
  59. aiohomematic/py.typed +0 -0
  60. aiohomematic/rega_scripts/fetch_all_device_data.fn +92 -0
  61. aiohomematic/rega_scripts/get_program_descriptions.fn +30 -0
  62. aiohomematic/rega_scripts/get_serial.fn +44 -0
  63. aiohomematic/rega_scripts/get_system_variable_descriptions.fn +30 -0
  64. aiohomematic/rega_scripts/set_program_state.fn +12 -0
  65. aiohomematic/rega_scripts/set_system_variable.fn +15 -0
  66. aiohomematic/store/__init__.py +34 -0
  67. aiohomematic/store/dynamic.py +551 -0
  68. aiohomematic/store/persistent.py +988 -0
  69. aiohomematic/store/visibility.py +812 -0
  70. aiohomematic/support.py +664 -0
  71. aiohomematic/validator.py +112 -0
  72. aiohomematic-2025.11.3.dist-info/METADATA +144 -0
  73. aiohomematic-2025.11.3.dist-info/RECORD +77 -0
  74. aiohomematic-2025.11.3.dist-info/WHEEL +5 -0
  75. aiohomematic-2025.11.3.dist-info/entry_points.txt +2 -0
  76. aiohomematic-2025.11.3.dist-info/licenses/LICENSE +21 -0
  77. aiohomematic-2025.11.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,61 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2021-2025
3
+ """
4
+ AioHomematic: a Python 3 library to interact with Homematic and HomematicIP backends.
5
+
6
+ Public API at the top-level package is defined by __all__.
7
+
8
+ This package provides a high-level API to discover devices and channels, read and write
9
+ parameters (data points), receive events, and manage programs and system variables.
10
+
11
+ Key layers and responsibilities:
12
+ - aiohomematic.central: Orchestrates clients, store, device creation and events.
13
+ - aiohomematic.client: Interface-specific clients (JSON-RPC/XML-RPC, Homegear) handling IO.
14
+ - aiohomematic.model: Data point abstraction for generic, hub, and calculated entities.
15
+ - aiohomematic.store: Persistent and runtime store for descriptions, values, and metadata.
16
+
17
+ Typical usage is to construct a CentralConfig, create a CentralUnit and start it, then
18
+ consume data points and events or issue write commands via the exposed API.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import asyncio
24
+ import logging
25
+ import signal
26
+ import sys
27
+ import threading
28
+ from typing import Final
29
+
30
+ from aiohomematic import central as hmcu, validator as _ahm_validator
31
+ from aiohomematic.const import VERSION
32
+
33
+ if sys.stdout.isatty():
34
+ logging.basicConfig(level=logging.INFO)
35
+
36
+ __version__: Final = VERSION
37
+ _LOGGER: Final = logging.getLogger(__name__)
38
+
39
+
40
+ # pylint: disable=unused-argument
41
+ # noinspection PyUnusedLocal
42
+ def signal_handler(sig, frame): # type: ignore[no-untyped-def]
43
+ """Handle signal to shut down central."""
44
+ _LOGGER.info("Got signal: %s. Shutting down central", str(sig))
45
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
46
+ for central in hmcu.CENTRAL_INSTANCES.values():
47
+ asyncio.run_coroutine_threadsafe(central.stop(), asyncio.get_running_loop())
48
+
49
+
50
+ # Perform lightweight startup validation once on import
51
+ try:
52
+ _ahm_validator.validate_startup()
53
+ except Exception as _exc: # pragma: no cover
54
+ # Fail-fast with a clear message if validation fails during import
55
+ raise RuntimeError(f"AioHomematic startup validation failed: {_exc}") from _exc
56
+
57
+ if threading.current_thread() is threading.main_thread() and sys.stdout.isatty():
58
+ signal.signal(signal.SIGINT, signal_handler)
59
+
60
+ # Define public API for the top-level package
61
+ __all__ = ["__version__"]
@@ -0,0 +1,212 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2021-2025
3
+ """Module with support for loop interaction."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import asyncio
8
+ from collections.abc import Callable, Collection, Coroutine
9
+ from concurrent.futures import ThreadPoolExecutor
10
+ from concurrent.futures._base import CancelledError
11
+ import contextlib
12
+ from functools import wraps
13
+ import logging
14
+ from time import monotonic
15
+ from types import CoroutineType
16
+ from typing import Any, Final, cast
17
+
18
+ from aiohomematic.const import BLOCK_LOG_TIMEOUT
19
+ from aiohomematic.exceptions import AioHomematicException
20
+ import aiohomematic.support as hms
21
+ from aiohomematic.support import extract_exc_args
22
+
23
+ _LOGGER: Final = logging.getLogger(__name__)
24
+
25
+
26
+ class Looper:
27
+ """Helper class for event loop support."""
28
+
29
+ def __init__(self) -> None:
30
+ """Init the loop helper."""
31
+ self._tasks: Final[set[asyncio.Future[Any]]] = set()
32
+ self._loop = asyncio.get_event_loop()
33
+
34
+ async def block_till_done(self, *, wait_time: float | None = None) -> None:
35
+ """
36
+ Block until all pending work is done.
37
+
38
+ If wait_time is set, stop waiting after the given number of seconds and log remaining tasks.
39
+ """
40
+ # To flush out any call_soon_threadsafe
41
+ await asyncio.sleep(0)
42
+ start_time: float | None = None
43
+ deadline: float | None = (monotonic() + wait_time) if wait_time is not None else None
44
+ current_task = asyncio.current_task()
45
+ while tasks := [task for task in self._tasks if task is not current_task and not cancelling(task=task)]:
46
+ # If we have a deadline and have exceeded it, log remaining tasks and break
47
+ if deadline is not None and monotonic() >= deadline:
48
+ for task in tasks:
49
+ _LOGGER.warning("Shutdown timeout reached; task still pending: %s", task)
50
+ break
51
+
52
+ pending_after_wait = await self._await_and_log_pending(pending=tasks, deadline=deadline)
53
+
54
+ # If deadline has been reached and tasks are still pending, log and break
55
+ if deadline is not None and monotonic() >= deadline and pending_after_wait:
56
+ for task in pending_after_wait:
57
+ _LOGGER.warning("Shutdown timeout reached; task still pending: %s", task)
58
+ break
59
+
60
+ if start_time is None:
61
+ # Avoid calling monotonic() until we know
62
+ # we may need to start logging blocked tasks.
63
+ start_time = 0
64
+ elif start_time == 0:
65
+ # If we have waited twice then we set the start
66
+ # time
67
+ start_time = monotonic()
68
+ elif monotonic() - start_time > BLOCK_LOG_TIMEOUT:
69
+ # We have waited at least three loops and new tasks
70
+ # continue to block. At this point we start
71
+ # logging all waiting tasks.
72
+ for task in tasks:
73
+ _LOGGER.debug("Waiting for task: %s", task)
74
+
75
+ async def _await_and_log_pending(
76
+ self, *, pending: Collection[asyncio.Future[Any]], deadline: float | None
77
+ ) -> set[asyncio.Future[Any]]:
78
+ """
79
+ Await and log tasks that take a long time, respecting an optional deadline.
80
+
81
+ Returns the set of pending tasks if the deadline has been reached (or zero timeout),
82
+ allowing the caller to decide about timeout logging. Returns an empty set if no tasks are pending.
83
+ """
84
+ wait_time = 0.0
85
+ pending_set: set[asyncio.Future[Any]] = set(pending)
86
+ while pending_set:
87
+ if deadline is None:
88
+ timeout = BLOCK_LOG_TIMEOUT
89
+ else:
90
+ remaining = int(max(0.0, deadline - monotonic()))
91
+ if (timeout := min(BLOCK_LOG_TIMEOUT, remaining)) == 0.0:
92
+ # Deadline reached; return current pending to caller for warning log
93
+ return pending_set
94
+ done, still_pending = await asyncio.wait(pending_set, timeout=timeout)
95
+ if not (pending_set := set(still_pending)):
96
+ return set()
97
+ wait_time += timeout
98
+ for task in pending_set:
99
+ _LOGGER.debug("Waited %s seconds for task: %s", wait_time, task)
100
+ # If the deadline was reached during the wait, let caller handle warning
101
+ if deadline is not None and monotonic() >= deadline:
102
+ return pending_set
103
+ return set()
104
+
105
+ def create_task(
106
+ self, *, target: Coroutine[Any, Any, Any] | Callable[[], Coroutine[Any, Any, Any]], name: str
107
+ ) -> None:
108
+ """
109
+ Schedule a coroutine to run in the loop.
110
+
111
+ Accepts either an already-created coroutine object or a zero-argument
112
+ callable that returns a coroutine. The callable form defers coroutine
113
+ creation until inside the event loop, which avoids "was never awaited"
114
+ warnings if callers only inspect the parameters (e.g. in tests).
115
+ """
116
+ try:
117
+ self._loop.call_soon_threadsafe(self._async_create_task, target, name)
118
+ except CancelledError:
119
+ # Scheduling failed; if a coroutine object was provided, close it to
120
+ # avoid 'was never awaited' warnings.
121
+ if asyncio.iscoroutine(target):
122
+ with contextlib.suppress(Exception):
123
+ cast(CoroutineType, target).close()
124
+ _LOGGER.debug("create_task: task cancelled for %s", name)
125
+ return
126
+
127
+ def _async_create_task[R]( # kwonly: disable
128
+ self, target: Coroutine[Any, Any, R] | Callable[[], Coroutine[Any, Any, R]], name: str
129
+ ) -> asyncio.Task[R]:
130
+ """Create a task from within the event loop. Must be run in the event loop."""
131
+ # If target is a callable, call it here to create the coroutine inside the loop
132
+ coro: Coroutine[Any, Any, R] = target if asyncio.iscoroutine(target) else target()
133
+ task = self._loop.create_task(coro, name=name)
134
+ self._tasks.add(task)
135
+ task.add_done_callback(self._tasks.remove)
136
+ return task
137
+
138
+ def run_coroutine(self, *, coro: Coroutine, name: str) -> Any:
139
+ """Call coroutine from sync."""
140
+ try:
141
+ return asyncio.run_coroutine_threadsafe(coro, self._loop).result()
142
+ except CancelledError: # pragma: no cover
143
+ _LOGGER.debug(
144
+ "run_coroutine: coroutine interrupted for %s",
145
+ name,
146
+ )
147
+ return None
148
+
149
+ def async_add_executor_job[T](
150
+ self,
151
+ target: Callable[..., T],
152
+ *args: Any,
153
+ name: str,
154
+ executor: ThreadPoolExecutor | None = None,
155
+ ) -> asyncio.Future[T]:
156
+ """Add an executor job from within the event_loop."""
157
+ try:
158
+ task = self._loop.run_in_executor(executor, target, *args)
159
+ self._tasks.add(task)
160
+ task.add_done_callback(self._tasks.remove)
161
+ except (TimeoutError, CancelledError) as err: # pragma: no cover
162
+ message = f"async_add_executor_job: task cancelled for {name} [{extract_exc_args(exc=err)}]"
163
+ _LOGGER.debug(message)
164
+ raise AioHomematicException(message) from err
165
+ return task
166
+
167
+ def cancel_tasks(self) -> None:
168
+ """Cancel running tasks."""
169
+ for task in self._tasks.copy():
170
+ if not task.cancelled():
171
+ task.cancel()
172
+
173
+
174
+ def cancelling(*, task: asyncio.Future[Any]) -> bool:
175
+ """Return True if task is cancelling."""
176
+ return bool((cancelling_ := getattr(task, "cancelling", None)) and cancelling_())
177
+
178
+
179
+ def loop_check[**P, R](func: Callable[P, R]) -> Callable[P, R]:
180
+ """
181
+ Annotation to mark method that must be run within the event loop.
182
+
183
+ Always wraps the function, but only performs loop checks when debug is enabled.
184
+ This allows tests to monkeypatch aiohomematic.support.debug_enabled at runtime.
185
+ """
186
+
187
+ _with_loop: set = set()
188
+
189
+ @wraps(func)
190
+ def wrapper_loop_check(*args: P.args, **kwargs: P.kwargs) -> R:
191
+ """Wrap loop check."""
192
+ return_value = func(*args, **kwargs)
193
+
194
+ # Only perform the (potentially expensive) loop check when debug is enabled.
195
+ if hms.debug_enabled():
196
+ try:
197
+ asyncio.get_running_loop()
198
+ loop_running = True
199
+ except Exception:
200
+ loop_running = False
201
+
202
+ if not loop_running and func not in _with_loop:
203
+ _with_loop.add(func)
204
+ _LOGGER.warning(
205
+ "Method %s must run in the event_loop. No loop detected.",
206
+ func.__name__,
207
+ )
208
+
209
+ return return_value
210
+
211
+ setattr(func, "_loop_check", True)
212
+ return cast(Callable[P, R], wrapper_loop_check)