Skip to content

Commit

Permalink
2023.9.1-103: Add on_show_display and on_night_mode triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan authored Oct 11, 2023
1 parent 77f5bf5 commit ed0f36b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
34 changes: 33 additions & 1 deletion components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -1563,7 +1586,6 @@ namespace esphome
this->icon_count++;
}


void EHMTX::draw_alarm()
{
if (this->display_alarm > 2)
Expand Down Expand Up @@ -1691,4 +1713,14 @@ namespace esphome
{
this->trigger();
}

void EHMTXShowDisplayTrigger::process(bool state)
{
this->trigger(state);
}

void EHMTXNightModeTrigger::process(bool state)
{
this->trigger(state);
}
}
20 changes: 20 additions & 0 deletions components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace esphome
class EHMTXExpiredScreenTrigger;
class EHMTXNextClockTrigger;
class EHMTXStartRunningTrigger;
class EHMTXShowDisplayTrigger;
class EHMTXNightModeTrigger;

class EHMTX : public PollingComponent, public api::CustomAPIDevice
{
Expand All @@ -79,6 +81,8 @@ namespace esphome
std::vector<EHMTXNextClockTrigger *> on_next_clock_triggers_;
std::vector<EHMTXStartRunningTrigger *> on_start_running_triggers_;
std::vector<EHMTXAddScreenTrigger *> on_add_screen_triggers_;
std::vector<EHMTXShowDisplayTrigger *> on_show_display_triggers_;
std::vector<EHMTXNightModeTrigger *> 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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -320,6 +326,20 @@ namespace esphome
void process();
};

class EHMTXShowDisplayTrigger : public Trigger<bool>
{
public:
explicit EHMTXShowDisplayTrigger(EHMTX *parent) { parent->add_on_show_display_trigger(this); }
void process(bool);
};

class EHMTXNightModeTrigger : public Trigger<bool>
{
public:
explicit EHMTXNightModeTrigger(EHMTX *parent) { parent->add_on_night_mode_trigger(this); }
void process(bool);
};

class EHMTX_Icon : public animation::Animation
{
protected:
Expand Down
20 changes: 20 additions & 0 deletions components/ehmtxv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
),
Expand Down

0 comments on commit ed0f36b

Please sign in to comment.