"""Nintendo Player.""" from .const import _LOGGER class Player: """A Nintendo Switch user profile. Represents a player profile on a Nintendo Switch console with their gaming activity. Attributes: player_id: Unique identifier for the player. nickname: Player's display name. player_image: URL to the player's Mii image. playing_time: Total playing time for the current day in minutes. apps: List of applications played today with playtime details. month_summary: Monthly usage summary data for this player. """ def __init__(self): """Init a player.""" self.player_image: str | None = None self.nickname: str | None = None self.apps: list = [] self.month_summary: dict = {} self.player_id: str | None = None self.playing_time: int = 0 def update_from_daily_summary(self, raw: list[dict]): """Update player data from a daily summary response. Args: raw: List of daily summary dictionaries from the API. """ _LOGGER.debug("Updating player %s daily summary", self.player_id) for player in raw[0].get("players", []): if self.player_id == player["profile"].get("playerId"): self.player_image = player["profile"].get("imageUri") self.nickname = player["profile"].get("nickname") self.playing_time = player.get("playingTime") self.apps = player.get("playedGames") break @classmethod def from_device_daily_summary(cls, raw: list[dict]) -> list["Player"]: """Create Player objects from a device daily summary response. Args: raw: List of daily summary dictionaries from the API. Returns: List of Player objects parsed from the summary. """ players = [] _LOGGER.debug("Building players from device daily summary.") for player in raw[0].get("players", []): parsed = cls() parsed.player_id = player["profile"].get("playerId") parsed.player_image = player["profile"].get("imageUri") parsed.nickname = player["profile"].get("nickname") parsed.playing_time = player.get("playingTime") parsed.apps = player.get("playedGames") players.append(parsed) _LOGGER.debug("Built player %s", parsed.player_id) return players @classmethod def from_profile(cls, raw: dict) -> "Player": """Create a Player object from a profile response. Args: raw: Profile dictionary from the API. Returns: A Player object parsed from the profile data. """ parsed = cls() parsed.player_id = raw.get("playerId") parsed.player_image = raw.get("imageUri") parsed.nickname = raw.get("nickname") return parsed