mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[update] Move update_state_to_string to update component and convert to PROGMEM_STRING_TABLE (#13796)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,12 +2,21 @@
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/controller_registry.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/progmem.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace update {
|
||||
|
||||
static const char *const TAG = "update";
|
||||
|
||||
// Update state strings indexed by UpdateState enum (0-3): UNKNOWN, NO UPDATE, UPDATE AVAILABLE, INSTALLING
|
||||
PROGMEM_STRING_TABLE(UpdateStateStrings, "UNKNOWN", "NO UPDATE", "UPDATE AVAILABLE", "INSTALLING");
|
||||
|
||||
const LogString *update_state_to_string(UpdateState state) {
|
||||
return UpdateStateStrings::get_log_str(static_cast<uint8_t>(state),
|
||||
static_cast<uint8_t>(UpdateState::UPDATE_STATE_UNKNOWN));
|
||||
}
|
||||
|
||||
void UpdateEntity::publish_state() {
|
||||
ESP_LOGD(TAG,
|
||||
"'%s' >>\n"
|
||||
|
||||
@@ -27,6 +27,8 @@ enum UpdateState : uint8_t {
|
||||
UPDATE_STATE_INSTALLING,
|
||||
};
|
||||
|
||||
const LogString *update_state_to_string(UpdateState state);
|
||||
|
||||
class UpdateEntity : public EntityBase, public EntityBase_DeviceClass {
|
||||
public:
|
||||
void publish_state();
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
#include "esphome/components/climate/climate.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPDATE
|
||||
#include "esphome/components/update/update_entity.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_WATER_HEATER
|
||||
#include "esphome/components/water_heater/water_heater.h"
|
||||
#endif
|
||||
@@ -2104,19 +2108,6 @@ std::string WebServer::event_json_(event::Event *obj, StringRef event_type, Json
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPDATE
|
||||
static const LogString *update_state_to_string(update::UpdateState state) {
|
||||
switch (state) {
|
||||
case update::UPDATE_STATE_NO_UPDATE:
|
||||
return LOG_STR("NO UPDATE");
|
||||
case update::UPDATE_STATE_AVAILABLE:
|
||||
return LOG_STR("UPDATE AVAILABLE");
|
||||
case update::UPDATE_STATE_INSTALLING:
|
||||
return LOG_STR("INSTALLING");
|
||||
default:
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
void WebServer::on_update(update::UpdateEntity *obj) {
|
||||
this->events_.deferrable_send_state(obj, "state", update_state_json_generator);
|
||||
}
|
||||
@@ -2158,7 +2149,7 @@ std::string WebServer::update_json_(update::UpdateEntity *obj, JsonDetail start_
|
||||
JsonObject root = builder.root();
|
||||
|
||||
char buf[PSTR_LOCAL_SIZE];
|
||||
set_json_icon_state_value(root, obj, "update", PSTR_LOCAL(update_state_to_string(obj->state)),
|
||||
set_json_icon_state_value(root, obj, "update", PSTR_LOCAL(update::update_state_to_string(obj->state)),
|
||||
obj->update_info.latest_version, start_config);
|
||||
if (start_config == DETAIL_ALL) {
|
||||
root[ESPHOME_F("current_version")] = obj->update_info.current_version;
|
||||
|
||||
Reference in New Issue
Block a user