mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 15:12:21 +01: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:
@@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.components import mqtt
|
||||
from esphome.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_ON_VALUE, \
|
||||
CONF_TRIGGER_ID, CONF_MQTT_ID
|
||||
CONF_TRIGGER_ID, CONF_MQTT_ID, CONF_NAME
|
||||
from esphome.core import CORE, coroutine
|
||||
|
||||
IS_PLATFORM_COMPONENT = True
|
||||
@@ -14,22 +14,23 @@ TextSensor = text_sensor_ns.class_('TextSensor', cg.Nameable)
|
||||
TextSensorPtr = TextSensor.operator('ptr')
|
||||
|
||||
TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger',
|
||||
cg.Trigger.template(cg.std_string))
|
||||
TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction', cg.Action)
|
||||
automation.Trigger.template(cg.std_string))
|
||||
TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction', automation.Action)
|
||||
|
||||
icon = cv.icon
|
||||
|
||||
TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
|
||||
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_variable_id(mqtt.MQTTTextSensor),
|
||||
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_id(mqtt.MQTTTextSensor),
|
||||
cv.Optional(CONF_ICON): icon,
|
||||
cv.Optional(CONF_ON_VALUE): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(TextSensorStateTrigger),
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(TextSensorStateTrigger),
|
||||
}),
|
||||
})
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_text_sensor_core_(var, config):
|
||||
cg.add(var.set_name(config[CONF_NAME]))
|
||||
if CONF_INTERNAL in config:
|
||||
cg.add(var.set_internal(config[CONF_INTERNAL]))
|
||||
if CONF_ICON in config:
|
||||
|
@@ -18,10 +18,7 @@ template<typename... Ts> class TextSensorPublishAction : public Action<Ts...> {
|
||||
public:
|
||||
TextSensorPublishAction(TextSensor *sensor) : sensor_(sensor) {}
|
||||
TEMPLATABLE_VALUE(std::string, state)
|
||||
void play(Ts... x) override {
|
||||
this->sensor_->publish_state(this->state_.value(x...));
|
||||
this->play_next(x...);
|
||||
}
|
||||
void play(Ts... x) override { this->sensor_->publish_state(this->state_.value(x...)); }
|
||||
|
||||
protected:
|
||||
TextSensor *sensor_;
|
||||
|
@@ -19,8 +19,8 @@ namespace text_sensor {
|
||||
|
||||
class TextSensor : public Nameable {
|
||||
public:
|
||||
explicit TextSensor(const std::string &name);
|
||||
explicit TextSensor();
|
||||
explicit TextSensor(const std::string &name);
|
||||
|
||||
void publish_state(std::string state);
|
||||
|
||||
|
Reference in New Issue
Block a user