aiohomematic 2025.8.8__py3-none-any.whl → 2025.8.9__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.

@@ -208,9 +208,15 @@ class DeviceDescriptionCache(BasePersistentCache):
208
208
 
209
209
  def add_device(self, interface_id: str, device_description: DeviceDescription) -> None:
210
210
  """Add a device to the cache."""
211
+ # Fast-path: If the address is not yet known, skip costly removal operations.
212
+ if (address := device_description["ADDRESS"]) not in self._device_descriptions[interface_id]:
213
+ self._raw_device_descriptions[interface_id].append(device_description)
214
+ self._process_device_description(interface_id=interface_id, device_description=device_description)
215
+ return
216
+ # Address exists: remove old entries before adding the new description.
211
217
  self._remove_device(
212
218
  interface_id=interface_id,
213
- addresses_to_remove=[device_description["ADDRESS"]],
219
+ addresses_to_remove=[address],
214
220
  )
215
221
  self._raw_device_descriptions[interface_id].append(device_description)
216
222
  self._process_device_description(interface_id=interface_id, device_description=device_description)
@@ -228,23 +234,22 @@ class DeviceDescriptionCache(BasePersistentCache):
228
234
 
229
235
  def _remove_device(self, interface_id: str, addresses_to_remove: list[str]) -> None:
230
236
  """Remove a device from the cache."""
237
+ # Use a set for faster membership checks
238
+ addresses_set = set(addresses_to_remove)
231
239
  self._raw_device_descriptions[interface_id] = [
232
- device
233
- for device in self._raw_device_descriptions[interface_id]
234
- if device["ADDRESS"] not in addresses_to_remove
240
+ device for device in self._raw_device_descriptions[interface_id] if device["ADDRESS"] not in addresses_set
235
241
  ]
236
- for address in addresses_to_remove:
237
- try:
238
- if ADDRESS_SEPARATOR not in address and self._addresses[interface_id].get(address):
239
- del self._addresses[interface_id][address]
240
- if self._device_descriptions[interface_id].get(address):
241
- del self._device_descriptions[interface_id][address]
242
- except KeyError:
243
- _LOGGER.warning("REMOVE_DEVICE failed: Unable to delete: %s", address)
244
-
245
- def get_addresses(self, interface_id: str) -> tuple[str, ...]:
246
- """Return the addresses by interface."""
247
- return tuple(self._addresses[interface_id].keys())
242
+ addr_map = self._addresses[interface_id]
243
+ desc_map = self._device_descriptions[interface_id]
244
+ for address in addresses_set:
245
+ # Pop with default to avoid KeyError and try/except overhead
246
+ if ADDRESS_SEPARATOR not in address:
247
+ addr_map.pop(address, None)
248
+ desc_map.pop(address, None)
249
+
250
+ def get_addresses(self, interface_id: str) -> frozenset[str]:
251
+ """Return the addresses by interface as a set."""
252
+ return frozenset(self._addresses[interface_id])
248
253
 
249
254
  def get_device_descriptions(self, interface_id: str) -> Mapping[str, DeviceDescription]:
250
255
  """Return the devices by interface."""
@@ -288,9 +293,10 @@ class DeviceDescriptionCache(BasePersistentCache):
288
293
  device_address = get_device_address(address)
289
294
  self._device_descriptions[interface_id][address] = device_description
290
295
 
291
- if device_address not in self._addresses[interface_id][device_address]:
292
- self._addresses[interface_id][device_address].add(device_address)
293
- self._addresses[interface_id][device_address].add(address)
296
+ # Avoid redundant membership checks; set.add is idempotent and cheaper than check+add
297
+ addr_set = self._addresses[interface_id][device_address]
298
+ addr_set.add(device_address)
299
+ addr_set.add(address)
294
300
 
295
301
  async def load(self) -> DataOperationResult:
296
302
  """Load device data from disk into _device_description_cache."""
@@ -420,13 +426,12 @@ class ParamsetDescriptionCache(BasePersistentCache):
420
426
  def _add_address_parameter(self, channel_address: str, paramsets: list[dict[str, Any]]) -> None:
421
427
  """Add address parameter to cache."""
422
428
  device_address, channel_no = get_split_channel_address(channel_address)
429
+ cache = self._address_parameter_cache
423
430
  for paramset in paramsets:
424
431
  if not paramset:
425
432
  continue
426
433
  for parameter in paramset:
427
- if (device_address, parameter) not in self._address_parameter_cache:
428
- self._address_parameter_cache[(device_address, parameter)] = set()
429
- self._address_parameter_cache[(device_address, parameter)].add(channel_no)
434
+ cache.setdefault((device_address, parameter), set()).add(channel_no)
430
435
 
431
436
  async def load(self) -> DataOperationResult:
432
437
  """Load paramset descriptions from disk into paramset cache."""