Skip to content

Commit

Permalink
Fix Commissioning (#143)
Browse files Browse the repository at this point in the history
* fix commissioning - remove temp workaround

* bump sdk version

* lint

* remove unused import

* assert unknown compressed_fabric_id
  • Loading branch information
marcelveldt authored Dec 23, 2022
1 parent e3a5c1c commit 2e4d9a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
29 changes: 11 additions & 18 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import asyncio
from collections import deque
from datetime import datetime
from functools import partial
Expand Down Expand Up @@ -56,19 +55,18 @@ def __init__(
self._nodes: dict[int, MatterNode] = {}
self.wifi_credentials_set: bool = False
self.thread_credentials_set: bool = False
self.compressed_fabric_id: int | None = None

@property
def fabric_id(self) -> int:
"""Return Fabric ID."""
return self.chip_controller.fabricId

@property
def compressed_fabric_id(self) -> int:
"""Return unique identifier for this initialized fabric."""
return self.chip_controller.GetCompressedFabricId()

async def start(self) -> None:
"""Async initialize of controller."""
self.compressed_fabric_id = await self._call_sdk(
self.chip_controller.GetCompressedFabricId
)
# load nodes from persistent storage
nodes_data = self.server.storage.get(DATA_KEY_NODES, {})
for node_id_str, node_dict in nodes_data.items():
Expand Down Expand Up @@ -114,22 +112,15 @@ async def commission_with_code(self, code: str) -> MatterNode:
"""
node_id = self._get_next_node_id()

# TODO TEMP !!!
# The call to CommissionWithCode returns early without waiting ?!
# This is most likely a bug in the SDK or its python wrapper
# success = await self._call_sdk(
# self.chip_controller.CommissionWithCode,
# setupPayload=code,
# nodeid=node_id,
# )
# if not success:
# raise NodeCommissionFailed(f"Commission with code failed for node {node_id}")
await self._call_sdk(
success = await self._call_sdk(
self.chip_controller.CommissionWithCode,
setupPayload=code,
nodeid=node_id,
)
await asyncio.sleep(60)
if not success:
raise NodeCommissionFailed(
f"Commission with code failed for node {node_id}"
)

# full interview of the device
await self.interview_node(node_id)
Expand All @@ -154,6 +145,7 @@ async def commission_on_network(
Returns full NodeInfo once complete.
"""
node_id = self._get_next_node_id()

success = await self._call_sdk(
self.chip_controller.CommissionOnNetwork,
nodeId=node_id,
Expand All @@ -165,6 +157,7 @@ async def commission_on_network(
raise NodeCommissionFailed(
f"Commission on network failed for node {node_id}"
)

# full interview of the device
await self.interview_node(node_id)
# make sure we start a subscription for this newly added node
Expand Down
1 change: 1 addition & 0 deletions matter_server/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def unsub():
@api_command(APICommand.SERVER_INFO)
def get_info(self) -> ServerInfo:
"""Return (version)info of the Matter Server."""
assert self.device_controller.compressed_fabric_id is not None
return ServerInfo(
fabric_id=self.device_controller.fabric_id,
compressed_fabric_id=self.device_controller.compressed_fabric_id,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ dependencies = [
"coloredlogs",
"dacite",
"orjson",
"home-assistant-chip-clusters==2022.11.1"
"home-assistant-chip-clusters==2022.12.0"
]

[project.optional-dependencies]
server = [
"home-assistant-chip-core==2022.11.1"
"home-assistant-chip-core==2022.12.0"
]
test = [
"black==22.10.0",
Expand Down

0 comments on commit 2e4d9a9

Please sign in to comment.