mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Migrate to voluptuous (#3207)
This commit is contained in:
parent
5059d8dde9
commit
95ea0c02b9
@ -7,33 +7,42 @@ https://home-assistant.io/components/media_player.panasonic_viera/
|
|||||||
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_SET,
|
|
||||||
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 (
|
||||||
|
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
|
||||||
|
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||||
|
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 = ['panasonic_viera==0.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['panasonic_viera==0.2']
|
DEFAULT_NAME = 'Panasonic Viera TV'
|
||||||
|
DEFAULT_PORT = 55000
|
||||||
|
|
||||||
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 | \
|
||||||
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \
|
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \
|
||||||
SUPPORT_TURN_OFF
|
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,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# 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 Panasonic Viera TV platform."""
|
"""Setup the Panasonic Viera TV platform."""
|
||||||
from panasonic_viera import DEFAULT_PORT, RemoteControl
|
from panasonic_viera import RemoteControl
|
||||||
|
|
||||||
name = config.get(CONF_NAME, 'Panasonic Viera TV')
|
name = config.get(CONF_NAME)
|
||||||
port = config.get(CONF_PORT, DEFAULT_PORT)
|
port = config.get(CONF_PORT)
|
||||||
|
|
||||||
if discovery_info:
|
if discovery_info:
|
||||||
_LOGGER.debug('%s', discovery_info)
|
_LOGGER.debug('%s', discovery_info)
|
||||||
@ -46,13 +55,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
add_devices([PanasonicVieraTVDevice(name, remote)])
|
add_devices([PanasonicVieraTVDevice(name, remote)])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Validate that all required config options are given
|
host = config.get(CONF_HOST)
|
||||||
if not validate_config({DOMAIN: config}, {DOMAIN: [CONF_HOST]}, _LOGGER):
|
|
||||||
return False
|
|
||||||
|
|
||||||
host = config.get(CONF_HOST, None)
|
|
||||||
|
|
||||||
remote = RemoteControl(host, port)
|
remote = RemoteControl(host, port)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote.get_mute()
|
remote.get_mute()
|
||||||
except (socket.timeout, TimeoutError, OSError):
|
except (socket.timeout, TimeoutError, OSError):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user