Use DeviceInfo attributes in fibaro (#186610)

This commit is contained in:
epenet
2026-10-15 11:42:53 +02:00
committed by GitHub
parent d32b97e87d
commit 3e899d8d76
2 changed files with 45 additions and 1 deletions
+4 -1
View File
@@ -183,6 +183,8 @@ class FibaroController:
manufacturer = None
self._device_infos[main_device.fibaro_id] = DeviceInfo(
# The identifiers should hold a string fibaro_id, which needs a migration.
# mypy can't see that fibaro_id is an int, as pyfibaro lacks a py.typed
identifiers={(DOMAIN, main_device.fibaro_id)},
manufacturer=manufacturer,
name=main_device.name,
@@ -203,7 +205,8 @@ class FibaroController:
def get_all_device_identifiers(self) -> list[set[tuple[str, str]]]:
"""Get all identifiers of fibaro integration."""
return [device["identifiers"] for device in self._device_infos.values()]
# The identifiers should hold a string fibaro_id, which needs a migration
return [{(DOMAIN, fibaro_id)} for fibaro_id in self._device_infos] # type: ignore[arg-type]
def get_room_name(self, room_id: int) -> str | None:
"""Get the room name by room id."""
+41
View File
@@ -2,14 +2,18 @@
from unittest.mock import Mock, patch
import pytest
from homeassistant.components.fibaro.const import DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
from .conftest import TEST_SERIALNUMBER, init_integration
from tests.common import MockConfigEntry
from tests.typing import WebSocketGenerator
async def test_unload_integration(
@@ -60,3 +64,40 @@ async def test_load_integration_links_device_to_hub(
assert hub_device is not None
assert light_device is not None
assert light_device.via_device_id == hub_device.id
@pytest.mark.parametrize(
("fibaro_id", "removable"),
[
pytest.param(3, False, id="served_by_controller"),
pytest.param(999, True, id="no_longer_served"),
],
)
async def test_remove_device(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
hass_ws_client: WebSocketGenerator,
mock_fibaro_client: Mock,
mock_config_entry: MockConfigEntry,
mock_light: Mock,
mock_room: Mock,
fibaro_id: int,
removable: bool,
) -> None:
"""Test only devices the controller no longer serves can be removed."""
assert await async_setup_component(hass, "config", {})
mock_fibaro_client.read_rooms.return_value = [mock_room]
mock_fibaro_client.read_devices.return_value = [mock_light]
with patch("homeassistant.components.fibaro.PLATFORMS", [Platform.LIGHT]):
await init_integration(hass, mock_config_entry)
# The identifiers hold the integer fibaro_id
device = device_registry.async_get_or_create(
config_entry_id=mock_config_entry.entry_id,
identifiers={(DOMAIN, fibaro_id)},
)
client = await hass_ws_client(hass)
response = await client.remove_device(device.id)
assert response["success"] is removable