mirror of
https://github.com/esphome/esphome.git
synced 2025-08-02 00:17:48 +00:00
Merge branch 'integration' into memory_api
This commit is contained in:
commit
4f30fd9668
@ -84,9 +84,11 @@ class LightColorValues {
|
|||||||
* @return The linearly interpolated LightColorValues.
|
* @return The linearly interpolated LightColorValues.
|
||||||
*/
|
*/
|
||||||
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion) {
|
static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion) {
|
||||||
// Directly interpolate the raw values to avoid getter/setter overhead
|
// Directly interpolate the raw values to avoid getter/setter overhead.
|
||||||
// Linear interpolation between two clamped values produces a clamped result,
|
// This is safe because:
|
||||||
// so we can skip the setters which include redundant clamping logic
|
// - All LightColorValues have their values clamped when set via the setters
|
||||||
|
// - std::lerp guarantees output is in the same range as inputs
|
||||||
|
// - Therefore the output doesn't need clamping, so we can skip the setters
|
||||||
LightColorValues v;
|
LightColorValues v;
|
||||||
v.color_mode_ = end.color_mode_;
|
v.color_mode_ = end.color_mode_;
|
||||||
v.state_ = std::lerp(start.state_, end.state_, completion);
|
v.state_ = std::lerp(start.state_, end.state_, completion);
|
||||||
|
@ -11,17 +11,6 @@ namespace light {
|
|||||||
// Helper to convert float 0-1 to uint8_t 0-255
|
// Helper to convert float 0-1 to uint8_t 0-255
|
||||||
static inline uint8_t to_uint8_scaled(float value) { return uint8_t(value * 255); }
|
static inline uint8_t to_uint8_scaled(float value) { return uint8_t(value * 255); }
|
||||||
|
|
||||||
// Helper to parse color component from JSON
|
|
||||||
static float parse_color_component(JsonObject &color, const char *key, LightCall &call,
|
|
||||||
LightCall &(LightCall::*setter)(float) ) {
|
|
||||||
if (color[key].is<uint8_t>()) {
|
|
||||||
float val = float(color[key]) / 255.0f;
|
|
||||||
(call.*setter)(val);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup table for color mode strings
|
// Lookup table for color mode strings
|
||||||
static const char *get_color_mode_json_str(ColorMode mode) {
|
static const char *get_color_mode_json_str(ColorMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
@ -115,16 +104,22 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO
|
|||||||
JsonObject color = root["color"];
|
JsonObject color = root["color"];
|
||||||
// HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
|
// HA also encodes brightness information in the r, g, b values, so extract that and set it as color brightness.
|
||||||
float max_rgb = 0.0f;
|
float max_rgb = 0.0f;
|
||||||
|
if (color["r"].is<uint8_t>()) {
|
||||||
float r = parse_color_component(color, "r", call, &LightCall::set_red);
|
float r = float(color["r"]) / 255.0f;
|
||||||
float g = parse_color_component(color, "g", call, &LightCall::set_green);
|
max_rgb = fmaxf(max_rgb, r);
|
||||||
float b = parse_color_component(color, "b", call, &LightCall::set_blue);
|
call.set_red(r);
|
||||||
|
}
|
||||||
max_rgb = fmaxf(max_rgb, r);
|
if (color["g"].is<uint8_t>()) {
|
||||||
max_rgb = fmaxf(max_rgb, g);
|
float g = float(color["g"]) / 255.0f;
|
||||||
max_rgb = fmaxf(max_rgb, b);
|
max_rgb = fmaxf(max_rgb, g);
|
||||||
|
call.set_green(g);
|
||||||
if (max_rgb > 0.0f) {
|
}
|
||||||
|
if (color["b"].is<uint8_t>()) {
|
||||||
|
float b = float(color["b"]) / 255.0f;
|
||||||
|
max_rgb = fmaxf(max_rgb, b);
|
||||||
|
call.set_blue(b);
|
||||||
|
}
|
||||||
|
if (color["r"].is<uint8_t>() || color["g"].is<uint8_t>() || color["b"].is<uint8_t>()) {
|
||||||
call.set_color_brightness(max_rgb);
|
call.set_color_brightness(max_rgb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user