on_icon_error

pull/15/head
LuBeDa 3 years ago
parent ffdd1875af
commit 92291d727b

@ -109,6 +109,7 @@ namespace esphome
} }
} }
ESP_LOGW(TAG, "icon: %s not found", name.c_str()); ESP_LOGW(TAG, "icon: %s not found", name.c_str());
return MAXICONS; return MAXICONS;
} }
@ -496,6 +497,10 @@ namespace esphome
{ {
ESP_LOGW(TAG, "icon %d not found => default: 0", icon); ESP_LOGW(TAG, "icon %d not found => default: 0", icon);
icon = 0; icon = 0;
for (auto *t : on_icon_error_triggers_)
{
t->process(iconname);
}
} }
EHMTX_queue *screen = this->find_icon_queue_element(icon); EHMTX_queue *screen = this->find_icon_queue_element(icon);
@ -551,6 +556,10 @@ namespace esphome
{ {
ESP_LOGW(TAG, "icon %d not found => default: 0", icon); ESP_LOGW(TAG, "icon %d not found => default: 0", icon);
icon = 0; icon = 0;
for (auto *t : on_icon_error_triggers_)
{
t->process(iconname);
}
} }
EHMTX_queue *screen = this->find_icon_queue_element(icon); EHMTX_queue *screen = this->find_icon_queue_element(icon);
screen->icon_name = iconname; screen->icon_name = iconname;
@ -599,6 +608,10 @@ namespace esphome
if (icon >= this->icon_count) if (icon >= this->icon_count)
{ {
ESP_LOGW(TAG, "full screen: icon %d not found => default: 0", icon); ESP_LOGW(TAG, "full screen: icon %d not found => default: 0", icon);
for (auto *t : on_icon_error_triggers_)
{
t->process(iconname);
}
icon = 0; icon = 0;
} }
EHMTX_queue *screen = this->find_icon_queue_element(icon); EHMTX_queue *screen = this->find_icon_queue_element(icon);
@ -881,6 +894,11 @@ namespace esphome
this->trigger(iconname, text); this->trigger(iconname, text);
} }
void EHMTXIconErrorTrigger::process(std::string iconname)
{
this->trigger(iconname);
}
void EHMTXExpiredScreenTrigger::process(std::string iconname, std::string text) void EHMTXExpiredScreenTrigger::process(std::string iconname, std::string text)
{ {
this->trigger(iconname, text); this->trigger(iconname, text);

@ -30,6 +30,7 @@ namespace esphome
class EHMTX_queue; class EHMTX_queue;
class EHMTX_Icon; class EHMTX_Icon;
class EHMTXNextScreenTrigger; class EHMTXNextScreenTrigger;
class EHMTXIconErrorTrigger;
class EHMTXExpiredScreenTrigger; class EHMTXExpiredScreenTrigger;
class EHMTXNextClockTrigger; class EHMTXNextClockTrigger;
@ -43,6 +44,7 @@ namespace esphome
bool show_day_of_week; bool show_day_of_week;
std::vector<EHMTXNextScreenTrigger *> on_next_screen_triggers_; std::vector<EHMTXNextScreenTrigger *> on_next_screen_triggers_;
std::vector<EHMTXIconErrorTrigger *> on_icon_error_triggers_;
std::vector<EHMTXExpiredScreenTrigger *> on_expired_screen_triggers_; std::vector<EHMTXExpiredScreenTrigger *> on_expired_screen_triggers_;
std::vector<EHMTXNextClockTrigger *> on_next_clock_triggers_; std::vector<EHMTXNextClockTrigger *> on_next_clock_triggers_;
EHMTX_queue *find_icon_queue_element(uint8_t icon); EHMTX_queue *find_icon_queue_element(uint8_t icon);
@ -127,7 +129,7 @@ namespace esphome
void set_clock_color(int r=C_RED, int g=C_GREEN, int b=C_BLUE); void set_clock_color(int r=C_RED, int g=C_GREEN, int b=C_BLUE);
void set_today_color(int r, int g, int b); void set_today_color(int r, int g, int b);
void set_weekday_color(int r, int g, int b); void set_weekday_color(int r, int g, int b);
void show_alarm(int r=CA_RED, int g=C_GREEN, int b=C_BLUE, int s= 2); void show_alarm(int r=CA_RED, int g=CA_GREEN, int b=CA_BLUE, int s= 2);
void show_gauge(int v,int r=C_RED, int g=C_GREEN, int b=C_BLUE); // int because of register_service void show_gauge(int v,int r=C_RED, int g=C_GREEN, int b=C_BLUE); // int because of register_service
void hide_gauge(); void hide_gauge();
void hide_indicator(); void hide_indicator();
@ -150,6 +152,7 @@ namespace esphome
void draw_indicator(); void draw_indicator();
void add_on_next_screen_trigger(EHMTXNextScreenTrigger *t) { this->on_next_screen_triggers_.push_back(t); } void add_on_next_screen_trigger(EHMTXNextScreenTrigger *t) { this->on_next_screen_triggers_.push_back(t); }
void add_on_icon_error_trigger(EHMTXIconErrorTrigger *t) { this->on_icon_error_triggers_.push_back(t); }
void add_on_expired_screen_trigger(EHMTXExpiredScreenTrigger *t) { this->on_expired_screen_triggers_.push_back(t); } 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_next_clock_trigger(EHMTXNextClockTrigger *t) { this->on_next_clock_triggers_.push_back(t); }
@ -197,6 +200,14 @@ namespace esphome
void process(std::string, std::string); void process(std::string, std::string);
}; };
class EHMTXIconErrorTrigger : public Trigger<std::string>
{
public:
explicit EHMTXIconErrorTrigger(EHMTX *parent) { parent->add_on_icon_error_trigger(this); }
void process(std::string);
};
class EHMTXExpiredScreenTrigger : public Trigger<std::string, std::string> class EHMTXExpiredScreenTrigger : public Trigger<std::string, std::string>
{ {
public: public:

@ -41,6 +41,10 @@ NextScreenTrigger = ehmtx_ns.class_(
"EHMTXNextScreenTrigger", automation.Trigger.template(cg.std_string) "EHMTXNextScreenTrigger", automation.Trigger.template(cg.std_string)
) )
IconErrorTrigger = ehmtx_ns.class_(
"EHMTXIconErrorTrigger", automation.Trigger.template(cg.std_string)
)
ExpiredScreenTrigger = ehmtx_ns.class_( ExpiredScreenTrigger = ehmtx_ns.class_(
"EHMTXExpiredScreenTrigger", automation.Trigger.template(cg.std_string) "EHMTXExpiredScreenTrigger", automation.Trigger.template(cg.std_string)
) )
@ -49,7 +53,6 @@ NextClockTrigger = ehmtx_ns.class_(
"EHMTXNextClockTrigger", automation.Trigger.template(cg.std_string) "EHMTXNextClockTrigger", automation.Trigger.template(cg.std_string)
) )
CONF_EHMTX = "ehmtx"
CONF_URL = "url" CONF_URL = "url"
CONF_FLAG = "flag" CONF_FLAG = "flag"
CONF_TIMECOMPONENT = "time_component" CONF_TIMECOMPONENT = "time_component"
@ -77,6 +80,7 @@ CONF_TIME_FORMAT = "time_format"
CONF_DATE_FORMAT = "date_format" CONF_DATE_FORMAT = "date_format"
CONF_ON_NEXT_SCREEN = "on_next_screen" CONF_ON_NEXT_SCREEN = "on_next_screen"
CONF_ON_NEXT_CLOCK = "on_next_clock" CONF_ON_NEXT_CLOCK = "on_next_clock"
CONF_ON_ICON_ERROR = "on_icon_error"
CONF_ON_EXPIRED_SCREEN= "on_expired_screen" CONF_ON_EXPIRED_SCREEN= "on_expired_screen"
CONF_SHOW_SECONDS = "show_seconds" CONF_SHOW_SECONDS = "show_seconds"
CONF_WEEK_START_MONDAY = "week_start_monday" CONF_WEEK_START_MONDAY = "week_start_monday"
@ -141,6 +145,11 @@ EHMTX_SCHEMA = cv.Schema({
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NextScreenTrigger), cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NextScreenTrigger),
} }
), ),
cv.Optional(CONF_ON_ICON_ERROR): automation.validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(IconErrorTrigger),
}
),
cv.Optional(CONF_ON_EXPIRED_SCREEN): automation.validate_automation( cv.Optional(CONF_ON_EXPIRED_SCREEN): automation.validate_automation(
{ {
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NextScreenTrigger), cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(NextScreenTrigger),
@ -361,4 +370,8 @@ async def to_code(config):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var) trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [(cg.std_string, "x"), (cg.std_string, "y")] , conf) await automation.build_automation(trigger, [(cg.std_string, "x"), (cg.std_string, "y")] , conf)
for conf in config.get(CONF_ON_ICON_ERROR, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [(cg.std_string, "x")] , conf)
await cg.register_component(var, config) await cg.register_component(var, config)

Loading…
Cancel
Save