From 13702d51b1201ae496c0b262549c3e80620ec183 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 27 Dec 2023 16:55:07 +0100 Subject: [PATCH] Add more fine grained control over Matter server commissioning for the Companion apps (#106237) --- homeassistant/components/matter/api.py | 10 ++++++++-- homeassistant/components/matter/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../config_entry_diagnostics_redacted.json | 1 - .../fixtures/nodes/device_diagnostics.json | 1 - tests/components/matter/test_api.py | 20 ++++++------------- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/matter/api.py b/homeassistant/components/matter/api.py index 227d0c73e89..2df21d8f7a2 100644 --- a/homeassistant/components/matter/api.py +++ b/homeassistant/components/matter/api.py @@ -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]) diff --git a/homeassistant/components/matter/manifest.json b/homeassistant/components/matter/manifest.json index f350cda9227..848e89660ed 100644 --- a/homeassistant/components/matter/manifest.json +++ b/homeassistant/components/matter/manifest.json @@ -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"] } diff --git a/requirements_all.txt b/requirements_all.txt index ecaf2d1e8d1..1a49b477398 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 653b80daf64..0a78ae734ee 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/matter/fixtures/config_entry_diagnostics_redacted.json b/tests/components/matter/fixtures/config_entry_diagnostics_redacted.json index c85ee4d70e3..503fd3b9a7a 100644 --- a/tests/components/matter/fixtures/config_entry_diagnostics_redacted.json +++ b/tests/components/matter/fixtures/config_entry_diagnostics_redacted.json @@ -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, diff --git a/tests/components/matter/fixtures/nodes/device_diagnostics.json b/tests/components/matter/fixtures/nodes/device_diagnostics.json index d95fbe5efa9..1d1d450e1f0 100644 --- a/tests/components/matter/fixtures/nodes/device_diagnostics.json +++ b/tests/components/matter/fixtures/nodes/device_diagnostics.json @@ -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, diff --git a/tests/components/matter/test_api.py b/tests/components/matter/test_api.py index 041920f653f..24dac910d33 100644 --- a/tests/components/matter/test_api.py +++ b/tests/components/matter/test_api.py @@ -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