diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 3cf0157b..76880822 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -76,24 +76,44 @@ namespace esphome { this->show_display = false; ESP_LOGD(TAG, "display off"); + + for (auto *t : on_show_display_triggers_) + { + t->process(this->show_display); + } } void EHMTX::set_display_on() { this->show_display = true; ESP_LOGD(TAG, "display on"); + + for (auto *t : on_show_display_triggers_) + { + t->process(this->show_display); + } } void EHMTX::set_night_mode_off() { this->night_mode = false; ESP_LOGD(TAG, "night mode off"); + + for (auto *t : on_night_mode_triggers_) + { + t->process(this->night_mode); + } } void EHMTX::set_night_mode_on() { this->night_mode = true; ESP_LOGD(TAG, "night mode on"); + + for (auto *t : on_night_mode_triggers_) + { + t->process(this->night_mode); + } } void EHMTX::set_today_color(int r, int g, int b) @@ -1554,6 +1574,9 @@ namespace esphome { ESP_LOGCONFIG(TAG, "weekstart: sunday"); } + ESP_LOGCONFIG(TAG, "Weekdays: %s Count: %d", EHMTXv2_WEEKDAYTEXT, this->GetWeekdayCharCount()); + ESP_LOGCONFIG(TAG, "Display: %s", this->show_display ? "On" : "Off"); + ESP_LOGCONFIG(TAG, "Night mode: %s", this->night_mode ? "On" : "Off"); } void EHMTX::add_icon(EHMTX_Icon *icon) @@ -1563,7 +1586,6 @@ namespace esphome this->icon_count++; } - void EHMTX::draw_alarm() { if (this->display_alarm > 2) @@ -1691,4 +1713,14 @@ namespace esphome { this->trigger(); } + + void EHMTXShowDisplayTrigger::process(bool state) + { + this->trigger(state); + } + + void EHMTXNightModeTrigger::process(bool state) + { + this->trigger(state); + } } diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index 1f7c8f5a..88a86114 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -62,6 +62,8 @@ namespace esphome class EHMTXExpiredScreenTrigger; class EHMTXNextClockTrigger; class EHMTXStartRunningTrigger; + class EHMTXShowDisplayTrigger; + class EHMTXNightModeTrigger; class EHMTX : public PollingComponent, public api::CustomAPIDevice { @@ -79,6 +81,8 @@ namespace esphome std::vector on_next_clock_triggers_; std::vector on_start_running_triggers_; std::vector on_add_screen_triggers_; + std::vector on_show_display_triggers_; + std::vector on_night_mode_triggers_; EHMTX_queue *find_icon_queue_element(uint8_t icon); EHMTX_queue *find_mode_queue_element(uint8_t mode); EHMTX_queue *find_mode_icon_queue_element(uint8_t mode, std::string name); @@ -228,6 +232,8 @@ namespace esphome void add_on_expired_screen_trigger(EHMTXExpiredScreenTrigger *t) { this->on_expired_screen_triggers_.push_back(t); } void add_on_next_clock_trigger(EHMTXNextClockTrigger *t) { this->on_next_clock_triggers_.push_back(t); } void add_on_start_running_trigger(EHMTXStartRunningTrigger *t) { this->on_start_running_triggers_.push_back(t); } + void add_on_show_display_trigger(EHMTXShowDisplayTrigger *t) { this->on_show_display_triggers_.push_back(t); } + void add_on_night_mode_trigger(EHMTXNightModeTrigger *t) { this->on_night_mode_triggers_.push_back(t); } void update(); uint8_t get_brightness(); @@ -320,6 +326,20 @@ namespace esphome void process(); }; + class EHMTXShowDisplayTrigger : public Trigger + { + public: + explicit EHMTXShowDisplayTrigger(EHMTX *parent) { parent->add_on_show_display_trigger(this); } + void process(bool); + }; + + class EHMTXNightModeTrigger : public Trigger + { + public: + explicit EHMTXNightModeTrigger(EHMTX *parent) { parent->add_on_night_mode_trigger(this); } + void process(bool); + }; + class EHMTX_Icon : public animation::Animation { protected: diff --git a/components/ehmtxv2/__init__.py b/components/ehmtxv2/__init__.py index 539ecfa5..84769326 100644 --- a/components/ehmtxv2/__init__.py +++ b/components/ehmtxv2/__init__.py @@ -74,6 +74,14 @@ def rgb565_888(v565): "EHMTXAddScreenTrigger", automation.Trigger.template(cg.std_string) ) +ShowDisplayTrigger = ehmtx_ns.class_( + "EHMTXShowDisplayTrigger", automation.Trigger.template(cg.std_string) +) + +NightModeTrigger = ehmtx_ns.class_( + "EHMTXNightModeTrigger", automation.Trigger.template(cg.std_string) +) + CONF_URL = "url" CONF_CLOCKINTERVAL = "clock_interval" CONF_ALWAYS_SHOW_RLINDICATORS = "always_show_rl_indicators" @@ -108,6 +116,8 @@ def rgb565_888(v565): CONF_ON_NEXT_CLOCK = "on_next_clock" CONF_ON_ICON_ERROR = "on_icon_error" CONF_ON_ADD_SCREEN = "on_add_screen" +CONF_ON_SHOW_DISPLAY = "on_show_display" +CONF_ON_NIGHT_MODE = "on_night_mode" CONF_WEEKDAYTEXT = "weekdays" CONF_ON_EXPIRED_SCREEN= "on_expired_screen" CONF_SHOW_SECONDS = "show_seconds" @@ -224,6 +234,16 @@ def rgb565_888(v565): cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ExpiredScreenTrigger), } ), + cv.Optional(CONF_ON_SHOW_DISPLAY): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ShowDisplayTrigger), + } + ), + cv.Optional(CONF_ON_NIGHT_MODE): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NightModeTrigger), + } + ), cv.Optional(CONF_NIGNT_MODE_SCREENS, default=DAFAULT_NIGNT_MODE_SCREENS): cv.All( cv.ensure_list(cv.one_of(1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19)), cv.Length(min=1, max=5) ),