mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Migrate to voluptuous (#3214)
This commit is contained in:
parent
6b787ee01e
commit
ea1e4ea215
@ -7,44 +7,51 @@ https://home-assistant.io/components/media_player.samsungtv/
|
|||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
import voluptuous as vol
|
||||||
DOMAIN, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
|
|
||||||
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
|
|
||||||
MediaPlayerDevice)
|
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
|
|
||||||
from homeassistant.helpers import validate_config
|
|
||||||
|
|
||||||
CONF_PORT = "port"
|
from homeassistant.components.media_player import (
|
||||||
CONF_TIMEOUT = "timeout"
|
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
|
||||||
|
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
|
||||||
|
MediaPlayerDevice, PLATFORM_SCHEMA)
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN, CONF_PORT)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
REQUIREMENTS = ['samsungctl==0.5.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['samsungctl==0.5.1']
|
CONF_TIMEOUT = 'timeout'
|
||||||
|
|
||||||
|
DEFAULT_NAME = 'Samsung TV Remote'
|
||||||
|
DEFAULT_PORT = 55000
|
||||||
|
DEFAULT_TIMEOUT = 0
|
||||||
|
|
||||||
SUPPORT_SAMSUNGTV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
SUPPORT_SAMSUNGTV = SUPPORT_PAUSE | SUPPORT_VOLUME_STEP | \
|
||||||
SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | \
|
SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | \
|
||||||
SUPPORT_NEXT_TRACK | SUPPORT_TURN_OFF
|
SUPPORT_NEXT_TRACK | SUPPORT_TURN_OFF
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
|
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Samsung TV platform."""
|
"""Setup the Samsung TV platform."""
|
||||||
# Validate that all required config options are given
|
name = config.get(CONF_NAME)
|
||||||
if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_HOST]}, _LOGGER):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Default the entity_name to 'Samsung TV Remote'
|
# Generate a configuration for the Samsung library
|
||||||
name = config.get(CONF_NAME, 'Samsung TV Remote')
|
|
||||||
|
|
||||||
# Generate a config for the Samsung lib
|
|
||||||
remote_config = {
|
remote_config = {
|
||||||
"name": "HomeAssistant",
|
'name': 'HomeAssistant',
|
||||||
"description": config.get(CONF_NAME, ''),
|
'description': config.get(CONF_NAME),
|
||||||
"id": "ha.component.samsung",
|
'id': 'ha.component.samsung',
|
||||||
"port": config.get(CONF_PORT, 55000),
|
'port': config.get(CONF_PORT),
|
||||||
"host": config.get(CONF_HOST),
|
'host': config.get(CONF_HOST),
|
||||||
"timeout": config.get(CONF_TIMEOUT, 0),
|
'timeout': config.get(CONF_TIMEOUT),
|
||||||
}
|
}
|
||||||
|
|
||||||
add_devices([SamsungTVDevice(name, remote_config)])
|
add_devices([SamsungTVDevice(name, remote_config)])
|
||||||
@ -56,7 +63,7 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
def __init__(self, name, config):
|
def __init__(self, name, config):
|
||||||
"""Initialize the samsung device."""
|
"""Initialize the Samsung device."""
|
||||||
from samsungctl import Remote
|
from samsungctl import Remote
|
||||||
# Save a reference to the imported class
|
# Save a reference to the imported class
|
||||||
self._remote_class = Remote
|
self._remote_class = Remote
|
||||||
@ -124,19 +131,19 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off media player."""
|
"""Turn off media player."""
|
||||||
self.send_key("KEY_POWEROFF")
|
self.send_key('KEY_POWEROFF')
|
||||||
|
|
||||||
def volume_up(self):
|
def volume_up(self):
|
||||||
"""Volume up the media player."""
|
"""Volume up the media player."""
|
||||||
self.send_key("KEY_VOLUP")
|
self.send_key('KEY_VOLUP')
|
||||||
|
|
||||||
def volume_down(self):
|
def volume_down(self):
|
||||||
"""Volume down media player."""
|
"""Volume down media player."""
|
||||||
self.send_key("KEY_VOLDOWN")
|
self.send_key('KEY_VOLDOWN')
|
||||||
|
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
self.send_key("KEY_MUTE")
|
self.send_key('KEY_MUTE')
|
||||||
|
|
||||||
def media_play_pause(self):
|
def media_play_pause(self):
|
||||||
"""Simulate play pause media player."""
|
"""Simulate play pause media player."""
|
||||||
@ -148,21 +155,21 @@ class SamsungTVDevice(MediaPlayerDevice):
|
|||||||
def media_play(self):
|
def media_play(self):
|
||||||
"""Send play command."""
|
"""Send play command."""
|
||||||
self._playing = True
|
self._playing = True
|
||||||
self.send_key("KEY_PLAY")
|
self.send_key('KEY_PLAY')
|
||||||
|
|
||||||
def media_pause(self):
|
def media_pause(self):
|
||||||
"""Send media pause command to media player."""
|
"""Send media pause command to media player."""
|
||||||
self._playing = False
|
self._playing = False
|
||||||
self.send_key("KEY_PAUSE")
|
self.send_key('KEY_PAUSE')
|
||||||
|
|
||||||
def media_next_track(self):
|
def media_next_track(self):
|
||||||
"""Send next track command."""
|
"""Send next track command."""
|
||||||
self.send_key("KEY_FF")
|
self.send_key('KEY_FF')
|
||||||
|
|
||||||
def media_previous_track(self):
|
def media_previous_track(self):
|
||||||
"""Send the previous track command."""
|
"""Send the previous track command."""
|
||||||
self.send_key("KEY_REWIND")
|
self.send_key('KEY_REWIND')
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
self.send_key("KEY_POWERON")
|
self.send_key('KEY_POWERON')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user