mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Add support for waking up Samsung TVs over the network (#6114)
* Add support for waking up Samsung TVs over the network * Return the correct supported features for samsungtv * Update requirements_all
This commit is contained in:
parent
9f4a9585d2
commit
b7b1429ac7
@ -12,12 +12,13 @@ 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_STEP,
|
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
|
||||||
SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA)
|
SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA, SUPPORT_TURN_ON)
|
||||||
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,
|
||||||
|
CONF_MAC)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['samsungctl==0.6.0']
|
REQUIREMENTS = ['samsungctl==0.6.0', 'wakeonlan==0.2.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
port = config.get(CONF_PORT)
|
port = config.get(CONF_PORT)
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
mac = config.get(CONF_MAC)
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config.get(CONF_TIMEOUT)
|
||||||
elif discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
tv_name, model, host = discovery_info
|
tv_name, model, host = discovery_info
|
||||||
@ -70,7 +72,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
ip_addr = socket.gethostbyname(host)
|
ip_addr = socket.gethostbyname(host)
|
||||||
if ip_addr not in known_devices:
|
if ip_addr not in known_devices:
|
||||||
known_devices.add(ip_addr)
|
known_devices.add(ip_addr)
|
||||||
add_devices([SamsungTVDevice(host, port, name, timeout)])
|
add_devices([SamsungTVDevice(host, port, name, timeout, mac)])
|
||||||
_LOGGER.info("Samsung TV %s:%d added as '%s'", host, port, name)
|
_LOGGER.info("Samsung TV %s:%d added as '%s'", host, port, name)
|
||||||
else:
|
else:
|
||||||
_LOGGER.info("Ignoring duplicate Samsung TV %s:%d", host, port)
|
_LOGGER.info("Ignoring duplicate Samsung TV %s:%d", host, port)
|
||||||
@ -79,14 +81,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
class SamsungTVDevice(MediaPlayerDevice):
|
class SamsungTVDevice(MediaPlayerDevice):
|
||||||
"""Representation of a Samsung TV."""
|
"""Representation of a Samsung TV."""
|
||||||
|
|
||||||
def __init__(self, host, port, name, timeout):
|
def __init__(self, host, port, name, timeout, mac):
|
||||||
"""Initialize the Samsung device."""
|
"""Initialize the Samsung device."""
|
||||||
from samsungctl import exceptions
|
from samsungctl import exceptions
|
||||||
from samsungctl import Remote
|
from samsungctl import Remote
|
||||||
|
from wakeonlan import wol
|
||||||
# Save a reference to the imported classes
|
# Save a reference to the imported classes
|
||||||
self._exceptions_class = exceptions
|
self._exceptions_class = exceptions
|
||||||
self._remote_class = Remote
|
self._remote_class = Remote
|
||||||
self._name = name
|
self._name = name
|
||||||
|
self._mac = mac
|
||||||
|
self._wol = wol
|
||||||
# Assume that the TV is not muted
|
# Assume that the TV is not muted
|
||||||
self._muted = False
|
self._muted = False
|
||||||
# Assume that the TV is in Play mode
|
# Assume that the TV is in Play mode
|
||||||
@ -158,6 +163,8 @@ class SamsungTVDevice(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:
|
||||||
|
return SUPPORT_SAMSUNGTV | SUPPORT_TURN_ON
|
||||||
return SUPPORT_SAMSUNGTV
|
return SUPPORT_SAMSUNGTV
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
@ -208,4 +215,7 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
self.send_key('KEY_POWERON')
|
if self._mac:
|
||||||
|
self._wol.send_magic_packet(self._mac)
|
||||||
|
else:
|
||||||
|
self.send_key('KEY_POWERON')
|
||||||
|
@ -726,6 +726,7 @@ vsure==0.11.1
|
|||||||
vtjp==0.1.14
|
vtjp==0.1.14
|
||||||
|
|
||||||
# homeassistant.components.media_player.panasonic_viera
|
# homeassistant.components.media_player.panasonic_viera
|
||||||
|
# homeassistant.components.media_player.samsungtv
|
||||||
# homeassistant.components.media_player.webostv
|
# homeassistant.components.media_player.webostv
|
||||||
# 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