1 """Sensor for Steam account status."""
3 from __future__
import annotations
5 from datetime
import datetime
6 from time
import localtime, mktime
7 from typing
import cast
15 from .
import SteamConfigEntry
19 STEAM_HEADER_IMAGE_FILE,
21 STEAM_MAIN_IMAGE_FILE,
24 from .coordinator
import SteamDataUpdateCoordinator
25 from .entity
import SteamEntity
32 entry: SteamConfigEntry,
33 async_add_entities: AddEntitiesCallback,
35 """Set up the Steam platform."""
38 for account
in entry.options[CONF_ACCOUNTS]
43 """A class for the Steam account."""
45 def __init__(self, coordinator: SteamDataUpdateCoordinator, account: str) ->
None:
46 """Initialize the sensor."""
50 name=f
"steam_{account}",
57 """Return the state of the sensor."""
60 return STEAM_STATUSES[cast(int, player[
"personastate"])]
65 """Return the state attributes of the sensor."""
70 attrs: dict[str, str | int | datetime] = {}
71 if game := player.get(
"gameextrainfo"):
73 if game_id := player.get(
"gameid"):
74 attrs[
"game_id"] = game_id
75 game_url = f
"{STEAM_API_URL}{player['gameid']}/"
76 attrs[
"game_image_header"] = f
"{game_url}{STEAM_HEADER_IMAGE_FILE}"
77 attrs[
"game_image_main"] = f
"{game_url}{STEAM_MAIN_IMAGE_FILE}"
79 attrs[
"game_icon"] = f
"{STEAM_ICON_URL}{game_id}/{info}.jpg"
82 if last_online := cast(int |
None, player.get(
"lastlogoff")):
84 if level := self.coordinator.data[self.
entity_descriptionentity_description.key][
"level"]:
85 attrs[
"level"] = level
89 """Get game icon identifier."""
90 if player.get(
"gameid")
in self.coordinator.game_icons:
91 return self.coordinator.game_icons[player[
"gameid"]]
93 self.coordinator.game_icons = {}
None __init__(self, SteamDataUpdateCoordinator coordinator, str account)
StateType native_value(self)
str|None _get_game_icon(self, dict player)
dict[str, str|int|datetime] extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, SteamConfigEntry entry, AddEntitiesCallback async_add_entities)