mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Display the configured esphome:comment on the WebServer (#4246)
This commit is contained in:
		| @@ -2,12 +2,12 @@ | |||||||
|  |  | ||||||
| #include "web_server.h" | #include "web_server.h" | ||||||
|  |  | ||||||
| #include "esphome/core/log.h" |  | ||||||
| #include "esphome/core/application.h" |  | ||||||
| #include "esphome/core/entity_base.h" |  | ||||||
| #include "esphome/core/util.h" |  | ||||||
| #include "esphome/components/json/json_util.h" | #include "esphome/components/json/json_util.h" | ||||||
| #include "esphome/components/network/util.h" | #include "esphome/components/network/util.h" | ||||||
|  | #include "esphome/core/application.h" | ||||||
|  | #include "esphome/core/entity_base.h" | ||||||
|  | #include "esphome/core/log.h" | ||||||
|  | #include "esphome/core/util.h" | ||||||
|  |  | ||||||
| #include "StreamString.h" | #include "StreamString.h" | ||||||
|  |  | ||||||
| @@ -105,6 +105,7 @@ void WebServer::setup() { | |||||||
|  |  | ||||||
|     client->send(json::build_json([this](JsonObject root) { |     client->send(json::build_json([this](JsonObject root) { | ||||||
|                    root["title"] = App.get_friendly_name().empty() ? App.get_name() : App.get_friendly_name(); |                    root["title"] = App.get_friendly_name().empty() ? App.get_name() : App.get_friendly_name(); | ||||||
|  |                    root["comment"] = App.get_comment(); | ||||||
|                    root["ota"] = this->allow_ota_; |                    root["ota"] = this->allow_ota_; | ||||||
|                    root["lang"] = "en"; |                    root["lang"] = "en"; | ||||||
|                  }).c_str(), |                  }).c_str(), | ||||||
|   | |||||||
| @@ -2,11 +2,11 @@ | |||||||
|  |  | ||||||
| #include <string> | #include <string> | ||||||
| #include <vector> | #include <vector> | ||||||
| #include "esphome/core/defines.h" |  | ||||||
| #include "esphome/core/preferences.h" |  | ||||||
| #include "esphome/core/component.h" | #include "esphome/core/component.h" | ||||||
|  | #include "esphome/core/defines.h" | ||||||
| #include "esphome/core/hal.h" | #include "esphome/core/hal.h" | ||||||
| #include "esphome/core/helpers.h" | #include "esphome/core/helpers.h" | ||||||
|  | #include "esphome/core/preferences.h" | ||||||
| #include "esphome/core/scheduler.h" | #include "esphome/core/scheduler.h" | ||||||
|  |  | ||||||
| #ifdef USE_BINARY_SENSOR | #ifdef USE_BINARY_SENSOR | ||||||
| @@ -53,8 +53,8 @@ namespace esphome { | |||||||
|  |  | ||||||
| class Application { | class Application { | ||||||
|  public: |  public: | ||||||
|   void pre_setup(const std::string &name, const std::string &friendly_name, const char *compilation_time, |   void pre_setup(const std::string &name, const std::string &friendly_name, const std::string &comment, | ||||||
|                  bool name_add_mac_suffix) { |                  const char *compilation_time, bool name_add_mac_suffix) { | ||||||
|     arch_init(); |     arch_init(); | ||||||
|     this->name_add_mac_suffix_ = name_add_mac_suffix; |     this->name_add_mac_suffix_ = name_add_mac_suffix; | ||||||
|     if (name_add_mac_suffix) { |     if (name_add_mac_suffix) { | ||||||
| @@ -68,6 +68,7 @@ class Application { | |||||||
|       this->name_ = name; |       this->name_ = name; | ||||||
|       this->friendly_name_ = friendly_name; |       this->friendly_name_ = friendly_name; | ||||||
|     } |     } | ||||||
|  |     this->comment_ = comment; | ||||||
|     this->compilation_time_ = compilation_time; |     this->compilation_time_ = compilation_time; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -138,11 +139,13 @@ class Application { | |||||||
|   /// Make a loop iteration. Call this in your loop() function. |   /// Make a loop iteration. Call this in your loop() function. | ||||||
|   void loop(); |   void loop(); | ||||||
|  |  | ||||||
|   /// Get the name of this Application set by set_name(). |   /// Get the name of this Application set by pre_setup(). | ||||||
|   const std::string &get_name() const { return this->name_; } |   const std::string &get_name() const { return this->name_; } | ||||||
|  |  | ||||||
|   /// Get the friendly name of this Application set by set_friendly_name(). |   /// Get the friendly name of this Application set by pre_setup(). | ||||||
|   const std::string &get_friendly_name() const { return this->friendly_name_; } |   const std::string &get_friendly_name() const { return this->friendly_name_; } | ||||||
|  |   /// Get the comment of this Application set by pre_setup(). | ||||||
|  |   const std::string &get_comment() const { return this->comment_; } | ||||||
|  |  | ||||||
|   bool is_name_add_mac_suffix_enabled() const { return this->name_add_mac_suffix_; } |   bool is_name_add_mac_suffix_enabled() const { return this->name_add_mac_suffix_; } | ||||||
|  |  | ||||||
| @@ -349,6 +352,7 @@ class Application { | |||||||
|  |  | ||||||
|   std::string name_; |   std::string name_; | ||||||
|   std::string friendly_name_; |   std::string friendly_name_; | ||||||
|  |   std::string comment_; | ||||||
|   std::string compilation_time_; |   std::string compilation_time_; | ||||||
|   bool name_add_mac_suffix_; |   bool name_add_mac_suffix_; | ||||||
|   uint32_t last_loop_{0}; |   uint32_t last_loop_{0}; | ||||||
|   | |||||||
| @@ -350,6 +350,7 @@ async def to_code(config): | |||||||
|         cg.App.pre_setup( |         cg.App.pre_setup( | ||||||
|             config[CONF_NAME], |             config[CONF_NAME], | ||||||
|             config[CONF_FRIENDLY_NAME], |             config[CONF_FRIENDLY_NAME], | ||||||
|  |             config.get(CONF_COMMENT, ""), | ||||||
|             cg.RawExpression('__DATE__ ", " __TIME__'), |             cg.RawExpression('__DATE__ ", " __TIME__'), | ||||||
|             config[CONF_NAME_ADD_MAC_SUFFIX], |             config[CONF_NAME_ADD_MAC_SUFFIX], | ||||||
|         ) |         ) | ||||||
|   | |||||||
| @@ -3,16 +3,16 @@ | |||||||
| // matter at all, as long as it compiles). | // matter at all, as long as it compiles). | ||||||
| // Not used during runtime nor for CI. | // Not used during runtime nor for CI. | ||||||
|  |  | ||||||
| #include <esphome/core/application.h> |  | ||||||
| #include <esphome/components/logger/logger.h> |  | ||||||
| #include <esphome/components/wifi/wifi_component.h> |  | ||||||
| #include <esphome/components/ota/ota_component.h> |  | ||||||
| #include <esphome/components/gpio/switch/gpio_switch.h> | #include <esphome/components/gpio/switch/gpio_switch.h> | ||||||
|  | #include <esphome/components/logger/logger.h> | ||||||
|  | #include <esphome/components/ota/ota_component.h> | ||||||
|  | #include <esphome/components/wifi/wifi_component.h> | ||||||
|  | #include <esphome/core/application.h> | ||||||
|  |  | ||||||
| using namespace esphome; | using namespace esphome; | ||||||
|  |  | ||||||
| void setup() { | void setup() { | ||||||
|   App.pre_setup("livingroom", "LivingRoom", __DATE__ ", " __TIME__, false); |   App.pre_setup("livingroom", "LivingRoom", "comment", __DATE__ ", " __TIME__, false); | ||||||
|   auto *log = new logger::Logger(115200, 512);  // NOLINT |   auto *log = new logger::Logger(115200, 512);  // NOLINT | ||||||
|   log->pre_setup(); |   log->pre_setup(); | ||||||
|   log->set_uart_selection(logger::UART_SELECTION_UART0); |   log->set_uart_selection(logger::UART_SELECTION_UART0); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user