mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
commit
a67d58948d
11 changed files with 621 additions and 574 deletions
|
@ -473,6 +473,7 @@ enum SensorStateClass {
|
||||||
STATE_CLASS_NONE = 0;
|
STATE_CLASS_NONE = 0;
|
||||||
STATE_CLASS_MEASUREMENT = 1;
|
STATE_CLASS_MEASUREMENT = 1;
|
||||||
STATE_CLASS_TOTAL_INCREASING = 2;
|
STATE_CLASS_TOTAL_INCREASING = 2;
|
||||||
|
STATE_CLASS_TOTAL = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SensorLastResetType {
|
enum SensorLastResetType {
|
||||||
|
|
|
@ -108,6 +108,8 @@ template<> const char *proto_enum_to_string<enums::SensorStateClass>(enums::Sens
|
||||||
return "STATE_CLASS_MEASUREMENT";
|
return "STATE_CLASS_MEASUREMENT";
|
||||||
case enums::STATE_CLASS_TOTAL_INCREASING:
|
case enums::STATE_CLASS_TOTAL_INCREASING:
|
||||||
return "STATE_CLASS_TOTAL_INCREASING";
|
return "STATE_CLASS_TOTAL_INCREASING";
|
||||||
|
case enums::STATE_CLASS_TOTAL:
|
||||||
|
return "STATE_CLASS_TOTAL";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ enum SensorStateClass : uint32_t {
|
||||||
STATE_CLASS_NONE = 0,
|
STATE_CLASS_NONE = 0,
|
||||||
STATE_CLASS_MEASUREMENT = 1,
|
STATE_CLASS_MEASUREMENT = 1,
|
||||||
STATE_CLASS_TOTAL_INCREASING = 2,
|
STATE_CLASS_TOTAL_INCREASING = 2,
|
||||||
|
STATE_CLASS_TOTAL = 3,
|
||||||
};
|
};
|
||||||
enum SensorLastResetType : uint32_t {
|
enum SensorLastResetType : uint32_t {
|
||||||
LAST_RESET_NONE = 0,
|
LAST_RESET_NONE = 0,
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <vector>
|
||||||
|
|
||||||
class UDP;
|
class UDP;
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,7 @@ STATE_CLASSES = {
|
||||||
"": StateClasses.STATE_CLASS_NONE,
|
"": StateClasses.STATE_CLASS_NONE,
|
||||||
"measurement": StateClasses.STATE_CLASS_MEASUREMENT,
|
"measurement": StateClasses.STATE_CLASS_MEASUREMENT,
|
||||||
"total_increasing": StateClasses.STATE_CLASS_TOTAL_INCREASING,
|
"total_increasing": StateClasses.STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
"total": StateClasses.STATE_CLASS_TOTAL,
|
||||||
}
|
}
|
||||||
validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_")
|
validate_state_class = cv.enum(STATE_CLASSES, lower=True, space="_")
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ std::string state_class_to_string(StateClass state_class) {
|
||||||
return "measurement";
|
return "measurement";
|
||||||
case STATE_CLASS_TOTAL_INCREASING:
|
case STATE_CLASS_TOTAL_INCREASING:
|
||||||
return "total_increasing";
|
return "total_increasing";
|
||||||
|
case STATE_CLASS_TOTAL:
|
||||||
|
return "total";
|
||||||
case STATE_CLASS_NONE:
|
case STATE_CLASS_NONE:
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -36,6 +36,7 @@ enum StateClass : uint8_t {
|
||||||
STATE_CLASS_NONE = 0,
|
STATE_CLASS_NONE = 0,
|
||||||
STATE_CLASS_MEASUREMENT = 1,
|
STATE_CLASS_MEASUREMENT = 1,
|
||||||
STATE_CLASS_TOTAL_INCREASING = 2,
|
STATE_CLASS_TOTAL_INCREASING = 2,
|
||||||
|
STATE_CLASS_TOTAL = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string state_class_to_string(StateClass state_class);
|
std::string state_class_to_string(StateClass state_class);
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -839,6 +839,7 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
||||||
return json::build_json([obj, start_config](JsonObject root) {
|
return json::build_json([obj, start_config](JsonObject root) {
|
||||||
set_json_id(root, obj, "climate-" + obj->get_object_id(), start_config);
|
set_json_id(root, obj, "climate-" + obj->get_object_id(), start_config);
|
||||||
const auto traits = obj->get_traits();
|
const auto traits = obj->get_traits();
|
||||||
|
int8_t accuracy = traits.get_temperature_accuracy_decimals();
|
||||||
char __buf[16];
|
char __buf[16];
|
||||||
|
|
||||||
if (start_config == DETAIL_ALL) {
|
if (start_config == DETAIL_ALL) {
|
||||||
|
@ -873,12 +874,15 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_state = false;
|
||||||
root["mode"] = PSTR_LOCAL(climate_mode_to_string(obj->mode));
|
root["mode"] = PSTR_LOCAL(climate_mode_to_string(obj->mode));
|
||||||
root["max_temp"] = traits.get_visual_max_temperature();
|
root["max_temp"] = value_accuracy_to_string(traits.get_visual_max_temperature(), accuracy);
|
||||||
root["min_temp"] = traits.get_visual_min_temperature();
|
root["min_temp"] = value_accuracy_to_string(traits.get_visual_min_temperature(), accuracy);
|
||||||
root["step"] = traits.get_visual_temperature_step();
|
root["step"] = traits.get_visual_temperature_step();
|
||||||
if (traits.get_supports_action()) {
|
if (traits.get_supports_action()) {
|
||||||
root["action"] = PSTR_LOCAL(climate_action_to_string(obj->action));
|
root["action"] = PSTR_LOCAL(climate_action_to_string(obj->action));
|
||||||
|
root["state"] = root["action"];
|
||||||
|
has_state = true;
|
||||||
}
|
}
|
||||||
if (traits.get_supports_fan_modes() && obj->fan_mode.has_value()) {
|
if (traits.get_supports_fan_modes() && obj->fan_mode.has_value()) {
|
||||||
root["fan_mode"] = PSTR_LOCAL(climate_fan_mode_to_string(obj->fan_mode.value()));
|
root["fan_mode"] = PSTR_LOCAL(climate_fan_mode_to_string(obj->fan_mode.value()));
|
||||||
|
@ -896,14 +900,23 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf
|
||||||
root["swing_mode"] = PSTR_LOCAL(climate_swing_mode_to_string(obj->swing_mode));
|
root["swing_mode"] = PSTR_LOCAL(climate_swing_mode_to_string(obj->swing_mode));
|
||||||
}
|
}
|
||||||
if (traits.get_supports_current_temperature()) {
|
if (traits.get_supports_current_temperature()) {
|
||||||
root["current_temperature"] = obj->current_temperature;
|
if (!std::isnan(obj->current_temperature)) {
|
||||||
|
root["current_temperature"] = value_accuracy_to_string(obj->current_temperature, accuracy);
|
||||||
|
} else {
|
||||||
|
root["current_temperature"] = "NA";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (traits.get_supports_two_point_target_temperature()) {
|
if (traits.get_supports_two_point_target_temperature()) {
|
||||||
root["current_temperature_low"] = obj->target_temperature_low;
|
root["target_temperature_low"] = value_accuracy_to_string(obj->target_temperature_low, accuracy);
|
||||||
root["current_temperature_high"] = obj->target_temperature_low;
|
root["target_temperature_high"] = value_accuracy_to_string(obj->target_temperature_high, accuracy);
|
||||||
|
if (!has_state) {
|
||||||
|
root["state"] =
|
||||||
|
value_accuracy_to_string((obj->target_temperature_high + obj->target_temperature_low) / 2.0f, accuracy);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
root["target_temperature"] = obj->target_temperature;
|
root["target_temperature"] = value_accuracy_to_string(obj->target_temperature, accuracy);
|
||||||
root["state"] = obj->target_temperature;
|
if (!has_state)
|
||||||
|
root["state"] = root["target_temperature"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2022.8.0b1"
|
__version__ = "2022.8.0b2"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
|
|
||||||
|
@ -956,6 +956,9 @@ STATE_CLASS_MEASUREMENT = "measurement"
|
||||||
# The state represents a total that only increases, a decrease is considered a reset.
|
# The state represents a total that only increases, a decrease is considered a reset.
|
||||||
STATE_CLASS_TOTAL_INCREASING = "total_increasing"
|
STATE_CLASS_TOTAL_INCREASING = "total_increasing"
|
||||||
|
|
||||||
|
# The state represents a total amount that can both increase and decrease, e.g. a net energy meter.
|
||||||
|
STATE_CLASS_TOTAL = "total"
|
||||||
|
|
||||||
KEY_CORE = "core"
|
KEY_CORE = "core"
|
||||||
KEY_TARGET_PLATFORM = "target_platform"
|
KEY_TARGET_PLATFORM = "target_platform"
|
||||||
KEY_TARGET_FRAMEWORK = "target_framework"
|
KEY_TARGET_FRAMEWORK = "target_framework"
|
||||||
|
|
|
@ -139,9 +139,19 @@ struct Color {
|
||||||
return Color(uint8_t((uint16_t(r) * 255U / max_rgb)), uint8_t((uint16_t(g) * 255U / max_rgb)),
|
return Color(uint8_t((uint16_t(r) * 255U / max_rgb)), uint8_t((uint16_t(g) * 255U / max_rgb)),
|
||||||
uint8_t((uint16_t(b) * 255U / max_rgb)), w);
|
uint8_t((uint16_t(b) * 255U / max_rgb)), w);
|
||||||
}
|
}
|
||||||
Color fade_to_white(uint8_t amnt) { return Color(255, 255, 255, 255) - (*this * amnt); }
|
|
||||||
Color fade_to_black(uint8_t amnt) { return *this * amnt; }
|
Color gradient(const Color &to_color, uint8_t amnt) {
|
||||||
Color gradient(const Color &to_color, uint8_t amnt) { return (*this * amnt) + (to_color * (255 - amnt)); }
|
Color new_color;
|
||||||
|
float amnt_f = float(amnt) / 255.0f;
|
||||||
|
new_color.r = amnt_f * (to_color.r - (*this).r) + (*this).r;
|
||||||
|
new_color.g = amnt_f * (to_color.g - (*this).g) + (*this).g;
|
||||||
|
new_color.b = amnt_f * (to_color.b - (*this).b) + (*this).b;
|
||||||
|
new_color.w = amnt_f * (to_color.w - (*this).w) + (*this).w;
|
||||||
|
return new_color;
|
||||||
|
}
|
||||||
|
Color fade_to_white(uint8_t amnt) { return (*this).gradient(Color::WHITE, amnt); }
|
||||||
|
Color fade_to_black(uint8_t amnt) { return (*this).gradient(Color::BLACK, amnt); }
|
||||||
|
|
||||||
Color lighten(uint8_t delta) { return *this + delta; }
|
Color lighten(uint8_t delta) { return *this + delta; }
|
||||||
Color darken(uint8_t delta) { return *this - delta; }
|
Color darken(uint8_t delta) { return *this - delta; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue