Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fabric label on commissioning #899

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ 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 set_default_fabric_label(self, label: str) -> None:
"""Set the default fabric label."""
await self.send_command(
APICommand.SET_DEFAULT_FABRIC_LABEL, require_schema=11, label=label
)

async def commission_with_code(
self, code: str, network_only: bool = False
) -> MatterNodeData:
Expand Down
2 changes: 1 addition & 1 deletion matter_server/common/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# schema version is used to determine compatibility between server and client
# bump schema if we add new features and/or make other (breaking) changes
SCHEMA_VERSION = 10
SCHEMA_VERSION = 11


VERBOSE_LOG_LEVEL = 5
1 change: 1 addition & 0 deletions matter_server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class APICommand(str, Enum):
IMPORT_TEST_NODE = "import_test_node"
CHECK_NODE_UPDATE = "check_node_update"
UPDATE_NODE = "update_node"
SET_DEFAULT_FABRIC_LABEL = "set_default_fabric_label"


EventCallBackType = Callable[[EventType, Any], None]
Expand Down
14 changes: 14 additions & 0 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(
self._custom_attribute_poller_timer: asyncio.TimerHandle | None = None
self._custom_attribute_poller_task: asyncio.Task | None = None
self._attribute_update_callbacks: dict[int, list[Callable]] = {}
self._default_fabric_label: str = "Home Assistant"
agners marked this conversation as resolved.
Show resolved Hide resolved

async def initialize(self) -> None:
"""Initialize the device controller."""
Expand Down Expand Up @@ -280,6 +281,11 @@ def get_node(self, node_id: int) -> MatterNodeData:
return node
raise NodeNotExists(f"Node {node_id} does not exist or is not yet interviewed")

@api_command(APICommand.SET_DEFAULT_FABRIC_LABEL)
async def set_default_fabric_label(self, label: str) -> None:
"""Set the default fabric label."""
self._default_fabric_label = label

@api_command(APICommand.COMMISSION_WITH_CODE)
async def commission_with_code(
self, code: str, network_only: bool = False
Expand Down Expand Up @@ -315,6 +321,14 @@ async def commission_with_code(
LOGGER.info("Commissioned Node ID: %s vs %s", commissioned_node_id, node_id)
if commissioned_node_id != node_id:
raise RuntimeError("Returned Node ID must match requested Node ID")

await self._chip_device_controller.send_command(
node_id,
0,
Clusters.OperationalCredentials.Commands.UpdateFabricLabel(
self._default_fabric_label
),
)
except ChipStackError as err:
raise NodeCommissionFailed(
f"Commission with code failed for node {node_id}."
Expand Down