Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Panasonic Viera TV on without WOL #22084

Merged
merged 13 commits into from
Mar 25, 2019
Merged
20 changes: 15 additions & 5 deletions homeassistant/components/panasonic_viera/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
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 | \
Expand All @@ -37,6 +40,7 @@
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,
})


Expand All @@ -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)
dgomes marked this conversation as resolved.
Show resolved Hide resolved

if discovery_info:
_LOGGER.debug('%s', discovery_info)
Expand All @@ -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
Expand All @@ -86,6 +92,7 @@ def __init__(self, mac, name, remote, host, uuid=None):
self._remote = remote
self._host = host
self._volume = 0
self._app_power = app_power
dgomes marked this conversation as resolved.
Show resolved Hide resolved

@property
def unique_id(self) -> str:
Expand Down Expand Up @@ -134,7 +141,7 @@ def is_volume_muted(self):
@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

Expand All @@ -143,6 +150,9 @@ def turn_on(self):
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."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down