You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.6 KiB
94 lines
2.6 KiB
#pragma once
|
|
|
|
#include "esphome/core/entity_base.h"
|
|
#include "esphome/core/log.h"
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/i2c/i2c.h"
|
|
#include "esphome/components/output/float_output.h"
|
|
// TODO: maybe use monochrome leds instead of floatoutput directly?:
|
|
/* #include "esphome/components/monochromatic/monochromatic_light_output.h" */
|
|
|
|
namespace esphome {
|
|
namespace showcase_component {
|
|
|
|
enum State{ Off, Auto, On };
|
|
|
|
static const char *TAG = "showcase_component.component";
|
|
|
|
class ShowcaseComponent : public i2c::I2CDevice, public Component, public EntityBase {
|
|
public:
|
|
State s_{Off};
|
|
float b_upper_{1.0};
|
|
float b_lower_{1.0};
|
|
|
|
void turn_on();
|
|
void turn_off();
|
|
|
|
void publish_state(){ this->remote_values_callback_.call(); }
|
|
|
|
void add_new_remote_values_callback(std::function<void()> &&send_callback) {
|
|
this->remote_values_callback_.add(std::move(send_callback));
|
|
}
|
|
|
|
void setup() override;
|
|
void loop() override;
|
|
void dump_config() override;
|
|
|
|
void set_upper(output::FloatOutput *upper) {this->upper_ = upper;}
|
|
void set_lower(output::FloatOutput *lower) {this->lower_ = lower;}
|
|
/* void set_upper(monochromatic::MonochromaticLightOutput *upper) {this->upper_ = upper;} */
|
|
/* void set_lower(monochromatic::MonochromaticLightOutput *lower) {this->lower_ = lower;} */
|
|
|
|
void write_state(State s){
|
|
ESP_LOGI(TAG, "Write_state");
|
|
this->s_ = s;
|
|
switch(s) {
|
|
case(On):
|
|
/* ESP_LOGI(TAG, "Set to On"); */
|
|
this->set_level(this->b_upper_, this->b_lower_);
|
|
break;
|
|
case(Off):
|
|
/* ESP_LOGI(TAG, "Set to Off"); */
|
|
this->upper_->set_level(0.0);
|
|
this->lower_->set_level(0.0);
|
|
break;
|
|
case(Auto):
|
|
/* ESP_LOGI(TAG, "Set to Auto"); */
|
|
break;
|
|
}
|
|
}
|
|
|
|
void set_level(float bright){
|
|
this->set_level(bright, bright);
|
|
/* this->upper_->write_state(upper); */
|
|
/* this->lower_->write_state(lower); */
|
|
}
|
|
|
|
void set_level(float upper, float lower){
|
|
this->set_level_upper(upper);
|
|
this->set_level_lower(lower);
|
|
/* this->upper_->write_state(upper); */
|
|
/* this->lower_->write_state(lower); */
|
|
}
|
|
|
|
void set_level_upper(float bright){
|
|
this->b_upper_ = bright;
|
|
this->upper_->set_level(bright);
|
|
}
|
|
|
|
void set_level_lower(float bright){
|
|
this->b_lower_ = bright;
|
|
this->lower_->set_level(bright);
|
|
}
|
|
protected:
|
|
CallbackManager<void()> remote_values_callback_{};
|
|
|
|
output::FloatOutput *upper_;
|
|
output::FloatOutput *lower_;
|
|
/* monochromatic::MonochromaticLightOutput *upper_; */
|
|
/* monochromatic::MonochromaticLightOutput *lower_; */
|
|
};
|
|
|
|
} // namespace empty_i2c_component
|
|
} // namespace esphome
|