Use Wake-on-LAN to turn on Panasonic Viera TV (#4809)
This commit is contained in:
parent
b318a033bb
commit
32dc518971
2 changed files with 22 additions and 5 deletions
|
@ -10,16 +10,20 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.media_player import (
|
||||
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
|
||||
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||
SUPPORT_TURN_ON, SUPPORT_TURN_OFF,
|
||||
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP, MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['panasonic_viera==0.2']
|
||||
REQUIREMENTS = ['panasonic_viera==0.2',
|
||||
'wakeonlan==0.2.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_MAC = 'mac'
|
||||
|
||||
DEFAULT_NAME = 'Panasonic Viera TV'
|
||||
DEFAULT_PORT = 55000
|
||||
|
||||
|
@ -30,6 +34,7 @@ SUPPORT_VIERATV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
|||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_MAC): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
})
|
||||
|
@ -40,6 +45,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
"""Setup the Panasonic Viera TV platform."""
|
||||
from panasonic_viera import RemoteControl
|
||||
|
||||
mac = config.get(CONF_MAC)
|
||||
name = config.get(CONF_NAME)
|
||||
port = config.get(CONF_PORT)
|
||||
|
||||
|
@ -51,22 +57,25 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
host = vals[0]
|
||||
remote = RemoteControl(host, port)
|
||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
||||
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
||||
return True
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
remote = RemoteControl(host, port)
|
||||
|
||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
||||
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
||||
return True
|
||||
|
||||
|
||||
class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
"""Representation of a Panasonic Viera TV."""
|
||||
|
||||
def __init__(self, name, remote):
|
||||
def __init__(self, mac, name, remote):
|
||||
"""Initialize the Panasonic device."""
|
||||
from wakeonlan import wol
|
||||
# Save a reference to the imported class
|
||||
self._wol = wol
|
||||
self._mac = mac
|
||||
self._name = name
|
||||
self._muted = False
|
||||
self._playing = True
|
||||
|
@ -116,8 +125,15 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def supported_media_commands(self):
|
||||
"""Flag of media commands that are supported."""
|
||||
if self._mac:
|
||||
return SUPPORT_VIERATV | SUPPORT_TURN_ON
|
||||
return SUPPORT_VIERATV
|
||||
|
||||
def turn_on(self):
|
||||
"""Turn on the media player."""
|
||||
if self._mac:
|
||||
self._wol.send_magic_packet(self._mac)
|
||||
|
||||
def turn_off(self):
|
||||
"""Turn off media player."""
|
||||
self.send_key('NRC_POWER-ONOFF')
|
||||
|
|
|
@ -604,6 +604,7 @@ vsure==0.11.1
|
|||
# homeassistant.components.sensor.vasttrafik
|
||||
vtjp==0.1.11
|
||||
|
||||
# homeassistant.components.media_player.panasonic_viera
|
||||
# homeassistant.components.switch.wake_on_lan
|
||||
wakeonlan==0.2.2
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue