67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "../common.h"
|
|
#include "interfaces.h"
|
|
#include "light_output.h"
|
|
#include "esphome/components/light/light_state.h"
|
|
|
|
namespace esphome {
|
|
namespace xiaomi {
|
|
namespace bslamp2 {
|
|
|
|
/**
|
|
* A custom LightState class for the Xiaomi Bedside Lamp 2.
|
|
*
|
|
* It is used by the DiscoAction to apply immediate light output
|
|
* updates, without saving or publishing the new state.
|
|
*/
|
|
class XiaomiBslamp2LightState : public light::LightState, public LightStateDiscoSupport {
|
|
public:
|
|
XiaomiBslamp2LightState(XiaomiBslamp2LightOutput *output) : light::LightState(output) { }
|
|
|
|
void disco_stop() {
|
|
light::LightStateRTCState recovered{};
|
|
if (this->rtc_.load(&recovered)) {
|
|
auto call = make_disco_call(true);
|
|
call.set_state(recovered.state);
|
|
call.set_brightness_if_supported(recovered.brightness);
|
|
call.set_color_brightness_if_supported(recovered.color_brightness);
|
|
call.set_red_if_supported(recovered.red);
|
|
call.set_green_if_supported(recovered.green);
|
|
call.set_blue_if_supported(recovered.blue);
|
|
call.set_white_if_supported(recovered.white);
|
|
call.set_color_temperature_if_supported(recovered.color_temp);
|
|
call.set_cold_white_if_supported(recovered.cold_white);
|
|
call.set_warm_white_if_supported(recovered.warm_white);
|
|
if (recovered.effect != 0) {
|
|
call.set_effect(recovered.effect);
|
|
} else {
|
|
call.set_transition_length_if_supported(0);
|
|
}
|
|
call.set_color_mode_if_supported(recovered.color_mode);
|
|
call.perform();
|
|
}
|
|
}
|
|
|
|
void disco_apply() {
|
|
this->output_->write_state(this);
|
|
this->next_write_ = false;
|
|
}
|
|
|
|
void set_night_light_color_temperature_calibration(float red, float green, float blue) {
|
|
auto *output = static_cast<XiaomiBslamp2LightOutput *>(this->output_);
|
|
output->set_night_light_color_temperature_calibration(red, green, blue);
|
|
}
|
|
|
|
light::LightCall make_disco_call(bool save_and_publish) {
|
|
auto call = this->make_call();
|
|
call.set_save(save_and_publish);
|
|
call.set_publish(save_and_publish);
|
|
return call;
|
|
}
|
|
};
|
|
|
|
} // namespace bslamp2
|
|
} // namespace xiaomi
|
|
} // namespace esphome
|