Xbox sensor - Extend error handling (#11637)
* Extend error handling fix #9016 * lint finding * Implement requested changes * Remove unneeded return statement
This commit is contained in:
parent
8bcaf832ae
commit
aad14b8b87
1 changed files with 16 additions and 4 deletions
|
@ -34,15 +34,22 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
api = xbox_api.XboxApi(config.get(CONF_API_KEY))
|
api = xbox_api.XboxApi(config.get(CONF_API_KEY))
|
||||||
devices = []
|
devices = []
|
||||||
|
|
||||||
|
# request personal profile to check api connection
|
||||||
|
profile = api.get_profile()
|
||||||
|
if profile.get('error_code') is not None:
|
||||||
|
_LOGGER.error("Can't setup XboxAPI connection. Check your account or "
|
||||||
|
" api key on xboxapi.com. Code: %s Description: %s ",
|
||||||
|
profile.get('error_code', STATE_UNKNOWN),
|
||||||
|
profile.get('error_message', STATE_UNKNOWN))
|
||||||
|
return
|
||||||
|
|
||||||
for xuid in config.get(CONF_XUID):
|
for xuid in config.get(CONF_XUID):
|
||||||
new_device = XboxSensor(hass, api, xuid)
|
new_device = XboxSensor(hass, api, xuid)
|
||||||
if new_device.success_init:
|
if new_device.success_init:
|
||||||
devices.append(new_device)
|
devices.append(new_device)
|
||||||
|
|
||||||
if devices:
|
if devices:
|
||||||
add_devices(devices)
|
add_devices(devices, True)
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class XboxSensor(Entity):
|
class XboxSensor(Entity):
|
||||||
|
@ -59,11 +66,16 @@ class XboxSensor(Entity):
|
||||||
# get profile info
|
# get profile info
|
||||||
profile = self._api.get_user_gamercard(self._xuid)
|
profile = self._api.get_user_gamercard(self._xuid)
|
||||||
|
|
||||||
if profile.get('success', True) and profile.get('code', 0) != 28:
|
if profile.get('success', True) and profile.get('code') is None:
|
||||||
self.success_init = True
|
self.success_init = True
|
||||||
self._gamertag = profile.get('gamertag')
|
self._gamertag = profile.get('gamertag')
|
||||||
self._picture = profile.get('gamerpicSmallSslImagePath')
|
self._picture = profile.get('gamerpicSmallSslImagePath')
|
||||||
else:
|
else:
|
||||||
|
_LOGGER.error("Can't get user profile %s. "
|
||||||
|
"Error Code: %s Description: %s",
|
||||||
|
self._xuid,
|
||||||
|
profile.get('code', STATE_UNKNOWN),
|
||||||
|
profile.get('description', STATE_UNKNOWN))
|
||||||
self.success_init = False
|
self.success_init = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue