From aed59aea7da06eaadc3f5e247405ace3dd805756 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 5 Sep 2016 17:39:21 +0200 Subject: [PATCH] Migrate to voluptuous (#3193) --- .../components/media_player/directv.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/media_player/directv.py b/homeassistant/components/media_player/directv.py index 7a32f02dc56..0a53ffbbed6 100644 --- a/homeassistant/components/media_player/directv.py +++ b/homeassistant/components/media_player/directv.py @@ -1,14 +1,22 @@ -"""Support for the DirecTV recievers.""" +""" +Support for the DirecTV recievers. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/media_player.directv/ +""" +import voluptuous as vol from homeassistant.components.media_player import ( MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO, SUPPORT_PAUSE, SUPPORT_PLAY_MEDIA, - SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_STOP, + SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_STOP, PLATFORM_SCHEMA, SUPPORT_NEXT_TRACK, SUPPORT_PREVIOUS_TRACK, MediaPlayerDevice) from homeassistant.const import ( - CONF_HOST, CONF_NAME, STATE_OFF, STATE_PLAYING) + CONF_HOST, CONF_NAME, STATE_OFF, STATE_PLAYING, CONF_PORT) +import homeassistant.helpers.config_validation as cv REQUIREMENTS = ['directpy==0.1'] +DEFAULT_NAME = 'DirecTV Receiver' DEFAULT_PORT = 8080 SUPPORT_DTV = SUPPORT_PAUSE | SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \ @@ -17,6 +25,12 @@ SUPPORT_DTV = SUPPORT_PAUSE | SUPPORT_TURN_ON | SUPPORT_TURN_OFF | \ KNOWN_HOSTS = [] +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, +}) + def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the DirecTV platform.""" @@ -34,8 +48,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): elif CONF_HOST in config: hosts.append([ - config.get(CONF_NAME, 'DirecTV Receiver'), - config[CONF_HOST], DEFAULT_PORT + config.get(CONF_NAME), config.get(CONF_HOST), config.get(CONF_PORT) ]) dtvs = []