mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Code quality improvements for Xbox integration (#156395)
This commit is contained in:
@@ -44,7 +44,6 @@ class XboxBinarySensorEntityDescription(
|
||||
"""Xbox binary sensor description."""
|
||||
|
||||
is_on_fn: Callable[[Person], bool | None]
|
||||
deprecated: bool | None = None
|
||||
|
||||
|
||||
def profile_attributes(person: Person, _: Title | None) -> dict[str, Any]:
|
||||
@@ -120,16 +119,16 @@ async def async_setup_entry(
|
||||
|
||||
current_xuids = set(coordinator.data.presence)
|
||||
if new_xuids := current_xuids - xuids_added:
|
||||
for xuid in new_xuids:
|
||||
async_add_entities(
|
||||
[
|
||||
XboxBinarySensorEntity(coordinator, xuid, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(
|
||||
hass, xuid, description, BINARY_SENSOR_DOMAIN
|
||||
)
|
||||
]
|
||||
)
|
||||
async_add_entities(
|
||||
[
|
||||
XboxBinarySensorEntity(coordinator, xuid, description)
|
||||
for xuid in new_xuids
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(
|
||||
hass, xuid, description, BINARY_SENSOR_DOMAIN
|
||||
)
|
||||
]
|
||||
)
|
||||
xuids_added |= new_xuids
|
||||
xuids_added &= current_xuids
|
||||
|
||||
|
||||
@@ -4,5 +4,3 @@ DOMAIN = "xbox"
|
||||
|
||||
OAUTH2_AUTHORIZE = "https://login.live.com/oauth20_authorize.srf"
|
||||
OAUTH2_TOKEN = "https://login.live.com/oauth20_token.srf"
|
||||
|
||||
EVENT_NEW_FAVORITE = "xbox/new_favorite"
|
||||
|
||||
@@ -58,14 +58,14 @@ class XboxData:
|
||||
class XboxUpdateCoordinator(DataUpdateCoordinator[XboxData]):
|
||||
"""Store Xbox Console Status."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: XboxConfigEntry
|
||||
consoles: SmartglassConsoleList
|
||||
client: XboxLiveClient
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: XboxConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
super().__init__(
|
||||
|
||||
@@ -94,8 +94,7 @@ class XboxBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
||||
"""Return entity specific state attributes."""
|
||||
return (
|
||||
fn(self.data, self.title_info)
|
||||
if hasattr(self.entity_description, "attributes_fn")
|
||||
and (fn := self.entity_description.attributes_fn)
|
||||
if (fn := self.entity_description.attributes_fn)
|
||||
else super().extra_state_attributes
|
||||
)
|
||||
|
||||
@@ -122,7 +121,7 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, console.id)},
|
||||
manufacturer="Microsoft",
|
||||
model=MAP_MODEL.get(self._console.console_type, "Unknown"),
|
||||
model=MAP_MODEL.get(self._console.console_type),
|
||||
name=console.name,
|
||||
)
|
||||
|
||||
@@ -135,11 +134,11 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
||||
def check_deprecated_entity(
|
||||
hass: HomeAssistant,
|
||||
xuid: str,
|
||||
entity_description: EntityDescription,
|
||||
entity_description: XboxBaseEntityDescription,
|
||||
entity_domain: str,
|
||||
) -> bool:
|
||||
"""Check for deprecated entity and remove it."""
|
||||
if not getattr(entity_description, "deprecated", False):
|
||||
if not entity_description.deprecated:
|
||||
return True
|
||||
ent_reg = er.async_get(hass)
|
||||
if entity_id := ent_reg.async_get_entity_id(
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Xbox",
|
||||
"codeowners": ["@hunterjm", "@tr4nt0r"],
|
||||
"config_flow": true,
|
||||
"dependencies": ["auth", "application_credentials"],
|
||||
"dependencies": ["application_credentials"],
|
||||
"dhcp": [
|
||||
{
|
||||
"hostname": "xbox*"
|
||||
|
||||
@@ -51,7 +51,6 @@ class XboxSensorEntityDescription(XboxBaseEntityDescription, SensorEntityDescrip
|
||||
"""Xbox sensor description."""
|
||||
|
||||
value_fn: Callable[[Person, Title | None], StateType | datetime]
|
||||
deprecated: bool | None = None
|
||||
|
||||
|
||||
def now_playing_attributes(_: Person, title: Title | None) -> dict[str, Any]:
|
||||
@@ -212,16 +211,14 @@ async def async_setup_entry(
|
||||
|
||||
current_xuids = set(coordinator.data.presence)
|
||||
if new_xuids := current_xuids - xuids_added:
|
||||
for xuid in new_xuids:
|
||||
async_add_entities(
|
||||
[
|
||||
XboxSensorEntity(coordinator, xuid, description)
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(
|
||||
hass, xuid, description, SENSOR_DOMAIN
|
||||
)
|
||||
]
|
||||
)
|
||||
async_add_entities(
|
||||
[
|
||||
XboxSensorEntity(coordinator, xuid, description)
|
||||
for xuid in new_xuids
|
||||
for description in SENSOR_DESCRIPTIONS
|
||||
if check_deprecated_entity(hass, xuid, description, SENSOR_DOMAIN)
|
||||
]
|
||||
)
|
||||
xuids_added |= new_xuids
|
||||
xuids_added &= current_xuids
|
||||
|
||||
|
||||
@@ -34,22 +34,10 @@ async def setup_credentials(hass: HomeAssistant) -> None:
|
||||
"""Fixture to setup credentials."""
|
||||
assert await async_setup_component(hass, "application_credentials", {})
|
||||
await async_import_client_credential(
|
||||
hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET), "imported-cred"
|
||||
hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET), "cloud"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_oauth2_implementation() -> Generator[AsyncMock]:
|
||||
"""Mock config entry oauth2 implementation."""
|
||||
with patch(
|
||||
"homeassistant.components.xbox.coordinator.async_get_config_entry_implementation",
|
||||
return_value=AsyncMock(),
|
||||
) as mock_client:
|
||||
client = mock_client.return_value
|
||||
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Mock Xbox configuration entry."""
|
||||
|
||||
Reference in New Issue
Block a user