Skip to content
Snippets Groups Projects
Unverified Commit fe00f355 authored by Fabian Affolter's avatar Fabian Affolter Committed by GitHub
Browse files

Imports twitch (#28517)

* Move imports

* Add unique_id
parent e91bb1ab
No related branches found
No related tags found
No related merge requests found
"""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."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment