diff --git a/homeassistant/components/devolo_home_control/__init__.py b/homeassistant/components/devolo_home_control/__init__.py index 46b8f9dcaea..b79d0a5c8fe 100644 --- a/homeassistant/components/devolo_home_control/__init__.py +++ b/homeassistant/components/devolo_home_control/__init__.py @@ -15,6 +15,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady +from homeassistant.helpers.device_registry import DeviceEntry from .const import ( CONF_MYDEVOLO, @@ -92,6 +93,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload +async def async_remove_config_entry_device( + hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry +) -> bool: + """Remove a config entry from a device.""" + return True + + def configure_mydevolo(conf: dict[str, Any] | MappingProxyType[str, Any]) -> Mydevolo: """Configure mydevolo.""" mydevolo = Mydevolo() diff --git a/tests/components/devolo_home_control/test_init.py b/tests/components/devolo_home_control/test_init.py index 311da47aac0..f12ea9486b4 100644 --- a/tests/components/devolo_home_control/test_init.py +++ b/tests/components/devolo_home_control/test_init.py @@ -1,13 +1,20 @@ """Tests for the devolo Home Control integration.""" +from collections.abc import Awaitable, Callable from unittest.mock import patch +from aiohttp import ClientWebSocketResponse from devolo_home_control_api.exceptions.gateway import GatewayOfflineError import pytest +from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN +from homeassistant.components.devolo_home_control import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant +from homeassistant.helpers import device_registry as dr +from homeassistant.setup import async_setup_component -from tests.components.devolo_home_control import configure_integration +from . import configure_integration +from .mocks import HomeControlMock, HomeControlMockBinarySensor async def test_setup_entry(hass: HomeAssistant, mock_zeroconf): @@ -53,3 +60,37 @@ async def test_unload_entry(hass: HomeAssistant): await hass.async_block_till_done() await hass.config_entries.async_unload(entry.entry_id) assert entry.state is ConfigEntryState.NOT_LOADED + + +async def test_remove_device( + hass: HomeAssistant, + hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]], +): + """Test removing a device.""" + assert await async_setup_component(hass, "config", {}) + entry = configure_integration(hass) + test_gateway = HomeControlMockBinarySensor() + with patch( + "homeassistant.components.devolo_home_control.HomeControl", + side_effect=[test_gateway, HomeControlMock()], + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + device_registry = dr.async_get(hass) + device_entry = device_registry.async_get_device(identifiers={(DOMAIN, "Test")}) + assert device_entry + + client = await hass_ws_client(hass) + await client.send_json( + { + "id": 1, + "type": "config/device_registry/remove_config_entry", + "config_entry_id": entry.entry_id, + "device_id": device_entry.id, + } + ) + response = await client.receive_json() + assert response["success"] + assert device_registry.async_get_device(identifiers={(DOMAIN, "Test")}) is None + assert hass.states.get(f"{BINARY_SENSOR_DOMAIN}.test") is None