mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 15:28:34 +08:00
[cover] Store cover state strings in flash on ESP8266 (#12196)
This commit is contained in:
@@ -13,25 +13,25 @@ static const char *const TAG = "cover";
|
|||||||
const float COVER_OPEN = 1.0f;
|
const float COVER_OPEN = 1.0f;
|
||||||
const float COVER_CLOSED = 0.0f;
|
const float COVER_CLOSED = 0.0f;
|
||||||
|
|
||||||
const char *cover_command_to_str(float pos) {
|
const LogString *cover_command_to_str(float pos) {
|
||||||
if (pos == COVER_OPEN) {
|
if (pos == COVER_OPEN) {
|
||||||
return "OPEN";
|
return LOG_STR("OPEN");
|
||||||
} else if (pos == COVER_CLOSED) {
|
} else if (pos == COVER_CLOSED) {
|
||||||
return "CLOSE";
|
return LOG_STR("CLOSE");
|
||||||
} else {
|
} else {
|
||||||
return "UNKNOWN";
|
return LOG_STR("UNKNOWN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char *cover_operation_to_str(CoverOperation op) {
|
const LogString *cover_operation_to_str(CoverOperation op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case COVER_OPERATION_IDLE:
|
case COVER_OPERATION_IDLE:
|
||||||
return "IDLE";
|
return LOG_STR("IDLE");
|
||||||
case COVER_OPERATION_OPENING:
|
case COVER_OPERATION_OPENING:
|
||||||
return "OPENING";
|
return LOG_STR("OPENING");
|
||||||
case COVER_OPERATION_CLOSING:
|
case COVER_OPERATION_CLOSING:
|
||||||
return "CLOSING";
|
return LOG_STR("CLOSING");
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return LOG_STR("UNKNOWN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ void CoverCall::perform() {
|
|||||||
if (traits.get_supports_position()) {
|
if (traits.get_supports_position()) {
|
||||||
ESP_LOGD(TAG, " Position: %.0f%%", *this->position_ * 100.0f);
|
ESP_LOGD(TAG, " Position: %.0f%%", *this->position_ * 100.0f);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGD(TAG, " Command: %s", cover_command_to_str(*this->position_));
|
ESP_LOGD(TAG, " Command: %s", LOG_STR_ARG(cover_command_to_str(*this->position_)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->tilt_.has_value()) {
|
if (this->tilt_.has_value()) {
|
||||||
@@ -169,7 +169,7 @@ void Cover::publish_state(bool save) {
|
|||||||
if (traits.get_supports_tilt()) {
|
if (traits.get_supports_tilt()) {
|
||||||
ESP_LOGD(TAG, " Tilt: %.0f%%", this->tilt * 100.0f);
|
ESP_LOGD(TAG, " Tilt: %.0f%%", this->tilt * 100.0f);
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, " Current Operation: %s", cover_operation_to_str(this->current_operation));
|
ESP_LOGD(TAG, " Current Operation: %s", LOG_STR_ARG(cover_operation_to_str(this->current_operation)));
|
||||||
|
|
||||||
this->state_callback_.call();
|
this->state_callback_.call();
|
||||||
#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY)
|
#if defined(USE_COVER) && defined(USE_CONTROLLER_REGISTRY)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/entity_base.h"
|
#include "esphome/core/entity_base.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
|
|
||||||
#include "cover_traits.h"
|
#include "cover_traits.h"
|
||||||
@@ -86,7 +87,7 @@ enum CoverOperation : uint8_t {
|
|||||||
COVER_OPERATION_CLOSING,
|
COVER_OPERATION_CLOSING,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *cover_operation_to_str(CoverOperation op);
|
const LogString *cover_operation_to_str(CoverOperation op);
|
||||||
|
|
||||||
/** Base class for all cover devices.
|
/** Base class for all cover devices.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ namespace web_server {
|
|||||||
|
|
||||||
static const char *const TAG = "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;
|
||||||
|
#define PSTR_LOCAL(mode_s) ESPHOME_strncpy_P(buf, (ESPHOME_PGM_P) ((mode_s)), PSTR_LOCAL_SIZE - 1)
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
|
#ifdef USE_WEBSERVER_PRIVATE_NETWORK_ACCESS
|
||||||
static const char *const HEADER_PNA_NAME = "Private-Network-Access-Name";
|
static const char *const HEADER_PNA_NAME = "Private-Network-Access-Name";
|
||||||
static const char *const HEADER_PNA_ID = "Private-Network-Access-ID";
|
static const char *const HEADER_PNA_ID = "Private-Network-Access-ID";
|
||||||
@@ -908,7 +912,8 @@ std::string WebServer::cover_json(cover::Cover *obj, JsonDetail start_config) {
|
|||||||
|
|
||||||
set_json_icon_state_value(root, obj, "cover", obj->is_fully_closed() ? "CLOSED" : "OPEN", obj->position,
|
set_json_icon_state_value(root, obj, "cover", obj->is_fully_closed() ? "CLOSED" : "OPEN", obj->position,
|
||||||
start_config);
|
start_config);
|
||||||
root["current_operation"] = cover::cover_operation_to_str(obj->current_operation);
|
char buf[PSTR_LOCAL_SIZE];
|
||||||
|
root["current_operation"] = PSTR_LOCAL(cover::cover_operation_to_str(obj->current_operation));
|
||||||
|
|
||||||
if (obj->get_traits().get_supports_position())
|
if (obj->get_traits().get_supports_position())
|
||||||
root["position"] = obj->position;
|
root["position"] = obj->position;
|
||||||
@@ -1272,9 +1277,6 @@ std::string WebServer::select_json(select::Select *obj, const char *value, JsonD
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Longest: HORIZONTAL
|
|
||||||
#define PSTR_LOCAL(mode_s) ESPHOME_strncpy_P(buf, (ESPHOME_PGM_P) ((mode_s)), 15)
|
|
||||||
|
|
||||||
#ifdef USE_CLIMATE
|
#ifdef USE_CLIMATE
|
||||||
void WebServer::on_climate_update(climate::Climate *obj) {
|
void WebServer::on_climate_update(climate::Climate *obj) {
|
||||||
if (!this->include_internal_ && obj->is_internal())
|
if (!this->include_internal_ && obj->is_internal())
|
||||||
|
|||||||
Reference in New Issue
Block a user