mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Merge pull request #6361 from GreenTurtwig/dev
Updated to catch timeout error
This commit is contained in:
commit
75817ad46d
@ -4,6 +4,8 @@ Sensor for Steam account status.
|
|||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/sensor.steam_online/
|
https://home-assistant.io/components/sensor.steam_online/
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -13,6 +15,8 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
|
|
||||||
REQUIREMENTS = ['steamodd==4.21']
|
REQUIREMENTS = ['steamodd==4.21']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_ACCOUNTS = 'accounts'
|
CONF_ACCOUNTS = 'accounts'
|
||||||
|
|
||||||
ICON = 'mdi:steam'
|
ICON = 'mdi:steam'
|
||||||
@ -23,6 +27,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.All(cv.ensure_list, [cv.string]),
|
vol.All(cv.ensure_list, [cv.string]),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
STATE_ONLINE = 'Online'
|
||||||
|
STATE_BUSY = 'Busy'
|
||||||
|
STATE_AWAY = 'Away'
|
||||||
|
STATE_SNOOZE = 'Snooze'
|
||||||
|
STATE_TRADE = 'Trade'
|
||||||
|
STATE_PLAY = 'Play'
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
@ -46,7 +57,7 @@ class SteamSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._profile.persona
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_id(self):
|
def entity_id(self):
|
||||||
@ -61,19 +72,28 @@ class SteamSensor(Entity):
|
|||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
|
try:
|
||||||
self._profile = self._steamod.user.profile(self._account)
|
self._profile = self._steamod.user.profile(self._account)
|
||||||
if self._profile.current_game[2] is None:
|
if self._profile.current_game[2] is None:
|
||||||
self._game = 'None'
|
self._game = 'None'
|
||||||
else:
|
else:
|
||||||
self._game = self._profile.current_game[2]
|
self._game = self._profile.current_game[2]
|
||||||
self._state = {
|
self._state = {
|
||||||
1: 'Online',
|
1: STATE_ONLINE,
|
||||||
2: 'Busy',
|
2: STATE_BUSY,
|
||||||
3: 'Away',
|
3: STATE_AWAY,
|
||||||
4: 'Snooze',
|
4: STATE_SNOOZE,
|
||||||
5: 'Trade',
|
5: STATE_TRADE,
|
||||||
6: 'Play',
|
6: STATE_PLAY,
|
||||||
}.get(self._profile.status, 'Offline')
|
}.get(self._profile.status, 'Offline')
|
||||||
|
self._name = self._profile.persona
|
||||||
|
self._avatar = self._profile.avatar_medium
|
||||||
|
except self._steamod.api.HTTPTimeoutError as error:
|
||||||
|
_LOGGER.warning(error)
|
||||||
|
self._game = 'Unknown'
|
||||||
|
self._state = 'Unknown'
|
||||||
|
self._name = 'Unknown'
|
||||||
|
self._avatar = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
@ -83,7 +103,7 @@ class SteamSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def entity_picture(self):
|
def entity_picture(self):
|
||||||
"""Avatar of the account."""
|
"""Avatar of the account."""
|
||||||
return self._profile.avatar_medium
|
return self._avatar
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user