diff --git a/plugwise_usb/nodes/circle.py b/plugwise_usb/nodes/circle.py index 4e9976137..b103bf508 100644 --- a/plugwise_usb/nodes/circle.py +++ b/plugwise_usb/nodes/circle.py @@ -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__) @@ -884,17 +892,7 @@ async def load(self) -> bool: _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) if await self.initialize(): await self._loaded_callback(NodeEvent.LOADED, self.mac) return True @@ -926,17 +924,7 @@ async def load(self) -> bool: 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 diff --git a/plugwise_usb/nodes/circle_plus.py b/plugwise_usb/nodes/circle_plus.py index 33842b0a2..817f49327 100644 --- a/plugwise_usb/nodes/circle_plus.py +++ b/plugwise_usb/nodes/circle_plus.py @@ -20,15 +20,16 @@ _LOGGER = logging.getLogger(__name__) FEATURES_CIRCLE_PLUS = ( + 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.""" @@ -36,45 +37,19 @@ 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") 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 async def clock_synchronize(self) -> bool: """Synchronize realtime clock. Returns true if successful."""