Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions plugwise_usb/nodes/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
CACHE_RELAY = "relay"
CACHE_RELAY_INIT = "relay_init"
CACHE_RELAY_LOCK = "relay_lock"
FEATURES_CIRCLE = (
NodeFeature.CIRCLE,
NodeFeature.RELAY,
NodeFeature.RELAY_INIT,
NodeFeature.RELAY_LOCK,
NodeFeature.ENERGY,
NodeFeature.POWER,
)

FuncT = TypeVar("FuncT", bound=Callable[..., Any])
_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -884,17 +892,7 @@
_LOGGER.debug("Loading Circle node %s from cache", self._mac_in_str)
if await self._load_from_cache():
self._loaded = True
self._setup_protocol(
CIRCLE_FIRMWARE_SUPPORT,
(
NodeFeature.CIRCLE,
NodeFeature.RELAY,
NodeFeature.RELAY_INIT,
NodeFeature.RELAY_LOCK,
NodeFeature.ENERGY,
NodeFeature.POWER,
),
)
self._setup_protocol(CIRCLE_FIRMWARE_SUPPORT, FEATURES_CIRCLE)

Check warning on line 895 in plugwise_usb/nodes/circle.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/nodes/circle.py#L895

Added line #L895 was not covered by tests
if await self.initialize():
await self._loaded_callback(NodeEvent.LOADED, self.mac)
return True
Expand Down Expand Up @@ -926,17 +924,7 @@
return False

self._loaded = True
self._setup_protocol(
CIRCLE_FIRMWARE_SUPPORT,
(
NodeFeature.CIRCLE,
NodeFeature.RELAY,
NodeFeature.RELAY_INIT,
NodeFeature.RELAY_LOCK,
NodeFeature.ENERGY,
NodeFeature.POWER,
),
)
self._setup_protocol(CIRCLE_FIRMWARE_SUPPORT, FEATURES_CIRCLE)
if not await self.initialize():
return False

Expand Down
47 changes: 11 additions & 36 deletions plugwise_usb/nodes/circle_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,36 @@
_LOGGER = logging.getLogger(__name__)

FEATURES_CIRCLE_PLUS = (
Copy link
Contributor

@dirixmjm dirixmjm Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try this patch while removing lines 23, 25-29. You need to include only the added CIRCLEPLUS feature here, the rest is already added in the circle.py->load() function.

The CirclePlus does then call super().load() first, and all circle features get added, then it calls setup_protocol adding CIRCLEPLUS feature.
This is more or less how SED nodes work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dirixmjm I had only intended this PR for showing my quick thoughts.
I will close it so you can properly fix/improve the code 🙂

NodeFeature.CIRCLE,
NodeFeature.CIRCLEPLUS,
NodeFeature.RELAY,
NodeFeature.RELAY_INIT,
NodeFeature.RELAY_LOCK,
NodeFeature.ENERGY,
NodeFeature.POWER,
NodeFeature.CIRCLE,
NodeFeature.CIRCLEPLUS,
)


class PlugwiseCirclePlus(PlugwiseCircle):
"""Plugwise Circle+ node."""

async def load(self) -> bool:
"""Load and activate Circle+ node features."""
if self._loaded:
return True
if self._cache_enabled:
_LOGGER.debug("Loading Circle node %s from cache", self._node_info.mac)
if await self._load_from_cache():
self._loaded = True
self._setup_protocol(CIRCLE_PLUS_FIRMWARE_SUPPORT, FEATURES_CIRCLE_PLUS)
if await self.initialize():
await self._loaded_callback(NodeEvent.LOADED, self.mac)
return True

_LOGGER.info(
"Loading Circle+ node %s from cache failed",
self._node_info.mac,
)
else:
_LOGGER.debug("Loading Circle+ node %s", self._node_info.mac)

# Check if node is online
if not self._available and not await self.is_online():
_LOGGER.warning(
"Failed to load Circle+ node %s because it is not online",
self._node_info.mac,
)
return False

# Get node info
if await self.node_info_update() is None:
_LOGGER.warning(
"Failed to load Circle+ node %s because it is not responding to information request",
self._node_info.mac,
)
_LOGGER.debug("Loading Circle + node %s", self._node_info.mac)
if not await super().load():
_LOGGER.debug("Loading of Circle base node failed")

Check warning on line 43 in plugwise_usb/nodes/circle_plus.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/nodes/circle_plus.py#L43

Added line #L43 was not covered by tests
return False

self._loaded = True
self._setup_protocol(CIRCLE_PLUS_FIRMWARE_SUPPORT, FEATURES_CIRCLE_PLUS)
if not await self.initialize():
return False
if await self.initialize():
await self._loaded_callback(NodeEvent.LOADED, self.mac)
return True

await self._loaded_callback(NodeEvent.LOADED, self.mac)
return True
_LOGGER.debug("Loading of Circle + node %s failed", self._node_info.mac)
return False

Check warning on line 52 in plugwise_usb/nodes/circle_plus.py

View check run for this annotation

Codecov / codecov/patch

plugwise_usb/nodes/circle_plus.py#L51-L52

Added lines #L51 - L52 were not covered by tests

async def clock_synchronize(self) -> bool:
"""Synchronize realtime clock. Returns true if successful."""
Expand Down
Loading