Use voluptuous for Command line platforms (#2968)
* Migrate to voluptuous * Fix pylint issues * Remove FIXME * Split setup test * Test with bootstrap * Remove lon and lat * Fix pylint issues
This commit is contained in:
1 parent
81628b01c2
commit
40c71b5d96
11 files changed
+199
-134
No files matched your search
@@ -7,30 +7,53 @@ https://home-assistant.io/components/switch.command_line/
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import CONF_VALUE_TEMPLATE
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (
|
||||
CONF_FRIENDLY_NAME, CONF_SWITCHES, CONF_VALUE_TEMPLATE, CONF_COMMAND_OFF,
|
||||
CONF_COMMAND_ON, CONF_COMMAND_STATE)
|
||||
from homeassistant.helpers import template
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SWITCH_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_COMMAND_OFF, default='true'): cv.string,
|
||||
vol.Optional(CONF_COMMAND_ON, default='true'): cv.string,
|
||||
vol.Optional(CONF_COMMAND_STATE): cv.string,
|
||||
vol.Optional(CONF_FRIENDLY_NAME): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_SWITCHES): vol.Schema({cv.slug: SWITCH_SCHEMA}),
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Find and return switches controlled by shell commands."""
|
||||
switches = config.get('switches', {})
|
||||
devices = []
|
||||
devices = config.get(CONF_SWITCHES, {})
|
||||
switches = []
|
||||
|
||||
for dev_name, properties in switches.items():
|
||||
devices.append(
|
||||
for device_name, device_config in devices.items():
|
||||
switches.append(
|
||||
CommandSwitch(
|
||||
hass,
|
||||
properties.get('name', dev_name),
|
||||
properties.get('oncmd', 'true'),
|
||||
properties.get('offcmd', 'true'),
|
||||
properties.get('statecmd', False),
|
||||
properties.get(CONF_VALUE_TEMPLATE, False)))
|
||||
device_config.get(CONF_FRIENDLY_NAME, device_name),
|
||||
device_config.get(CONF_COMMAND_ON),
|
||||
device_config.get(CONF_COMMAND_OFF),
|
||||
device_config.get(CONF_COMMAND_STATE),
|
||||
device_config.get(CONF_VALUE_TEMPLATE)
|
||||
)
|
||||
)
|
||||
|
||||
add_devices_callback(devices)
|
||||
if not switches:
|
||||
_LOGGER.error("No switches added")
|
||||
return False
|
||||
|
||||
add_devices(switches)
|
||||
|
||||
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
||||
Reference in new issue
Block a user