mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Moar Custom platforms
This commit is contained in:
35
esphome/components/template/output/__init__.py
Normal file
35
esphome/components/template/output/__init__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.components import output
|
||||
from esphome.const import CONF_ID, CONF_TYPE
|
||||
from .. import template_ns
|
||||
|
||||
TemplateBinaryOutput = template_ns.class_('TemplateBinaryOutput', output.BinaryOutput)
|
||||
TemplateFloatOutput = template_ns.class_('TemplateFloatOutput', output.FloatOutput)
|
||||
|
||||
CONF_BINARY = 'binary'
|
||||
CONF_FLOAT = 'float'
|
||||
CONF_WRITE_ACTION = 'write_action'
|
||||
|
||||
CONFIG_SCHEMA = cv.typed_schema({
|
||||
CONF_BINARY: output.BINARY_OUTPUT_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(TemplateBinaryOutput),
|
||||
cv.Required(CONF_WRITE_ACTION): automation.validate_automation(single=True),
|
||||
}),
|
||||
CONF_FLOAT: output.FLOAT_OUTPUT_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(TemplateFloatOutput),
|
||||
cv.Required(CONF_WRITE_ACTION): automation.validate_automation(single=True),
|
||||
}),
|
||||
}, lower=True)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
if config[CONF_TYPE] == CONF_BINARY:
|
||||
yield automation.build_automation(var.get_trigger(), [(bool, 'state')],
|
||||
config[CONF_WRITE_ACTION])
|
||||
else:
|
||||
yield automation.build_automation(var.get_trigger(), [(float, 'state')],
|
||||
config[CONF_WRITE_ACTION])
|
||||
yield output.register_output(var, config)
|
||||
31
esphome/components/template/output/template_output.h
Normal file
31
esphome/components/template/output/template_output.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/output/binary_output.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace template_ {
|
||||
|
||||
class TemplateBinaryOutput : public output::BinaryOutput {
|
||||
public:
|
||||
Trigger<bool> *get_trigger() const { return trigger_; }
|
||||
|
||||
protected:
|
||||
void write_state(bool state) override { this->trigger_->trigger(state); }
|
||||
|
||||
Trigger<bool> *trigger_ = new Trigger<bool>();
|
||||
};
|
||||
|
||||
class TemplateFloatOutput : public output::FloatOutput {
|
||||
public:
|
||||
Trigger<float> *get_trigger() const { return trigger_; }
|
||||
|
||||
protected:
|
||||
void write_state(float state) override { this->trigger_->trigger(state); }
|
||||
|
||||
Trigger<float> *trigger_ = new Trigger<float>();
|
||||
};
|
||||
|
||||
} // namespace template_
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user