From b4c8d10dbcbdb8d8ccb6f1dcb227ba6378f321d1 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sun, 4 Sep 2016 18:32:12 +0200 Subject: [PATCH] Migrate to voluptuous (#3179) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐬 --- homeassistant/components/sensor/torque.py | 38 ++++++++++++++++------- homeassistant/const.py | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/sensor/torque.py b/homeassistant/components/sensor/torque.py index 55c6aef31d0..c05217692ac 100644 --- a/homeassistant/components/sensor/torque.py +++ b/homeassistant/components/sensor/torque.py @@ -4,19 +4,28 @@ Support for the Torque OBD application. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.torque/ """ - +import logging import re -from homeassistant.helpers.entity import Entity -from homeassistant.components.http import HomeAssistantView +import voluptuous as vol -DOMAIN = 'torque' -DEPENDENCIES = ['http'] -SENSOR_EMAIL_FIELD = 'eml' -DEFAULT_NAME = 'vehicle' -ENTITY_NAME_FORMAT = '{0} {1}' +from homeassistant.components.http import HomeAssistantView +from homeassistant.components.sensor import PLATFORM_SCHEMA +from homeassistant.const import (CONF_EMAIL, CONF_NAME) +from homeassistant.helpers.entity import Entity +import homeassistant.helpers.config_validation as cv + +_LOGGER = logging.getLogger(__name__) API_PATH = '/api/torque' + +DEFAULT_NAME = 'vehicle' +DEPENDENCIES = ['http'] +DOMAIN = 'torque' + +ENTITY_NAME_FORMAT = '{0} {1}' + +SENSOR_EMAIL_FIELD = 'eml' SENSOR_NAME_KEY = r'userFullName(\w+)' SENSOR_UNIT_KEY = r'userUnit(\w+)' SENSOR_VALUE_KEY = r'k(\w+)' @@ -25,6 +34,11 @@ NAME_KEY = re.compile(SENSOR_NAME_KEY) UNIT_KEY = re.compile(SENSOR_UNIT_KEY) VALUE_KEY = re.compile(SENSOR_VALUE_KEY) +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_EMAIL): cv.string, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, +}) + def decode(value): """Double-decode required.""" @@ -39,12 +53,12 @@ def convert_pid(value): # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """Setup Torque platform.""" - vehicle = config.get('name', DEFAULT_NAME) - email = config.get('email', None) + vehicle = config.get(CONF_NAME) + email = config.get(CONF_EMAIL) sensors = {} - hass.wsgi.register_view(TorqueReceiveDataView(hass, email, vehicle, - sensors, add_devices)) + hass.wsgi.register_view(TorqueReceiveDataView( + hass, email, vehicle, sensors, add_devices)) return True diff --git a/homeassistant/const.py b/homeassistant/const.py index ce0d829e76b..311c1a5f166 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -44,6 +44,7 @@ CONF_DISARM_AFTER_TRIGGER = 'disarm_after_trigger' CONF_DISCOVERY = 'discovery' CONF_DISPLAY_OPTIONS = 'display_options' CONF_ELEVATION = 'elevation' +CONF_EMAIL = 'email' CONF_ENTITY_ID = 'entity_id' CONF_ENTITY_NAMESPACE = 'entity_namespace' CONF_EVENT = 'event'