mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00: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:
@@ -2,20 +2,21 @@ import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_ID, CONF_NAME, CONF_PIN
|
||||
from esphome.const import CONF_ID, CONF_PIN
|
||||
from .. import gpio_ns
|
||||
|
||||
GPIOBinarySensor = gpio_ns.class_('GPIOBinarySensor', binary_sensor.BinarySensor, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(GPIOBinarySensor),
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(GPIOBinarySensor),
|
||||
cv.Required(CONF_PIN): pins.gpio_input_pin_schema
|
||||
}).extend(cv.COMPONENT_SCHEMA))
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
|
||||
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
|
||||
rhs = GPIOBinarySensor.new(config[CONF_NAME], pin)
|
||||
gpio = cg.Pvariable(config[CONF_ID], rhs)
|
||||
yield cg.register_component(gpio, config)
|
||||
yield binary_sensor.register_binary_sensor(gpio, config)
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
@@ -19,8 +19,6 @@ void GPIOBinarySensor::dump_config() {
|
||||
void GPIOBinarySensor::loop() { this->publish_state(this->pin_->digital_read()); }
|
||||
|
||||
float GPIOBinarySensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
GPIOBinarySensor::GPIOBinarySensor(const std::string &name, GPIOPin *pin)
|
||||
: binary_sensor::BinarySensor(name), pin_(pin) {}
|
||||
|
||||
} // namespace gpio
|
||||
} // namespace esphome
|
||||
|
||||
@@ -8,8 +8,7 @@ namespace gpio {
|
||||
|
||||
class GPIOBinarySensor : public binary_sensor::BinarySensor, public Component {
|
||||
public:
|
||||
explicit GPIOBinarySensor(const std::string &name, GPIOPin *pin);
|
||||
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
/// Setup pin
|
||||
|
||||
@@ -9,13 +9,15 @@ GPIOBinaryOutput = gpio_ns.class_('GPIOBinaryOutput', output.BinaryOutput,
|
||||
cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = output.BINARY_OUTPUT_SCHEMA.extend({
|
||||
cv.Required(CONF_ID): cv.declare_variable_id(GPIOBinaryOutput),
|
||||
cv.Required(CONF_ID): cv.declare_id(GPIOBinaryOutput),
|
||||
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield output.register_output(var, config)
|
||||
yield cg.register_component(var, config)
|
||||
|
||||
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
|
||||
gpio = cg.new_Pvariable(config[CONF_ID], pin)
|
||||
yield output.register_output(gpio, config)
|
||||
yield cg.register_component(gpio, config)
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace gpio {
|
||||
|
||||
class GPIOBinaryOutput : public output::BinaryOutput, public Component {
|
||||
public:
|
||||
explicit GPIOBinaryOutput(GPIOPin *pin) : pin_(pin) {}
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
|
||||
void setup() override {
|
||||
this->turn_off();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import switch
|
||||
from esphome.const import CONF_ID, CONF_INTERLOCK, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE
|
||||
from esphome.const import CONF_ID, CONF_INTERLOCK, CONF_PIN, CONF_RESTORE_MODE
|
||||
from .. import gpio_ns
|
||||
|
||||
GPIOSwitch = gpio_ns.class_('GPIOSwitch', switch.Switch, cg.Component)
|
||||
@@ -15,27 +15,28 @@ RESTORE_MODES = {
|
||||
'ALWAYS_ON': GPIOSwitchRestoreMode.GPIO_SWITCH_ALWAYS_ON,
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.nameable(switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(GPIOSwitch),
|
||||
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(GPIOSwitch),
|
||||
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_RESTORE_MODE, default='RESTORE_DEFAULT_OFF'):
|
||||
cv.one_of(*RESTORE_MODES, upper=True, space='_'),
|
||||
cv.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_variable_id(switch.Switch)),
|
||||
}).extend(cv.COMPONENT_SCHEMA))
|
||||
cv.enum(RESTORE_MODES, upper=True, space='_'),
|
||||
cv.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_id(switch.Switch)),
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
|
||||
rhs = GPIOSwitch.new(config[CONF_NAME], pin)
|
||||
gpio = cg.Pvariable(config[CONF_ID], rhs)
|
||||
yield cg.register_component(gpio, config)
|
||||
yield switch.register_switch(gpio, config)
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield switch.register_switch(var, config)
|
||||
|
||||
cg.add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]]))
|
||||
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||
|
||||
if CONF_INTERLOCK in config:
|
||||
interlock = []
|
||||
for it in config[CONF_INTERLOCK]:
|
||||
lock = yield cg.get_variable(it)
|
||||
interlock.append(lock)
|
||||
cg.add(gpio.set_interlock(interlock))
|
||||
cg.add(var.set_interlock(interlock))
|
||||
|
||||
@@ -6,8 +6,6 @@ namespace gpio {
|
||||
|
||||
static const char *TAG = "switch.gpio";
|
||||
|
||||
GPIOSwitch::GPIOSwitch(const std::string &name, GPIOPin *pin) : Switch(name), Component(), pin_(pin) {}
|
||||
|
||||
float GPIOSwitch::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
void GPIOSwitch::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up GPIO Switch '%s'...", this->name_.c_str());
|
||||
|
||||
@@ -15,7 +15,7 @@ enum GPIOSwitchRestoreMode {
|
||||
|
||||
class GPIOSwitch : public switch_::Switch, public Component {
|
||||
public:
|
||||
GPIOSwitch(const std::string &name, GPIOPin *pin);
|
||||
void set_pin(GPIOPin *pin) { pin_ = pin; }
|
||||
|
||||
void set_restore_mode(GPIOSwitchRestoreMode restore_mode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user