From 3e899d8d76b473a075a50a0fd5134ff2ccbe314e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 15 Oct 2026 11:42:53 +0200 Subject: [PATCH] Use DeviceInfo attributes in fibaro (#186610) --- homeassistant/components/fibaro/__init__.py | 5 ++- tests/components/fibaro/test_init.py | 41 +++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/fibaro/__init__.py b/homeassistant/components/fibaro/__init__.py index d7ad8998e86e..9268e924e950 100644 --- a/homeassistant/components/fibaro/__init__.py +++ b/homeassistant/components/fibaro/__init__.py @@ -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.""" diff --git a/tests/components/fibaro/test_init.py b/tests/components/fibaro/test_init.py index e9adfa72c5ce..2d020efeebbb 100644 --- a/tests/components/fibaro/test_init.py +++ b/tests/components/fibaro/test_init.py @@ -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