diff --git a/components/custom_monochromatic/monochromatic_light_output.h b/components/custom_monochromatic/monochromatic_light_output.h index eabda9c..41c5a15 100644 --- a/components/custom_monochromatic/monochromatic_light_output.h +++ b/components/custom_monochromatic/monochromatic_light_output.h @@ -1,15 +1,15 @@ #pragma once -#include "esphome/core/log.h" #include "esphome/components/i2c/i2c.h" #include "esphome/components/light/light_output.h" #include "esphome/components/output/float_output.h" #include "esphome/core/component.h" +#include "esphome/core/log.h" namespace esphome { namespace c_monochromatic { -enum State{ Off, Auto, On }; +enum State { Off, Auto, On }; class MonochromaticLightOutput : public light::LightOutput, public i2c::I2CDevice, @@ -27,46 +27,48 @@ public: return traits; } void write_state(light::LightState *state) override { - this->light_state_ = state; - state->current_values_as_brightness(&(this -> bright_)); - this->upper_->set_level(this->bright_); - this->lower_->set_level(this->bright_); + if (this->state_ == Off) { + this->light_state_ = state; + state->current_values_as_brightness(&(this->bright_)); + this->upper_->set_level(this->bright_); + this->lower_->set_level(this->bright_); + } } - void set_state(State s){ + void set_state(State s) { this->state_ = s; - switch(s){ - case(On): - /* this -> light_state_->turn_on(); */ - this -> upper_ -> set_level(this->bright_); - this -> lower_ -> set_level(this->bright_); - break; - case(Off): - /* this -> light_state_->turn_off(); */ - this -> upper_ -> set_level(0.0); - this -> lower_ -> set_level(0.0); - break; - case(Auto): - break; + switch (s) { + case (On): + /* this -> light_state_->turn_on(); */ + this->upper_->set_level(this->bright_); + this->lower_->set_level(this->bright_); + break; + case (Off): + /* this -> light_state_->turn_off(); */ + this->upper_->set_level(0.0); + this->lower_->set_level(0.0); + break; + case (Auto): + break; } /* this -> write_state(this -> light_state_); */ } - void loop(){ + void loop() { uint8_t data = 10; this->read_register(0x0, &data, 0x1); /* ESP_LOGI(TAG, "READ value: %d", data); */ - if(data != 0){ - if(data & 1){ - this->set_state(Off); - ESP_LOGI("TEST", "Set to Off", data); + if (data != 0) { + if (data & 1) { + this->set_state(Off); + ESP_LOGI("TEST", "Set to Off", data); /* } else if ( data & 2 ){ */ /* this->set_state(Auto); */ - /* ESP_LOGI(TAG, "Set to Auto", data); */ - } else if ( data & 4 ){ - this->set_state(On); - ESP_LOGI("TEST", "Set to On", data); - } + /* ESP_LOGI(TAG, "Set to Auto", data); */ + } else if (data & 4) { + this->set_state(On); + ESP_LOGI("TEST", "Set to On", data); + } } /* if(this->state_ == Auto) { */ /* if(data & 8){ */