mirror of
https://github.com/esphome/esphome.git
synced 2025-10-05 19:33:47 +01:00
add-black (#1593)
* Add black Update pre commit Update pre commit add empty line * Format with black
This commit is contained in:
committed by
GitHub
parent
2b60b0f1fa
commit
69879920eb
@@ -4,23 +4,23 @@ from esphome import automation
|
||||
from esphome.automation import maybe_simple_id
|
||||
from esphome.const import CONF_ID, CONF_MODE
|
||||
|
||||
CODEOWNERS = ['@esphome/core']
|
||||
script_ns = cg.esphome_ns.namespace('script')
|
||||
Script = script_ns.class_('Script', automation.Trigger.template())
|
||||
ScriptExecuteAction = script_ns.class_('ScriptExecuteAction', automation.Action)
|
||||
ScriptStopAction = script_ns.class_('ScriptStopAction', automation.Action)
|
||||
ScriptWaitAction = script_ns.class_('ScriptWaitAction', automation.Action, cg.Component)
|
||||
IsRunningCondition = script_ns.class_('IsRunningCondition', automation.Condition)
|
||||
SingleScript = script_ns.class_('SingleScript', Script)
|
||||
RestartScript = script_ns.class_('RestartScript', Script)
|
||||
QueueingScript = script_ns.class_('QueueingScript', Script, cg.Component)
|
||||
ParallelScript = script_ns.class_('ParallelScript', Script)
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
script_ns = cg.esphome_ns.namespace("script")
|
||||
Script = script_ns.class_("Script", automation.Trigger.template())
|
||||
ScriptExecuteAction = script_ns.class_("ScriptExecuteAction", automation.Action)
|
||||
ScriptStopAction = script_ns.class_("ScriptStopAction", automation.Action)
|
||||
ScriptWaitAction = script_ns.class_("ScriptWaitAction", automation.Action, cg.Component)
|
||||
IsRunningCondition = script_ns.class_("IsRunningCondition", automation.Condition)
|
||||
SingleScript = script_ns.class_("SingleScript", Script)
|
||||
RestartScript = script_ns.class_("RestartScript", Script)
|
||||
QueueingScript = script_ns.class_("QueueingScript", Script, cg.Component)
|
||||
ParallelScript = script_ns.class_("ParallelScript", Script)
|
||||
|
||||
CONF_SINGLE = 'single'
|
||||
CONF_RESTART = 'restart'
|
||||
CONF_QUEUED = 'queued'
|
||||
CONF_PARALLEL = 'parallel'
|
||||
CONF_MAX_RUNS = 'max_runs'
|
||||
CONF_SINGLE = "single"
|
||||
CONF_RESTART = "restart"
|
||||
CONF_QUEUED = "queued"
|
||||
CONF_PARALLEL = "parallel"
|
||||
CONF_MAX_RUNS = "max_runs"
|
||||
|
||||
SCRIPT_MODES = {
|
||||
CONF_SINGLE: SingleScript,
|
||||
@@ -34,8 +34,10 @@ def check_max_runs(value):
|
||||
if CONF_MAX_RUNS not in value:
|
||||
return value
|
||||
if value[CONF_MODE] not in [CONF_QUEUED, CONF_PARALLEL]:
|
||||
raise cv.Invalid("The option 'max_runs' is only valid in 'queue' and 'parallel' mode.",
|
||||
path=[CONF_MAX_RUNS])
|
||||
raise cv.Invalid(
|
||||
"The option 'max_runs' is only valid in 'queue' and 'parallel' mode.",
|
||||
path=[CONF_MAX_RUNS],
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
@@ -45,13 +47,18 @@ def assign_declare_id(value):
|
||||
return value
|
||||
|
||||
|
||||
CONFIG_SCHEMA = automation.validate_automation({
|
||||
# Don't declare id as cv.declare_id yet, because the ID type
|
||||
# dpeends on the mode. Will be checked later with assign_declare_id
|
||||
cv.Required(CONF_ID): cv.string_strict,
|
||||
cv.Optional(CONF_MODE, default=CONF_SINGLE): cv.one_of(*SCRIPT_MODES, lower=True),
|
||||
cv.Optional(CONF_MAX_RUNS): cv.positive_int,
|
||||
}, extra_validators=cv.All(check_max_runs, assign_declare_id))
|
||||
CONFIG_SCHEMA = automation.validate_automation(
|
||||
{
|
||||
# Don't declare id as cv.declare_id yet, because the ID type
|
||||
# dpeends on the mode. Will be checked later with assign_declare_id
|
||||
cv.Required(CONF_ID): cv.string_strict,
|
||||
cv.Optional(CONF_MODE, default=CONF_SINGLE): cv.one_of(
|
||||
*SCRIPT_MODES, lower=True
|
||||
),
|
||||
cv.Optional(CONF_MAX_RUNS): cv.positive_int,
|
||||
},
|
||||
extra_validators=cv.All(check_max_runs, assign_declare_id),
|
||||
)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
@@ -74,25 +81,35 @@ def to_code(config):
|
||||
yield automation.build_automation(trigger, [], conf)
|
||||
|
||||
|
||||
@automation.register_action('script.execute', ScriptExecuteAction, maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(Script),
|
||||
}))
|
||||
@automation.register_action(
|
||||
"script.execute",
|
||||
ScriptExecuteAction,
|
||||
maybe_simple_id(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(Script),
|
||||
}
|
||||
),
|
||||
)
|
||||
def script_execute_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action('script.stop', ScriptStopAction, maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(Script)
|
||||
}))
|
||||
@automation.register_action(
|
||||
"script.stop",
|
||||
ScriptStopAction,
|
||||
maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_stop_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action('script.wait', ScriptWaitAction, maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(Script)
|
||||
}))
|
||||
@automation.register_action(
|
||||
"script.wait",
|
||||
ScriptWaitAction,
|
||||
maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_wait_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
@@ -100,9 +117,11 @@ def script_wait_action_to_code(config, action_id, template_arg, args):
|
||||
yield var
|
||||
|
||||
|
||||
@automation.register_condition('script.is_running', IsRunningCondition, automation.maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(Script)
|
||||
}))
|
||||
@automation.register_condition(
|
||||
"script.is_running",
|
||||
IsRunningCondition,
|
||||
automation.maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_is_running_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
Reference in New Issue
Block a user