From 1888496354dd9c861ba92d97d4bd32e743cb97d5 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 17:51:30 +0100 Subject: [PATCH 01/39] Try adding initial NodeInfoRequest to the Stick --- plugwise_usb/connection/__init__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 9a2cf7fe0..61c381bc7 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -7,8 +7,9 @@ from typing import Any from ..api import StickEvent +from ..constants import UTF8 from ..exceptions import NodeError, StickError -from ..messages.requests import PlugwiseRequest, StickInitRequest +from ..messages.requests import NodeInfoRequest, PlugwiseRequest, StickInitRequest from ..messages.responses import PlugwiseResponse, StickInitResponse from .manager import StickConnectionManager from .queue import StickQueue @@ -26,6 +27,8 @@ def __init__(self) -> None: self._unsubscribe_stick_event: Callable[[], None] | None = None self._init_sequence_id: bytes | None = None self._is_initialized = False + self._fw_stick: str | None = None + self._hw_stick: str | None = None self._mac_stick: str | None = None self._mac_nc: str | None = None self._network_id: int | None = None @@ -43,6 +46,16 @@ def is_connected(self) -> bool: """Return connection state from connection manager.""" return self._manager.is_connected + @property + def firmware_stick(self) -> str | None: + """Firmware version of the Stick.""" + return self._fw_stick + + @property + def hardware_stick(self) -> str | None: + """Hardware version of the Stick.""" + return self._hw_stick + @property def mac_stick(self) -> str: """MAC address of USB-Stick. Raises StickError when not connected.""" @@ -167,6 +180,14 @@ async def initialize_stick(self) -> None: self._network_id = init_response.network_id self._is_initialized = True + # add Stick NodeInfoRequest + info_request = NodeInfoRequest( + self.send, bytes(self._mac_stick, UTF8), retries=1 + ) + info_response = await info_request.send() + self._fw_stick = info_response.firmware + self._hw_stick = info_response.hardware + if not self._network_online: raise StickError("Zigbee network connection to Circle+ is down.") From 68e9ed63f92fb8eca1c31cb4402acacc67acb5b8 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 18:02:44 +0100 Subject: [PATCH 02/39] Add Stick NodeInfoResponse --- tests/stick_test_data.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/stick_test_data.py b/tests/stick_test_data.py index be98c323c..8f61aef6b 100644 --- a/tests/stick_test_data.py +++ b/tests/stick_test_data.py @@ -38,6 +38,19 @@ + b"4321" # network_id + b"00", # unknown2 ), + b"\x05\x05\x03\x03002301234567890123451AE2\r\n": ( + "Node Info of stick 0123456789012345", + b"000000C1", # Success ack + b"0024" # msg_id + + b"0123456789012345" # mac + + b"22026A68" # datetime + + b"00044280" # log address 20 + + b"01" # relay + + b"01" # hz + + b"000000730007" # hw_ver + + b"4E0843A9" # fw_ver + + b"01", # node_type (Circle+) + ), b"\x05\x05\x03\x03002300987654321012341AE2\r\n": ( "Node Info of network controller 0098765432101234", b"000000C1", # Success ack From e60afeb1894f3b24dabd7ac57664e47a10766096 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 18:55:34 +0100 Subject: [PATCH 03/39] Fix --- tests/stick_test_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stick_test_data.py b/tests/stick_test_data.py index 8f61aef6b..c2d20cfd2 100644 --- a/tests/stick_test_data.py +++ b/tests/stick_test_data.py @@ -38,7 +38,7 @@ + b"4321" # network_id + b"00", # unknown2 ), - b"\x05\x05\x03\x03002301234567890123451AE2\r\n": ( + b"\x05\x05\x03\x0300230123456789012345A0EC\r\n": ( "Node Info of stick 0123456789012345", b"000000C1", # Success ack b"0024" # msg_id From 2c449be465e9180e7bc8f043eb51e007b89c6a06 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 19:02:32 +0100 Subject: [PATCH 04/39] Debug, full test-output --- scripts/tests_and_coverage.sh | 3 ++- tests/test_usb.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 884a5221b..7e62cab10 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -23,7 +23,8 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || + PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then diff --git a/tests/test_usb.py b/tests/test_usb.py index bfd4ec430..9b4e94dea 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -460,6 +460,8 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: await stick.initialize() assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" + _LOGGER.debug("HOI fw_stick: %s", stick.firmware_stick) + _LOGGER.debug("HOI hw_stick: %s", stick.hardware_stick) assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 232b029783881240e7e993618fc94e5062db5744 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 19:21:15 +0100 Subject: [PATCH 05/39] Fix data --- tests/stick_test_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/stick_test_data.py b/tests/stick_test_data.py index c2d20cfd2..91dab5bec 100644 --- a/tests/stick_test_data.py +++ b/tests/stick_test_data.py @@ -36,7 +36,7 @@ + b"01" # network_is_online + b"0098765432101234" # circle_plus_mac + b"4321" # network_id - + b"00", # unknown2 + + b"FF", # unknown2 ), b"\x05\x05\x03\x0300230123456789012345A0EC\r\n": ( "Node Info of stick 0123456789012345", @@ -49,7 +49,7 @@ + b"01" # hz + b"000000730007" # hw_ver + b"4E0843A9" # fw_ver - + b"01", # node_type (Circle+) + + b"00", # node_type (Stick) ), b"\x05\x05\x03\x03002300987654321012341AE2\r\n": ( "Node Info of network controller 0098765432101234", From ed8c72aa965dc60adb4b9b45d02248dcfb60c4b9 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 19:25:23 +0100 Subject: [PATCH 06/39] Add Stick properties --- plugwise_usb/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index 5eb1ac63d..a1ee49837 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -117,6 +117,16 @@ def joined_nodes(self) -> int | None: return None return len(self._network.registry) + 1 + @property + def firmware_stick(self) -> str: + """Firmware of USB-Stick.""" + return self._controller.firmware_stick + + @property + def hardware_stick(self) -> str: + """Hardware of USB-Stick.""" + return self._controller.hardware_stick + @property def mac_stick(self) -> str: """MAC address of USB-Stick. Raises StickError is connection is missing.""" From 870dfb3eaca118c9dde53563834e90094bf8959b Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Fri, 7 Feb 2025 19:41:18 +0100 Subject: [PATCH 07/39] Add stick-hw-fw asserts --- tests/test_usb.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index 9b4e94dea..056b4e6a6 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -460,8 +460,10 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: await stick.initialize() assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" - _LOGGER.debug("HOI fw_stick: %s", stick.firmware_stick) - _LOGGER.debug("HOI hw_stick: %s", stick.hardware_stick) + assert stick.firmware_stick == dt( + 2011, 6, 27, 8, 47, 37, tzinfo=UTC + ) + assert stick.hardware_stick == "000000730007" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 43a51847e568b22e9ef5d662629da30be1c55447 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 10:22:29 +0100 Subject: [PATCH 08/39] Use existing function --- plugwise_usb/connection/__init__.py | 50 ++++++++++++++++++++++++----- plugwise_usb/network/__init__.py | 34 ++------------------ 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 61c381bc7..26154faff 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -9,8 +9,18 @@ from ..api import StickEvent from ..constants import UTF8 from ..exceptions import NodeError, StickError -from ..messages.requests import NodeInfoRequest, PlugwiseRequest, StickInitRequest -from ..messages.responses import PlugwiseResponse, StickInitResponse +from ..messages.requests import ( + NodeInfoRequest, + NodePingRequest, + PlugwiseRequest, + StickInitRequest, +) +from ..messages.responses import ( + NodeInfoResponse, + NodePingResponse, + PlugwiseResponse, + StickInitResponse, +) from .manager import StickConnectionManager from .queue import StickQueue @@ -181,16 +191,40 @@ async def initialize_stick(self) -> None: self._is_initialized = True # add Stick NodeInfoRequest - info_request = NodeInfoRequest( - self.send, bytes(self._mac_stick, UTF8), retries=1 - ) - info_response = await info_request.send() - self._fw_stick = info_response.firmware - self._hw_stick = info_response.hardware + node_info, _ = await self.get_node_details(self._mac_stick, False) + if node_info is not None: + self._fw_stick = node_info.firmware + self._hw_stick = node_info.hardware if not self._network_online: raise StickError("Zigbee network connection to Circle+ is down.") + async def get_node_details( + self, mac: str, ping_first: bool + ) -> tuple[NodeInfoResponse | None, NodePingResponse | None]: + """Return node discovery type.""" + ping_response: NodePingResponse | None = None + if ping_first: + # Define ping request with one retry + ping_request = NodePingRequest( + self.send, bytes(mac, UTF8), retries=1 + ) + try: + ping_response = await ping_request.send(suppress_node_errors=True) + except StickError: + return (None, None) + if ping_response is None: + return (None, None) + + info_request = NodeInfoRequest( + self.send, bytes(mac, UTF8), retries=1 + ) + try: + info_response = await info_request.send() + except StickError: + return (None, None) + return (info_response, ping_response) + async def send( self, request: PlugwiseRequest, suppress_node_errors: bool = True ) -> PlugwiseResponse | None: diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index ff06d5921..43d62f3f9 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -15,11 +15,7 @@ from ..constants import UTF8 from ..exceptions import CacheError, MessageError, NodeError, StickError, StickTimeout from ..helpers.util import validate_mac -from ..messages.requests import ( - CirclePlusAllowJoiningRequest, - NodeInfoRequest, - NodePingRequest, -) +from ..messages.requests import CirclePlusAllowJoiningRequest, NodePingRequest from ..messages.responses import ( NODE_AWAKE_RESPONSE_ID, NODE_JOIN_ID, @@ -365,32 +361,6 @@ def _create_node_object( self._nodes[mac].cache_folder_create = self._cache_folder_create self._nodes[mac].cache_enabled = True - async def get_node_details( - self, mac: str, ping_first: bool - ) -> tuple[NodeInfoResponse | None, NodePingResponse | None]: - """Return node discovery type.""" - ping_response: NodePingResponse | None = None - if ping_first: - # Define ping request with one retry - ping_request = NodePingRequest( - self._controller.send, bytes(mac, UTF8), retries=1 - ) - try: - ping_response = await ping_request.send(suppress_node_errors=True) - except StickError: - return (None, None) - if ping_response is None: - return (None, None) - - info_request = NodeInfoRequest( - self._controller.send, bytes(mac, UTF8), retries=1 - ) - try: - info_response = await info_request.send() - except StickError: - return (None, None) - return (info_response, ping_response) - async def _discover_battery_powered_node( self, address: int, @@ -432,7 +402,7 @@ async def _discover_node( # Node type is unknown, so we need to discover it first _LOGGER.debug("Starting the discovery of node %s", mac) - node_info, node_ping = await self.get_node_details(mac, ping_first) + node_info, node_ping = await self._controller.get_node_details(mac, ping_first) if node_info is None: return False self._create_node_object(mac, address, node_info.node_type) From c3845ded062fd27d8fba08c63d470dfd0367dc7e Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 10:24:35 +0100 Subject: [PATCH 09/39] Back to short test-output --- scripts/tests_and_coverage.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/tests_and_coverage.sh b/scripts/tests_and_coverage.sh index 7e62cab10..884a5221b 100755 --- a/scripts/tests_and_coverage.sh +++ b/scripts/tests_and_coverage.sh @@ -23,8 +23,7 @@ set +u if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "test_and_coverage" ] ; then # Python tests (rerun with debug if failures) - # PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || - PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ + PYTHONPATH=$(pwd) pytest -qx tests/ --cov='.' --no-cov-on-fail --cov-report term-missing || PYTHONPATH=$(pwd) pytest -xrpP --log-level debug tests/ fi if [ -z "${GITHUB_ACTIONS}" ] || [ "$1" == "linting" ] ; then From 82e434b06bb3c04f7b4f954b93dff95f7524bc99 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 13:02:31 +0100 Subject: [PATCH 10/39] Enter real stick-response data --- tests/stick_test_data.py | 10 +++++----- tests/test_usb.py | 4 +--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/stick_test_data.py b/tests/stick_test_data.py index 91dab5bec..e3623f61e 100644 --- a/tests/stick_test_data.py +++ b/tests/stick_test_data.py @@ -43,11 +43,11 @@ b"000000C1", # Success ack b"0024" # msg_id + b"0123456789012345" # mac - + b"22026A68" # datetime - + b"00044280" # log address 20 - + b"01" # relay - + b"01" # hz - + b"000000730007" # hw_ver + + b"00000000" # datetime + + b"00000000" # log address 0 + + b"00" # relay + + b"80" # hz + + b"653907008512" # hw_ver + b"4E0843A9" # fw_ver + b"00", # node_type (Stick) ), diff --git a/tests/test_usb.py b/tests/test_usb.py index 056b4e6a6..b2c33cf43 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -460,9 +460,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: await stick.initialize() assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" - assert stick.firmware_stick == dt( - 2011, 6, 27, 8, 47, 37, tzinfo=UTC - ) + assert stick.firmware_stick == None assert stick.hardware_stick == "000000730007" assert not stick.network_discovered assert stick.network_state From 08347c144864d377e7be5a671cae9de16f0e9cd6 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 13:18:34 +0100 Subject: [PATCH 11/39] Debug --- plugwise_usb/messages/properties.py | 3 +++ plugwise_usb/messages/responses.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 40f76d4f8..0d9f4c2a0 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -2,6 +2,7 @@ import binascii from datetime import UTC, date, datetime, time, timedelta +import logging import struct from typing import Any @@ -9,6 +10,7 @@ from ..exceptions import MessageError from ..helpers.util import int_to_uint +_LOGGER = logging.getLogger(__name__) class BaseType: """Generic single instance property.""" @@ -227,6 +229,7 @@ def __init__(self, year: int = 0, month: int = 1, minutes: int = 0) -> None: def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" + _LOGGER.debug("HOI val: %s", val) if val == b"FFFFFFFF": self._value = None else: diff --git a/plugwise_usb/messages/responses.py b/plugwise_usb/messages/responses.py index 205ac4680..5a3b26db9 100644 --- a/plugwise_usb/messages/responses.py +++ b/plugwise_usb/messages/responses.py @@ -4,6 +4,7 @@ from datetime import datetime from enum import Enum +import logging from typing import Any, Final from ..api import NodeType @@ -41,6 +42,8 @@ SWITCH_GROUP_RESPONSE_SEQ_ID, ) +_LOGGER = logging.getLogger(__name__) + class StickResponseType(bytes, Enum): """Response message types for stick.""" @@ -190,6 +193,7 @@ def deserialize(self, response: bytes, has_footer: bool = True) -> None: self._mac = response[:16] response = response[16:] if len(response) > 0: + _LOGGER.debug("HOI response: %s", response) try: response = self._parse_params(response) except ValueError as ve: @@ -203,8 +207,12 @@ def deserialize(self, response: bytes, has_footer: bool = True) -> None: def _parse_params(self, response: bytes) -> bytes: for param in self._params: my_val = response[: len(param)] + _LOGGER.debug("HOI param: %s", param) + _LOGGER.debug("HOI my_val: %s", my_val) param.deserialize(my_val) response = response[len(my_val) :] + _LOGGER.debug("HOI response: %s", response) + return response def __len__(self) -> int: From 6a3d753872ea96b0eb44fa90a9ef50f23f278b6b Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 13:50:56 +0100 Subject: [PATCH 12/39] Handle Stick zero-response for firmware --- plugwise_usb/messages/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 0d9f4c2a0..453ccb471 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -230,7 +230,7 @@ def __init__(self, year: int = 0, month: int = 1, minutes: int = 0) -> None: def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" _LOGGER.debug("HOI val: %s", val) - if val == b"FFFFFFFF": + if val == b"FFFFFFFF" or val == b"00000000": self._value = None else: CompositeType.deserialize(self, val) From 28a5667f289635139453a08ed0faeded0a9ad79c Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 13:55:20 +0100 Subject: [PATCH 13/39] Fix assert --- tests/test_usb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index b2c33cf43..65fcc9aec 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == None - assert stick.hardware_stick == "000000730007" + assert stick.hardware_stick == "653907008512" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 0602201fb0b278b04d3fe45fd465fed93a9cdeb0 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 14:01:31 +0100 Subject: [PATCH 14/39] Disable --- plugwise_usb/connection/__init__.py | 10 +++++----- tests/test_usb.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 26154faff..4c765a275 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -190,11 +190,11 @@ async def initialize_stick(self) -> None: self._network_id = init_response.network_id self._is_initialized = True - # add Stick NodeInfoRequest - node_info, _ = await self.get_node_details(self._mac_stick, False) - if node_info is not None: - self._fw_stick = node_info.firmware - self._hw_stick = node_info.hardware + # # add Stick NodeInfoRequest + # node_info, _ = await self.get_node_details(self._mac_stick, False) + # if node_info is not None: + # self._fw_stick = node_info.firmware + # self._hw_stick = node_info.hardware if not self._network_online: raise StickError("Zigbee network connection to Circle+ is down.") diff --git a/tests/test_usb.py b/tests/test_usb.py index 65fcc9aec..23982934b 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == None - assert stick.hardware_stick == "653907008512" + assert stick.hardware_stick == None # "653907008512" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 5f06d7cab6cd4c44782e78b58de095859ce578ce Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 14:11:07 +0100 Subject: [PATCH 15/39] Try --- plugwise_usb/network/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 43d62f3f9..10b99e806 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -286,6 +286,17 @@ def _unsubscribe_to_protocol_events(self) -> None: # endregion + async def discover_stick(self, load: bool = False) -> bool: + """Fetch data from the Stick.""" + if self._controller.mac_stick is None: + raise NodeError("Unknown mac address for the Stick.") + + _LOGGER.debug("Optain Stick info") + node_info, _ = await self._controller.get_node_details(self._controller.mac_stick, ping_first=False) + if node_info is not None: + self._controller.fw_stick = node_info.firmware + self._controller.hw_stick = node_info.hardware + # region - Coordinator async def discover_network_coordinator(self, load: bool = False) -> bool: """Discover the Zigbee network coordinator (Circle+/Stealth+).""" @@ -482,6 +493,7 @@ async def start(self) -> None: async def discover_nodes(self, load: bool = True) -> bool: """Discover nodes.""" + await self.discover_stick(load=load) await self.discover_network_coordinator(load=load) if not self._is_running: await self.start() From b08603d3126fe845cb7cb651581f2beca8cec6ab Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 14:29:04 +0100 Subject: [PATCH 16/39] Debug --- plugwise_usb/network/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 10b99e806..1fc5e3235 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -291,12 +291,15 @@ async def discover_stick(self, load: bool = False) -> bool: if self._controller.mac_stick is None: raise NodeError("Unknown mac address for the Stick.") - _LOGGER.debug("Optain Stick info") + _LOGGER.debug("Obtain Stick info") node_info, _ = await self._controller.get_node_details(self._controller.mac_stick, ping_first=False) if node_info is not None: + _LOGGER.debug("HOI fw_stick before: %s", self._controller.fw_stick) self._controller.fw_stick = node_info.firmware self._controller.hw_stick = node_info.hardware - + _LOGGER.debug("HOI fw_stick: %s", self._controller.fw_stick) + _LOGGER.debug("HOI hw_stick: %s", self._controller.hw_stick) + # region - Coordinator async def discover_network_coordinator(self, load: bool = False) -> bool: """Discover the Zigbee network coordinator (Circle+/Stealth+).""" From e434f273d278485c0964eae780a2ecd749bc5650 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 14:40:26 +0100 Subject: [PATCH 17/39] Fixes --- plugwise_usb/network/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 1fc5e3235..68dae9536 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -294,11 +294,11 @@ async def discover_stick(self, load: bool = False) -> bool: _LOGGER.debug("Obtain Stick info") node_info, _ = await self._controller.get_node_details(self._controller.mac_stick, ping_first=False) if node_info is not None: - _LOGGER.debug("HOI fw_stick before: %s", self._controller.fw_stick) - self._controller.fw_stick = node_info.firmware - self._controller.hw_stick = node_info.hardware - _LOGGER.debug("HOI fw_stick: %s", self._controller.fw_stick) - _LOGGER.debug("HOI hw_stick: %s", self._controller.hw_stick) + _LOGGER.debug("HOI fw_stick before: %s", self._controller._fw_stick) + self._controller._fw_stick = node_info.firmware + self._controller._hw_stick = node_info.hardware + _LOGGER.debug("HOI fw_stick: %s", self._controller._fw_stick) + _LOGGER.debug("HOI hw_stick: %s", self._controller._hw_stick) # region - Coordinator async def discover_network_coordinator(self, load: bool = False) -> bool: From 37f30f15595d83b6478f4c1d67bef762387c67a7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 15:05:28 +0100 Subject: [PATCH 18/39] Try --- plugwise_usb/messages/properties.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 453ccb471..ee79ef94a 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -392,6 +392,9 @@ def serialize(self) -> bytes: def deserialize(self, val: bytes) -> None: """Convert data into integer value based on log address formatted data.""" + if val == b"00000000": + self._value = int(0) + return Int.deserialize(self, val) self._value = (self.value - LOGADDR_OFFSET) // 32 From d7591aafee736c3e6ccdc09f877421a0f931423a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 15:16:18 +0100 Subject: [PATCH 19/39] Add debug-message --- plugwise_usb/messages/properties.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index ee79ef94a..31a49d96c 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -231,6 +231,7 @@ def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" _LOGGER.debug("HOI val: %s", val) if val == b"FFFFFFFF" or val == b"00000000": + _LOGGER.debug("Invalid DateTime value result") self._value = None else: CompositeType.deserialize(self, val) From 2c9e1a82f7609c53894b945b9b47e7890bacb7c7 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Sun, 9 Feb 2025 15:21:04 +0100 Subject: [PATCH 20/39] Try --- plugwise_usb/__init__.py | 4 ++-- plugwise_usb/connection/__init__.py | 18 +++++++++--------- tests/test_usb.py | 5 ++++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index a1ee49837..0c8345da7 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -120,12 +120,12 @@ def joined_nodes(self) -> int | None: @property def firmware_stick(self) -> str: """Firmware of USB-Stick.""" - return self._controller.firmware_stick + return self._controller._fw_stick @property def hardware_stick(self) -> str: """Hardware of USB-Stick.""" - return self._controller.hardware_stick + return self._controller._hw_stick @property def mac_stick(self) -> str: diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 4c765a275..dc85a61da 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -56,15 +56,15 @@ def is_connected(self) -> bool: """Return connection state from connection manager.""" return self._manager.is_connected - @property - def firmware_stick(self) -> str | None: - """Firmware version of the Stick.""" - return self._fw_stick - - @property - def hardware_stick(self) -> str | None: - """Hardware version of the Stick.""" - return self._hw_stick + # @property + # def firmware_stick(self) -> str | None: + # """Firmware version of the Stick.""" + # return self._fw_stick + + # @property + # def hardware_stick(self) -> str | None: + # """Hardware version of the Stick.""" + # return self._hw_stick @property def mac_stick(self) -> str: diff --git a/tests/test_usb.py b/tests/test_usb.py index 23982934b..a832bcd08 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == None - assert stick.hardware_stick == None # "653907008512" + assert stick.hardware_stick == None assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 @@ -578,6 +578,9 @@ async def test_stick_node_discovered_subscription( events=(pw_api.NodeEvent.AWAKE,), ) + #assert stick.firmware_stick == None + assert stick.hardware_stick == "653907008512" + # Inject NodeAwakeResponse message to trigger a 'node discovered' event mock_serial.inject_message(b"004F555555555555555500", b"FFFE") mac_awake_node = await self.test_node_awake From d52826acc4065f5916a37f6fce3c134770554f96 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 08:44:10 +0100 Subject: [PATCH 21/39] Remove logging, add missing --- plugwise_usb/__init__.py | 10 ++++++++++ plugwise_usb/network/__init__.py | 7 ++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index 0c8345da7..c9fe4b180 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -316,6 +316,16 @@ async def load_nodes(self) -> bool: ) return await self._network.discover_nodes(load=True) + @raise_not_connected + @raise_not_initialized + async def discover_stick(self) -> None: + """Discover all nodes.""" + if self._network is None: + raise StickError( + "Cannot load nodes when network is not initialized" + ) + await self._network.discover_stick() + @raise_not_connected @raise_not_initialized async def discover_coordinator(self, load: bool = False) -> None: diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 68dae9536..9f4379ebc 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -286,19 +286,16 @@ def _unsubscribe_to_protocol_events(self) -> None: # endregion - async def discover_stick(self, load: bool = False) -> bool: + async def discover_stick(self) -> bool: """Fetch data from the Stick.""" if self._controller.mac_stick is None: raise NodeError("Unknown mac address for the Stick.") - _LOGGER.debug("Obtain Stick info") + _LOGGER.debug("Obtaining Stick info") node_info, _ = await self._controller.get_node_details(self._controller.mac_stick, ping_first=False) if node_info is not None: - _LOGGER.debug("HOI fw_stick before: %s", self._controller._fw_stick) self._controller._fw_stick = node_info.firmware self._controller._hw_stick = node_info.hardware - _LOGGER.debug("HOI fw_stick: %s", self._controller._fw_stick) - _LOGGER.debug("HOI hw_stick: %s", self._controller._hw_stick) # region - Coordinator async def discover_network_coordinator(self, load: bool = False) -> bool: From 66cd442a958e68e654c2758fec23190ff436086f Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 08:46:25 +0100 Subject: [PATCH 22/39] Fix --- plugwise_usb/network/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 9f4379ebc..2659f6b5b 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -493,7 +493,7 @@ async def start(self) -> None: async def discover_nodes(self, load: bool = True) -> bool: """Discover nodes.""" - await self.discover_stick(load=load) + await self.discover_stick() await self.discover_network_coordinator(load=load) if not self._is_running: await self.start() From 003c65c77e281d52ac308de3b0784d599643a7ee Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 08:47:49 +0100 Subject: [PATCH 23/39] Update stick hardware assert --- tests/test_usb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index a832bcd08..396ebc9dc 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == None - assert stick.hardware_stick == None + assert stick.hardware_stick == "070085" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 9e03770bb2ca60b4562a3ed575416fb0130a9945 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 08:51:13 +0100 Subject: [PATCH 24/39] Try --- plugwise_usb/__init__.py | 4 ++-- plugwise_usb/connection/__init__.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index c9fe4b180..77b5d1421 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -120,12 +120,12 @@ def joined_nodes(self) -> int | None: @property def firmware_stick(self) -> str: """Firmware of USB-Stick.""" - return self._controller._fw_stick + return self._controller.firmware_stick @property def hardware_stick(self) -> str: """Hardware of USB-Stick.""" - return self._controller._hw_stick + return self._controller.hardware_stick @property def mac_stick(self) -> str: diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index dc85a61da..4c765a275 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -56,15 +56,15 @@ def is_connected(self) -> bool: """Return connection state from connection manager.""" return self._manager.is_connected - # @property - # def firmware_stick(self) -> str | None: - # """Firmware version of the Stick.""" - # return self._fw_stick - - # @property - # def hardware_stick(self) -> str | None: - # """Hardware version of the Stick.""" - # return self._hw_stick + @property + def firmware_stick(self) -> str | None: + """Firmware version of the Stick.""" + return self._fw_stick + + @property + def hardware_stick(self) -> str | None: + """Hardware version of the Stick.""" + return self._hw_stick @property def mac_stick(self) -> str: From 4ec68b2a3ef87816a4833221607a0b4b1b04c59c Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 08:56:23 +0100 Subject: [PATCH 25/39] Add stick firmware-assert --- tests/test_usb.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index 396ebc9dc..d9270ceb6 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == None - assert stick.hardware_stick == "070085" + assert stick.hardware_stick == None assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 @@ -578,7 +578,9 @@ async def test_stick_node_discovered_subscription( events=(pw_api.NodeEvent.AWAKE,), ) - #assert stick.firmware_stick == None + assert stick.firmware_stick == dt( + 2011, 6, 27, 8, 47, 37, tzinfo=UTC + ) assert stick.hardware_stick == "653907008512" # Inject NodeAwakeResponse message to trigger a 'node discovered' event From 1a78559e4f6fecee47de30facd670f79948e5c5e Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:19:00 +0100 Subject: [PATCH 26/39] Remove, not needed --- plugwise_usb/__init__.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index 77b5d1421..a1ee49837 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -316,16 +316,6 @@ async def load_nodes(self) -> bool: ) return await self._network.discover_nodes(load=True) - @raise_not_connected - @raise_not_initialized - async def discover_stick(self) -> None: - """Discover all nodes.""" - if self._network is None: - raise StickError( - "Cannot load nodes when network is not initialized" - ) - await self._network.discover_stick() - @raise_not_connected @raise_not_initialized async def discover_coordinator(self, load: bool = False) -> None: From 439747941c37e076476f5f578898bf38564bde8a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:27:22 +0100 Subject: [PATCH 27/39] Collect Stick data during initialization --- plugwise_usb/connection/__init__.py | 10 +++++----- plugwise_usb/network/__init__.py | 12 ------------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 4c765a275..9ee3f2270 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -190,11 +190,11 @@ async def initialize_stick(self) -> None: self._network_id = init_response.network_id self._is_initialized = True - # # add Stick NodeInfoRequest - # node_info, _ = await self.get_node_details(self._mac_stick, False) - # if node_info is not None: - # self._fw_stick = node_info.firmware - # self._hw_stick = node_info.hardware + # Add Stick NodeInfoRequest + node_info, _ = await self.get_node_details(self._mac_stick, ping_first=False) + if node_info is not None: + self._fw_stick = node_info.firmware + self._hw_stick = node_info.hardware if not self._network_online: raise StickError("Zigbee network connection to Circle+ is down.") diff --git a/plugwise_usb/network/__init__.py b/plugwise_usb/network/__init__.py index 2659f6b5b..cab52a073 100644 --- a/plugwise_usb/network/__init__.py +++ b/plugwise_usb/network/__init__.py @@ -285,17 +285,6 @@ def _unsubscribe_to_protocol_events(self) -> None: self._unsubscribe_stick_event = None # endregion - - async def discover_stick(self) -> bool: - """Fetch data from the Stick.""" - if self._controller.mac_stick is None: - raise NodeError("Unknown mac address for the Stick.") - - _LOGGER.debug("Obtaining Stick info") - node_info, _ = await self._controller.get_node_details(self._controller.mac_stick, ping_first=False) - if node_info is not None: - self._controller._fw_stick = node_info.firmware - self._controller._hw_stick = node_info.hardware # region - Coordinator async def discover_network_coordinator(self, load: bool = False) -> bool: @@ -493,7 +482,6 @@ async def start(self) -> None: async def discover_nodes(self, load: bool = True) -> bool: """Discover nodes.""" - await self.discover_stick() await self.discover_network_coordinator(load=load) if not self._is_running: await self.start() From b1314a0718439269dfc4e088c181cabca4f901cd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:29:20 +0100 Subject: [PATCH 28/39] Adapt asserts --- tests/test_usb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index d9270ceb6..095243d58 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -460,8 +460,8 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: await stick.initialize() assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" - assert stick.firmware_stick == None - assert stick.hardware_stick == None + assert stick.firmware_stick == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC) + assert stick.hardware_stick == "653907008512" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From c703f2e0fbae97548e246846903a718a7e43a564 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:38:46 +0100 Subject: [PATCH 29/39] Translate to short hardware-version --- plugwise_usb/connection/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 9ee3f2270..92c6c7593 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -9,6 +9,7 @@ from ..api import StickEvent from ..constants import UTF8 from ..exceptions import NodeError, StickError +from ..helpers.util import version_to_model from ..messages.requests import ( NodeInfoRequest, NodePingRequest, @@ -194,7 +195,8 @@ async def initialize_stick(self) -> None: node_info, _ = await self.get_node_details(self._mac_stick, ping_first=False) if node_info is not None: self._fw_stick = node_info.firmware - self._hw_stick = node_info.hardware + hardware, _ = version_to_model(node_info.hardware) + self._hw_stick = hardware if not self._network_online: raise StickError("Zigbee network connection to Circle+ is down.") From 02c2724196814988285199657e331d027d56898f Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:41:13 +0100 Subject: [PATCH 30/39] Adapt and clean-up test-asserts --- tests/test_usb.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_usb.py b/tests/test_usb.py index 095243d58..1fcf09f90 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,7 +461,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC) - assert stick.hardware_stick == "653907008512" + assert stick.hardware_stick == "070085" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 @@ -578,11 +578,6 @@ async def test_stick_node_discovered_subscription( events=(pw_api.NodeEvent.AWAKE,), ) - assert stick.firmware_stick == dt( - 2011, 6, 27, 8, 47, 37, tzinfo=UTC - ) - assert stick.hardware_stick == "653907008512" - # Inject NodeAwakeResponse message to trigger a 'node discovered' event mock_serial.inject_message(b"004F555555555555555500", b"FFFE") mac_awake_node = await self.test_node_awake From 008b59a4b6c03616abb96fc7abdf5bae074f8907 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:43:59 +0100 Subject: [PATCH 31/39] Clean up debug-logging --- plugwise_usb/messages/properties.py | 1 - plugwise_usb/messages/responses.py | 7 ------- 2 files changed, 8 deletions(-) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 31a49d96c..19f8bf4b4 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -229,7 +229,6 @@ def __init__(self, year: int = 0, month: int = 1, minutes: int = 0) -> None: def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" - _LOGGER.debug("HOI val: %s", val) if val == b"FFFFFFFF" or val == b"00000000": _LOGGER.debug("Invalid DateTime value result") self._value = None diff --git a/plugwise_usb/messages/responses.py b/plugwise_usb/messages/responses.py index 5a3b26db9..50dedbccc 100644 --- a/plugwise_usb/messages/responses.py +++ b/plugwise_usb/messages/responses.py @@ -4,7 +4,6 @@ from datetime import datetime from enum import Enum -import logging from typing import Any, Final from ..api import NodeType @@ -42,8 +41,6 @@ SWITCH_GROUP_RESPONSE_SEQ_ID, ) -_LOGGER = logging.getLogger(__name__) - class StickResponseType(bytes, Enum): """Response message types for stick.""" @@ -193,7 +190,6 @@ def deserialize(self, response: bytes, has_footer: bool = True) -> None: self._mac = response[:16] response = response[16:] if len(response) > 0: - _LOGGER.debug("HOI response: %s", response) try: response = self._parse_params(response) except ValueError as ve: @@ -207,11 +203,8 @@ def deserialize(self, response: bytes, has_footer: bool = True) -> None: def _parse_params(self, response: bytes) -> bytes: for param in self._params: my_val = response[: len(param)] - _LOGGER.debug("HOI param: %s", param) - _LOGGER.debug("HOI my_val: %s", my_val) param.deserialize(my_val) response = response[len(my_val) :] - _LOGGER.debug("HOI response: %s", response) return response From d0de7256c18d29c3e1fef81f6d1cba1f2d038c5a Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 17:52:27 +0100 Subject: [PATCH 32/39] Clean-up --- plugwise_usb/messages/properties.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 19f8bf4b4..2e42dc4f1 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -2,7 +2,6 @@ import binascii from datetime import UTC, date, datetime, time, timedelta -import logging import struct from typing import Any @@ -10,7 +9,6 @@ from ..exceptions import MessageError from ..helpers.util import int_to_uint -_LOGGER = logging.getLogger(__name__) class BaseType: """Generic single instance property.""" @@ -230,7 +228,6 @@ def __init__(self, year: int = 0, month: int = 1, minutes: int = 0) -> None: def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" if val == b"FFFFFFFF" or val == b"00000000": - _LOGGER.debug("Invalid DateTime value result") self._value = None else: CompositeType.deserialize(self, val) From 7de9d4605326323d70ff387abf7a23df15fe35ed Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 19:06:45 +0100 Subject: [PATCH 33/39] Pylint fix --- plugwise_usb/messages/properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugwise_usb/messages/properties.py b/plugwise_usb/messages/properties.py index 2e42dc4f1..a2a065aa4 100644 --- a/plugwise_usb/messages/properties.py +++ b/plugwise_usb/messages/properties.py @@ -227,7 +227,7 @@ def __init__(self, year: int = 0, month: int = 1, minutes: int = 0) -> None: def deserialize(self, val: bytes) -> None: """Convert data into datetime based on timestamp with offset to Y2k.""" - if val == b"FFFFFFFF" or val == b"00000000": + if val in (b"FFFFFFFF", b"00000000"): self._value = None else: CompositeType.deserialize(self, val) From d3a494ab7f4d33aca91405801270c4a0473ec7bd Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Wed, 12 Feb 2025 19:14:11 +0100 Subject: [PATCH 34/39] Bump to a30 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9f437c73d..3d5ffa621 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "v0.40.0a29" +version = "v0.40.0a30" license = {file = "LICENSE"} description = "Plugwise USB (Stick) module for Python 3." readme = "README.md" From ea09df7a77a270cc1ab5378da67fbb64bf69e8da Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 13 Feb 2025 08:30:44 +0100 Subject: [PATCH 35/39] Add Stick-name property --- plugwise_usb/__init__.py | 5 +++++ plugwise_usb/connection/__init__.py | 1 + 2 files changed, 6 insertions(+) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index a1ee49837..3699db56a 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -137,6 +137,11 @@ def mac_coordinator(self) -> str: """MAC address of the network coordinator (Circle+). Raises StickError is connection is missing.""" return self._controller.mac_coordinator + @property + def name(self) -> str: + """Return name of Stick.""" + return self._controller._stick_name + @property def network_discovered(self) -> bool: """Indicate if discovery of network is active. Raises StickError is connection is missing.""" diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 92c6c7593..484479c03 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -184,6 +184,7 @@ async def initialize_stick(self) -> None: + f"' {self._manager.serial_path}'" ) self._mac_stick = init_response.mac_decoded + self._stick_name = f"Stick {self._mac_stick[-5:]}" self._network_online = init_response.network_online # Replace first 2 characters by 00 for mac of circle+ node From a2d395a7a05861b8242b90ff336f63ce5af38637 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 13 Feb 2025 08:31:56 +0100 Subject: [PATCH 36/39] Add related test-assert --- tests/test_usb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_usb.py b/tests/test_usb.py index 1fcf09f90..470b67709 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -459,6 +459,7 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert await self.test_connected await stick.initialize() assert stick.mac_stick == "0123456789012345" + assert stick.name == "Stick 12345" assert stick.mac_coordinator == "0098765432101234" assert stick.firmware_stick == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC) assert stick.hardware_stick == "070085" From ef0df7cc4819fdaf620f27566c5bb34e52511d73 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 13 Feb 2025 08:34:34 +0100 Subject: [PATCH 37/39] Bump to a31 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3d5ffa621..f084e85d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "plugwise_usb" -version = "v0.40.0a30" +version = "v0.40.0a31" license = {file = "LICENSE"} description = "Plugwise USB (Stick) module for Python 3." readme = "README.md" From f3b2e2a08760cbb358f645cf415068a2dbd607e6 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 13 Feb 2025 08:39:30 +0100 Subject: [PATCH 38/39] Simplify property-names, improve --- plugwise_usb/__init__.py | 4 ++-- plugwise_usb/connection/__init__.py | 1 + tests/test_usb.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index 3699db56a..a28c4ec79 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -118,12 +118,12 @@ def joined_nodes(self) -> int | None: return len(self._network.registry) + 1 @property - def firmware_stick(self) -> str: + def firmware(self) -> str: """Firmware of USB-Stick.""" return self._controller.firmware_stick @property - def hardware_stick(self) -> str: + def hardware(self) -> str: """Hardware of USB-Stick.""" return self._controller.hardware_stick diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 484479c03..9f842eab3 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -44,6 +44,7 @@ def __init__(self) -> None: self._mac_nc: str | None = None self._network_id: int | None = None self._network_online = False + self._stick_name: str | None = None @property def is_initialized(self) -> bool: diff --git a/tests/test_usb.py b/tests/test_usb.py index 470b67709..c96e5cc27 100644 --- a/tests/test_usb.py +++ b/tests/test_usb.py @@ -461,8 +461,8 @@ async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None: assert stick.mac_stick == "0123456789012345" assert stick.name == "Stick 12345" assert stick.mac_coordinator == "0098765432101234" - assert stick.firmware_stick == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC) - assert stick.hardware_stick == "070085" + assert stick.firmware == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC) + assert stick.hardware == "070085" assert not stick.network_discovered assert stick.network_state assert stick.network_id == 17185 From 62ed3254bde3cb6b28c764b470a005b081661080 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk Date: Thu, 13 Feb 2025 08:45:10 +0100 Subject: [PATCH 39/39] Fix --- plugwise_usb/__init__.py | 2 +- plugwise_usb/connection/__init__.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugwise_usb/__init__.py b/plugwise_usb/__init__.py index a28c4ec79..a00ca68da 100644 --- a/plugwise_usb/__init__.py +++ b/plugwise_usb/__init__.py @@ -140,7 +140,7 @@ def mac_coordinator(self) -> str: @property def name(self) -> str: """Return name of Stick.""" - return self._controller._stick_name + return self._controller.stick_name @property def network_discovered(self) -> bool: diff --git a/plugwise_usb/connection/__init__.py b/plugwise_usb/connection/__init__.py index 9f842eab3..bb2559b3c 100644 --- a/plugwise_usb/connection/__init__.py +++ b/plugwise_usb/connection/__init__.py @@ -44,7 +44,7 @@ def __init__(self) -> None: self._mac_nc: str | None = None self._network_id: int | None = None self._network_online = False - self._stick_name: str | None = None + self.stick_name: str | None = None @property def is_initialized(self) -> bool: @@ -185,7 +185,7 @@ async def initialize_stick(self) -> None: + f"' {self._manager.serial_path}'" ) self._mac_stick = init_response.mac_decoded - self._stick_name = f"Stick {self._mac_stick[-5:]}" + self.stick_name = f"Stick {self._mac_stick[-5:]}" self._network_online = init_response.network_online # Replace first 2 characters by 00 for mac of circle+ node