mirror of
https://github.com/home-assistant/core.git
synced 2026-07-12 17:18:04 +01:00
Deprecate entities in Xbox integration (#154891)
This commit is contained in:
@@ -11,6 +11,7 @@ from xbox.webapi.api.provider.people.models import Person
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
@@ -18,7 +19,7 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import XboxConfigEntry, XboxUpdateCoordinator
|
||||
from .entity import XboxBaseEntity
|
||||
from .entity import XboxBaseEntity, check_deprecated_entity
|
||||
|
||||
|
||||
class XboxBinarySensor(StrEnum):
|
||||
@@ -37,6 +38,7 @@ class XboxBinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||
|
||||
is_on_fn: Callable[[Person], bool | None]
|
||||
entity_picture_fn: Callable[[Person], str | None] | None = None
|
||||
deprecated: bool | None = None
|
||||
|
||||
|
||||
def profile_pic(person: Person) -> str | None:
|
||||
@@ -82,13 +84,8 @@ SENSOR_DESCRIPTIONS: tuple[XboxBinarySensorEntityDescription, ...] = (
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_PARTY,
|
||||
translation_key=XboxBinarySensor.IN_PARTY,
|
||||
is_on_fn=(
|
||||
lambda x: bool(x.multiplayer_summary.in_party)
|
||||
if x.multiplayer_summary
|
||||
else None
|
||||
),
|
||||
entity_registry_enabled_default=False,
|
||||
is_on_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_GAME,
|
||||
@@ -97,13 +94,8 @@ SENSOR_DESCRIPTIONS: tuple[XboxBinarySensorEntityDescription, ...] = (
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.IN_MULTIPLAYER,
|
||||
translation_key=XboxBinarySensor.IN_MULTIPLAYER,
|
||||
is_on_fn=(
|
||||
lambda x: bool(x.multiplayer_summary.in_multiplayer_session)
|
||||
if x.multiplayer_summary
|
||||
else None
|
||||
),
|
||||
entity_registry_enabled_default=False,
|
||||
is_on_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxBinarySensorEntityDescription(
|
||||
key=XboxBinarySensor.HAS_GAME_PASS,
|
||||
@@ -121,7 +113,9 @@ async def async_setup_entry(
|
||||
"""Set up Xbox Live friends."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
update_friends = partial(async_update_friends, coordinator, {}, async_add_entities)
|
||||
update_friends = partial(
|
||||
async_update_friends, hass, coordinator, {}, async_add_entities
|
||||
)
|
||||
|
||||
entry.async_on_unload(coordinator.async_add_listener(update_friends))
|
||||
|
||||
@@ -152,6 +146,7 @@ class XboxBinarySensorEntity(XboxBaseEntity, BinarySensorEntity):
|
||||
|
||||
@callback
|
||||
def async_update_friends(
|
||||
hass: HomeAssistant,
|
||||
coordinator: XboxUpdateCoordinator,
|
||||
current: dict[str, list[XboxBinarySensorEntity]],
|
||||
async_add_entities,
|
||||
@@ -163,10 +158,11 @@ def async_update_friends(
|
||||
# Process new favorites, add them to Home Assistant
|
||||
new_entities: list[XboxBinarySensorEntity] = []
|
||||
for xuid in new_ids - current_ids:
|
||||
current[xuid] = [
|
||||
XboxBinarySensorEntity(coordinator, xuid, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
]
|
||||
current[xuid] = []
|
||||
for description in SENSOR_DESCRIPTIONS:
|
||||
entity = XboxBinarySensorEntity(coordinator, xuid, description)
|
||||
if check_deprecated_entity(hass, entity, BINARY_SENSOR_DOMAIN):
|
||||
current[xuid].append(entity)
|
||||
new_entities = new_entities + current[xuid]
|
||||
if new_entities:
|
||||
async_add_entities(new_entities)
|
||||
|
||||
@@ -4,6 +4,10 @@ from __future__ import annotations
|
||||
|
||||
from xbox.webapi.api.provider.smartglass.models import ConsoleType, SmartglassConsole
|
||||
|
||||
from homeassistant.components.automation import automations_with_entity
|
||||
from homeassistant.components.script import scripts_with_entity
|
||||
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
|
||||
@@ -83,3 +87,29 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
||||
def data(self) -> ConsoleData:
|
||||
"""Return coordinator data for this console."""
|
||||
return self.coordinator.data.consoles[self._console.id]
|
||||
|
||||
|
||||
def entity_used_in(hass: HomeAssistant, entity_id: str) -> list[str]:
|
||||
"""Get list of related automations and scripts."""
|
||||
used_in = automations_with_entity(hass, entity_id)
|
||||
used_in += scripts_with_entity(hass, entity_id)
|
||||
return used_in
|
||||
|
||||
|
||||
def check_deprecated_entity(
|
||||
hass: HomeAssistant,
|
||||
entity: XboxBaseEntity,
|
||||
entity_domain: str,
|
||||
) -> bool:
|
||||
"""Check for deprecated entity and remove it."""
|
||||
if not getattr(entity.entity_description, "deprecated", False):
|
||||
return True
|
||||
ent_reg = er.async_get(hass)
|
||||
if entity_id := ent_reg.async_get_entity_id(
|
||||
entity_domain,
|
||||
DOMAIN,
|
||||
f"{entity.xuid}_{entity.entity_description.key}",
|
||||
):
|
||||
ent_reg.async_remove(entity_id)
|
||||
|
||||
return False
|
||||
|
||||
@@ -7,12 +7,6 @@
|
||||
"gamer_score": {
|
||||
"default": "mdi:alpha-g-circle"
|
||||
},
|
||||
"account_tier": {
|
||||
"default": "mdi:microsoft-xbox"
|
||||
},
|
||||
"gold_tenure": {
|
||||
"default": "mdi:microsoft-xbox"
|
||||
},
|
||||
"last_online": {
|
||||
"default": "mdi:account-clock"
|
||||
},
|
||||
@@ -27,15 +21,9 @@
|
||||
"online": {
|
||||
"default": "mdi:account"
|
||||
},
|
||||
"in_party": {
|
||||
"default": "mdi:account-group"
|
||||
},
|
||||
"in_game": {
|
||||
"default": "mdi:microsoft-xbox-controller"
|
||||
},
|
||||
"in_multiplayer": {
|
||||
"default": "mdi:account-multiple"
|
||||
},
|
||||
"has_game_pass": {
|
||||
"default": "mdi:microsoft-xbox"
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ from functools import partial
|
||||
from xbox.webapi.api.provider.people.models import Person
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
@@ -20,7 +21,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .coordinator import XboxConfigEntry, XboxUpdateCoordinator
|
||||
from .entity import XboxBaseEntity
|
||||
from .entity import XboxBaseEntity, check_deprecated_entity
|
||||
|
||||
|
||||
class XboxSensor(StrEnum):
|
||||
@@ -40,6 +41,7 @@ class XboxSensorEntityDescription(SensorEntityDescription):
|
||||
"""Xbox sensor description."""
|
||||
|
||||
value_fn: Callable[[Person], StateType | datetime]
|
||||
deprecated: bool | None = None
|
||||
|
||||
|
||||
SENSOR_DESCRIPTIONS: tuple[XboxSensorEntityDescription, ...] = (
|
||||
@@ -55,15 +57,13 @@ SENSOR_DESCRIPTIONS: tuple[XboxSensorEntityDescription, ...] = (
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.ACCOUNT_TIER,
|
||||
translation_key=XboxSensor.ACCOUNT_TIER,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda x: x.detail.account_tier if x.detail else None,
|
||||
value_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.GOLD_TENURE,
|
||||
translation_key=XboxSensor.GOLD_TENURE,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda x: x.detail.tenure if x.detail else None,
|
||||
value_fn=lambda _: None,
|
||||
deprecated=True,
|
||||
),
|
||||
XboxSensorEntityDescription(
|
||||
key=XboxSensor.LAST_ONLINE,
|
||||
@@ -96,7 +96,9 @@ async def async_setup_entry(
|
||||
"""Set up Xbox Live friends."""
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
update_friends = partial(async_update_friends, coordinator, {}, async_add_entities)
|
||||
update_friends = partial(
|
||||
async_update_friends, hass, coordinator, {}, async_add_entities
|
||||
)
|
||||
|
||||
config_entry.async_on_unload(coordinator.async_add_listener(update_friends))
|
||||
update_friends()
|
||||
@@ -115,6 +117,7 @@ class XboxSensorEntity(XboxBaseEntity, SensorEntity):
|
||||
|
||||
@callback
|
||||
def async_update_friends(
|
||||
hass: HomeAssistant,
|
||||
coordinator: XboxUpdateCoordinator,
|
||||
current: dict[str, list[XboxSensorEntity]],
|
||||
async_add_entities,
|
||||
@@ -126,10 +129,11 @@ def async_update_friends(
|
||||
# Process new favorites, add them to Home Assistant
|
||||
new_entities: list[XboxSensorEntity] = []
|
||||
for xuid in new_ids - current_ids:
|
||||
current[xuid] = [
|
||||
XboxSensorEntity(coordinator, xuid, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
]
|
||||
current[xuid] = []
|
||||
for description in SENSOR_DESCRIPTIONS:
|
||||
entity = XboxSensorEntity(coordinator, xuid, description)
|
||||
if check_deprecated_entity(hass, entity, SENSOR_DOMAIN):
|
||||
current[xuid].append(entity)
|
||||
new_entities = new_entities + current[xuid]
|
||||
if new_entities:
|
||||
async_add_entities(new_entities)
|
||||
|
||||
@@ -37,12 +37,6 @@
|
||||
"name": "Gamerscore",
|
||||
"unit_of_measurement": "points"
|
||||
},
|
||||
"account_tier": {
|
||||
"name": "Account tier"
|
||||
},
|
||||
"gold_tenure": {
|
||||
"name": "Gold tenure"
|
||||
},
|
||||
"last_online": {
|
||||
"name": "Last online"
|
||||
},
|
||||
@@ -56,15 +50,9 @@
|
||||
}
|
||||
},
|
||||
"binary_sensor": {
|
||||
"in_party": {
|
||||
"name": "In party"
|
||||
},
|
||||
"in_game": {
|
||||
"name": "In game"
|
||||
},
|
||||
"in_multiplayer": {
|
||||
"name": "In multiplayer"
|
||||
},
|
||||
"has_game_pass": {
|
||||
"name": "Subscribed to Xbox Game Pass"
|
||||
}
|
||||
|
||||
@@ -96,102 +96,6 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.erics273_in_multiplayer-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.erics273_in_multiplayer',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In multiplayer',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_MULTIPLAYER: 'in_multiplayer'>,
|
||||
'unique_id': '2533274913657542_in_multiplayer',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.erics273_in_multiplayer-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'erics273 In multiplayer',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.erics273_in_multiplayer',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.erics273_in_party-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.erics273_in_party',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In party',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_PARTY: 'in_party'>,
|
||||
'unique_id': '2533274913657542_in_party',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.erics273_in_party-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'erics273 In party',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.erics273_in_party',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.erics273_subscribed_to_xbox_game_pass-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -337,102 +241,6 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.gsr_ae_in_multiplayer-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.gsr_ae_in_multiplayer',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In multiplayer',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_MULTIPLAYER: 'in_multiplayer'>,
|
||||
'unique_id': '271958441785640_in_multiplayer',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.gsr_ae_in_multiplayer-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'GSR Ae In multiplayer',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.gsr_ae_in_multiplayer',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.gsr_ae_in_party-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.gsr_ae_in_party',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In party',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_PARTY: 'in_party'>,
|
||||
'unique_id': '271958441785640_in_party',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.gsr_ae_in_party-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'GSR Ae In party',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.gsr_ae_in_party',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.gsr_ae_subscribed_to_xbox_game_pass-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -578,102 +386,6 @@
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.ikken_hissatsuu_in_multiplayer-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.ikken_hissatsuu_in_multiplayer',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In multiplayer',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_MULTIPLAYER: 'in_multiplayer'>,
|
||||
'unique_id': '2533274838782903_in_multiplayer',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.ikken_hissatsuu_in_multiplayer-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ikken Hissatsuu In multiplayer',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.ikken_hissatsuu_in_multiplayer',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.ikken_hissatsuu_in_party-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'binary_sensor.ikken_hissatsuu_in_party',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'In party',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxBinarySensor.IN_PARTY: 'in_party'>,
|
||||
'unique_id': '2533274838782903_in_party',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.ikken_hissatsuu_in_party-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ikken Hissatsuu In party',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.ikken_hissatsuu_in_party',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.ikken_hissatsuu_subscribed_to_xbox_game_pass-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
||||
@@ -1,52 +1,4 @@
|
||||
# serializer version: 1
|
||||
# name: test_sensors[sensor.erics273_account_tier-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.erics273_account_tier',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Account tier',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.ACCOUNT_TIER: 'account_tier'>,
|
||||
'unique_id': '2533274913657542_account_tier',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.erics273_account_tier-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'erics273 Account tier',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.erics273_account_tier',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'Silver',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.erics273_follower-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -194,54 +146,6 @@
|
||||
'state': '3802',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.erics273_gold_tenure-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.erics273_gold_tenure',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gold tenure',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.GOLD_TENURE: 'gold_tenure'>,
|
||||
'unique_id': '2533274913657542_gold_tenure',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.erics273_gold_tenure-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'erics273 Gold tenure',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.erics273_gold_tenure',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.erics273_last_online-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -339,54 +243,6 @@
|
||||
'state': 'Last seen 17h ago: Home',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_account_tier-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gsr_ae_account_tier',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Account tier',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.ACCOUNT_TIER: 'account_tier'>,
|
||||
'unique_id': '271958441785640_account_tier',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_account_tier-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'GSR Ae Account tier',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gsr_ae_account_tier',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'Gold',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_follower-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -534,54 +390,6 @@
|
||||
'state': '27750',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_gold_tenure-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gsr_ae_gold_tenure',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gold tenure',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.GOLD_TENURE: 'gold_tenure'>,
|
||||
'unique_id': '271958441785640_gold_tenure',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_gold_tenure-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'GSR Ae Gold tenure',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gsr_ae_gold_tenure',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.gsr_ae_last_online-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -679,54 +487,6 @@
|
||||
'state': 'Last seen 49m ago: Xbox App',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_account_tier-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.ikken_hissatsuu_account_tier',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Account tier',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.ACCOUNT_TIER: 'account_tier'>,
|
||||
'unique_id': '2533274838782903_account_tier',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_account_tier-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ikken Hissatsuu Account tier',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.ikken_hissatsuu_account_tier',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'Gold',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_follower-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@@ -874,54 +634,6 @@
|
||||
'state': '27210',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_gold_tenure-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.ikken_hissatsuu_gold_tenure',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gold tenure',
|
||||
'platform': 'xbox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': <XboxSensor.GOLD_TENURE: 'gold_tenure'>,
|
||||
'unique_id': '2533274838782903_gold_tenure',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_gold_tenure-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Ikken Hissatsuu Gold tenure',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.ikken_hissatsuu_gold_tenure',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '8',
|
||||
})
|
||||
# ---
|
||||
# name: test_sensors[sensor.ikken_hissatsuu_last_online-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
||||
@@ -6,6 +6,9 @@ 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
|
||||
@@ -40,3 +43,39 @@ 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,6 +6,9 @@ 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
|
||||
@@ -40,3 +43,39 @@ 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