mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 11:38:48 +00:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -895,7 +895,11 @@ void PrometheusHandler::valve_row_(AsyncResponseStream *stream, valve::Valve *ob
|
||||
stream->print(ESPHOME_F("\",name=\""));
|
||||
stream->print(relabel_name_(obj).c_str());
|
||||
stream->print(ESPHOME_F("\",operation=\""));
|
||||
stream->print(valve::valve_operation_to_str(obj->current_operation));
|
||||
#ifdef USE_STORE_LOG_STR_IN_FLASH
|
||||
stream->print((const __FlashStringHelper *) valve::valve_operation_to_str(obj->current_operation));
|
||||
#else
|
||||
stream->print((const char *) valve::valve_operation_to_str(obj->current_operation));
|
||||
#endif
|
||||
stream->print(ESPHOME_F("\"} "));
|
||||
stream->print(ESPHOME_F("1.0"));
|
||||
stream->print(ESPHOME_F("\n"));
|
||||
|
||||
@@ -12,25 +12,25 @@ static const char *const TAG = "valve";
|
||||
const float VALVE_OPEN = 1.0f;
|
||||
const float VALVE_CLOSED = 0.0f;
|
||||
|
||||
const char *valve_command_to_str(float pos) {
|
||||
const LogString *valve_command_to_str(float pos) {
|
||||
if (pos == VALVE_OPEN) {
|
||||
return "OPEN";
|
||||
return LOG_STR("OPEN");
|
||||
} else if (pos == VALVE_CLOSED) {
|
||||
return "CLOSE";
|
||||
return LOG_STR("CLOSE");
|
||||
} else {
|
||||
return "UNKNOWN";
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
const char *valve_operation_to_str(ValveOperation op) {
|
||||
const LogString *valve_operation_to_str(ValveOperation op) {
|
||||
switch (op) {
|
||||
case VALVE_OPERATION_IDLE:
|
||||
return "IDLE";
|
||||
return LOG_STR("IDLE");
|
||||
case VALVE_OPERATION_OPENING:
|
||||
return "OPENING";
|
||||
return LOG_STR("OPENING");
|
||||
case VALVE_OPERATION_CLOSING:
|
||||
return "CLOSING";
|
||||
return LOG_STR("CLOSING");
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void ValveCall::perform() {
|
||||
if (traits.get_supports_position()) {
|
||||
ESP_LOGD(TAG, " Position: %.0f%%", *this->position_ * 100.0f);
|
||||
} else {
|
||||
ESP_LOGD(TAG, " Command: %s", valve_command_to_str(*this->position_));
|
||||
ESP_LOGD(TAG, " Command: %s", LOG_STR_ARG(valve_command_to_str(*this->position_)));
|
||||
}
|
||||
}
|
||||
if (this->toggle_.has_value()) {
|
||||
@@ -146,7 +146,7 @@ void Valve::publish_state(bool save) {
|
||||
ESP_LOGD(TAG, " State: UNKNOWN");
|
||||
}
|
||||
}
|
||||
ESP_LOGD(TAG, " Current Operation: %s", valve_operation_to_str(this->current_operation));
|
||||
ESP_LOGD(TAG, " Current Operation: %s", LOG_STR_ARG(valve_operation_to_str(this->current_operation)));
|
||||
|
||||
this->state_callback_.call();
|
||||
#if defined(USE_VALVE) && defined(USE_CONTROLLER_REGISTRY)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/preferences.h"
|
||||
#include "valve_traits.h"
|
||||
|
||||
@@ -81,7 +82,7 @@ enum ValveOperation : uint8_t {
|
||||
VALVE_OPERATION_CLOSING,
|
||||
};
|
||||
|
||||
const char *valve_operation_to_str(ValveOperation op);
|
||||
const LogString *valve_operation_to_str(ValveOperation op);
|
||||
|
||||
/** Base class for all valve devices.
|
||||
*
|
||||
|
||||
@@ -41,8 +41,8 @@ namespace web_server {
|
||||
|
||||
static const char *const TAG = "web_server";
|
||||
|
||||
// Longest: HORIZONTAL (10 chars + null terminator, rounded up)
|
||||
static constexpr size_t PSTR_LOCAL_SIZE = 16;
|
||||
// Longest: UPDATE AVAILABLE (16 chars + null terminator, rounded up)
|
||||
static constexpr size_t PSTR_LOCAL_SIZE = 18;
|
||||
#define PSTR_LOCAL(mode_s) ESPHOME_strncpy_P(buf, (ESPHOME_PGM_P) ((mode_s)), PSTR_LOCAL_SIZE - 1)
|
||||
|
||||
#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
|
||||
@@ -1565,7 +1565,8 @@ std::string WebServer::valve_json(valve::Valve *obj, JsonDetail start_config) {
|
||||
|
||||
set_json_icon_state_value(root, obj, "valve", obj->is_fully_closed() ? "CLOSED" : "OPEN", obj->position,
|
||||
start_config);
|
||||
root["current_operation"] = valve::valve_operation_to_str(obj->current_operation);
|
||||
char buf[PSTR_LOCAL_SIZE];
|
||||
root["current_operation"] = PSTR_LOCAL(valve::valve_operation_to_str(obj->current_operation));
|
||||
|
||||
if (obj->get_traits().get_supports_position())
|
||||
root["position"] = obj->position;
|
||||
@@ -1715,16 +1716,16 @@ std::string WebServer::event_json(event::Event *obj, const std::string &event_ty
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPDATE
|
||||
static const char *update_state_to_string(update::UpdateState state) {
|
||||
static const LogString *update_state_to_string(update::UpdateState state) {
|
||||
switch (state) {
|
||||
case update::UPDATE_STATE_NO_UPDATE:
|
||||
return "NO UPDATE";
|
||||
return LOG_STR("NO UPDATE");
|
||||
case update::UPDATE_STATE_AVAILABLE:
|
||||
return "UPDATE AVAILABLE";
|
||||
return LOG_STR("UPDATE AVAILABLE");
|
||||
case update::UPDATE_STATE_INSTALLING:
|
||||
return "INSTALLING";
|
||||
return LOG_STR("INSTALLING");
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
return LOG_STR("UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1767,8 +1768,9 @@ std::string WebServer::update_json(update::UpdateEntity *obj, JsonDetail start_c
|
||||
json::JsonBuilder builder;
|
||||
JsonObject root = builder.root();
|
||||
|
||||
set_json_icon_state_value(root, obj, "update", update_state_to_string(obj->state), obj->update_info.latest_version,
|
||||
start_config);
|
||||
char buf[PSTR_LOCAL_SIZE];
|
||||
set_json_icon_state_value(root, obj, "update", PSTR_LOCAL(update_state_to_string(obj->state)),
|
||||
obj->update_info.latest_version, start_config);
|
||||
if (start_config == DETAIL_ALL) {
|
||||
root["current_version"] = obj->update_info.current_version;
|
||||
root["title"] = obj->update_info.title;
|
||||
|
||||
Reference in New Issue
Block a user