Remove async_remove_config_entry_device from Yoto
The coordinator already removes players that left the account, so this handler could never allow a deletion. Automatic removal alone satisfies the stale-devices rule.
This commit is contained in:
@@ -5,7 +5,6 @@ import aiohttp
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady, OAuth2TokenRequestError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
ImplementationUnavailableError,
|
||||
OAuth2Session,
|
||||
@@ -44,16 +43,3 @@ async def async_setup_entry(hass: HomeAssistant, entry: YotoConfigEntry) -> bool
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: YotoConfigEntry) -> bool:
|
||||
"""Unload a Yoto config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
entry: YotoConfigEntry,
|
||||
device_entry: dr.DeviceEntry,
|
||||
) -> bool:
|
||||
"""Allow deleting a device whose player is no longer in the account."""
|
||||
coordinator = entry.runtime_data
|
||||
return not any(
|
||||
identifier[0] == DOMAIN and identifier[1] in coordinator.data
|
||||
for identifier in device_entry.identifiers
|
||||
)
|
||||
|
||||
@@ -7,7 +7,6 @@ from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
from yoto_api import Device, YotoAPIError, YotoError, YotoPlayer
|
||||
|
||||
from homeassistant.components.yoto import async_remove_config_entry_device
|
||||
from homeassistant.components.yoto.const import (
|
||||
DOMAIN,
|
||||
SCAN_INTERVAL,
|
||||
@@ -294,26 +293,3 @@ async def test_stale_device_removed(
|
||||
|
||||
assert device_registry.async_get_device(identifiers={(DOMAIN, PLAYER_ID)}) is None
|
||||
mock_yoto_client.unsubscribe_player_events.assert_called_once_with(PLAYER_ID)
|
||||
|
||||
|
||||
async def test_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
mock_yoto_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
) -> None:
|
||||
"""A device is removable only once its player is gone from the account."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
present = device_registry.async_get_device(identifiers={(DOMAIN, PLAYER_ID)})
|
||||
assert present is not None
|
||||
assert (
|
||||
await async_remove_config_entry_device(hass, mock_config_entry, present)
|
||||
is False
|
||||
)
|
||||
|
||||
gone = device_registry.async_get_or_create(
|
||||
config_entry_id=mock_config_entry.entry_id,
|
||||
identifiers={(DOMAIN, "gone-player")},
|
||||
)
|
||||
assert await async_remove_config_entry_device(hass, mock_config_entry, gone) is True
|
||||
|
||||
Reference in New Issue
Block a user