Skip to content

Commit

Permalink
Extend DP_KEY with interface_id
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ committed Nov 12, 2024
1 parent d95280c commit a9041d7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 27 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Version 2024.11.1 (2024-11-09)
# Version 2024.11.1 (2024-11-12)

- Add basic support for json clients
- Add data_point_path event
- Add getDeviceDescription, getParamsetDescription, listDevices, getValue, setValue, getParamset, putParamset to json_rpc
- Extend DP_KEY with interface_id
- Rename event to data_point_event

# Version 2024.11.0 (2024-11-04)
Expand Down
2 changes: 2 additions & 0 deletions hahomematic/caches/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def add_set_value(
)

data_point_key = get_data_point_key(
interface_id=self._interface_id,
channel_address=channel_address,
paramset_key=ParamsetKey.VALUES,
parameter=parameter,
Expand All @@ -68,6 +69,7 @@ def add_put_paramset(
data_point_keys: set[DP_KEY] = set()
for parameter, value in values.items():
data_point_key = get_data_point_key(
interface_id=self._interface_id,
channel_address=channel_address,
paramset_key=paramset_key,
parameter=parameter,
Expand Down
29 changes: 9 additions & 20 deletions hahomematic/central/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ async def data_point_event(
return

data_point_key = get_data_point_key(
interface_id=interface_id,
channel_address=channel_address,
paramset_key=ParamsetKey.VALUES,
parameter=parameter,
Expand Down Expand Up @@ -1003,7 +1004,6 @@ async def data_point_event(
reduce_args(args=ex.args),
)

@callback_event
async def data_point_path_event(self, path_state: str, value: str) -> None:
"""If a device emits some sort event, we will handle it here."""
_LOGGER.debug(
Expand All @@ -1014,25 +1014,14 @@ async def data_point_path_event(self, path_state: str, value: str) -> None:

if (
data_point_key := self._data_point_path_event_subscriptions.get(path_state)
) is not None and data_point_key in self._data_point_key_event_subscriptions:
try:
for callback_handler in self._data_point_key_event_subscriptions[data_point_key]:
if callable(callback_handler):
await callback_handler(value)
except RuntimeError as rte: # pragma: no cover
_LOGGER.debug(
"DATA_POINT_PATH_EVENT: RuntimeError [%s]. Failed to call callback for: %s, %s",
reduce_args(args=rte.args),
path_state,
value,
)
except Exception as ex: # pragma: no cover
_LOGGER.warning(
"DATA_POINT_PATH_EVENT failed: Unable to call callback for: %s, %s, %s",
path_state,
value,
reduce_args(args=ex.args),
)
) is not None:
interface_id, channel_address, paramset_key, parameter = data_point_key
await self.data_point_event(
interface_id=interface_id,
channel_address=channel_address,
parameter=parameter,
value=value,
)

@callback_backend_system(system_event=BackendSystemEvent.LIST_DEVICES)
def list_devices(self, interface_id: str) -> list[DeviceDescription]:
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ def _async_event_changed(*args: Any, **kwargs: Any) -> None:
)
ev.set()

channel_address, paramset_key, parameter = data_point_key
interface_id, channel_address, paramset_key, parameter = data_point_key
if dp := device.get_generic_data_point(
channel_address=channel_address,
parameter=parameter,
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class ParameterType(StrEnum):
)

# channel_address, paramset_key,parameter
DP_KEY = tuple[str, ParamsetKey, str]
DP_KEY = tuple[str, str, ParamsetKey, str]

HMIP_FIRMWARE_UPDATE_IN_PROGRESS_STATES: Final[tuple[DeviceFirmwareState, ...]] = (
DeviceFirmwareState.DO_UPDATE_PENDING,
Expand Down
1 change: 1 addition & 0 deletions hahomematic/model/data_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ def is_un_ignored(self) -> bool:
def data_point_key(self) -> DP_KEY:
"""Return data_point key value."""
return get_data_point_key(
interface_id=self._device.interface_id,
channel_address=self._channel.address,
paramset_key=self._paramset_key,
parameter=self._parameter,
Expand Down
14 changes: 12 additions & 2 deletions hahomematic/model/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ def get_generic_data_point(
if paramset_key:
return self._generic_data_points.get(
get_data_point_key(
interface_id=self._device.interface_id,
channel_address=self._address,
paramset_key=paramset_key,
parameter=parameter,
Expand All @@ -895,6 +896,7 @@ def get_generic_data_point(

if dp := self._generic_data_points.get(
get_data_point_key(
interface_id=self._device.interface_id,
channel_address=self._address,
paramset_key=ParamsetKey.VALUES,
parameter=parameter,
Expand All @@ -903,6 +905,7 @@ def get_generic_data_point(
return dp
return self._generic_data_points.get(
get_data_point_key(
interface_id=self._device.interface_id,
channel_address=self._address,
paramset_key=ParamsetKey.MASTER,
parameter=parameter,
Expand All @@ -913,6 +916,7 @@ def get_generic_event(self, parameter: str) -> GenericEvent | None:
"""Return a generic event from device."""
return self._generic_events.get(
get_data_point_key(
interface_id=self._device.interface_id,
channel_address=self._address,
paramset_key=ParamsetKey.VALUES,
parameter=parameter,
Expand Down Expand Up @@ -1080,7 +1084,10 @@ def _add_entry_to_device_cache(
) -> None:
"""Add value to cache."""
key = get_data_point_key(
channel_address=channel_address, paramset_key=paramset_key, parameter=parameter
interface_id=self._device.interface_id,
channel_address=channel_address,
paramset_key=paramset_key,
parameter=parameter,
)
# write value to cache even if an exception has occurred
# to avoid repetitive calls to CCU within max_age
Expand Down Expand Up @@ -1109,7 +1116,10 @@ def _get_value_from_cache(

# Try to get data from device cache
key = get_data_point_key(
channel_address=channel_address, paramset_key=paramset_key, parameter=parameter
interface_id=self._device.interface_id,
channel_address=channel_address,
paramset_key=paramset_key,
parameter=parameter,
)
if (
cache_entry := self._device_cache.get(key, CacheEntry.empty())
Expand Down
6 changes: 4 additions & 2 deletions hahomematic/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ def is_paramset_key(paramset_key: ParamsetKey | str) -> bool:
)


def get_data_point_key(channel_address: str, paramset_key: ParamsetKey, parameter: str) -> DP_KEY:
def get_data_point_key(
interface_id: str, channel_address: str, paramset_key: ParamsetKey, parameter: str
) -> DP_KEY:
"""Return a data point key."""
return (str(channel_address), paramset_key, str(parameter))
return (str(interface_id), str(channel_address), paramset_key, str(parameter))


@lru_cache(maxsize=2048)
Expand Down

0 comments on commit a9041d7

Please sign in to comment.