diff --git a/homeassistant/components/media_player/panasonic_viera.py b/homeassistant/components/media_player/panasonic_viera.py index bbac8f243d3..b345fcf4884 100644 --- a/homeassistant/components/media_player/panasonic_viera.py +++ b/homeassistant/components/media_player/panasonic_viera.py @@ -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') diff --git a/requirements_all.txt b/requirements_all.txt index 81b6eef84a4..6bc661d6ba0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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