mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 14:38:10 +01:00
Display the configured esphome:comment on the WebServer (#4246)
This commit is contained in:
parent
05420291ce
commit
11518364a1
4 changed files with 21 additions and 15 deletions
|
@ -2,12 +2,12 @@
|
|||
|
||||
#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/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"
|
||||
|
||||
|
@ -105,6 +105,7 @@ void WebServer::setup() {
|
|||
|
||||
client->send(json::build_json([this](JsonObject root) {
|
||||
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["lang"] = "en";
|
||||
}).c_str(),
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
#include "esphome/core/scheduler.h"
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
|
@ -53,8 +53,8 @@ namespace esphome {
|
|||
|
||||
class Application {
|
||||
public:
|
||||
void pre_setup(const std::string &name, const std::string &friendly_name, const char *compilation_time,
|
||||
bool name_add_mac_suffix) {
|
||||
void pre_setup(const std::string &name, const std::string &friendly_name, const std::string &comment,
|
||||
const char *compilation_time, bool name_add_mac_suffix) {
|
||||
arch_init();
|
||||
this->name_add_mac_suffix_ = name_add_mac_suffix;
|
||||
if (name_add_mac_suffix) {
|
||||
|
@ -68,6 +68,7 @@ class Application {
|
|||
this->name_ = name;
|
||||
this->friendly_name_ = friendly_name;
|
||||
}
|
||||
this->comment_ = comment;
|
||||
this->compilation_time_ = compilation_time;
|
||||
}
|
||||
|
||||
|
@ -138,11 +139,13 @@ class Application {
|
|||
/// Make a loop iteration. Call this in your loop() function.
|
||||
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_; }
|
||||
|
||||
/// 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_; }
|
||||
/// 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_; }
|
||||
|
||||
|
@ -349,6 +352,7 @@ class Application {
|
|||
|
||||
std::string name_;
|
||||
std::string friendly_name_;
|
||||
std::string comment_;
|
||||
std::string compilation_time_;
|
||||
bool name_add_mac_suffix_;
|
||||
uint32_t last_loop_{0};
|
||||
|
|
|
@ -350,6 +350,7 @@ async def to_code(config):
|
|||
cg.App.pre_setup(
|
||||
config[CONF_NAME],
|
||||
config[CONF_FRIENDLY_NAME],
|
||||
config.get(CONF_COMMENT, ""),
|
||||
cg.RawExpression('__DATE__ ", " __TIME__'),
|
||||
config[CONF_NAME_ADD_MAC_SUFFIX],
|
||||
)
|
||||
|
|
|
@ -3,16 +3,16 @@
|
|||
// matter at all, as long as it compiles).
|
||||
// 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/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;
|
||||
|
||||
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
|
||||
log->pre_setup();
|
||||
log->set_uart_selection(logger::UART_SELECTION_UART0);
|
||||
|
|
Loading…
Reference in a new issue