Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
be7c054
Add plus_pair_request function
bouwew Feb 2, 2026
dcd4d83
Document pairing process
bouwew Feb 7, 2026
ae1bd0b
Add 0001-0002 req-resp-pair
bouwew Feb 7, 2026
69758df
Add init stick
bouwew Feb 7, 2026
9ceb1b6
Improve docstring
bouwew Feb 7, 2026
2c0f5f5
Improve pair_plus_device()
bouwew Feb 7, 2026
c11061d
Add todo for maybe needed functionality
bouwew Feb 7, 2026
cd41634
Fix typos, return type
bouwew Feb 7, 2026
039f7ba
Correct imports, improve docstring
bouwew Feb 7, 2026
20a0939
Ruff fixes
bouwew Feb 7, 2026
b5c2906
Make sure the Stick is ready to pair, as suggested
bouwew Feb 8, 2026
6a540c4
Fix spelling
bouwew Feb 8, 2026
4bb21f5
Remove quotes, move
bouwew Feb 8, 2026
cb1606a
Set output as bool and use
bouwew Feb 8, 2026
fa15fee
Add missing await
bouwew Feb 8, 2026
ec78858
Add 0003 response to docstring
bouwew Feb 8, 2026
136e598
Start adding pairing test
bouwew Feb 8, 2026
cf9e6aa
Add missing connected()
bouwew Feb 8, 2026
46ede6d
Add pairing-test
bouwew Feb 8, 2026
52be6d8
Link to stick_pair_data
bouwew Feb 8, 2026
0aecfc6
Fix stick_pair_data
bouwew Feb 8, 2026
c737441
Set network to offline
bouwew Feb 8, 2026
f7d1916
Try
bouwew Feb 8, 2026
c2db830
Try 2
bouwew Feb 8, 2026
7390e28
Try 3
bouwew Feb 8, 2026
f0b74d2
Add StickInitShortResponse
bouwew Feb 8, 2026
2bff791
Remove commented-out in response
bouwew Feb 8, 2026
708fe62
Update length
bouwew Feb 8, 2026
37a40f9
Adapt StickInitRequest send()
bouwew Feb 8, 2026
67b6386
Update length StickInitResponse
bouwew Feb 8, 2026
eaf087b
Clean up
bouwew Feb 8, 2026
c3d4b3e
Full test-output - test_pairing
bouwew Feb 8, 2026
5c8e33b
Allow init to fail
bouwew Feb 8, 2026
c7a699e
Add sleep
bouwew Feb 8, 2026
8b6472e
Call pair_plus_request()
bouwew Feb 8, 2026
75f9c8f
Connected and initialized is not required
bouwew Feb 8, 2026
c85e79e
fixup: pair-plus Python code fixed using Ruff
Feb 8, 2026
480bad8
There can only be one response
bouwew Feb 8, 2026
690c656
Use inheritance for StickInitResponse
bouwew Feb 8, 2026
8056de4
Move pair_plus_device() to connection
bouwew Feb 8, 2026
8a75fdf
Correct plus-mac
bouwew Feb 8, 2026
54c0a2e
Add stick-mac to 0002 response
bouwew Feb 8, 2026
2192877
Move RESPONSE_MESSAGES
bouwew Feb 9, 2026
1a19a49
Don't test network down first
bouwew Feb 9, 2026
e9126d0
Add missing import
bouwew Feb 9, 2026
33c4bcc
Connect first
bouwew Feb 9, 2026
14848e9
Try
bouwew Feb 9, 2026
58a3c2d
fixup: pair-plus Python code fixed using Ruff
Feb 9, 2026
e9520c7
Try 3
bouwew Feb 10, 2026
207ba78
Try 4
bouwew Feb 10, 2026
2dd2e77
Try not allowed
bouwew Feb 10, 2026
443c89b
Extra bit
bouwew Feb 10, 2026
c4390a5
CirclePlusConnectReqyest: shorter args
bouwew Feb 10, 2026
4669cc9
fixup: pair-plus Python code fixed using Ruff
Feb 10, 2026
cdc9b90
Add stick-mac to 0005-response, remove extra bit
bouwew Feb 10, 2026
e3d094e
Ruffed
bouwew Feb 10, 2026
12e2871
Shorten args, must be length=16
bouwew Feb 10, 2026
c9972d7
Add missing CRC, can be corrected later
bouwew Feb 10, 2026
426c4a9
Try
bouwew Feb 12, 2026
dcc61b8
Try 2
bouwew Feb 13, 2026
4af6d39
Fixes
bouwew Feb 13, 2026
eea571d
Correct CRC
bouwew Feb 13, 2026
17f1ed6
Try allowed
bouwew Feb 13, 2026
9c5e0a6
Change to Circle+ mac in 0005-response
bouwew Feb 13, 2026
033af0c
Ruff-cleanup
bouwew Feb 13, 2026
43ef3f4
Bump to v0.48.0a1 test-version
bouwew Feb 13, 2026
8002eb1
Update CHANGELOG
bouwew Feb 13, 2026
bfc0f09
Implement StickInitShortResponse-handling in class StickController
bouwew Feb 16, 2026
75e3781
Back to full test-output
bouwew Feb 16, 2026
1eb6f0c
Improve
bouwew Feb 16, 2026
06d5a2b
Correct CHANGELOG after rebase
bouwew Feb 16, 2026
02ef4b0
Bump to v0.48.0a2 test-version
bouwew Feb 16, 2026
56d5421
Run all test-files in case of failure
bouwew Feb 16, 2026
2a8d65a
Revert back to python 3.13
bouwew Feb 17, 2026
e3f3e6c
Bump to a3
bouwew Feb 17, 2026
09ce79b
Try-except stick-initialize
bouwew Feb 17, 2026
72977c8
Ruff fix
bouwew Feb 17, 2026
77cf3a2
Add log-warning
bouwew Feb 17, 2026
d4d7ba1
Bump to a4
bouwew Feb 17, 2026
c6ae8be
Remove is_connected requirement for mac_stick
bouwew Feb 18, 2026
a583c4e
Bump to a5
bouwew Feb 18, 2026
7782bd2
Disable now invalid test
bouwew Feb 18, 2026
caa8de1
More debug-logging
bouwew Feb 19, 2026
285c9c6
Bump to a6
bouwew Feb 19, 2026
2539340
Move debug message
bouwew Feb 19, 2026
347d2c5
Bump to a7
bouwew Feb 19, 2026
d95a4c1
Revert adding try-except
bouwew Feb 19, 2026
c836c02
Replace debuggers by distinct message
bouwew Feb 20, 2026
fd76e29
Bump to a8
bouwew Feb 20, 2026
cfcaa7d
Remove unneeded StickError raises
bouwew Feb 20, 2026
aae05e8
Update relevant test-asserts
bouwew Feb 20, 2026
46fb7ae
Ruff fixes
bouwew Feb 20, 2026
5cadd33
Correct -update test_stick_network_down()
bouwew Feb 20, 2026
ce24dd5
Fix pylint warnings
bouwew Feb 20, 2026
f4ff1d5
More adapting to StickInitShortResponse
bouwew Feb 20, 2026
160c69c
Bump to a9
bouwew Feb 20, 2026
24e2356
Update Stick properties mac_stick, mac_coordinator and name
bouwew Feb 20, 2026
ce87106
Update docstring
bouwew Feb 20, 2026
8ae2d45
Update network_online docstring
bouwew Feb 20, 2026
9d45f0a
Bump to a10
bouwew Feb 20, 2026
504a6f5
fixup: pair-plus Python code fixed using Ruff
Feb 20, 2026
420d925
Responses: line up Int() use
bouwew Feb 23, 2026
e26b1cf
Add missing decode_mac=False
bouwew Feb 23, 2026
8f3f05c
Correct 0002-format in response
bouwew Feb 23, 2026
ae9ca33
Bump to a11
bouwew Feb 23, 2026
c2d4fbf
Exit when network is not online
bouwew Feb 23, 2026
985c894
Bump to a12
bouwew Feb 23, 2026
2022dc2
Revert "Exit when network is not online"
bouwew Feb 23, 2026
9cc15ef
Remove logger-HOI-lines
bouwew Feb 23, 2026
e69abe0
Bump to a13
bouwew Feb 23, 2026
84d123f
Don't collect NodeInfo during pairing
bouwew Feb 23, 2026
8c7cd6a
Update 0004-request
bouwew Feb 23, 2026
47c4aeb
Update test-related
bouwew Feb 23, 2026
0d01a7c
Ruffed
bouwew Feb 23, 2026
95af5b6
Update docstring
bouwew Feb 23, 2026
73fcc12
Bump to a14
bouwew Feb 24, 2026
bbd4e77
0005-response: add missing decode_mac=False
bouwew Feb 24, 2026
c532d34
Improve docstring
bouwew Feb 24, 2026
3042d96
Adapt 0005-test-response
bouwew Mar 2, 2026
e7b6bed
Add init to StickNetworkInfoRequest
bouwew Mar 3, 2026
b18001e
And adapt use
bouwew Mar 3, 2026
cf98621
Disable guarding that breaks 0004-0005 sequence detection
bouwew Mar 4, 2026
dbe78e8
Fix CHANGELOG after rebase
bouwew Mar 4, 2026
e4d6a4f
Update pair_plus_device() docsting
bouwew Sep 1, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
- commitcheck
strategy:
matrix:
python-version: ["3.14"]
python-version: ["3.13"]
steps:
- name: Check out committed code
uses: actions/checkout@v7
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Ongoing

