mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +00:00
Fix Xbox Live integration (#38146)
* Fix Xbox Live component The API moved to a different domain, so the integration was broken. The library upgrade contains the required fixes. * Fix API connectivity check * Access dict values directly
This commit is contained in:
parent
632a36d819
commit
21db4a4160
@ -2,6 +2,6 @@
|
|||||||
"domain": "xbox_live",
|
"domain": "xbox_live",
|
||||||
"name": "Xbox Live",
|
"name": "Xbox Live",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/xbox_live",
|
"documentation": "https://www.home-assistant.io/integrations/xbox_live",
|
||||||
"requirements": ["xboxapi==0.1.1"],
|
"requirements": ["xboxapi==2.0.0"],
|
||||||
"codeowners": ["@MartinHjelmare"]
|
"codeowners": ["@MartinHjelmare"]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from xboxapi import xbox_api
|
from xboxapi import Client
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL
|
from homeassistant.const import CONF_API_KEY, CONF_SCAN_INTERVAL
|
||||||
@ -28,17 +28,17 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Xbox platform."""
|
"""Set up the Xbox platform."""
|
||||||
api = xbox_api.XboxApi(config[CONF_API_KEY])
|
api = Client(api_key=config[CONF_API_KEY])
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
# request personal profile to check api connection
|
# request profile info to check api connection
|
||||||
profile = api.get_profile()
|
response = api.api_get("profile")
|
||||||
if profile.get("error_code") is not None:
|
if not response.ok:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Can't setup XboxAPI connection. Check your account or "
|
"Can't setup X API connection. Check your account or "
|
||||||
"api key on xboxapi.com. Code: %s Description: %s ",
|
"api key on xapi.us. Code: %s Description: %s ",
|
||||||
profile.get("error_code", "unknown"),
|
response.status_code,
|
||||||
profile.get("error_message", "unknown"),
|
response.reason,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
def get_user_gamercard(api, xuid):
|
def get_user_gamercard(api, xuid):
|
||||||
"""Get profile info."""
|
"""Get profile info."""
|
||||||
gamercard = api.get_user_gamercard(xuid)
|
gamercard = api.gamer(gamertag="", xuid=xuid).get("gamercard")
|
||||||
_LOGGER.debug("User gamercard: %s", gamercard)
|
_LOGGER.debug("User gamercard: %s", gamercard)
|
||||||
|
|
||||||
if gamercard.get("success", True) and gamercard.get("code") is None:
|
if gamercard.get("success", True) and gamercard.get("code") is None:
|
||||||
@ -82,11 +82,11 @@ class XboxSensor(Entity):
|
|||||||
self._presence = []
|
self._presence = []
|
||||||
self._xuid = xuid
|
self._xuid = xuid
|
||||||
self._api = api
|
self._api = api
|
||||||
self._gamertag = gamercard.get("gamertag")
|
self._gamertag = gamercard["gamertag"]
|
||||||
self._gamerscore = gamercard.get("gamerscore")
|
self._gamerscore = gamercard["gamerscore"]
|
||||||
self._interval = interval
|
self._interval = interval
|
||||||
self._picture = gamercard.get("gamerpicSmallSslImagePath")
|
self._picture = gamercard["gamerpicSmallSslImagePath"]
|
||||||
self._tier = gamercard.get("tier")
|
self._tier = gamercard["tier"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -111,10 +111,8 @@ class XboxSensor(Entity):
|
|||||||
attributes["tier"] = self._tier
|
attributes["tier"] = self._tier
|
||||||
|
|
||||||
for device in self._presence:
|
for device in self._presence:
|
||||||
for title in device.get("titles"):
|
for title in device["titles"]:
|
||||||
attributes[
|
attributes[f'{device["type"]} {title["placement"]}'] = title["name"]
|
||||||
f'{device.get("type")} {title.get("placement")}'
|
|
||||||
] = title.get("name")
|
|
||||||
|
|
||||||
return attributes
|
return attributes
|
||||||
|
|
||||||
@ -140,7 +138,7 @@ class XboxSensor(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update state data from Xbox API."""
|
"""Update state data from Xbox API."""
|
||||||
presence = self._api.get_user_presence(self._xuid)
|
presence = self._api.gamer(gamertag="", xuid=self._xuid).get("presence")
|
||||||
_LOGGER.debug("User presence: %s", presence)
|
_LOGGER.debug("User presence: %s", presence)
|
||||||
self._state = presence.get("state")
|
self._state = presence["state"]
|
||||||
self._presence = presence.get("devices", [])
|
self._presence = presence.get("devices", [])
|
||||||
|
@ -2219,7 +2219,7 @@ wolf_smartset==0.1.4
|
|||||||
xbee-helper==0.0.7
|
xbee-helper==0.0.7
|
||||||
|
|
||||||
# homeassistant.components.xbox_live
|
# homeassistant.components.xbox_live
|
||||||
xboxapi==0.1.1
|
xboxapi==2.0.0
|
||||||
|
|
||||||
# homeassistant.components.xfinity
|
# homeassistant.components.xfinity
|
||||||
xfinity-gateway==0.0.4
|
xfinity-gateway==0.0.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user