mirror of
https://github.com/home-assistant/core.git
synced 2025-11-12 20:40:18 +00:00
Config and service validation for shell_command component.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user