mirror of
https://github.com/esphome/esphome.git
synced 2026-10-11 13:54:12 +00:00
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "esphome/components/light/light_output.h"
|
|
#include "esphome/components/light/light_state.h"
|
|
|
|
namespace esphome::light::testing {
|
|
|
|
namespace {
|
|
|
|
class BrightnessOutput : public LightOutput {
|
|
public:
|
|
LightTraits get_traits() override {
|
|
LightTraits traits;
|
|
traits.set_supported_color_modes({ColorMode::BRIGHTNESS});
|
|
return traits;
|
|
}
|
|
void write_state(LightState *state) override {}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
// get_gamma_correct() reads the gamma codegen stores after the lookup table, rounded to two decimals.
|
|
TEST(LightStateGamma, ReadsTheGammaStoredWithTheTable) {
|
|
static constexpr GammaTable TABLE{{}, 280};
|
|
BrightnessOutput output;
|
|
LightState state(&output);
|
|
state.set_gamma_table(&TABLE);
|
|
EXPECT_FLOAT_EQ(state.get_gamma_correct(), 2.8f);
|
|
EXPECT_EQ(state.get_gamma_table(), TABLE.lut);
|
|
}
|
|
|
|
TEST(LightStateGamma, IsZeroWithoutATable) {
|
|
BrightnessOutput output;
|
|
LightState state(&output);
|
|
EXPECT_FLOAT_EQ(state.get_gamma_correct(), 0.0f);
|
|
EXPECT_EQ(state.get_gamma_table(), nullptr);
|
|
}
|
|
|
|
} // namespace esphome::light::testing
|