diff --git a/changelog.md b/changelog.md index 7ddf5d73..4765584e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,10 +1,16 @@ +# Version 2024.10.1 (2024-10-04) + +- Fix rx_mode lazy_config +- Make DEFAULT optional due to homegear support +- Move context var to own module + # Version 2024.10.0 (2024-10-03) - Add config option for max read workers - Disable collector for stop events - Improve logging when raising exception - Log exception at the most outer service -- Make UPDATEABLE and DEFAULT optional due to homegear support +- Make UPDATEABLE optional due to homegear support - Raise exception on set_value, put_paramset - Remove command queue diff --git a/hahomematic/__init__.py b/hahomematic/__init__.py index 4d437694..00e8e696 100644 --- a/hahomematic/__init__.py +++ b/hahomematic/__init__.py @@ -8,7 +8,6 @@ from __future__ import annotations import asyncio -from contextvars import ContextVar import logging import signal import sys @@ -17,9 +16,6 @@ from hahomematic import central as hmcu -# context var for storing if call is running within a service -IN_SERVICE_VAR: ContextVar[bool] = ContextVar("in_service_var", default=False) - if sys.stdout.isatty(): logging.basicConfig(level=logging.INFO) diff --git a/hahomematic/const.py b/hahomematic/const.py index e894149e..b8730db1 100644 --- a/hahomematic/const.py +++ b/hahomematic/const.py @@ -398,7 +398,7 @@ class RxMode(IntEnum): BURST = 2 CONFIG = 4 WAKEUP = 8 - LAZY_CONFIG = 10 + LAZY_CONFIG = 16 class CommandRxMode(StrEnum): diff --git a/hahomematic/context.py b/hahomematic/context.py new file mode 100644 index 00000000..b11d5a2c --- /dev/null +++ b/hahomematic/context.py @@ -0,0 +1,8 @@ +"""Collection of context variables.""" + +from __future__ import annotations + +from contextvars import ContextVar + +# context var for storing if call is running within a service +IN_SERVICE_VAR: ContextVar[bool] = ContextVar("in_service_var", default=False) diff --git a/hahomematic/platforms/decorators.py b/hahomematic/platforms/decorators.py index 7ecdd95f..70e8c14b 100644 --- a/hahomematic/platforms/decorators.py +++ b/hahomematic/platforms/decorators.py @@ -10,7 +10,7 @@ import logging from typing import Any, ParamSpec, TypeVar -import hahomematic +from hahomematic.context import IN_SERVICE_VAR from hahomematic.exceptions import BaseHomematicException from hahomematic.support import reduce_args @@ -141,17 +141,17 @@ def service_decorator(func: Callable[P, Awaitable[T]]) -> Callable[P, Awaitable[ async def service_wrapper(*args: P.args, **kwargs: P.kwargs) -> T: """Wrap service to log exception.""" token: Token | None = None - if not hahomematic.IN_SERVICE_VAR.get(): - token = hahomematic.IN_SERVICE_VAR.set(True) + if not IN_SERVICE_VAR.get(): + token = IN_SERVICE_VAR.set(True) try: return_value = await func(*args, **kwargs) if token: - hahomematic.IN_SERVICE_VAR.reset(token) + IN_SERVICE_VAR.reset(token) return return_value # noqa: TRY300 except BaseHomematicException as bhe: if token: - hahomematic.IN_SERVICE_VAR.reset(token) - if not hahomematic.IN_SERVICE_VAR.get() and log_level > logging.NOTSET: + IN_SERVICE_VAR.reset(token) + if not IN_SERVICE_VAR.get() and log_level > logging.NOTSET: logging.getLogger(args[0].__module__).log( level=log_level, msg=reduce_args(args=bhe.args) ) diff --git a/hahomematic/platforms/entity.py b/hahomematic/platforms/entity.py index fe7aec03..9e5b5fe0 100644 --- a/hahomematic/platforms/entity.py +++ b/hahomematic/platforms/entity.py @@ -13,7 +13,6 @@ import voluptuous as vol -import hahomematic from hahomematic import central as hmcu, client as hmcl, support as hms from hahomematic.async_support import loop_check from hahomematic.config import WAIT_FOR_CALLBACK @@ -41,6 +40,7 @@ ParameterType, ParamsetKey, ) +from hahomematic.context import IN_SERVICE_VAR from hahomematic.exceptions import BaseHomematicException, HaHomematicException from hahomematic.platforms import device as hmd from hahomematic.platforms.decorators import config_property, get_service_calls, state_property @@ -815,13 +815,13 @@ def bind_decorator[_CallableT: Callable[..., Any]](func: _CallableT) -> _Callabl async def bind_wrapper(*args: Any, **kwargs: Any) -> Any: """Wrap method to add collector.""" token: Token | None = None - if not hahomematic.IN_SERVICE_VAR.get(): - token = hahomematic.IN_SERVICE_VAR.set(True) + if not IN_SERVICE_VAR.get(): + token = IN_SERVICE_VAR.set(True) try: if not enabled: return_value = await func(*args, **kwargs) if token: - hahomematic.IN_SERVICE_VAR.reset(token) + IN_SERVICE_VAR.reset(token) return return_value try: collector_exists = args[argument_index] is not None @@ -831,19 +831,19 @@ async def bind_wrapper(*args: Any, **kwargs: Any) -> Any: if collector_exists: return_value = await func(*args, **kwargs) if token: - hahomematic.IN_SERVICE_VAR.reset(token) + IN_SERVICE_VAR.reset(token) return return_value collector = CallParameterCollector(client=args[0].channel.device.client) kwargs[_COLLECTOR_ARGUMENT_NAME] = collector return_value = await func(*args, **kwargs) await collector.send_data(wait_for_callback=wait_for_callback) if token: - hahomematic.IN_SERVICE_VAR.reset(token) + IN_SERVICE_VAR.reset(token) return return_value # noqa:TRY300 except BaseHomematicException as bhe: if token: - hahomematic.IN_SERVICE_VAR.reset(token) - in_service = hahomematic.IN_SERVICE_VAR.get() + IN_SERVICE_VAR.reset(token) + in_service = IN_SERVICE_VAR.get() if not in_service and log_level > logging.NOTSET: logging.getLogger(args[0].__module__).log( level=log_level, msg=reduce_args(args=bhe.args) diff --git a/hahomematic/support.py b/hahomematic/support.py index 37d9d0dd..4dd40d8b 100644 --- a/hahomematic/support.py +++ b/hahomematic/support.py @@ -427,9 +427,9 @@ def _make_value_hashable(value: Any) -> Any: def get_rx_modes(mode: int) -> tuple[RxMode, ...]: """Convert int to rx modes.""" rx_modes: set[RxMode] = set() - if mode == 10: + if mode & RxMode.LAZY_CONFIG: + mode -= RxMode.LAZY_CONFIG rx_modes.add(RxMode.LAZY_CONFIG) - return tuple(rx_modes) if mode & RxMode.WAKEUP: mode -= RxMode.WAKEUP rx_modes.add(RxMode.WAKEUP) diff --git a/pyproject.toml b/pyproject.toml index b910b87b..c15cad1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "hahomematic" -version = "2024.10.0" +version = "2024.10.1" license = {text = "MIT License"} description = "Homematic interface for Home Assistant running on Python 3." readme = "README.md"