Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
fe00f355
Unverified
Commit
fe00f355
authored
5 years ago
by
Fabian Affolter
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Imports twitch (#28517)
* Move imports * Add unique_id
parent
e91bb1ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/twitch/sensor.py
+14
-9
14 additions, 9 deletions
homeassistant/components/twitch/sensor.py
with
14 additions
and
9 deletions
homeassistant/components/twitch/sensor.py
+
14
−
9
View file @
fe00f355
"""
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.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment