From 8e6a053eadba7d5f8941f1aae0c07d9a75980a46 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 26 Jul 2025 21:11:57 -1000 Subject: [PATCH] preen --- esphome/components/light/light_color_values.h | 2 ++ esphome/components/light/light_state.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/esphome/components/light/light_color_values.h b/esphome/components/light/light_color_values.h index 8ec6cf0bfe..9a37f6b424 100644 --- a/esphome/components/light/light_color_values.h +++ b/esphome/components/light/light_color_values.h @@ -85,6 +85,8 @@ class LightColorValues { */ static LightColorValues lerp(const LightColorValues &start, const LightColorValues &end, float completion) { // Directly interpolate the raw values to avoid getter/setter overhead + // Linear interpolation between two clamped values produces a clamped result, + // so we can skip the setters which include redundant clamping logic LightColorValues v; v.color_mode_ = end.color_mode_; v.state_ = std::lerp(start.state_, end.state_, completion); diff --git a/esphome/components/light/light_state.cpp b/esphome/components/light/light_state.cpp index fd0aafe4c6..ff0a2b2127 100644 --- a/esphome/components/light/light_state.cpp +++ b/esphome/components/light/light_state.cpp @@ -24,7 +24,8 @@ void LightState::setup() { } // When supported color temperature range is known, initialize color temperature setting within bounds. - float min_mireds = this->get_traits().get_min_mireds(); + auto traits = this->get_traits(); + float min_mireds = traits.get_min_mireds(); if (min_mireds > 0) { this->remote_values.set_color_temperature(min_mireds); this->current_values.set_color_temperature(min_mireds); @@ -43,11 +44,8 @@ void LightState::setup() { this->rtc_ = global_preferences->make_preference(this->get_object_id_hash()); // Attempt to load from preferences, else fall back to default values if (!this->rtc_.load(&recovered)) { - recovered.state = false; - if (this->restore_mode_ == LIGHT_RESTORE_DEFAULT_ON || - this->restore_mode_ == LIGHT_RESTORE_INVERTED_DEFAULT_ON) { - recovered.state = true; - } + recovered.state = (this->restore_mode_ == LIGHT_RESTORE_DEFAULT_ON || + this->restore_mode_ == LIGHT_RESTORE_INVERTED_DEFAULT_ON); } else if (this->restore_mode_ == LIGHT_RESTORE_INVERTED_DEFAULT_OFF || this->restore_mode_ == LIGHT_RESTORE_INVERTED_DEFAULT_ON) { // Inverted restore state