mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use Wake-on-LAN to turn on Panasonic Viera TV (#4809)
This commit is contained in:
parent
b318a033bb
commit
32dc518971
@ -10,16 +10,20 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
|
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)
|
SUPPORT_VOLUME_STEP, MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
|
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
|
||||||
import homeassistant.helpers.config_validation as cv
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_MAC = 'mac'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Panasonic Viera TV'
|
DEFAULT_NAME = 'Panasonic Viera TV'
|
||||||
DEFAULT_PORT = 55000
|
DEFAULT_PORT = 55000
|
||||||
|
|
||||||
@ -30,6 +34,7 @@ SUPPORT_VIERATV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
|||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Optional(CONF_MAC): cv.string,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
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."""
|
"""Setup the Panasonic Viera TV platform."""
|
||||||
from panasonic_viera import RemoteControl
|
from panasonic_viera import RemoteControl
|
||||||
|
|
||||||
|
mac = config.get(CONF_MAC)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
port = config.get(CONF_PORT)
|
port = config.get(CONF_PORT)
|
||||||
|
|
||||||
@ -51,22 +57,25 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
host = vals[0]
|
host = vals[0]
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
|
|
||||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
add_devices([PanasonicVieraTVDevice(mac, name, remote)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class PanasonicVieraTVDevice(MediaPlayerDevice):
|
class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||||
"""Representation of a Panasonic Viera TV."""
|
"""Representation of a Panasonic Viera TV."""
|
||||||
|
|
||||||
def __init__(self, name, remote):
|
def __init__(self, mac, name, remote):
|
||||||
"""Initialize the Panasonic device."""
|
"""Initialize the Panasonic device."""
|
||||||
|
from wakeonlan import wol
|
||||||
# Save a reference to the imported class
|
# Save a reference to the imported class
|
||||||
|
self._wol = wol
|
||||||
|
self._mac = mac
|
||||||
self._name = name
|
self._name = name
|
||||||
self._muted = False
|
self._muted = False
|
||||||
self._playing = True
|
self._playing = True
|
||||||
@ -116,8 +125,15 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def supported_media_commands(self):
|
def supported_media_commands(self):
|
||||||
"""Flag of media commands that are supported."""
|
"""Flag of media commands that are supported."""
|
||||||
|
if self._mac:
|
||||||
|
return SUPPORT_VIERATV | SUPPORT_TURN_ON
|
||||||
return SUPPORT_VIERATV
|
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):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
self.send_key('NRC_POWER-ONOFF')
|
self.send_key('NRC_POWER-ONOFF')
|
||||||
|
@ -604,6 +604,7 @@ vsure==0.11.1
|
|||||||
# homeassistant.components.sensor.vasttrafik
|
# homeassistant.components.sensor.vasttrafik
|
||||||
vtjp==0.1.11
|
vtjp==0.1.11
|
||||||
|
|
||||||
|
# homeassistant.components.media_player.panasonic_viera
|
||||||
# homeassistant.components.switch.wake_on_lan
|
# homeassistant.components.switch.wake_on_lan
|
||||||
wakeonlan==0.2.2
|
wakeonlan==0.2.2
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user