Turn Panasonic Viera TV on without WOL (#22084)
* Turn the TV on via remote * Turn the TV on via remote * Use turn_on() from panasonic-viera==0.3.2 * make power option configurable * add app_power as argument * formatting
This commit is contained in:
parent
7f940423ad
commit
adca598172
2 changed files with 16 additions and 6 deletions
|
@ -19,12 +19,15 @@ from homeassistant.const import (
|
|||
CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['panasonic_viera==0.3.1', 'wakeonlan==1.1.6']
|
||||
REQUIREMENTS = ['panasonic_viera==0.3.2', 'wakeonlan==1.1.6']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_APP_POWER = 'app_power'
|
||||
|
||||
DEFAULT_NAME = 'Panasonic Viera TV'
|
||||
DEFAULT_PORT = 55000
|
||||
DEFAULT_APP_POWER = False
|
||||
|
||||
SUPPORT_VIERATV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
||||
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||
|
@ -37,6 +40,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
vol.Optional(CONF_MAC): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_APP_POWER, default=DEFAULT_APP_POWER): cv.boolean,
|
||||
})
|
||||
|
||||
|
||||
|
@ -47,6 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
mac = config.get(CONF_MAC)
|
||||
name = config.get(CONF_NAME)
|
||||
port = config.get(CONF_PORT)
|
||||
app_power = config.get(CONF_APP_POWER)
|
||||
|
||||
if discovery_info:
|
||||
_LOGGER.debug('%s', discovery_info)
|
||||
|
@ -59,20 +64,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
else:
|
||||
uuid = None
|
||||
remote = RemoteControl(host, port)
|
||||
add_entities([PanasonicVieraTVDevice(mac, name, remote, host, uuid)])
|
||||
add_entities([PanasonicVieraTVDevice(
|
||||
mac, name, remote, host, app_power, uuid)])
|
||||
return True
|
||||
|
||||
host = config.get(CONF_HOST)
|
||||
remote = RemoteControl(host, port)
|
||||
|
||||
add_entities([PanasonicVieraTVDevice(mac, name, remote, host)])
|
||||
add_entities([PanasonicVieraTVDevice(mac, name, remote, host, app_power)])
|
||||
return True
|
||||
|
||||
|
||||
class PanasonicVieraTVDevice(MediaPlayerDevice):
|
||||
"""Representation of a Panasonic Viera TV."""
|
||||
|
||||
def __init__(self, mac, name, remote, host, uuid=None):
|
||||
def __init__(self, mac, name, remote, host, app_power, uuid=None):
|
||||
"""Initialize the Panasonic device."""
|
||||
import wakeonlan
|
||||
# Save a reference to the imported class
|
||||
|
@ -86,6 +92,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||
self._remote = remote
|
||||
self._host = host
|
||||
self._volume = 0
|
||||
self._app_power = app_power
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
|
@ -134,7 +141,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||
@property
|
||||
def supported_features(self):
|
||||
"""Flag media player features that are supported."""
|
||||
if self._mac:
|
||||
if self._mac or self._app_power:
|
||||
return SUPPORT_VIERATV | SUPPORT_TURN_ON
|
||||
return SUPPORT_VIERATV
|
||||
|
||||
|
@ -143,6 +150,9 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||
if self._mac:
|
||||
self._wol.send_magic_packet(self._mac, ip_address=self._host)
|
||||
self._state = STATE_ON
|
||||
elif self._app_power:
|
||||
self._remote.turn_on()
|
||||
self._state = STATE_ON
|
||||
|
||||
def turn_off(self):
|
||||
"""Turn off media player."""
|
||||
|
|
|
@ -802,7 +802,7 @@ paho-mqtt==1.4.0
|
|||
panacotta==0.1
|
||||
|
||||
# homeassistant.components.panasonic_viera.media_player
|
||||
panasonic_viera==0.3.1
|
||||
panasonic_viera==0.3.2
|
||||
|
||||
# homeassistant.components.dunehd.media_player
|
||||
pdunehd==1.3
|
||||
|
|
Loading…
Add table
Reference in a new issue