Skip to content

Commit

Permalink
Allow to commission with code on network only (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Dec 21, 2023
1 parent 839c034 commit 6204809
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
15 changes: 11 additions & 4 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,20 @@ def get_node(self, node_id: int) -> MatterNode:
return node
raise NodeNotExists(f"Node {node_id} does not exist or is not yet interviewed")

async def commission_with_code(self, code: str) -> MatterNodeData:
async def commission_with_code(
self, code: str, network_only: bool = False
) -> MatterNodeData:
"""
Commission a device using QRCode or ManualPairingCode.
Commission a device using a QR Code or Manual Pairing Code.
Returns basic MatterNodeData once complete.
:param code: The QR Code or Manual Pairing Code for device commissioning.
:param network_only: If True, restricts device discovery to network only.
:return: The NodeInfo of the commissioned device.
"""
data = await self.send_command(APICommand.COMMISSION_WITH_CODE, code=code)
data = await self.send_command(
APICommand.COMMISSION_WITH_CODE, code=code, network_only=network_only
)
return dataclass_from_dict(MatterNodeData, data)

async def commission_on_network(
Expand Down
13 changes: 10 additions & 3 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Controller that Manages Matter devices."""
# pylint: disable=too-many-lines

from __future__ import annotations

Expand Down Expand Up @@ -145,11 +146,16 @@ def get_node(self, node_id: int) -> MatterNodeData:
raise NodeNotExists(f"Node {node_id} does not exist or is not yet interviewed")

@api_command(APICommand.COMMISSION_WITH_CODE)
async def commission_with_code(self, code: str) -> MatterNodeData:
async def commission_with_code(
self, code: str, network_only: bool = False
) -> MatterNodeData:
"""
Commission a device using QRCode or ManualPairingCode.
Commission a device using a QR Code or Manual Pairing Code.
Returns full NodeInfo once complete.
:param code: The QR Code or Manual Pairing Code for device commissioning.
:param network_only: If True, restricts device discovery to network only.
:return: The NodeInfo of the commissioned device.
"""
if self.chip_controller is None:
raise RuntimeError("Device Controller not initialized.")
Expand All @@ -166,6 +172,7 @@ async def commission_with_code(self, code: str) -> MatterNodeData:
self.chip_controller.CommissionWithCode,
setupPayload=code,
nodeid=node_id,
networkOnly=network_only,
)
if not success:
raise NodeCommissionFailed(
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ dependencies = [
"coloredlogs",
"dacite",
"orjson",
"home-assistant-chip-clusters==2023.10.2"
"home-assistant-chip-clusters==2023.12.0"
]

[project.optional-dependencies]
server = [
"home-assistant-chip-core==2023.10.2",
"home-assistant-chip-core==2023.12.0",
"cryptography==41.0.7"
]
test = [
Expand Down
2 changes: 1 addition & 1 deletion tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async def test_server_start(
{"code": "test_code"},
strict=True,
)
) == {"code": "test_code"}
) == {"code": "test_code", "network_only": False}
assert (
parse_arguments(
server.command_handlers[APICommand.COMMISSION_ON_NETWORK].signature,
Expand Down

0 comments on commit 6204809

Please sign in to comment.