Config and service validation for shell_command component.
This commit is contained in:
parent
1deaf2fe8f
commit
d90f31bf6e
2 changed files with 28 additions and 26 deletions
|
@ -7,26 +7,26 @@ https://home-assistant.io/components/shell_command/
|
|||
import logging
|
||||
import subprocess
|
||||
|
||||
from homeassistant.util import slugify
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
DOMAIN = 'shell_command'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
cv.slug: cv.string,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
SHELL_COMMAND_SCHEMA = vol.Schema({})
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Setup the shell_command component."""
|
||||
conf = config.get(DOMAIN)
|
||||
|
||||
if not isinstance(conf, dict):
|
||||
_LOGGER.error('Expected configuration to be a dictionary')
|
||||
return False
|
||||
|
||||
for name in conf.keys():
|
||||
if name != slugify(name):
|
||||
_LOGGER.error('Invalid service name: %s. Try %s',
|
||||
name, slugify(name))
|
||||
return False
|
||||
conf = config.get(DOMAIN, {})
|
||||
|
||||
def service_handler(call):
|
||||
"""Execute a shell command service."""
|
||||
|
@ -38,6 +38,6 @@ def setup(hass, config):
|
|||
_LOGGER.exception('Error running command')
|
||||
|
||||
for name in conf.keys():
|
||||
hass.services.register(DOMAIN, name, service_handler)
|
||||
|
||||
hass.services.register(DOMAIN, name, service_handler,
|
||||
schema=SHELL_COMMAND_SCHEMA)
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue