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
0e9c51a4
Commit
0e9c51a4
authored
9 years ago
by
happyleaves
Browse files
Options
Downloads
Patches
Plain Diff
twitch sensor
parent
d3a21bee
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.coveragerc
+1
-0
1 addition, 0 deletions
.coveragerc
homeassistant/components/sensor/twitch.py
+31
-36
31 additions, 36 deletions
homeassistant/components/sensor/twitch.py
with
32 additions
and
36 deletions
.coveragerc
+
1
−
0
View file @
0e9c51a4
...
@@ -97,6 +97,7 @@ omit =
...
@@ -97,6 +97,7 @@ omit =
homeassistant/components/sensor/temper.py
homeassistant/components/sensor/temper.py
homeassistant/components/sensor/time_date.py
homeassistant/components/sensor/time_date.py
homeassistant/components/sensor/transmission.py
homeassistant/components/sensor/transmission.py
homeassistant/components/sensor/twitch.py
homeassistant/components/sensor/worldclock.py
homeassistant/components/sensor/worldclock.py
homeassistant/components/switch/arest.py
homeassistant/components/switch/arest.py
homeassistant/components/switch/command_switch.py
homeassistant/components/switch/command_switch.py
...
...
This diff is collapsed.
Click to expand it.
homeassistant/components/
media_playe
r/twitch.py
→
homeassistant/components/
senso
r/twitch.py
+
31
−
36
View file @
0e9c51a4
"""
"""
homeassistant.components.
media_playe
r.twitch
homeassistant.components.
senso
r.twitch
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Twitch stream status.
Twitch stream 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/
media_playe
r.twitch/
https://home-assistant.io/components/
senso
r.twitch/
"""
"""
from
homeassistant.const
import
STATE_PLAYING
,
STATE_OFF
from
homeassistant.helpers.entity
import
Entity
from
homeassistant.const
import
ATTR_ENTITY_PICTURE
from
homeassistant.components.media_player
import
(
STATE_STREAMING
=
'
streaming
'
MediaPlayerDevice
,
MEDIA_TYPE_CHANNEL
)
STATE_OFFLINE
=
'
offline
'
ATTR_GAME
=
'
game
'
ATTR_TITLE
=
'
title
'
ICON
=
'
mdi:twitch
'
REQUIREMENTS
=
[
'
python-twitch==1.2.0
'
]
REQUIREMENTS
=
[
'
python-twitch==1.2.0
'
]
DOMAIN
=
'
twitch
'
DOMAIN
=
'
twitch
'
...
@@ -20,28 +24,34 @@ DOMAIN = 'twitch'
...
@@ -20,28 +24,34 @@ DOMAIN = 'twitch'
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
def
setup_platform
(
hass
,
config
,
add_devices
,
discovery_info
=
None
):
"""
Sets up the Twitch platform.
"""
"""
Sets up the Twitch platform.
"""
add_devices
(
add_devices
(
[
Twitch
Device
(
channel
)
for
channel
in
config
.
get
(
'
channels
'
,
[])])
[
Twitch
Sensor
(
channel
)
for
channel
in
config
.
get
(
'
channels
'
,
[])])
class
Twitch
Device
(
MediaPlayerDevice
):
class
Twitch
Sensor
(
Entity
):
"""
Represents an Twitch channel.
"""
"""
Represents an Twitch channel.
"""
# pylint: disable=abstract-method
# pylint: disable=abstract-method
def
__init__
(
self
,
channel
):
def
__init__
(
self
,
channel
):
self
.
_channel
=
channel
self
.
_channel
=
channel
self
.
_state
=
STATE_OFF
self
.
_state
=
STATE_OFF
LINE
self
.
_preview
=
None
self
.
_preview
=
None
self
.
_game
=
None
self
.
_game
=
None
self
.
_title
=
None
self
.
_title
=
None
self
.
update
()
@property
@property
def
should_poll
(
self
):
def
should_poll
(
self
):
"""
Device should be polled.
"""
"""
Device should be polled.
"""
return
True
return
True
@property
def
name
(
self
):
"""
Returns the name of the device.
"""
return
self
.
_channel
@property
@property
def
state
(
self
):
def
state
(
self
):
"""
State of the
playe
r.
"""
"""
State of the
senso
r.
"""
return
self
.
_state
return
self
.
_state
# pylint: disable=no-member
# pylint: disable=no-member
...
@@ -53,35 +63,20 @@ class TwitchDevice(MediaPlayerDevice):
...
@@ -53,35 +63,20 @@ class TwitchDevice(MediaPlayerDevice):
self
.
_game
=
stream
.
get
(
'
channel
'
).
get
(
'
game
'
)
self
.
_game
=
stream
.
get
(
'
channel
'
).
get
(
'
game
'
)
self
.
_title
=
stream
.
get
(
'
channel
'
).
get
(
'
status
'
)
self
.
_title
=
stream
.
get
(
'
channel
'
).
get
(
'
status
'
)
self
.
_preview
=
stream
.
get
(
'
preview
'
).
get
(
'
small
'
)
self
.
_preview
=
stream
.
get
(
'
preview
'
).
get
(
'
small
'
)
self
.
_state
=
STATE_
PLAY
ING
self
.
_state
=
STATE_
STREAM
ING
else
:
else
:
self
.
_state
=
STATE_OFF
self
.
_state
=
STATE_OFF
LINE
@property
@property
def
name
(
self
):
def
state_attributes
(
self
):
"""
Channel name.
"""
"""
Returns the state attributes.
"""
return
self
.
_channel
if
self
.
_state
==
STATE_STREAMING
:
return
{
ATTR_GAME
:
self
.
_game
,
ATTR_TITLE
:
self
.
_title
,
ATTR_ENTITY_PICTURE
:
self
.
_preview
}
@property
@property
def
media_title
(
self
):
def
icon
(
self
):
"""
Channel title.
"""
return
ICON
return
self
.
_title
@property
def
app_name
(
self
):
"""
Game name.
"""
return
self
.
_game
@property
def
media_image_url
(
self
):
"""
Image preview url of the live stream.
"""
return
self
.
_preview
@property
def
media_content_type
(
self
):
"""
Media type (channel).
"""
return
MEDIA_TYPE_CHANNEL
def
media_pause
(
self
):
"""
Must implement because UI can pause.
"""
pass
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