parent
e91bb1ab08
commit
fe00f3558e
1 changed files with 14 additions and 9 deletions
|
@ -1,11 +1,13 @@
|
|||
"""Support for the Twitch stream status."""
|
||||
import logging
|
||||
|
||||
from requests.exceptions import HTTPError
|
||||
from twitch import TwitchClient
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -14,6 +16,7 @@ ATTR_TITLE = "title"
|
|||
|
||||
CONF_CHANNELS = "channels"
|
||||
CONF_CLIENT_ID = "client_id"
|
||||
|
||||
ICON = "mdi:twitch"
|
||||
|
||||
STATE_OFFLINE = "offline"
|
||||
|
@ -22,18 +25,16 @@ 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]),
|
||||
vol.Required(CONF_CHANNELS): vol.All(cv.ensure_list, [cv.string]),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Twitch platform."""
|
||||
from twitch import TwitchClient
|
||||
from requests.exceptions import HTTPError
|
||||
|
||||
channels = config.get(CONF_CHANNELS, [])
|
||||
client = TwitchClient(client_id=config.get(CONF_CLIENT_ID))
|
||||
channels = config[CONF_CHANNELS]
|
||||
client_id = config[CONF_CLIENT_ID]
|
||||
client = TwitchClient(client_id=client_id)
|
||||
|
||||
try:
|
||||
client.ingests.get_server_list()
|
||||
|
@ -55,8 +56,7 @@ class TwitchSensor(Entity):
|
|||
self._user = user
|
||||
self._channel = self._user.name
|
||||
self._id = self._user.id
|
||||
self._state = STATE_OFFLINE
|
||||
self._preview = self._game = self._title = None
|
||||
self._state = self._preview = self._game = self._title = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -84,6 +84,11 @@ class TwitchSensor(Entity):
|
|||
if self._state == STATE_STREAMING:
|
||||
return {ATTR_GAME: self._game, ATTR_TITLE: self._title}
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return unique ID for this sensor."""
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Icon to use in the frontend, if any."""
|
||||
|
|
Loading…
Add table
Reference in a new issue