1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-07 05:42:20 +01:00
* Add black

Update pre commit

Update pre commit

add empty line

* Format with black
This commit is contained in:
Guillermo Ruffino
2021-03-07 16:03:16 -03:00
committed by GitHub
parent 2b60b0f1fa
commit 69879920eb
398 changed files with 21624 additions and 12644 deletions

View File

@@ -3,40 +3,58 @@ import esphome.config_validation as cv
from esphome import automation
from esphome.automation import Condition, maybe_simple_id
from esphome.components import mqtt
from esphome.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_INVERTED, CONF_ON_TURN_OFF, \
CONF_ON_TURN_ON, CONF_TRIGGER_ID, CONF_MQTT_ID, CONF_NAME
from esphome.const import (
CONF_ICON,
CONF_ID,
CONF_INTERNAL,
CONF_INVERTED,
CONF_ON_TURN_OFF,
CONF_ON_TURN_ON,
CONF_TRIGGER_ID,
CONF_MQTT_ID,
CONF_NAME,
)
from esphome.core import CORE, coroutine, coroutine_with_priority
CODEOWNERS = ['@esphome/core']
CODEOWNERS = ["@esphome/core"]
IS_PLATFORM_COMPONENT = True
switch_ns = cg.esphome_ns.namespace('switch_')
Switch = switch_ns.class_('Switch', cg.Nameable)
SwitchPtr = Switch.operator('ptr')
switch_ns = cg.esphome_ns.namespace("switch_")
Switch = switch_ns.class_("Switch", cg.Nameable)
SwitchPtr = Switch.operator("ptr")
ToggleAction = switch_ns.class_('ToggleAction', automation.Action)
TurnOffAction = switch_ns.class_('TurnOffAction', automation.Action)
TurnOnAction = switch_ns.class_('TurnOnAction', automation.Action)
SwitchPublishAction = switch_ns.class_('SwitchPublishAction', automation.Action)
ToggleAction = switch_ns.class_("ToggleAction", automation.Action)
TurnOffAction = switch_ns.class_("TurnOffAction", automation.Action)
TurnOnAction = switch_ns.class_("TurnOnAction", automation.Action)
SwitchPublishAction = switch_ns.class_("SwitchPublishAction", automation.Action)
SwitchCondition = switch_ns.class_('SwitchCondition', Condition)
SwitchTurnOnTrigger = switch_ns.class_('SwitchTurnOnTrigger', automation.Trigger.template())
SwitchTurnOffTrigger = switch_ns.class_('SwitchTurnOffTrigger', automation.Trigger.template())
SwitchCondition = switch_ns.class_("SwitchCondition", Condition)
SwitchTurnOnTrigger = switch_ns.class_(
"SwitchTurnOnTrigger", automation.Trigger.template()
)
SwitchTurnOffTrigger = switch_ns.class_(
"SwitchTurnOffTrigger", automation.Trigger.template()
)
icon = cv.icon
SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_id(mqtt.MQTTSwitchComponent),
cv.Optional(CONF_ICON): icon,
cv.Optional(CONF_INVERTED): cv.boolean,
cv.Optional(CONF_ON_TURN_ON): automation.validate_automation({
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOnTrigger),
}),
cv.Optional(CONF_ON_TURN_OFF): automation.validate_automation({
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOffTrigger),
}),
})
SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend(
{
cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSwitchComponent),
cv.Optional(CONF_ICON): icon,
cv.Optional(CONF_INVERTED): cv.boolean,
cv.Optional(CONF_ON_TURN_ON): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOnTrigger),
}
),
cv.Optional(CONF_ON_TURN_OFF): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SwitchTurnOffTrigger),
}
),
}
)
@coroutine
@@ -68,26 +86,28 @@ def register_switch(var, config):
yield setup_switch_core_(var, config)
SWITCH_ACTION_SCHEMA = maybe_simple_id({
cv.Required(CONF_ID): cv.use_id(Switch),
})
SWITCH_ACTION_SCHEMA = maybe_simple_id(
{
cv.Required(CONF_ID): cv.use_id(Switch),
}
)
@automation.register_action('switch.toggle', ToggleAction, SWITCH_ACTION_SCHEMA)
@automation.register_action('switch.turn_off', TurnOffAction, SWITCH_ACTION_SCHEMA)
@automation.register_action('switch.turn_on', TurnOnAction, SWITCH_ACTION_SCHEMA)
@automation.register_action("switch.toggle", ToggleAction, SWITCH_ACTION_SCHEMA)
@automation.register_action("switch.turn_off", TurnOffAction, SWITCH_ACTION_SCHEMA)
@automation.register_action("switch.turn_on", TurnOnAction, SWITCH_ACTION_SCHEMA)
def switch_toggle_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_condition('switch.is_on', SwitchCondition, SWITCH_ACTION_SCHEMA)
@automation.register_condition("switch.is_on", SwitchCondition, SWITCH_ACTION_SCHEMA)
def switch_is_on_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, True)
@automation.register_condition('switch.is_off', SwitchCondition, SWITCH_ACTION_SCHEMA)
@automation.register_condition("switch.is_off", SwitchCondition, SWITCH_ACTION_SCHEMA)
def switch_is_off_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, False)
@@ -96,4 +116,4 @@ def switch_is_off_to_code(config, condition_id, template_arg, args):
@coroutine_with_priority(100.0)
def to_code(config):
cg.add_global(switch_ns.using)
cg.add_define('USE_SWITCH')
cg.add_define("USE_SWITCH")