2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
|
|
|
#include "esphome/components/output/float_output.h"
|
|
|
|
#include "esphome/components/light/light_output.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace rgbww {
|
|
|
|
|
|
|
|
class RGBWWLightOutput : public light::LightOutput {
|
|
|
|
public:
|
2019-04-22 21:56:30 +02:00
|
|
|
void set_red(output::FloatOutput *red) { red_ = red; }
|
|
|
|
void set_green(output::FloatOutput *green) { green_ = green; }
|
|
|
|
void set_blue(output::FloatOutput *blue) { blue_ = blue; }
|
|
|
|
void set_cold_white(output::FloatOutput *cold_white) { cold_white_ = cold_white; }
|
|
|
|
void set_warm_white(output::FloatOutput *warm_white) { warm_white_ = warm_white; }
|
2021-07-29 19:11:56 +02:00
|
|
|
void set_cold_white_temperature(float cold_white_temperature) { cold_white_temperature_ = cold_white_temperature; }
|
|
|
|
void set_warm_white_temperature(float warm_white_temperature) { warm_white_temperature_ = warm_white_temperature; }
|
2020-04-08 14:31:23 +02:00
|
|
|
void set_constant_brightness(bool constant_brightness) { constant_brightness_ = constant_brightness; }
|
2020-07-10 01:29:44 +02:00
|
|
|
void set_color_interlock(bool color_interlock) { color_interlock_ = color_interlock; }
|
2019-04-17 12:06:00 +02:00
|
|
|
light::LightTraits get_traits() override {
|
|
|
|
auto traits = light::LightTraits();
|
2021-07-29 19:11:56 +02:00
|
|
|
if (this->color_interlock_)
|
|
|
|
traits.set_supported_color_modes({light::ColorMode::RGB, light::ColorMode::COLD_WARM_WHITE});
|
|
|
|
else
|
|
|
|
traits.set_supported_color_modes({light::ColorMode::RGB_COLD_WARM_WHITE});
|
2019-05-28 20:44:27 +02:00
|
|
|
traits.set_min_mireds(this->cold_white_temperature_);
|
2019-05-30 09:33:47 +02:00
|
|
|
traits.set_max_mireds(this->warm_white_temperature_);
|
2019-04-17 12:06:00 +02:00
|
|
|
return traits;
|
|
|
|
}
|
|
|
|
void write_state(light::LightState *state) override {
|
|
|
|
float red, green, blue, cwhite, wwhite;
|
2021-08-09 06:44:52 +02:00
|
|
|
state->current_values_as_rgbww(&red, &green, &blue, &cwhite, &wwhite, this->constant_brightness_);
|
2019-04-17 12:06:00 +02:00
|
|
|
this->red_->set_level(red);
|
|
|
|
this->green_->set_level(green);
|
|
|
|
this->blue_->set_level(blue);
|
|
|
|
this->cold_white_->set_level(cwhite);
|
|
|
|
this->warm_white_->set_level(wwhite);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
output::FloatOutput *red_;
|
|
|
|
output::FloatOutput *green_;
|
|
|
|
output::FloatOutput *blue_;
|
|
|
|
output::FloatOutput *cold_white_;
|
|
|
|
output::FloatOutput *warm_white_;
|
2021-07-29 19:11:56 +02:00
|
|
|
float cold_white_temperature_{0};
|
|
|
|
float warm_white_temperature_{0};
|
2020-04-08 14:31:23 +02:00
|
|
|
bool constant_brightness_;
|
2020-07-10 01:29:44 +02:00
|
|
|
bool color_interlock_{false};
|
2019-04-17 12:06:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rgbww
|
|
|
|
} // namespace esphome
|