Skip to content

Commit 2e4d9a9

Browse files
authored
Fix Commissioning (#143)
* fix commissioning - remove temp workaround * bump sdk version * lint * remove unused import * assert unknown compressed_fabric_id
1 parent e3a5c1c commit 2e4d9a9

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

matter_server/server/device_controller.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import asyncio
65
from collections import deque
76
from datetime import datetime
87
from functools import partial
@@ -56,19 +55,18 @@ def __init__(
5655
self._nodes: dict[int, MatterNode] = {}
5756
self.wifi_credentials_set: bool = False
5857
self.thread_credentials_set: bool = False
58+
self.compressed_fabric_id: int | None = None
5959

6060
@property
6161
def fabric_id(self) -> int:
6262
"""Return Fabric ID."""
6363
return self.chip_controller.fabricId
6464

65-
@property
66-
def compressed_fabric_id(self) -> int:
67-
"""Return unique identifier for this initialized fabric."""
68-
return self.chip_controller.GetCompressedFabricId()
69-
7065
async def start(self) -> None:
7166
"""Async initialize of controller."""
67+
self.compressed_fabric_id = await self._call_sdk(
68+
self.chip_controller.GetCompressedFabricId
69+
)
7270
# load nodes from persistent storage
7371
nodes_data = self.server.storage.get(DATA_KEY_NODES, {})
7472
for node_id_str, node_dict in nodes_data.items():
@@ -114,22 +112,15 @@ async def commission_with_code(self, code: str) -> MatterNode:
114112
"""
115113
node_id = self._get_next_node_id()
116114

117-
# TODO TEMP !!!
118-
# The call to CommissionWithCode returns early without waiting ?!
119-
# This is most likely a bug in the SDK or its python wrapper
120-
# success = await self._call_sdk(
121-
# self.chip_controller.CommissionWithCode,
122-
# setupPayload=code,
123-
# nodeid=node_id,
124-
# )
125-
# if not success:
126-
# raise NodeCommissionFailed(f"Commission with code failed for node {node_id}")
127-
await self._call_sdk(
115+
success = await self._call_sdk(
128116
self.chip_controller.CommissionWithCode,
129117
setupPayload=code,
130118
nodeid=node_id,
131119
)
132-
await asyncio.sleep(60)
120+
if not success:
121+
raise NodeCommissionFailed(
122+
f"Commission with code failed for node {node_id}"
123+
)
133124

134125
# full interview of the device
135126
await self.interview_node(node_id)
@@ -154,6 +145,7 @@ async def commission_on_network(
154145
Returns full NodeInfo once complete.
155146
"""
156147
node_id = self._get_next_node_id()
148+
157149
success = await self._call_sdk(
158150
self.chip_controller.CommissionOnNetwork,
159151
nodeId=node_id,
@@ -165,6 +157,7 @@ async def commission_on_network(
165157
raise NodeCommissionFailed(
166158
f"Commission on network failed for node {node_id}"
167159
)
160+
168161
# full interview of the device
169162
await self.interview_node(node_id)
170163
# make sure we start a subscription for this newly added node

matter_server/server/server.py

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def unsub():
125125
@api_command(APICommand.SERVER_INFO)
126126
def get_info(self) -> ServerInfo:
127127
"""Return (version)info of the Matter Server."""
128+
assert self.device_controller.compressed_fabric_id is not None
128129
return ServerInfo(
129130
fabric_id=self.device_controller.fabric_id,
130131
compressed_fabric_id=self.device_controller.compressed_fabric_id,

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ dependencies = [
2525
"coloredlogs",
2626
"dacite",
2727
"orjson",
28-
"home-assistant-chip-clusters==2022.11.1"
28+
"home-assistant-chip-clusters==2022.12.0"
2929
]
3030

3131
[project.optional-dependencies]
3232
server = [
33-
"home-assistant-chip-core==2022.11.1"
33+
"home-assistant-chip-core==2022.12.0"
3434
]
3535
test = [
3636
"black==22.10.0",

0 commit comments

Comments
 (0)