From b6da4a53d5e6f3712b0187db163118b7777ae9b2 Mon Sep 17 00:00:00 2001 From: Fabian Affolter <mail@fabian-affolter.ch> Date: Mon, 22 Aug 2016 11:28:58 +0200 Subject: [PATCH] Use voluptuous for dweet and arduino (#2926) * Migrate to voluptuous * Migrate to voluptuous * One import is enough --- homeassistant/components/arduino.py | 25 ++++++++++++++++--------- homeassistant/components/dweet.py | 22 ++++++++++------------ homeassistant/const.py | 7 +++++++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/arduino.py b/homeassistant/components/arduino.py index 0a981940842..85431eb2753 100644 --- a/homeassistant/components/arduino.py +++ b/homeassistant/components/arduino.py @@ -6,27 +6,34 @@ https://home-assistant.io/components/arduino/ """ import logging +import voluptuous as vol + from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP) -from homeassistant.helpers import validate_config +from homeassistant.const import CONF_PORT +import homeassistant.helpers.config_validation as cv -DOMAIN = "arduino" REQUIREMENTS = ['PyMata==2.12'] -BOARD = None + _LOGGER = logging.getLogger(__name__) +BOARD = None + +DOMAIN = 'arduino' + +CONFIG_SCHEMA = vol.Schema({ + DOMAIN: vol.Schema({ + vol.Required(CONF_PORT): cv.string, + }), +}) + def setup(hass, config): """Setup the Arduino component.""" - if not validate_config(config, - {DOMAIN: ['port']}, - _LOGGER): - return False - import serial global BOARD try: - BOARD = ArduinoBoard(config[DOMAIN]['port']) + BOARD = ArduinoBoard(config[DOMAIN][CONF_PORT]) except (serial.serialutil.SerialException, FileNotFoundError): _LOGGER.exception("Your port is not accessible.") return False diff --git a/homeassistant/components/dweet.py b/homeassistant/components/dweet.py index 49c1e74f232..9a17a7aeea3 100644 --- a/homeassistant/components/dweet.py +++ b/homeassistant/components/dweet.py @@ -6,40 +6,38 @@ https://home-assistant.io/components/dweet/ """ import logging from datetime import timedelta + import voluptuous as vol -from homeassistant.const import EVENT_STATE_CHANGED, STATE_UNKNOWN +from homeassistant.const import ( + CONF_NAME, CONF_WHITELIST, EVENT_STATE_CHANGED, STATE_UNKNOWN) import homeassistant.helpers.config_validation as cv from homeassistant.helpers import state as state_helper from homeassistant.util import Throttle +REQUIREMENTS = ['dweepy==0.2.0'] _LOGGER = logging.getLogger(__name__) -DOMAIN = "dweet" -DEPENDENCIES = [] - -REQUIREMENTS = ['dweepy==0.2.0'] - -CONF_NAME = 'name' -CONF_WHITELIST = 'whitelist' +DOMAIN = 'dweet' MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=1) CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ vol.Required(CONF_NAME): cv.string, - vol.Required(CONF_WHITELIST): cv.string, + vol.Required(CONF_WHITELIST, default=[]): + vol.All(cv.ensure_list, [cv.entity_id]), }), -}, extra=vol.ALLOW_EXTRA) +}) # pylint: disable=too-many-locals def setup(hass, config): """Setup the Dweet.io component.""" conf = config[DOMAIN] - name = conf[CONF_NAME] - whitelist = conf.get(CONF_WHITELIST, []) + name = conf.get(CONF_NAME) + whitelist = conf.get(CONF_WHITELIST) json_body = {} def dweet_event_listener(event): diff --git a/homeassistant/const.py b/homeassistant/const.py index 13733d24e75..4bf1785fe7b 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -25,6 +25,7 @@ CONF_ALIAS = 'alias' CONF_API_KEY = 'api_key' CONF_BEFORE = 'before' CONF_BELOW = 'below' +CONF_BLACKLIST = 'blacklist' CONF_CODE = 'code' CONF_CONDITION = 'condition' CONF_CUSTOMIZE = 'customize' @@ -51,19 +52,25 @@ CONF_PAYLOAD = 'payload' CONF_PENDING_TIME = 'pending_time' CONF_PLATFORM = 'platform' CONF_PORT = 'port' +CONF_PREFIX = 'prefix' CONF_RESOURCE = 'resource' CONF_RESOURCES = 'resources' CONF_SCAN_INTERVAL = 'scan_interval' CONF_SENSOR_CLASS = 'sensor_class' +CONF_SSL = 'ssl' CONF_STATE = 'state' CONF_TEMPERATURE_UNIT = 'temperature_unit' CONF_TIME_ZONE = 'time_zone' +CONF_TOKEN = 'token' CONF_TRIGGER_TIME = 'trigger_time' CONF_UNIT_OF_MEASUREMENT = 'unit_of_measurement' CONF_UNIT_SYSTEM = 'unit_system' +CONF_URL = 'url' CONF_USERNAME = 'username' CONF_VALUE_TEMPLATE = 'value_template' +CONF_VERIFY_SSL = 'verify_ssl' CONF_WEEKDAY = 'weekday' +CONF_WHITELIST = 'whitelist' CONF_ZONE = 'zone' # #### EVENTS ####