Set default Matter fabric label (#127252)

This commit is contained in:
Stefan Agner 2024-10-03 12:36:24 +02:00 committed by GitHub
parent df8269e772
commit abf3da2fa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from matter_server.client import MatterClient
from matter_server.client.exceptions import (
CannotConnect,
InvalidServerVersion,
NotConnected,
ServerVersionTooNew,
ServerVersionTooOld,
)
@ -132,6 +133,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
listen_task.cancel()
raise ConfigEntryNotReady("Matter client not ready") from err
# Set default fabric
try:
await matter_client.set_default_fabric_label(
hass.config.location_name or "Home"
)
except (NotConnected, MatterError) as err:
raise ConfigEntryNotReady("Failed to set default fabric label") from err
if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}

View File

@ -6,6 +6,6 @@
"dependencies": ["websocket_api"],
"documentation": "https://www.home-assistant.io/integrations/matter",
"iot_class": "local_push",
"requirements": ["python-matter-server==6.5.2"],
"requirements": ["python-matter-server==6.6.0"],
"zeroconf": ["_matter._tcp.local.", "_matterc._udp.local."]
}

View File

@ -2352,7 +2352,7 @@ python-linkplay==0.0.12
# python-lirc==1.2.3
# homeassistant.components.matter
python-matter-server==6.5.2
python-matter-server==6.6.0
# homeassistant.components.xiaomi_miio
python-miio==0.5.12

View File

@ -1870,7 +1870,7 @@ python-kasa[speedups]==0.7.4
python-linkplay==0.0.12
# homeassistant.components.matter
python-matter-server==6.5.2
python-matter-server==6.6.0
# homeassistant.components.xiaomi_miio
python-miio==0.5.12

View File

@ -9,6 +9,7 @@ from unittest.mock import AsyncMock, MagicMock, call, patch
from aiohasupervisor import SupervisorError
from matter_server.client.exceptions import (
CannotConnect,
NotConnected,
ServerVersionTooNew,
ServerVersionTooOld,
)
@ -64,6 +65,7 @@ async def test_entry_setup_unload(
await hass.async_block_till_done()
assert matter_client.connect.call_count == 1
assert matter_client.set_default_fabric_label.call_count == 1
assert entry.state is ConfigEntryState.LOADED
entity_state = hass.states.get("light.mock_onoff_light_light")
assert entity_state
@ -108,6 +110,26 @@ async def test_connect_failed(
assert entry.state is ConfigEntryState.SETUP_RETRY
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_set_default_fabric_label_failed(
hass: HomeAssistant,
matter_client: MagicMock,
) -> None:
"""Test failure during client connection."""
entry = MockConfigEntry(domain=DOMAIN, data={"url": "ws://localhost:5580/ws"})
entry.add_to_hass(hass)
matter_client.set_default_fabric_label.side_effect = NotConnected()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert matter_client.connect.call_count == 1
assert matter_client.set_default_fabric_label.call_count == 1
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_connect_timeout(
hass: HomeAssistant,
matter_client: MagicMock,