Add support for Roku TVs to be powered on or off (#25590)

This commit is contained in:
Manuel Díez
2019-07-31 00:01:51 -04:00
committed by Martin Hjelmare
parent 1e8a4dd0bc
commit 42c50c5b5e
5 changed files with 30 additions and 17 deletions

View File

@ -74,7 +74,7 @@ def scan_for_rokus(hass):
continue
devices.append('Name: {0}<br />Host: {1}<br />'.format(
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))
if not devices:
devices = ['No device(s) found']
@ -98,7 +98,7 @@ def _setup_roku(hass, hass_config, roku_config):
r_info = roku.device_info
hass.data[DATA_ROKU][host] = {
ATTR_ROKU: r_info.sernum
ATTR_ROKU: r_info.serial_num
}
discovery.load_platform(

View File

@ -3,7 +3,7 @@
"name": "Roku",
"documentation": "https://www.home-assistant.io/components/roku",
"requirements": [
"python-roku==3.1.5"
"roku==3.0.0"
],
"dependencies": [],
"codeowners": []

View File

@ -6,9 +6,9 @@ from homeassistant.components.media_player import MediaPlayerDevice
from homeassistant.components.media_player.const import (
MEDIA_TYPE_MOVIE, SUPPORT_NEXT_TRACK, SUPPORT_PLAY,
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,
STATE_PLAYING)
STATE_PLAYING, STATE_OFF)
DEFAULT_PORT = 8060
@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
SUPPORT_ROKU = SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK |\
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(
@ -41,11 +41,13 @@ class RokuDevice(MediaPlayerDevice):
self.channels = []
self.current_app = None
self._device_info = {}
self._power_state = "Unknown"
def update(self):
"""Retrieve latest state."""
try:
self._device_info = self.roku.device_info
self._power_state = self.roku.power_state
self.ip_address = self.roku.host
self.channels = self.get_source_list()
@ -69,13 +71,16 @@ class RokuDevice(MediaPlayerDevice):
@property
def name(self):
"""Return the name of the device."""
if self._device_info.userdevicename:
return self._device_info.userdevicename
return "Roku {}".format(self._device_info.sernum)
if self._device_info.user_device_name:
return self._device_info.user_device_name
return "Roku {}".format(self._device_info.serial_num)
@property
def state(self):
"""Return the state of the device."""
if self._power_state == "Off":
return STATE_OFF
if self.current_app is None:
return None
@ -97,7 +102,7 @@ class RokuDevice(MediaPlayerDevice):
@property
def unique_id(self):
"""Return a unique, HASS-friendly identifier for this entity."""
return self._device_info.sernum
return self._device_info.serial_num
@property
def media_content_type(self):
@ -148,6 +153,14 @@ class RokuDevice(MediaPlayerDevice):
"""List of available input sources."""
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):
"""Send play/pause command."""
if self.current_app is not None:

View File

@ -36,14 +36,14 @@ class RokuRemote(remote.RemoteDevice):
@property
def name(self):
"""Return the name of the device."""
if self._device_info.userdevicename:
return self._device_info.userdevicename
return "Roku {}".format(self._device_info.sernum)
if self._device_info.user_device_name:
return self._device_info.user_device_name
return "Roku {}".format(self._device_info.serial_num)
@property
def unique_id(self):
"""Return a unique ID."""
return self._device_info.sernum
return self._device_info.serial_num
@property
def is_on(self):

View File

@ -1494,9 +1494,6 @@ python-qbittorrent==0.3.1
# homeassistant.components.ripple
python-ripple-api==0.0.3
# homeassistant.components.roku
python-roku==3.1.5
# homeassistant.components.sochain
python-sochain-api==0.0.2
@ -1642,6 +1639,9 @@ rjpl==0.3.5
# homeassistant.components.rocketchat
rocketchat-API==0.6.1
# homeassistant.components.roku
roku==3.0.0
# homeassistant.components.roomba
roombapy==1.3.1