Skip to content

Commit

Permalink
Remove cached_property from all properties that are directly accessed…
Browse files Browse the repository at this point in the history
… attributes (#166)

remove cached_property from all props that are directly accessed attributes
  • Loading branch information
dmulcahey authored Aug 13, 2024
1 parent 5384ba5 commit 8c3a508
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
3 changes: 1 addition & 2 deletions zha/application/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from dataclasses import dataclass
from datetime import timedelta
from enum import Enum
from functools import cached_property
import logging
import time
from typing import Any, Final, Self, TypeVar, cast
Expand Down Expand Up @@ -347,7 +346,7 @@ def create_platform_entities(self) -> None:
)
self.config.platforms[platform].clear()

@cached_property
@property
def radio_concurrency(self) -> int:
"""Maximum configured radio concurrency."""
return self.application_controller._concurrent_requests_semaphore.max_value # pylint: disable=protected-access
Expand Down
10 changes: 5 additions & 5 deletions zha/application/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def state_class(self) -> str | None:
return None

@final
@cached_property
@property
def unique_id(self) -> str:
"""Return the unique id."""
return self._unique_id
Expand Down Expand Up @@ -364,17 +364,17 @@ def info_object(self) -> BaseEntityInfo:
available=self.available,
)

@cached_property
@property
def device(self) -> Device:
"""Return the device."""
return self._device

@cached_property
@property
def endpoint(self) -> Endpoint:
"""Return the endpoint."""
return self._endpoint

@cached_property
@property
def should_poll(self) -> bool:
"""Return True if we need to poll for state changes."""
return False
Expand Down Expand Up @@ -462,7 +462,7 @@ def group_id(self) -> int:
"""Return the group id."""
return self._group.group_id

@cached_property
@property
def group(self) -> Group:
"""Return the group."""
return self._group
Expand Down
10 changes: 5 additions & 5 deletions zha/zigbee/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def __repr__(self) -> str:
f"quirk_id: {self.quirk_id}"
)

@cached_property
@property
def device(self) -> zigpy.device.Device:
"""Return underlying Zigpy device."""
return self._zigpy_device
Expand All @@ -262,7 +262,7 @@ def name(self) -> str:
"""Return device name."""
return f"{self.manufacturer} {self.model}"

@cached_property
@property
def ieee(self) -> EUI64:
"""Return ieee address for device."""
return self._zigpy_device.ieee
Expand Down Expand Up @@ -305,7 +305,7 @@ def manufacturer_code(self) -> int | None:

return self._zigpy_device.node_desc.manufacturer_code

@cached_property
@property
def nwk(self) -> NWK:
"""Return nwk for device."""
return self._zigpy_device.nwk
Expand Down Expand Up @@ -392,7 +392,7 @@ def skip_configuration(self) -> bool:
"""Return true if the device should not issue configuration related commands."""
return self._zigpy_device.skip_configuration or bool(self.is_active_coordinator)

@cached_property
@property
def gateway(self):
"""Return the gateway for this device."""
return self._gateway
Expand Down Expand Up @@ -467,7 +467,7 @@ def identify_ch(self, cluster_handler: ClusterHandler) -> None:
if self._identify_ch is None:
self._identify_ch = cluster_handler

@cached_property
@property
def zdo_cluster_handler(self) -> ZDOClusterHandler:
"""Return ZDO cluster handler."""
return self._zdo_handler
Expand Down
18 changes: 8 additions & 10 deletions zha/zigbee/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def __init__(self, zha_group: Group, device: Device, endpoint_id: int) -> None:
self._device: Device = device
self._endpoint_id: int = endpoint_id

@cached_property
@property
def group(self) -> Group:
"""Return the group this member belongs to."""
return self._group

@cached_property
@property
def endpoint_id(self) -> int:
"""Return the endpoint id for this group member."""
return self._endpoint_id
Expand All @@ -92,7 +92,7 @@ def endpoint(self) -> GroupEndpoint:
"""Return the endpoint for this group member."""
return self._device.device.endpoints.get(self.endpoint_id)

@cached_property
@property
def device(self) -> Device:
"""Return the ZHA device for this group member."""
return self._device
Expand Down Expand Up @@ -164,27 +164,27 @@ def name(self) -> str:
"""Return group name."""
return self._zigpy_group.name

@cached_property
@property
def group_id(self) -> int:
"""Return group name."""
return self._zigpy_group.group_id

@cached_property
@property
def endpoint(self) -> zigpy.endpoint.Endpoint:
"""Return the endpoint for this group."""
return self._zigpy_group.endpoint

@cached_property
@property
def group_entities(self) -> dict[str, GroupEntity]:
"""Return the platform entities of the group."""
return self._group_entities

@cached_property
@property
def zigpy_group(self) -> ZigpyGroup:
"""Return the zigpy group."""
return self._zigpy_group

@cached_property
@property
def gateway(self) -> Gateway:
"""Return the gateway for this group."""
return self._gateway
Expand Down Expand Up @@ -253,8 +253,6 @@ def clear_caches(self) -> None:
delattr(self, "info_object")
if hasattr(self, "members"):
delattr(self, "members")
if hasattr(self, "group_entities"):
delattr(self, "group_entities")

def update_entity_subscriptions(self) -> None:
"""Update the entity event subscriptions.
Expand Down

0 comments on commit 8c3a508

Please sign in to comment.