2
2
3
3
from __future__ import annotations
4
4
5
- import asyncio
6
5
from collections import deque
7
6
from datetime import datetime
8
7
from functools import partial
@@ -56,19 +55,18 @@ def __init__(
56
55
self ._nodes : dict [int , MatterNode ] = {}
57
56
self .wifi_credentials_set : bool = False
58
57
self .thread_credentials_set : bool = False
58
+ self .compressed_fabric_id : int | None = None
59
59
60
60
@property
61
61
def fabric_id (self ) -> int :
62
62
"""Return Fabric ID."""
63
63
return self .chip_controller .fabricId
64
64
65
- @property
66
- def compressed_fabric_id (self ) -> int :
67
- """Return unique identifier for this initialized fabric."""
68
- return self .chip_controller .GetCompressedFabricId ()
69
-
70
65
async def start (self ) -> None :
71
66
"""Async initialize of controller."""
67
+ self .compressed_fabric_id = await self ._call_sdk (
68
+ self .chip_controller .GetCompressedFabricId
69
+ )
72
70
# load nodes from persistent storage
73
71
nodes_data = self .server .storage .get (DATA_KEY_NODES , {})
74
72
for node_id_str , node_dict in nodes_data .items ():
@@ -114,22 +112,15 @@ async def commission_with_code(self, code: str) -> MatterNode:
114
112
"""
115
113
node_id = self ._get_next_node_id ()
116
114
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 (
128
116
self .chip_controller .CommissionWithCode ,
129
117
setupPayload = code ,
130
118
nodeid = node_id ,
131
119
)
132
- await asyncio .sleep (60 )
120
+ if not success :
121
+ raise NodeCommissionFailed (
122
+ f"Commission with code failed for node { node_id } "
123
+ )
133
124
134
125
# full interview of the device
135
126
await self .interview_node (node_id )
@@ -154,6 +145,7 @@ async def commission_on_network(
154
145
Returns full NodeInfo once complete.
155
146
"""
156
147
node_id = self ._get_next_node_id ()
148
+
157
149
success = await self ._call_sdk (
158
150
self .chip_controller .CommissionOnNetwork ,
159
151
nodeId = node_id ,
@@ -165,6 +157,7 @@ async def commission_on_network(
165
157
raise NodeCommissionFailed (
166
158
f"Commission on network failed for node { node_id } "
167
159
)
160
+
168
161
# full interview of the device
169
162
await self .interview_node (node_id )
170
163
# make sure we start a subscription for this newly added node
0 commit comments