mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add support for Roku TVs to be powered on or off (#25590)
This commit is contained in:
parent
1e8a4dd0bc
commit
42c50c5b5e
@ -74,7 +74,7 @@ def scan_for_rokus(hass):
|
|||||||
continue
|
continue
|
||||||
devices.append('Name: {0}<br />Host: {1}<br />'.format(
|
devices.append('Name: {0}<br />Host: {1}<br />'.format(
|
||||||
r_info.userdevicename if r_info.userdevicename
|
r_info.userdevicename if r_info.userdevicename
|
||||||
else "{} {}".format(r_info.modelname, r_info.sernum),
|
else "{} {}".format(r_info.modelname, r_info.serial_num),
|
||||||
roku.host))
|
roku.host))
|
||||||
if not devices:
|
if not devices:
|
||||||
devices = ['No device(s) found']
|
devices = ['No device(s) found']
|
||||||
@ -98,7 +98,7 @@ def _setup_roku(hass, hass_config, roku_config):
|
|||||||
r_info = roku.device_info
|
r_info = roku.device_info
|
||||||
|
|
||||||
hass.data[DATA_ROKU][host] = {
|
hass.data[DATA_ROKU][host] = {
|
||||||
ATTR_ROKU: r_info.sernum
|
ATTR_ROKU: r_info.serial_num
|
||||||
}
|
}
|
||||||
|
|
||||||
discovery.load_platform(
|
discovery.load_platform(
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Roku",
|
"name": "Roku",
|
||||||
"documentation": "https://www.home-assistant.io/components/roku",
|
"documentation": "https://www.home-assistant.io/components/roku",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"python-roku==3.1.5"
|
"roku==3.0.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -6,9 +6,9 @@ from homeassistant.components.media_player import MediaPlayerDevice
|
|||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
MEDIA_TYPE_MOVIE, SUPPORT_NEXT_TRACK, SUPPORT_PLAY,
|
MEDIA_TYPE_MOVIE, SUPPORT_NEXT_TRACK, SUPPORT_PLAY,
|
||||||
SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE,
|
SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE,
|
||||||
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET)
|
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_TURN_ON, SUPPORT_TURN_OFF)
|
||||||
from homeassistant.const import (CONF_HOST, STATE_HOME, STATE_IDLE,
|
from homeassistant.const import (CONF_HOST, STATE_HOME, STATE_IDLE,
|
||||||
STATE_PLAYING)
|
STATE_PLAYING, STATE_OFF)
|
||||||
|
|
||||||
DEFAULT_PORT = 8060
|
DEFAULT_PORT = 8060
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
SUPPORT_ROKU = SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK |\
|
SUPPORT_ROKU = SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK |\
|
||||||
SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\
|
||||||
SUPPORT_SELECT_SOURCE | SUPPORT_PLAY
|
SUPPORT_SELECT_SOURCE | SUPPORT_PLAY | SUPPORT_TURN_ON | SUPPORT_TURN_OFF
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
@ -41,11 +41,13 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
self.channels = []
|
self.channels = []
|
||||||
self.current_app = None
|
self.current_app = None
|
||||||
self._device_info = {}
|
self._device_info = {}
|
||||||
|
self._power_state = "Unknown"
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
try:
|
try:
|
||||||
self._device_info = self.roku.device_info
|
self._device_info = self.roku.device_info
|
||||||
|
self._power_state = self.roku.power_state
|
||||||
self.ip_address = self.roku.host
|
self.ip_address = self.roku.host
|
||||||
self.channels = self.get_source_list()
|
self.channels = self.get_source_list()
|
||||||
|
|
||||||
@ -69,13 +71,16 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
if self._device_info.userdevicename:
|
if self._device_info.user_device_name:
|
||||||
return self._device_info.userdevicename
|
return self._device_info.user_device_name
|
||||||
return "Roku {}".format(self._device_info.sernum)
|
return "Roku {}".format(self._device_info.serial_num)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
|
if self._power_state == "Off":
|
||||||
|
return STATE_OFF
|
||||||
|
|
||||||
if self.current_app is None:
|
if self.current_app is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -97,7 +102,7 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique, HASS-friendly identifier for this entity."""
|
"""Return a unique, HASS-friendly identifier for this entity."""
|
||||||
return self._device_info.sernum
|
return self._device_info.serial_num
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_content_type(self):
|
def media_content_type(self):
|
||||||
@ -148,6 +153,14 @@ class RokuDevice(MediaPlayerDevice):
|
|||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
return self.channels
|
return self.channels
|
||||||
|
|
||||||
|
def turn_on(self):
|
||||||
|
"""Turn on the Roku."""
|
||||||
|
self.roku.power()
|
||||||
|
|
||||||
|
def turn_off(self):
|
||||||
|
"""Turn off the Roku."""
|
||||||
|
self.roku.poweroff()
|
||||||
|
|
||||||
def media_play_pause(self):
|
def media_play_pause(self):
|
||||||
"""Send play/pause command."""
|
"""Send play/pause command."""
|
||||||
if self.current_app is not None:
|
if self.current_app is not None:
|
||||||
|
@ -36,14 +36,14 @@ class RokuRemote(remote.RemoteDevice):
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
if self._device_info.userdevicename:
|
if self._device_info.user_device_name:
|
||||||
return self._device_info.userdevicename
|
return self._device_info.user_device_name
|
||||||
return "Roku {}".format(self._device_info.sernum)
|
return "Roku {}".format(self._device_info.serial_num)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return self._device_info.sernum
|
return self._device_info.serial_num
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
@ -1494,9 +1494,6 @@ python-qbittorrent==0.3.1
|
|||||||
# homeassistant.components.ripple
|
# homeassistant.components.ripple
|
||||||
python-ripple-api==0.0.3
|
python-ripple-api==0.0.3
|
||||||
|
|
||||||
# homeassistant.components.roku
|
|
||||||
python-roku==3.1.5
|
|
||||||
|
|
||||||
# homeassistant.components.sochain
|
# homeassistant.components.sochain
|
||||||
python-sochain-api==0.0.2
|
python-sochain-api==0.0.2
|
||||||
|
|
||||||
@ -1642,6 +1639,9 @@ rjpl==0.3.5
|
|||||||
# homeassistant.components.rocketchat
|
# homeassistant.components.rocketchat
|
||||||
rocketchat-API==0.6.1
|
rocketchat-API==0.6.1
|
||||||
|
|
||||||
|
# homeassistant.components.roku
|
||||||
|
roku==3.0.0
|
||||||
|
|
||||||
# homeassistant.components.roomba
|
# homeassistant.components.roomba
|
||||||
roombapy==1.3.1
|
roombapy==1.3.1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user