- PR [405](https://github.com/plugwise/python-plugwise-usb/pull/405): Try adding plus-device pairing (untested!!)

## v0.47.8 - 2026-07-01

PR [459](https://github.com/plugwise/python-plugwise-usb/pull/459): Reduce logging for SEDs
Expand All @@ -23,7 +27,7 @@ PR [422](https://github.com/plugwise/python-plugwise-usb/pull/422): Add missing
## v0.47.3 - 2026-03-04

- PR [418](https://github.com/plugwise/python-plugwise-usb/pull/418): Improve raise-message for better debugging
- PR [405](https://github.com/plugwise/python-plugwise-usb/pull/405): Fix recent Ruff errors
- PR [409](https://github.com/plugwise/python-plugwise-usb/pull/409): Fix recent Ruff errors

## v0.47.2 - 2026-01-29

Expand Down
37 changes: 28 additions & 9 deletions plugwise_usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,27 @@ def hardware(self) -> str:
return self._controller.hardware_stick

@property
def mac_stick(self) -> str:
"""MAC address of USB-Stick. Raises StickError is connection is missing."""
def mac_stick(self) -> str | None:
"""MAC address of USB-Stick.

Returns None when the connection to the Stick fails.
"""
return self._controller.mac_stick

@property
def mac_coordinator(self) -> str:
"""MAC address of the network coordinator (Circle+). Raises StickError is connection is missing."""
def mac_coordinator(self) -> str | None:
"""MAC address of the network coordinator (Circle+).

Returns none when there is no connection, not paired, not present in the network.
"""
return self._controller.mac_coordinator

@property
def name(self) -> str:
"""Return name of Stick."""
def name(self) -> str | None:
"""Return name of Stick.

Returns None when the connection to the Stick fails.
"""
return self._controller.stick_name

@property
Expand Down Expand Up @@ -237,8 +246,8 @@ async def setup(self, discover: bool = True, load: bool = True) -> None:
if not self.is_connected:
await self.connect()
if not self.is_initialized:
await self.initialize()
if discover:
initialized = await self.initialize()
if initialized and discover:
await self.start_network()
await self.discover_coordinator()
await self.discover_nodes()
Expand Down Expand Up @@ -266,10 +275,18 @@ async def connect(self, port: str | None = None) -> None:
self._port,
)

async def plus_pair_request(self, mac: str) -> bool:
"""Send a pair request to a Plus device."""
return await self._controller.pair_plus_device(mac)

@raise_not_connected
async def initialize(self, create_root_cache_folder: bool = False) -> None:
async def initialize(self, create_root_cache_folder: bool = False) -> bool:
"""Initialize connection to USB-Stick."""
await self._controller.initialize_stick()
# Check if network is offline = StickInitShortResponse
if self._controller.mac_coordinator is None:
return False

if self._network is None:
self._network = StickNetwork(self._controller)
self._network.cache_folder = self._cache_folder
Expand All @@ -278,6 +295,8 @@ async def initialize(self, create_root_cache_folder: bool = False) -> None:
if self._cache_enabled:
await self._network.initialize_cache()

return True

@raise_not_connected
@raise_not_initialized
async def start_network(self) -> None:
Expand Down
118 changes: 83 additions & 35 deletions plugwise_usb/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@

from ..api import StickEvent
from ..constants import UTF8
from ..exceptions import NodeError, StickError
from ..helpers.util import version_to_model
from ..exceptions import MessageError, NodeError, StickError
from ..helpers.util import validate_mac, version_to_model
from ..messages.requests import (
CirclePlusConnectRequest,
NodeInfoRequest,
NodePingRequest,
PlugwiseRequest,
StickInitRequest,
StickNetworkInfoRequest,
)
from ..messages.responses import (
NodeInfoResponse,
NodePingResponse,
PlugwiseResponse,
StickInitResponse,
StickInitShortResponse,
)
from .manager import StickConnectionManager
from .queue import StickQueue
Expand Down Expand Up @@ -69,38 +72,27 @@ def hardware_stick(self) -> str | None:
return self._hw_stick

@property
def mac_stick(self) -> str:
"""MAC address of USB-Stick. Raises StickError when not connected."""
if not self._manager.is_connected or self._mac_stick is None:
raise StickError(
"No mac address available. Connect and initialize USB-Stick first."
)
def mac_stick(self) -> str | None:
"""MAC address of USB-Stick."""
return self._mac_stick

@property
def mac_coordinator(self) -> str:
"""Return MAC address of the Zigbee network coordinator (Circle+).

Raises StickError when not connected.
"""
if not self._manager.is_connected or self._mac_nc is None:
raise StickError(
"No mac address available. Connect and initialize USB-Stick first."
)
def mac_coordinator(self) -> str | None:
"""Return MAC address of the Zigbee network coordinator (Circle+)."""
return self._mac_nc

@property
def network_id(self) -> int:
"""Returns the Zigbee network ID. Raises StickError when not connected."""
if not self._manager.is_connected or self._network_id is None:
raise StickError(
"No network ID available. Connect and initialize USB-Stick first."
)
def network_id(self) -> int | None:
"""Returns the Zigbee network ID."""
return self._network_id

@property
def network_online(self) -> bool:
"""Return the network state."""
"""Return the network state.

The ZigBee network is online when the Stick is connected and a
StickInitResponse indicates that the ZigBee network is online.
"""
if not self._manager.is_connected:
raise StickError(
"Network status not available. Connect and initialize USB-Stick first."
Expand Down Expand Up @@ -159,7 +151,7 @@ async def _handle_stick_event(self, event: StickEvent) -> None:
elif event == StickEvent.DISCONNECTED and self._queue.is_running:
await self._queue.stop()

async def initialize_stick(self) -> None:
async def initialize_stick(self, node_info=True) -> None:
"""Initialize connection to the USB-stick."""
if not self._manager.is_connected:
raise StickError(
Expand All @@ -170,7 +162,9 @@ async def initialize_stick(self) -> None:

try:
request = StickInitRequest(self.send)
init_response: StickInitResponse | None = await request.send()
init_response: (
StickInitResponse | StickInitShortResponse | None
) = await request.send()
except StickError as err:
raise StickError(
"No response from USB-Stick to initialization request."
Expand All @@ -186,26 +180,80 @@ async def initialize_stick(self) -> None:
self._mac_stick = init_response.mac_decoded
self.stick_name = f"Stick {self._mac_stick[-5:]}"
self._network_online = init_response.network_online
if self._network_online:
# Replace first 2 characters by 00 for mac of circle+ node
self._mac_nc = init_response.mac_network_controller
self._network_id = init_response.network_id

# Replace first 2 characters by 00 for mac of circle+ node
self._mac_nc = init_response.mac_network_controller
self._network_id = init_response.network_id
self._is_initialized = True

# Add Stick NodeInfoRequest
if not node_info:
return

# Collect Stick NodeInfo
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._fw_stick = node_info.firmware # type: ignore
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.")
async def pair_plus_device(self, mac: str) -> bool:
"""Pair Plus-device to Plugwise Stick.

The pairing process should look like:
Repeat sending 0001 (& 000A) until 0002 response is receiced
0001 -> 0003, 000A -> 0011S, 0001 -> 0003, 000A - 0011S, 0001 -> 0002 & 0003, 000A - 0011S
After receiving 0002-response, start sending the first 0004-request:
0004 00001 -> 0061 & 0005, 0001 -> 0002, 000A -> 0011S
After receiving 0061 (NODE_REJOIN_ID), ~30 seconds later, send the 2nd 0004-request:
0004 0101 -> 0061 & 0005, 000A -> 0011, receiving a full StickInitResponse means the pairing was succesful.
Follow up requesting NodeInfo etc (0023, 0060)

0001 - 0002 - 0003: StickNetworkInfoRequest - StickNetworkInfoResponse - NodeSpecificResponse
000A - 0011S/0011: StickInitRequest - StickInitShortResponse/StickInitResponse
0004 - 0005: CirclePlusConnectRequest - CirclePlusConnectResponse, the Plus-device will then send a NodeRejoinResponse (0061).
"""
_LOGGER.debug("Pair Plus-device with mac: %s", mac)
if not validate_mac(mac):
raise NodeError(f"Pairing failed: MAC {mac} invalid")

# Collect network info
try:
request = StickNetworkInfoRequest(self.send)
info_response = await request.send()
except MessageError as exc:
raise NodeError(f"Pairing failed: {exc}") from exc
if info_response is None:
raise NodeError(
"Pairing failed, StickNetworkInfoResponse is None"
) from None

# Init Stick
try:
await self.initialize_stick(node_info=False)
except StickError as exc:
raise NodeError(
f"Pairing failed, failed to initialize Stick: {exc}"
) from exc

try:
request = CirclePlusConnectRequest(self.send, bytes(mac, UTF8))
response = await request.send()
except MessageError as exc:
raise NodeError(f"Pairing failed: {exc}") from exc
if response is None:
raise NodeError(
"Pairing failed, CirclePlusConnectResponse is None"
) from None
if response.allowed.value != 1:
raise NodeError("Pairing failed, not allowed")

return True

async def get_node_details(
self, mac: str, ping_first: bool
) -> tuple[NodeInfoResponse | None, NodePingResponse | None]:
"""Return node discovery type."""
"""Collect NodeInfo data from the Stick."""
ping_response: NodePingResponse | None = None
if ping_first:
# Define ping request with one retry
Expand Down Expand Up @@ -234,7 +282,7 @@ async def send(
return await self._queue.submit(request)
try:
return await self._queue.submit(request)
except (NodeError, StickError):
except NodeError, StickError:
return None

def _reset_states(self) -> None:
Expand Down
10 changes: 5 additions & 5 deletions plugwise_usb/connection/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ async def _notify_node_response_subscribers(

notify_tasks: list[Coroutine[Any, Any, bool]] = []
for node_subscription in self._node_response_subscribers.values():
if (
node_subscription.mac is not None
and node_subscription.mac != node_response.mac
):
continue
# if (
# node_subscription.mac is not None
# and node_subscription.mac != node_response.mac
# ):
# continue
if (
node_subscription.response_ids is not None
and node_response.identifier not in node_subscription.response_ids
Expand Down
38 changes: 26 additions & 12 deletions plugwise_usb/messages/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
NodeSpecificResponse,
PlugwiseResponse,
StickInitResponse,
StickInitShortResponse,
StickNetworkInfoResponse,
StickResponse,
StickResponseType,
Expand Down Expand Up @@ -363,8 +364,18 @@ class StickNetworkInfoRequest(PlugwiseRequest):
_identifier = b"0001"
_reply_identifier = b"0002"

def __init__(
self,
send_fn: Callable[[PlugwiseRequest, bool], Awaitable[PlugwiseResponse | None]],
) -> None:
"""Initialize StickInitRequest message object."""
super().__init__(send_fn, None)
self._max_retries = 1

async def send(self) -> StickNetworkInfoResponse | None:
"""Send request."""
if self._send_fn is None:
raise MessageError("Send function missing")
result = await self._send_request()
if isinstance(result, StickNetworkInfoResponse):
return result
Expand Down Expand Up @@ -399,14 +410,17 @@ async def send(self) -> CirclePlusConnectResponse | None:
# This message has an exceptional format and therefore
# need to override the serialize method
def serialize(self) -> bytes:
"""Convert message to serialized list of bytes."""
# This command has
# args: byte
# key, byte
# network info.index, ulong
# network key = 0
args = b"00000000000000000000"
msg: bytes = self._identifier + args
"""Convert message to serialized list of bytes.

Parameters
----------
- special_id: byte - observed sequence with retry: b"0001", B"0101",
- and args: byte.

"""
special_id = b"0001"
args = b"0000000000000000"
msg: bytes = self._identifier + special_id + args
if self._mac is not None:
msg += self._mac
checksum = self.calculate_checksum(msg)
Expand Down Expand Up @@ -523,7 +537,7 @@ class StickInitRequest(PlugwiseRequest):
"""Initialize USB-Stick.

Supported protocols : 1.0, 2.0
Response message : StickInitResponse
Response message : StickInitResponse or StickInitShortResponse
"""

_identifier = b"000A"
Expand All @@ -537,17 +551,17 @@ def __init__(
super().__init__(send_fn, None)
self._max_retries = 1

async def send(self) -> StickInitResponse | None:
async def send(self) -> StickInitResponse | StickInitShortResponse | None:
"""Send request."""
if self._send_fn is None:
raise MessageError("Send function missing")
result = await self._send_request()
if isinstance(result, StickInitResponse):
if isinstance(result, StickInitResponse | StickInitShortResponse):
return result
if result is None:
return None
raise MessageError(
f"Invalid response message. Received {result.__class__.__name__}, expected StickInitResponse"
f"Invalid response message. Received {result.__class__.__name__}, expected StickInitResponse/StickInitShortResponse"
)


Expand Down
Loading
Loading