mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +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:
@@ -1,7 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_COMPONENT_ID, CONF_NAME, CONF_PAGE_ID, CONF_ID
|
||||
from esphome.const import CONF_COMPONENT_ID, CONF_PAGE_ID, CONF_ID
|
||||
from . import nextion_ns
|
||||
from .display import Nextion
|
||||
|
||||
@@ -11,18 +11,21 @@ CONF_NEXTION_ID = 'nextion_id'
|
||||
|
||||
NextionTouchComponent = nextion_ns.class_('NextionTouchComponent', binary_sensor.BinarySensor)
|
||||
|
||||
CONFIG_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(NextionTouchComponent),
|
||||
cv.GenerateID(CONF_NEXTION_ID): cv.use_variable_id(Nextion),
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(NextionTouchComponent),
|
||||
cv.GenerateID(CONF_NEXTION_ID): cv.use_id(Nextion),
|
||||
|
||||
cv.Required(CONF_PAGE_ID): cv.uint8_t,
|
||||
cv.Required(CONF_COMPONENT_ID): cv.uint8_t,
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
hub = yield cg.get_variable(config[CONF_NEXTION_ID])
|
||||
rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID],
|
||||
config[CONF_COMPONENT_ID])
|
||||
var = cg.Pvariable(config[CONF_ID], rhs)
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
|
||||
hub = yield cg.get_variable(config[CONF_NEXTION_ID])
|
||||
cg.add(hub.register_touch_component(var))
|
||||
|
||||
cg.add(var.set_component_id(config[CONF_COMPONENT_ID]))
|
||||
cg.add(var.set_page_id(config[CONF_PAGE_ID]))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import display, uart
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_UPDATE_INTERVAL
|
||||
from esphome.const import CONF_ID, CONF_LAMBDA
|
||||
from . import nextion_ns
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
@@ -11,9 +11,8 @@ Nextion = nextion_ns.class_('Nextion', cg.PollingComponent, uart.UARTDevice)
|
||||
NextionRef = Nextion.operator('ref')
|
||||
|
||||
CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(Nextion),
|
||||
cv.Optional(CONF_UPDATE_INTERVAL, default='5s'): cv.update_interval,
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
|
||||
cv.GenerateID(): cv.declare_id(Nextion),
|
||||
}).extend(cv.polling_component_schema('5s')).extend(uart.UART_DEVICE_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
|
||||
@@ -263,11 +263,6 @@ void Nextion::set_nextion_rtc_time(time::ESPTime time) {
|
||||
void Nextion::set_backlight_brightness(uint8_t brightness) { this->send_command_printf("dim=%u", brightness); }
|
||||
void Nextion::set_touch_sleep_timeout(uint16_t timeout) { this->send_command_printf("thsp=%u", timeout); }
|
||||
|
||||
NextionTouchComponent *Nextion::make_touch_component(const std::string &name, uint8_t page_id, uint8_t component_id) {
|
||||
auto *ret = new NextionTouchComponent(name, page_id, component_id);
|
||||
this->touch_.push_back(ret);
|
||||
return ret;
|
||||
}
|
||||
void Nextion::set_writer(const nextion_writer_t &writer) { this->writer_ = writer; }
|
||||
void Nextion::set_component_text_printf(const char *component, const char *format, ...) {
|
||||
va_list arg;
|
||||
@@ -285,8 +280,6 @@ void NextionTouchComponent::process(uint8_t page_id, uint8_t component_id, bool
|
||||
this->publish_state(on);
|
||||
}
|
||||
}
|
||||
NextionTouchComponent::NextionTouchComponent(const std::string &name, uint8_t page_id, uint8_t component_id)
|
||||
: BinarySensor(name), page_id_(page_id), component_id_(component_id) {}
|
||||
|
||||
} // namespace nextion
|
||||
} // namespace esphome
|
||||
|
||||
@@ -19,8 +19,6 @@ using nextion_writer_t = std::function<void(Nextion &)>;
|
||||
|
||||
class Nextion : public PollingComponent, public uart::UARTDevice {
|
||||
public:
|
||||
Nextion() : PollingComponent(0) {}
|
||||
|
||||
/**
|
||||
* Set the text of a component to a static string.
|
||||
* @param component The component name.
|
||||
@@ -189,7 +187,7 @@ class Nextion : public PollingComponent, public uart::UARTDevice {
|
||||
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
NextionTouchComponent *make_touch_component(const std::string &name, uint8_t page_id, uint8_t component_id);
|
||||
void register_touch_component(NextionTouchComponent *obj) { this->touch_.push_back(obj); }
|
||||
void setup() override;
|
||||
float get_setup_priority() const override;
|
||||
void update() override;
|
||||
@@ -222,7 +220,8 @@ class Nextion : public PollingComponent, public uart::UARTDevice {
|
||||
|
||||
class NextionTouchComponent : public binary_sensor::BinarySensor {
|
||||
public:
|
||||
NextionTouchComponent(const std::string &name, uint8_t page_id, uint8_t component_id);
|
||||
void set_page_id(uint8_t page_id) { page_id_ = page_id; }
|
||||
void set_component_id(uint8_t component_id) { component_id_ = component_id; }
|
||||
void process(uint8_t page_id, uint8_t component_id, bool on);
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user