mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-29 17:28:28 +02:00
Cleanup dashboard JS (#491)
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.automation import ACTION_REGISTRY
|
||||
from esphome.components import switch
|
||||
from esphome.const import CONF_ASSUMED_STATE, CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \
|
||||
from esphome.const import CONF_ASSUMED_STATE, CONF_ID, CONF_LAMBDA, CONF_OPTIMISTIC, \
|
||||
CONF_RESTORE_STATE, CONF_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION
|
||||
from .. import template_ns
|
||||
|
||||
TemplateSwitch = template_ns.class_('TemplateSwitch', switch.Switch, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = cv.nameable(switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(TemplateSwitch),
|
||||
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(TemplateSwitch),
|
||||
cv.Optional(CONF_LAMBDA): cv.lambda_,
|
||||
cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean,
|
||||
cv.Optional(CONF_ASSUMED_STATE, default=False): cv.boolean,
|
||||
cv.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_RESTORE_STATE, default=False): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA))
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME])
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield switch.register_switch(var, config)
|
||||
|
||||
@@ -40,15 +39,13 @@ def to_code(config):
|
||||
cg.add(var.set_restore_state(config[CONF_RESTORE_STATE]))
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register('switch.template.publish', cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_variable_id(switch.Switch),
|
||||
@automation.register_action('switch.template.publish', switch.SwitchPublishAction, cv.Schema({
|
||||
cv.Required(CONF_ID): cv.use_id(switch.Switch),
|
||||
cv.Required(CONF_STATE): cv.templatable(cv.boolean),
|
||||
}))
|
||||
def switch_template_publish_to_code(config, action_id, template_arg, args):
|
||||
var = yield cg.get_variable(config[CONF_ID])
|
||||
type = switch.SwitchPublishAction.template(template_arg)
|
||||
rhs = type.new(var)
|
||||
action = cg.Pvariable(action_id, rhs, type=type)
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
template_ = yield cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(action.set_state(template_))
|
||||
yield action
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace template_ {
|
||||
|
||||
static const char *TAG = "template.switch";
|
||||
|
||||
TemplateSwitch::TemplateSwitch(const std::string &name)
|
||||
: switch_::Switch(name), Component(), turn_on_trigger_(new Trigger<>()), turn_off_trigger_(new Trigger<>()) {}
|
||||
TemplateSwitch::TemplateSwitch() : turn_on_trigger_(new Trigger<>()), turn_off_trigger_(new Trigger<>()) {}
|
||||
|
||||
void TemplateSwitch::loop() {
|
||||
if (!this->f_.has_value())
|
||||
return;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace template_ {
|
||||
|
||||
class TemplateSwitch : public switch_::Switch, public Component {
|
||||
public:
|
||||
explicit TemplateSwitch(const std::string &name);
|
||||
TemplateSwitch();
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
Reference in New Issue
Block a user