Use voluptuous for RPi GPIO (#3371)
* Migrate to voluptuous * Remove the check for lists
This commit is contained in:
1 parent
2b7d1fe20d
commit
04d31e4ef4
4 files changed
+85
-40
No files matched your search
@@ -4,26 +4,43 @@ Allows to configure a switch using RPi GPIO.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/switch.rpi_gpio/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA
|
||||
import homeassistant.components.rpi_gpio as rpi_gpio
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['rpi_gpio']
|
||||
|
||||
CONF_PULL_MODE = 'pull_mode'
|
||||
CONF_PORTS = 'ports'
|
||||
CONF_INVERT_LOGIC = 'invert_logic'
|
||||
|
||||
DEFAULT_INVERT_LOGIC = False
|
||||
|
||||
DEPENDENCIES = ['rpi_gpio']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_SWITCHES_SCHEMA = vol.Schema({
|
||||
cv.positive_int: cv.string,
|
||||
})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_PORTS): _SWITCHES_SCHEMA,
|
||||
vol.Optional(CONF_INVERT_LOGIC, default=DEFAULT_INVERT_LOGIC): cv.boolean,
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Raspberry PI GPIO devices."""
|
||||
invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC)
|
||||
invert_logic = config.get(CONF_INVERT_LOGIC)
|
||||
|
||||
switches = []
|
||||
ports = config.get('ports')
|
||||
ports = config.get(CONF_PORTS)
|
||||
for port, name in ports.items():
|
||||
switches.append(RPiGPIOSwitch(name, port, invert_logic))
|
||||
add_devices(switches)
|
||||
|
||||
Reference in new issue
Block a user