Skip to content
Merged
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
8 changes: 6 additions & 2 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ async def commission_with_code(self, code: str) -> MatterNodeData:
data = await self.send_command(APICommand.COMMISSION_WITH_CODE, code=code)
return dataclass_from_dict(MatterNodeData, data)

async def commission_on_network(self, setup_pin_code: int) -> MatterNodeData:
async def commission_on_network(
self, setup_pin_code: int, ip_addr: str | None = None
) -> MatterNodeData:
"""
Do the routine for OnNetworkCommissioning.

Expand All @@ -130,7 +132,9 @@ async def commission_on_network(self, setup_pin_code: int) -> MatterNodeData:
Returns basic MatterNodeData once complete.
"""
data = await self.send_command(
APICommand.COMMISSION_ON_NETWORK, setup_pin_code=setup_pin_code
APICommand.COMMISSION_ON_NETWORK,
setup_pin_code=setup_pin_code,
ip_addr=ip_addr,
)
return dataclass_from_dict(MatterNodeData, data)

Expand Down
43 changes: 30 additions & 13 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ async def commission_on_network(
setup_pin_code: int,
filter_type: int = 0,
filter: Any = None, # pylint: disable=redefined-builtin
ip_addr: str | None = None,
) -> MatterNodeData:
"""
Do the routine for OnNetworkCommissioning, with a filter for mDNS discovery.
Expand All @@ -226,20 +227,36 @@ async def commission_on_network(

node_id = self._get_next_node_id()

LOGGER.info(
"Starting Matter commissioning on network using Node ID %s.", node_id
)
success = await self._call_sdk(
self.chip_controller.CommissionOnNetwork,
nodeId=node_id,
setupPinCode=setup_pin_code,
filterType=filter_type,
filter=filter,
)
if not success:
raise NodeCommissionFailed(
f"Commission on network failed for node {node_id}"
if ip_addr is None:
LOGGER.info(
"Starting Matter commissioning on network using Node ID %s.", node_id
)
success = await self._call_sdk(
self.chip_controller.CommissionOnNetwork,
nodeId=node_id,
setupPinCode=setup_pin_code,
filterType=filter_type,
filter=filter,
)
if not success:
raise NodeCommissionFailed(
f"Commission on network failed for node {node_id}"
)
else:
LOGGER.info(
"Starting Matter commissioning with IP using Node ID %s.", node_id
)
success = await self._call_sdk(
self.chip_controller.CommissionIP,
nodeid=node_id,
setupPinCode=setup_pin_code,
ipaddr=ip_addr,
)
if not success:
raise NodeCommissionFailed(
f"Commission using IP failed for node {node_id}"
)

LOGGER.info("Matter commissioning of Node ID %s successful.", node_id)

# full interview of the device
Expand Down
15 changes: 14 additions & 1 deletion tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,20 @@ async def test_server_start(
{"setup_pin_code": 1234},
strict=True,
)
) == {"setup_pin_code": 1234, "filter_type": 0, "filter": None}
) == {"setup_pin_code": 1234, "filter_type": 0, "filter": None, "ip_addr": None}
assert (
parse_arguments(
server.command_handlers[APICommand.COMMISSION_ON_NETWORK].signature,
server.command_handlers[APICommand.COMMISSION_ON_NETWORK].type_hints,
{"setup_pin_code": 1234, "ip_addr": "fd82:c9e9:5cb7:1:2c5c:ed99:ecf:4460"},
strict=True,
)
) == {
"setup_pin_code": 1234,
"filter_type": 0,
"filter": None,
"ip_addr": "fd82:c9e9:5cb7:1:2c5c:ed99:ecf:4460",
}
assert (
parse_arguments(
server.command_handlers[APICommand.SET_WIFI_CREDENTIALS].signature,
Expand Down