From 29e61c8913f2316e2c9180aeeb95cdcc49d4f64f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 26 Jul 2025 21:27:44 -1000 Subject: [PATCH] revert --- .../components/light/light_json_schema.cpp | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/esphome/components/light/light_json_schema.cpp b/esphome/components/light/light_json_schema.cpp index 20127fab33..7af6dadd12 100644 --- a/esphome/components/light/light_json_schema.cpp +++ b/esphome/components/light/light_json_schema.cpp @@ -11,17 +11,6 @@ namespace light { // 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); } -// Helper to parse color component from JSON -static bool parse_color_component(JsonObject &color, const char *key, LightCall &call, - LightCall &(LightCall::*setter)(float), float &out_value) { - if (color[key].is()) { - out_value = float(color[key]) / 255.0f; - (call.*setter)(out_value); - return true; - } - return false; -} - // Lookup table for color mode strings static const char *get_color_mode_json_str(ColorMode mode) { switch (mode) { @@ -115,23 +104,22 @@ void LightJSONSchema::parse_color_json(LightState &state, LightCall &call, JsonO JsonObject color = root["color"]; // 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; - bool has_rgb = false; - float r, g, b; - - if (parse_color_component(color, "r", call, &LightCall::set_red, r)) { + if (color["r"].is()) { + float r = float(color["r"]) / 255.0f; max_rgb = fmaxf(max_rgb, r); - has_rgb = true; + call.set_red(r); } - if (parse_color_component(color, "g", call, &LightCall::set_green, g)) { + if (color["g"].is()) { + float g = float(color["g"]) / 255.0f; max_rgb = fmaxf(max_rgb, g); - has_rgb = true; + call.set_green(g); } - if (parse_color_component(color, "b", call, &LightCall::set_blue, b)) { + if (color["b"].is()) { + float b = float(color["b"]) / 255.0f; max_rgb = fmaxf(max_rgb, b); - has_rgb = true; + call.set_blue(b); } - - if (has_rgb) { + if (color["r"].is() || color["g"].is() || color["b"].is()) { call.set_color_brightness(max_rgb); }