diff --git a/homeassistant/components/xbox/__init__.py b/homeassistant/components/xbox/__init__.py index bee773d2094..6e8492e45ca 100644 --- a/homeassistant/components/xbox/__init__.py +++ b/homeassistant/components/xbox/__init__.py @@ -180,7 +180,7 @@ class XboxUpdateCoordinator(DataUpdateCoordinator): name=DOMAIN, update_interval=timedelta(seconds=10), ) - self.data: XboxData = XboxData({}, []) + self.data: XboxData = XboxData({}, {}) self.client: XboxLiveClient = client self.consoles: SmartglassConsoleList = consoles @@ -230,7 +230,7 @@ class XboxUpdateCoordinator(DataUpdateCoordinator): ) # Update user presence - presence_data = {} + presence_data: dict[str, PresenceData] = {} batch: PeopleResponse = await self.client.people.get_friends_own_batch( [self.client.xuid] ) @@ -262,7 +262,7 @@ def _build_presence_data(person: Person) -> PresenceData: online=person.presence_state == "Online", status=person.presence_text, in_party=person.multiplayer_summary.in_party > 0, - in_game=active_app and active_app.is_game, + in_game=active_app is not None and active_app.is_game, in_multiplayer=person.multiplayer_summary.in_multiplayer_session, gamer_score=person.gamer_score, gold_tenure=person.detail.tenure, diff --git a/homeassistant/components/xbox/base_sensor.py b/homeassistant/components/xbox/base_sensor.py index 024feb294b5..5d0f3f92434 100644 --- a/homeassistant/components/xbox/base_sensor.py +++ b/homeassistant/components/xbox/base_sensor.py @@ -33,7 +33,7 @@ class XboxBaseSensorEntity(CoordinatorEntity[XboxUpdateCoordinator]): return self.coordinator.data.presence.get(self.xuid) @property - def name(self) -> str: + def name(self) -> str | None: """Return the name of the sensor.""" if not self.data: return None @@ -45,7 +45,7 @@ class XboxBaseSensorEntity(CoordinatorEntity[XboxUpdateCoordinator]): return f"{self.data.gamertag} {attr_name}" @property - def entity_picture(self) -> str: + def entity_picture(self) -> str | None: """Return the gamer pic.""" if not self.data: return None diff --git a/homeassistant/components/xbox/binary_sensor.py b/homeassistant/components/xbox/binary_sensor.py index 7cf7ca6a6a5..ac97d502c55 100644 --- a/homeassistant/components/xbox/binary_sensor.py +++ b/homeassistant/components/xbox/binary_sensor.py @@ -54,7 +54,7 @@ def async_update_friends( current_ids = set(current) # Process new favorites, add them to Home Assistant - new_entities = [] + new_entities: list[XboxBinarySensorEntity] = [] for xuid in new_ids - current_ids: current[xuid] = [ XboxBinarySensorEntity(coordinator, xuid, attribute) @@ -75,7 +75,7 @@ def async_update_friends( async def async_remove_entities( xuid: str, coordinator: XboxUpdateCoordinator, - current: dict[str, XboxBinarySensorEntity], + current: dict[str, list[XboxBinarySensorEntity]], ) -> None: """Remove friend sensors from Home Assistant.""" registry = er.async_get(coordinator.hass) diff --git a/homeassistant/components/xbox/browse_media.py b/homeassistant/components/xbox/browse_media.py index b6e5a89efb3..ee1eabf1e00 100644 --- a/homeassistant/components/xbox/browse_media.py +++ b/homeassistant/components/xbox/browse_media.py @@ -1,7 +1,7 @@ """Support for media browsing.""" from __future__ import annotations -from typing import NamedTuple +from typing import TYPE_CHECKING, NamedTuple from xbox.webapi.api.client import XboxLiveClient from xbox.webapi.api.provider.catalog.const import HOME_APP_IDS, SYSTEM_PFN_ID_MAP @@ -65,6 +65,8 @@ async def build_item_response( can_expand=True, children=[], ) + if TYPE_CHECKING: + assert library_info.children is not None # Add Home id_type = AlternateIdType.LEGACY_XBOX_PRODUCT_ID @@ -84,7 +86,7 @@ async def build_item_response( title="Home", can_play=True, can_expand=False, - thumbnail=home_thumb.uri, + thumbnail=None if home_thumb is None else home_thumb.uri, ) ) @@ -107,7 +109,7 @@ async def build_item_response( title="Live TV", can_play=True, can_expand=False, - thumbnail=tv_thumb.uri, + thumbnail=None if tv_thumb is None else tv_thumb.uri, ) ) diff --git a/homeassistant/components/xbox/media_source.py b/homeassistant/components/xbox/media_source.py index c6dae46a955..21b9b25ce2d 100644 --- a/homeassistant/components/xbox/media_source.py +++ b/homeassistant/components/xbox/media_source.py @@ -55,7 +55,7 @@ def async_parse_identifier( identifier = item.identifier or "" start = ["", "", ""] items = identifier.lstrip("/").split("~~", 2) - return tuple(items + start[len(items) :]) + return tuple(items + start[len(items) :]) # type: ignore[return-value] @dataclass @@ -201,7 +201,7 @@ class XboxSource(MediaSource): ) -def _build_game_item(item: InstalledPackage, images: list[Image]): +def _build_game_item(item: InstalledPackage, images: dict[str, list[Image]]): """Build individual game.""" thumbnail = "" image = _find_media_image(images.get(item.one_store_product_id, [])) diff --git a/homeassistant/components/xbox/sensor.py b/homeassistant/components/xbox/sensor.py index 02b4f8b84a4..9cba49d1dcb 100644 --- a/homeassistant/components/xbox/sensor.py +++ b/homeassistant/components/xbox/sensor.py @@ -56,7 +56,7 @@ def async_update_friends( current_ids = set(current) # Process new favorites, add them to Home Assistant - new_entities = [] + new_entities: list[XboxSensorEntity] = [] for xuid in new_ids - current_ids: current[xuid] = [ XboxSensorEntity(coordinator, xuid, attribute) @@ -77,7 +77,7 @@ def async_update_friends( async def async_remove_entities( xuid: str, coordinator: XboxUpdateCoordinator, - current: dict[str, XboxSensorEntity], + current: dict[str, list[XboxSensorEntity]], ) -> None: """Remove friend sensors from Home Assistant.""" registry = er.async_get(coordinator.hass) diff --git a/mypy.ini b/mypy.ini index a8af4b574f4..13be5d712f4 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2842,21 +2842,3 @@ ignore_errors = true [mypy-homeassistant.components.withings.config_flow] ignore_errors = true - -[mypy-homeassistant.components.xbox] -ignore_errors = true - -[mypy-homeassistant.components.xbox.base_sensor] -ignore_errors = true - -[mypy-homeassistant.components.xbox.binary_sensor] -ignore_errors = true - -[mypy-homeassistant.components.xbox.browse_media] -ignore_errors = true - -[mypy-homeassistant.components.xbox.media_source] -ignore_errors = true - -[mypy-homeassistant.components.xbox.sensor] -ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index e49f16455f7..199d6d00a7d 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -82,12 +82,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.withings.binary_sensor", "homeassistant.components.withings.common", "homeassistant.components.withings.config_flow", - "homeassistant.components.xbox", - "homeassistant.components.xbox.base_sensor", - "homeassistant.components.xbox.binary_sensor", - "homeassistant.components.xbox.browse_media", - "homeassistant.components.xbox.media_source", - "homeassistant.components.xbox.sensor", ] # Component modules which should set no_implicit_reexport = true.