mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
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
@ -19,12 +19,15 @@ from homeassistant.const import (
|
|||||||
CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON)
|
CONF_HOST, CONF_MAC, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON)
|
||||||
import homeassistant.helpers.config_validation as cv
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_APP_POWER = 'app_power'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Panasonic Viera TV'
|
DEFAULT_NAME = 'Panasonic Viera TV'
|
||||||
DEFAULT_PORT = 55000
|
DEFAULT_PORT = 55000
|
||||||
|
DEFAULT_APP_POWER = False
|
||||||
|
|
||||||
SUPPORT_VIERATV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
SUPPORT_VIERATV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
||||||
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
@ -37,6 +40,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_MAC): 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,
|
||||||
|
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)
|
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)
|
||||||
|
app_power = config.get(CONF_APP_POWER)
|
||||||
|
|
||||||
if discovery_info:
|
if discovery_info:
|
||||||
_LOGGER.debug('%s', discovery_info)
|
_LOGGER.debug('%s', discovery_info)
|
||||||
@ -59,20 +64,21 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
else:
|
else:
|
||||||
uuid = None
|
uuid = None
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
add_entities([PanasonicVieraTVDevice(mac, name, remote, host, uuid)])
|
add_entities([PanasonicVieraTVDevice(
|
||||||
|
mac, name, remote, host, app_power, uuid)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
|
|
||||||
add_entities([PanasonicVieraTVDevice(mac, name, remote, host)])
|
add_entities([PanasonicVieraTVDevice(mac, name, remote, host, app_power)])
|
||||||
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, mac, name, remote, host, uuid=None):
|
def __init__(self, mac, name, remote, host, app_power, uuid=None):
|
||||||
"""Initialize the Panasonic device."""
|
"""Initialize the Panasonic device."""
|
||||||
import wakeonlan
|
import wakeonlan
|
||||||
# Save a reference to the imported class
|
# Save a reference to the imported class
|
||||||
@ -86,6 +92,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||||||
self._remote = remote
|
self._remote = remote
|
||||||
self._host = host
|
self._host = host
|
||||||
self._volume = 0
|
self._volume = 0
|
||||||
|
self._app_power = app_power
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -134,7 +141,7 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
"""Flag media player features that are supported."""
|
"""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 | SUPPORT_TURN_ON
|
||||||
return SUPPORT_VIERATV
|
return SUPPORT_VIERATV
|
||||||
|
|
||||||
@ -143,6 +150,9 @@ class PanasonicVieraTVDevice(MediaPlayerDevice):
|
|||||||
if self._mac:
|
if self._mac:
|
||||||
self._wol.send_magic_packet(self._mac, ip_address=self._host)
|
self._wol.send_magic_packet(self._mac, ip_address=self._host)
|
||||||
self._state = STATE_ON
|
self._state = STATE_ON
|
||||||
|
elif self._app_power:
|
||||||
|
self._remote.turn_on()
|
||||||
|
self._state = STATE_ON
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
|
@ -802,7 +802,7 @@ paho-mqtt==1.4.0
|
|||||||
panacotta==0.1
|
panacotta==0.1
|
||||||
|
|
||||||
# homeassistant.components.panasonic_viera.media_player
|
# homeassistant.components.panasonic_viera.media_player
|
||||||
panasonic_viera==0.3.1
|
panasonic_viera==0.3.2
|
||||||
|
|
||||||
# homeassistant.components.dunehd.media_player
|
# homeassistant.components.dunehd.media_player
|
||||||
pdunehd==1.3
|
pdunehd==1.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user