mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Remove cleanup code for removed entities from Xbox integration (#173688)
This commit is contained in:
@@ -9,7 +9,6 @@ from pythonxbox.api.provider.people.models import Person
|
||||
from pythonxbox.api.provider.titlehub.models import Title
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
@@ -17,12 +16,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import XboxConfigEntry
|
||||
from .entity import (
|
||||
XboxBaseEntity,
|
||||
XboxBaseEntityDescription,
|
||||
check_deprecated_entity,
|
||||
profile_pic,
|
||||
)
|
||||
from .entity import XboxBaseEntity, XboxBaseEntityDescription, profile_pic
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
@@ -31,9 +25,7 @@ class XboxBinarySensor(StrEnum):
|
||||
"""Xbox binary sensor."""
|
||||
|
||||
ONLINE = "online"
|
||||
IN_PARTY = "in_party"
|
||||
IN_GAME = "in_game"
|
||||
IN_MULTIPLAYER = "in_multiplayer"
|
||||
HAS_GAME_PASS = "has_game_pass"
|
||||
|
||||
|
||||
@@ -81,21 +73,11 @@ SENSOR_DESCRIPTIONS: tuple[XboxBinarySensorEntityDescription, ...] = (
|
||||
entity_picture_fn=profile_pic,
|
||||
attributes_fn=profile_attributes,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_PARTY,
|
||||
is_on_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_GAME,
|
||||
translation_key=XboxBinarySensor.IN_GAME,
|
||||
is_on_fn=in_game,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_MULTIPLAYER,
|
||||
is_on_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.HAS_GAME_PASS,
|
||||
translation_key=XboxBinarySensor.HAS_GAME_PASS,
|
||||
@@ -118,9 +100,6 @@ async def async_setup_entry(
|
||||
[
|
||||
XboxBinarySensorEntity(coordinator, entry.unique_id, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(
|
||||
hass, entry.unique_id, description, BINARY_SENSOR_DOMAIN
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
@@ -130,9 +109,6 @@ async def async_setup_entry(
|
||||
XboxBinarySensorEntity(coordinator, subentry.unique_id, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if subentry.unique_id
|
||||
and check_deprecated_entity(
|
||||
hass, subentry.unique_id, description, BINARY_SENSOR_DOMAIN
|
||||
)
|
||||
and subentry.unique_id in coordinator.data.presence
|
||||
and subentry.subentry_type == "friend"
|
||||
],
|
||||
|
||||
@@ -9,8 +9,6 @@ from pythonxbox.api.provider.smartglass.models import ConsoleType, SmartglassCon
|
||||
from pythonxbox.api.provider.titlehub.models import Title
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
@@ -40,7 +38,6 @@ class XboxBaseEntityDescription(EntityDescription):
|
||||
attributes_fn: Callable[[Person, Title | None], Mapping[str, Any] | None] | None = (
|
||||
None
|
||||
)
|
||||
deprecated: bool | None = None
|
||||
|
||||
|
||||
class XboxBaseEntity(CoordinatorEntity[XboxPresenceCoordinator]):
|
||||
@@ -145,26 +142,6 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxConsoleStatusCoordinator]):
|
||||
return self.coordinator.data.get(self._console.id) is not None
|
||||
|
||||
|
||||
def check_deprecated_entity(
|
||||
hass: HomeAssistant,
|
||||
xuid: str,
|
||||
entity_description: XboxBaseEntityDescription,
|
||||
entity_domain: str,
|
||||
) -> bool:
|
||||
"""Check for deprecated entity and remove it."""
|
||||
if not entity_description.deprecated:
|
||||
return True
|
||||
ent_reg = er.async_get(hass)
|
||||
if entity_id := ent_reg.async_get_entity_id(
|
||||
entity_domain,
|
||||
DOMAIN,
|
||||
f"{xuid}_{entity_description.key}",
|
||||
):
|
||||
ent_reg.async_remove(entity_id)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def to_https(image_url: str) -> str:
|
||||
"""Convert image URLs to secure URLs."""
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from pythonxbox.api.provider.smartglass.models import SmartglassConsole, Storage
|
||||
from pythonxbox.api.provider.titlehub.models import Title
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
EntityCategory,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
@@ -27,13 +26,7 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import XboxConfigEntry, XboxConsolesCoordinator
|
||||
from .entity import (
|
||||
MAP_MODEL,
|
||||
XboxBaseEntity,
|
||||
XboxBaseEntityDescription,
|
||||
check_deprecated_entity,
|
||||
to_https,
|
||||
)
|
||||
from .entity import MAP_MODEL, XboxBaseEntity, XboxBaseEntityDescription, to_https
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
@@ -58,8 +51,6 @@ class XboxSensor(StrEnum):
|
||||
|
||||
STATUS = "status"
|
||||
GAMER_SCORE = "gamer_score"
|
||||
ACCOUNT_TIER = "account_tier"
|
||||
GOLD_TENURE = "gold_tenure"
|
||||
LAST_ONLINE = "last_online"
|
||||
FOLLOWING = "following"
|
||||
FOLLOWER = "follower"
|
||||
@@ -200,16 +191,6 @@ SENSOR_DESCRIPTIONS: tuple[XboxSensorEntityDescription, ...] = (
|
||||
value_fn=lambda x, _: x.gamer_score,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.ACCOUNT_TIER,
|
||||
value_fn=lambda _, __: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.GOLD_TENURE,
|
||||
value_fn=lambda _, __: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.LAST_ONLINE,
|
||||
translation_key=XboxSensor.LAST_ONLINE,
|
||||
@@ -304,9 +285,6 @@ async def async_setup_entry(
|
||||
[
|
||||
XboxSensorEntity(presence, config_entry.unique_id, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(
|
||||
hass, config_entry.unique_id, description, SENSOR_DOMAIN
|
||||
)
|
||||
]
|
||||
)
|
||||
for subentry_id, subentry in config_entry.subentries.items():
|
||||
@@ -315,9 +293,6 @@ async def async_setup_entry(
|
||||
XboxSensorEntity(presence, subentry.unique_id, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if subentry.unique_id
|
||||
and check_deprecated_entity(
|
||||
hass, subentry.unique_id, description, SENSOR_DOMAIN
|
||||
)
|
||||
and subentry.unique_id in presence.data.presence
|
||||
and subentry.subentry_type == "friend"
|
||||
],
|
||||
|
||||
@@ -6,9 +6,6 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.xbox.binary_sensor import XboxBinarySensor
|
||||
from homeassistant.components.xbox.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -43,39 +40,3 @@ async def test_binary_sensors(
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "key"),
|
||||
[
|
||||
("gsr_ae_in_multiplayer", XboxBinarySensor.IN_MULTIPLAYER),
|
||||
("gsr_ae_in_party", XboxBinarySensor.IN_PARTY),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("xbox_live_client", "entity_registry_enabled_by_default")
|
||||
async def test_binary_sensor_deprecation_remove_disabled(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
entity_id: str,
|
||||
key: XboxBinarySensor,
|
||||
) -> None:
|
||||
"""Test we remove a deprecated binary sensor."""
|
||||
|
||||
entity_registry.async_get_or_create(
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"271958441785640_{key}",
|
||||
suggested_object_id=entity_id,
|
||||
)
|
||||
|
||||
assert entity_registry is not None
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert entity_registry.async_get(f"binary_sensor.{entity_id}") is None
|
||||
|
||||
@@ -6,9 +6,6 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.xbox.const import DOMAIN
|
||||
from homeassistant.components.xbox.sensor import XboxSensor
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -43,39 +40,3 @@ async def test_sensors(
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity_id", "key"),
|
||||
[
|
||||
("gsr_ae_account_tier", XboxSensor.ACCOUNT_TIER),
|
||||
("gsr_ae_gold_tenure", XboxSensor.GOLD_TENURE),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("xbox_live_client", "entity_registry_enabled_by_default")
|
||||
async def test_sensor_deprecation_remove_entity(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
entity_id: str,
|
||||
key: XboxSensor,
|
||||
) -> None:
|
||||
"""Test we remove a deprecated sensor."""
|
||||
|
||||
entity_registry.async_get_or_create(
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
f"271958441785640_{key}",
|
||||
suggested_object_id=entity_id,
|
||||
)
|
||||
|
||||
assert entity_registry is not None
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert entity_registry.async_get(f"sensor.{entity_id}") is None
|
||||
|
||||
Reference in New Issue
Block a user