parent
9514f491f0
commit
5dfeb1e02a
|
@ -15,6 +15,7 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MYDEVOLO,
|
CONF_MYDEVOLO,
|
||||||
|
@ -92,6 +93,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return unload
|
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:
|
def configure_mydevolo(conf: dict[str, Any] | MappingProxyType[str, Any]) -> Mydevolo:
|
||||||
"""Configure mydevolo."""
|
"""Configure mydevolo."""
|
||||||
mydevolo = Mydevolo()
|
mydevolo = Mydevolo()
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
"""Tests for the devolo Home Control integration."""
|
"""Tests for the devolo Home Control integration."""
|
||||||
|
from collections.abc import Awaitable, Callable
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from aiohttp import ClientWebSocketResponse
|
||||||
from devolo_home_control_api.exceptions.gateway import GatewayOfflineError
|
from devolo_home_control_api.exceptions.gateway import GatewayOfflineError
|
||||||
import pytest
|
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.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
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):
|
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.async_block_till_done()
|
||||||
await hass.config_entries.async_unload(entry.entry_id)
|
await hass.config_entries.async_unload(entry.entry_id)
|
||||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
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
|
||||||
|
|
Loading…
Reference in New Issue