Skip to content

Commit

Permalink
Set default Matter fabric label (home-assistant#127252)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners authored Oct 3, 2024
1 parent df8269e commit abf3da2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions homeassistant/components/matter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from matter_server.client.exceptions import (
CannotConnect,
InvalidServerVersion,
NotConnected,
ServerVersionTooNew,
ServerVersionTooOld,
)
Expand Down Expand Up @@ -132,6 +133,14 @@ async def on_hass_stop(event: Event) -> None:
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] = {}

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/matter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/components/matter/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aiohasupervisor import SupervisorError
from matter_server.client.exceptions import (
CannotConnect,
NotConnected,
ServerVersionTooNew,
ServerVersionTooOld,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit abf3da2

Please sign in to comment.