Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created July 24, 2021 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/432da1de1e5ab70af44cda733db6d7e6 to your computer and use it in GitHub Desktop.
Save Habbie/432da1de1e5ab70af44cda733db6d7e6 to your computer and use it in GitHub Desktop.
diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp
index 17a2725d..f9f29e81 100644
--- a/esphome/core/application.cpp
+++ b/esphome/core/application.cpp
@@ -11,7 +11,7 @@ namespace esphome {
static const char *const TAG = "app";
-void Application::register_component_(Component *comp) {
+void Application::register_component_(Component *comp, std::string id) {
if (comp == nullptr) {
ESP_LOGW(TAG, "Tried to register null component!");
return;
@@ -23,6 +23,7 @@ void Application::register_component_(Component *comp) {
return;
}
}
+ comp->esphome_component_name = id;
this->components_.push_back(comp);
}
void Application::setup() {
diff --git a/esphome/core/application.h b/esphome/core/application.h
index e065552a..6595c37e 100644
--- a/esphome/core/application.h
+++ b/esphome/core/application.h
@@ -90,9 +90,9 @@ class Application {
#endif
/// Register the component in this Application instance.
- template<class C> C *register_component(C *c) {
+ template<class C> C *register_component(C *c, std::string id) {
static_assert(std::is_base_of<Component, C>::value, "Only Component subclasses can be registered");
- this->register_component_((Component *) c);
+ this->register_component_((Component *) c, id);
return c;
}
@@ -230,7 +230,7 @@ class Application {
protected:
friend Component;
- void register_component_(Component *comp);
+ void register_component_(Component *comp, std::string id);
void calculate_looping_components_();
diff --git a/esphome/core/component.cpp b/esphome/core/component.cpp
index 09c91fbb..32415dbe 100644
--- a/esphome/core/component.cpp
+++ b/esphome/core/component.cpp
@@ -93,7 +93,8 @@ void Component::call() {
}
}
void Component::mark_failed() {
- ESP_LOGE(TAG, "Component was marked as failed.");
+ ESP_LOGE(TAG, "Component (%s) was marked as failed. Config dump of failing component follows:", this->esphome_component_name.c_str());
+ this->dump_config();
this->component_state_ &= ~COMPONENT_STATE_MASK;
this->component_state_ |= COMPONENT_STATE_FAILED;
this->status_set_error();
diff --git a/esphome/core/component.h b/esphome/core/component.h
index 001620fe..f8706287 100644
--- a/esphome/core/component.h
+++ b/esphome/core/component.h
@@ -130,6 +130,8 @@ class Component {
bool has_overridden_loop() const;
+ std::string esphome_component_name;
+
protected:
virtual void call_loop();
virtual void call_setup();
diff --git a/esphome/cpp_helpers.py b/esphome/cpp_helpers.py
index 1d66eabf..e12d3154 100644
--- a/esphome/cpp_helpers.py
+++ b/esphome/cpp_helpers.py
@@ -54,7 +54,7 @@ async def register_component(var, config):
add(var.set_setup_priority(config[CONF_SETUP_PRIORITY]))
if CONF_UPDATE_INTERVAL in config:
add(var.set_update_interval(config[CONF_UPDATE_INTERVAL]))
- add(App.register_component(var))
+ add(App.register_component(var, id_))
return var
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment