Add Steam game ID and screenshot paths as attributes (#32005)

* Update Steam intergration to list screenshot paths and Steam game ID

* Steam entity_picture now changed to game art when in-game

* Steam - changing API endpoints to constants

* Steam - formatting code for lint

* Update sensor.py

*Removing entity_picture image switching based on current playing game

* Steam - tidying up code

* Update homeassistant/components/steam_online/sensor.py

Co-Authored-By: springstan <46536646+springstan@users.noreply.github.com>

Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
This commit is contained in:
Kris Bennett 2020-03-09 20:38:24 +10:00 committed by GitHub
parent df86668dfc
commit f7f6c47973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -28,6 +28,10 @@ STATE_SNOOZE = "snooze"
STATE_LOOKING_TO_TRADE = "looking_to_trade"
STATE_LOOKING_TO_PLAY = "looking_to_play"
STEAM_API_URL = "https://steamcdn-a.akamaihd.net/steam/apps/"
STEAM_HEADER_IMAGE_FILE = "header.jpg"
STEAM_MAIN_IMAGE_FILE = "capsule_616x353.jpg"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_API_KEY): cv.string,
@ -73,6 +77,7 @@ class SteamSensor(Entity):
self._account = account
self._profile = None
self._game = None
self._game_id = None
self._state = None
self._name = None
self._avatar = None
@ -104,6 +109,7 @@ class SteamSensor(Entity):
try:
self._profile = self._steamod.user.profile(self._account)
self._game = self._get_current_game()
self._game_id = self._profile.current_game[0]
self._state = {
1: STATE_ONLINE,
2: STATE_BUSY,
@ -119,6 +125,7 @@ class SteamSensor(Entity):
except self._steamod.api.HTTPTimeoutError as error:
_LOGGER.warning(error)
self._game = None
self._game_id = None
self._state = None
self._name = None
self._avatar = None
@ -170,6 +177,11 @@ class SteamSensor(Entity):
attr = {}
if self._game is not None:
attr["game"] = self._game
if self._game_id is not None:
attr["game_id"] = self._game_id
game_url = f"{STEAM_API_URL}{self._game_id}/"
attr["game_image_header"] = f"{game_url}{STEAM_HEADER_IMAGE_FILE}"
attr["game_image_main"] = f"{game_url}{STEAM_MAIN_IMAGE_FILE}"
if self._last_online is not None:
attr["last_online"] = self._last_online
if self._level is not None: