This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+18 -20
View File
@@ -9,21 +9,22 @@ import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
ATTR_GAME = 'game'
ATTR_TITLE = 'title'
ATTR_GAME = "game"
ATTR_TITLE = "title"
CONF_CHANNELS = 'channels'
CONF_CLIENT_ID = 'client_id'
ICON = 'mdi:twitch'
CONF_CHANNELS = "channels"
CONF_CLIENT_ID = "client_id"
ICON = "mdi:twitch"
STATE_OFFLINE = 'offline'
STATE_STREAMING = 'streaming'
STATE_OFFLINE = "offline"
STATE_STREAMING = "streaming"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CHANNELS, default=[]):
vol.All(cv.ensure_list, [cv.string]),
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CHANNELS, default=[]): vol.All(cv.ensure_list, [cv.string]),
}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
@@ -81,10 +82,7 @@ class TwitchSensor(Entity):
def device_state_attributes(self):
"""Return the state attributes."""
if self._state == STATE_STREAMING:
return {
ATTR_GAME: self._game,
ATTR_TITLE: self._title,
}
return {ATTR_GAME: self._game, ATTR_TITLE: self._title}
@property
def icon(self):
@@ -96,10 +94,10 @@ class TwitchSensor(Entity):
"""Update device state."""
stream = self._client.streams.get_stream_by_user(self._id)
if stream:
self._game = stream.get('channel').get('game')
self._title = stream.get('channel').get('status')
self._preview = stream.get('preview').get('medium')
self._game = stream.get("channel").get("game")
self._title = stream.get("channel").get("status")
self._preview = stream.get("preview").get("medium")
self._state = STATE_STREAMING
else:
self._preview = self._client.users.get_by_id(self._id).get('logo')
self._preview = self._client.users.get_by_id(self._id).get("logo")
self._state = STATE_OFFLINE