Add more fine grained control over Matter server commissioning for the Companion apps (#106237)

pull/106486/head
Marcel van der Veldt 2023-12-27 16:55:07 +01:00 committed by GitHub
parent 117ff21c48
commit 13702d51b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 21 deletions

View File

@ -85,6 +85,7 @@ def async_handle_failed_command(
{
vol.Required(TYPE): "matter/commission",
vol.Required("code"): str,
vol.Optional("network_only"): bool,
}
)
@websocket_api.async_response
@ -97,7 +98,9 @@ async def websocket_commission(
matter: MatterAdapter,
) -> None:
"""Add a device to the network and commission the device."""
await matter.matter_client.commission_with_code(msg["code"])
await matter.matter_client.commission_with_code(
msg["code"], network_only=msg.get("network_only", True)
)
connection.send_result(msg[ID])
@ -106,6 +109,7 @@ async def websocket_commission(
{
vol.Required(TYPE): "matter/commission_on_network",
vol.Required("pin"): int,
vol.Optional("ip_addr"): str,
}
)
@websocket_api.async_response
@ -118,7 +122,9 @@ async def websocket_commission_on_network(
matter: MatterAdapter,
) -> None:
"""Commission a device already on the network."""
await matter.matter_client.commission_on_network(msg["pin"])
await matter.matter_client.commission_on_network(
msg["pin"], ip_addr=msg.get("ip_addr", None)
)
connection.send_result(msg[ID])

View File

@ -6,5 +6,5 @@
"dependencies": ["websocket_api"],
"documentation": "https://www.home-assistant.io/integrations/matter",
"iot_class": "local_push",
"requirements": ["python-matter-server==5.0.0"]
"requirements": ["python-matter-server==5.1.1"]
}

View File

@ -2201,7 +2201,7 @@ python-kasa[speedups]==0.5.4
# python-lirc==1.2.3
# homeassistant.components.matter
python-matter-server==5.0.0
python-matter-server==5.1.1
# homeassistant.components.xiaomi_miio
python-miio==0.5.12

View File

@ -1659,7 +1659,7 @@ python-juicenet==1.1.0
python-kasa[speedups]==0.5.4
# homeassistant.components.matter
python-matter-server==5.0.0
python-matter-server==5.1.1
# homeassistant.components.xiaomi_miio
python-miio==0.5.12

View File

@ -14,7 +14,6 @@
"node_id": 5,
"date_commissioned": "2023-01-16T21:07:57.508440",
"last_interview": "2023-01-16T21:07:57.508448",
"last_subscription_attempt": 0,
"interview_version": 2,
"attributes": {
"0/4/0": 128,

View File

@ -3,7 +3,6 @@
"date_commissioned": "2023-01-16T21:07:57.508440",
"last_interview": "2023-01-16T21:07:57.508448",
"interview_version": 2,
"last_subscription_attempt": 0,
"attributes": {
"0/4/0": 128,
"0/4/65532": 1,

View File

@ -32,7 +32,7 @@ async def test_commission(
msg = await ws_client.receive_json()
assert msg["success"]
matter_client.commission_with_code.assert_called_once_with("12345678")
matter_client.commission_with_code.assert_called_once_with("12345678", True)
matter_client.commission_with_code.reset_mock()
matter_client.commission_with_code.side_effect = InvalidCommand(
@ -40,17 +40,13 @@ async def test_commission(
)
await ws_client.send_json(
{
ID: 2,
TYPE: "matter/commission",
"code": "12345678",
}
{ID: 2, TYPE: "matter/commission", "code": "12345678", "network_only": False}
)
msg = await ws_client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == "9"
matter_client.commission_with_code.assert_called_once_with("12345678")
matter_client.commission_with_code.assert_called_once_with("12345678", False)
# This tests needs to be adjusted to remove lingering tasks
@ -74,7 +70,7 @@ async def test_commission_on_network(
msg = await ws_client.receive_json()
assert msg["success"]
matter_client.commission_on_network.assert_called_once_with(1234)
matter_client.commission_on_network.assert_called_once_with(1234, None)
matter_client.commission_on_network.reset_mock()
matter_client.commission_on_network.side_effect = NodeCommissionFailed(
@ -82,17 +78,13 @@ async def test_commission_on_network(
)
await ws_client.send_json(
{
ID: 2,
TYPE: "matter/commission_on_network",
"pin": 1234,
}
{ID: 2, TYPE: "matter/commission_on_network", "pin": 1234, "ip_addr": "1.2.3.4"}
)
msg = await ws_client.receive_json()
assert not msg["success"]
assert msg["error"]["code"] == "1"
matter_client.commission_on_network.assert_called_once_with(1234)
matter_client.commission_on_network.assert_called_once_with(1234, "1.2.3.4")
# This tests needs to be adjusted to remove lingering tasks