From b199c61c8876e3c99153e0988d03ca6a3e5ff622 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Thu, 25 Aug 2016 06:36:41 +0200 Subject: [PATCH] Migrate to voluptuous (#2955) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐬 --- .../components/switch/wake_on_lan.py | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/switch/wake_on_lan.py b/homeassistant/components/switch/wake_on_lan.py index 779f4759442..0ecbd51a11b 100644 --- a/homeassistant/components/switch/wake_on_lan.py +++ b/homeassistant/components/switch/wake_on_lan.py @@ -8,27 +8,35 @@ import logging import platform import subprocess as sp -from homeassistant.components.switch import SwitchDevice +import voluptuous as vol + +from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) +import homeassistant.helpers.config_validation as cv +from homeassistant.const import (CONF_HOST, CONF_NAME) -_LOGGER = logging.getLogger(__name__) REQUIREMENTS = ['wakeonlan==0.2.2'] -DEFAULT_NAME = "Wake on LAN" +_LOGGER = logging.getLogger(__name__) + +CONF_MAC_ADDRESS = 'mac_address' + +DEFAULT_NAME = 'Wake on LAN' DEFAULT_PING_TIMEOUT = 1 +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_MAC_ADDRESS): cv.string, + vol.Optional(CONF_HOST): cv.string, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, +}) + def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Add wake on lan switch.""" - if config.get('mac_address') is None: - _LOGGER.error("Missing required variable: mac_address") - return False + name = config.get(CONF_NAME) + host = config.get(CONF_HOST) + mac_address = config.get(CONF_MAC_ADDRESS) - add_devices_callback([WOLSwitch( - hass, - config.get('name', DEFAULT_NAME), - config.get('host'), - config.get('mac_address'), - )]) + add_devices_callback([WOLSwitch(hass, name, host, mac_address)]) class WOLSwitch(SwitchDevice):