Migrate to voluptuous (#3179)

🐬
This commit is contained in:
Fabian Affolter authored and Teagan Glenn committed 2016-09-04 10:32:12 -06:00
1 parent cd67368bb7
commit b4c8d10dbc
2 files changed
+27 -12

No files matched your search

+26 -12
View File
@@ -4,19 +4,28 @@ Support for the Torque OBD application.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.torque/ https://home-assistant.io/components/sensor.torque/
""" """
import logging
import re import re
from homeassistant.helpers.entity import Entity import voluptuous as vol
from homeassistant.components.http import HomeAssistantView
DOMAIN = 'torque' from homeassistant.components.http import HomeAssistantView
DEPENDENCIES = ['http'] from homeassistant.components.sensor import PLATFORM_SCHEMA
SENSOR_EMAIL_FIELD = 'eml' from homeassistant.const import (CONF_EMAIL, CONF_NAME)
DEFAULT_NAME = 'vehicle' from homeassistant.helpers.entity import Entity
ENTITY_NAME_FORMAT = '{0} {1}' import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
API_PATH = '/api/torque' 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_NAME_KEY = r'userFullName(\w+)'
SENSOR_UNIT_KEY = r'userUnit(\w+)' SENSOR_UNIT_KEY = r'userUnit(\w+)'
SENSOR_VALUE_KEY = r'k(\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) UNIT_KEY = re.compile(SENSOR_UNIT_KEY)
VALUE_KEY = re.compile(SENSOR_VALUE_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): def decode(value):
"""Double-decode required.""" """Double-decode required."""
@@ -39,12 +53,12 @@ def convert_pid(value):
# 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 Torque platform.""" """Setup Torque platform."""
vehicle = config.get('name', DEFAULT_NAME) vehicle = config.get(CONF_NAME)
email = config.get('email', None) email = config.get(CONF_EMAIL)
sensors = {} sensors = {}
hass.wsgi.register_view(TorqueReceiveDataView(hass, email, vehicle, hass.wsgi.register_view(TorqueReceiveDataView(
sensors, add_devices)) hass, email, vehicle, sensors, add_devices))
return True return True
+1
View File
@@ -44,6 +44,7 @@ CONF_DISARM_AFTER_TRIGGER = 'disarm_after_trigger'
CONF_DISCOVERY = 'discovery' CONF_DISCOVERY = 'discovery'
CONF_DISPLAY_OPTIONS = 'display_options' CONF_DISPLAY_OPTIONS = 'display_options'
CONF_ELEVATION = 'elevation' CONF_ELEVATION = 'elevation'
CONF_EMAIL = 'email'
CONF_ENTITY_ID = 'entity_id' CONF_ENTITY_ID = 'entity_id'
CONF_ENTITY_NAMESPACE = 'entity_namespace' CONF_ENTITY_NAMESPACE = 'entity_namespace'
CONF_EVENT = 'event' CONF_EVENT = 'event'