Migrate to voluptuous (#3737)

This commit is contained in:
Fabian Affolter 2016-10-11 09:56:57 +02:00 committed by Paulus Schoutsen
parent 0568ef025b
commit a99f36f519
2 changed files with 56 additions and 21 deletions

View file

@ -8,28 +8,44 @@ https://home-assistant.io/components/sensor.arduino/
"""
import logging
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
import homeassistant.components.arduino as arduino
from homeassistant.const import DEVICE_DEFAULT_NAME
from homeassistant.const import CONF_NAME
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
CONF_PINS = 'pins'
CONF_TYPE = 'analog'
DEPENDENCIES = ['arduino']
_LOGGER = logging.getLogger(__name__)
PIN_SCHEMA = vol.Schema({
vol.Required(CONF_NAME): cv.string,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_PINS):
vol.Schema({cv.positive_int: PIN_SCHEMA}),
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Arduino platform."""
"""Set up the Arduino platform."""
# Verify that the Arduino board is present
if arduino.BOARD is None:
_LOGGER.error('A connection has not been made to the Arduino board.')
_LOGGER.error("A connection has not been made to the Arduino board")
return False
pins = config.get(CONF_PINS)
sensors = []
pins = config.get('pins')
for pinnum, pin in pins.items():
if pin.get('name'):
sensors.append(ArduinoSensor(pin.get('name'),
pinnum,
'analog'))
sensors.append(ArduinoSensor(pin.get(CONF_NAME), pinnum, CONF_TYPE))
add_devices(sensors)
@ -39,7 +55,7 @@ class ArduinoSensor(Entity):
def __init__(self, name, pin, pin_type):
"""Initialize the sensor."""
self._pin = pin
self._name = name or DEVICE_DEFAULT_NAME
self._name = name
self.pin_type = pin_type
self.direction = 'in'
self._value = None