|
5 | 5 | from pyvesync import VeSync |
6 | 6 | from pyvesync.utils.errors import VeSyncLoginError |
7 | 7 |
|
8 | | -from homeassistant.components.vesync import SERVICE_UPDATE_DEVS, async_setup_entry |
| 8 | +from homeassistant.components.vesync import ( |
| 9 | + SERVICE_UPDATE_DEVS, |
| 10 | + async_remove_config_entry_device, |
| 11 | + async_setup_entry, |
| 12 | +) |
9 | 13 | from homeassistant.components.vesync.const import DOMAIN, VS_MANAGER |
10 | 14 | from homeassistant.config_entries import ConfigEntry, ConfigEntryState |
11 | 15 | from homeassistant.const import Platform |
12 | 16 | from homeassistant.core import HomeAssistant |
13 | | -from homeassistant.helpers import entity_registry as er |
| 17 | +from homeassistant.helpers import device_registry as dr, entity_registry as er |
14 | 18 |
|
15 | 19 | from tests.common import MockConfigEntry |
16 | 20 |
|
@@ -165,3 +169,51 @@ async def test_migrate_config_entry( |
165 | 169 | e for e in entity_registry.entities.values() if e.domain == "humidifer" |
166 | 170 | ] |
167 | 171 | assert len(humidifer_entities) == 1 |
| 172 | + |
| 173 | + |
| 174 | +async def test_async_remove_config_entry_device_positive( |
| 175 | + hass: HomeAssistant, |
| 176 | + device_registry: dr.DeviceRegistry, |
| 177 | + config_entry: ConfigEntry, |
| 178 | + manager: VeSync, |
| 179 | + fan, |
| 180 | +) -> None: |
| 181 | + """Test removing a config entry from a device when no match is found.""" |
| 182 | + |
| 183 | + await hass.config_entries.async_setup(config_entry.entry_id) |
| 184 | + await hass.async_block_till_done() |
| 185 | + manager._dev_list["fans"].append(fan) |
| 186 | + |
| 187 | + device_entry = device_registry.async_get_or_create( |
| 188 | + config_entry_id=config_entry.entry_id, |
| 189 | + identifiers={(DOMAIN, "test_device")}, |
| 190 | + ) |
| 191 | + |
| 192 | + result = await async_remove_config_entry_device(hass, config_entry, device_entry) |
| 193 | + |
| 194 | + assert result is True |
| 195 | + |
| 196 | + |
| 197 | +async def test_async_remove_config_entry_device_negative( |
| 198 | + hass: HomeAssistant, |
| 199 | + device_registry: dr.DeviceRegistry, |
| 200 | + config_entry: ConfigEntry, |
| 201 | + manager: VeSync, |
| 202 | + fan, |
| 203 | +) -> None: |
| 204 | + """Test removing a config entry from a device when a match is found.""" |
| 205 | + |
| 206 | + assert await hass.config_entries.async_setup(config_entry.entry_id) |
| 207 | + await hass.async_block_till_done() |
| 208 | + manager._dev_list["fans"].append(fan) |
| 209 | + |
| 210 | + device_entry = device_registry.async_get_or_create( |
| 211 | + config_entry_id=config_entry.entry_id, |
| 212 | + identifiers={(DOMAIN, "fan")}, |
| 213 | + ) |
| 214 | + |
| 215 | + # Call the remove method |
| 216 | + result = await async_remove_config_entry_device(hass, config_entry, device_entry) |
| 217 | + |
| 218 | + # Assert it returns False (device matched) |
| 219 | + assert result is False |
0 commit comments