66 uint16_t red{0}, green{0}, blue{0}, white{0};
71 ESP_LOGV(TAG,
"Counts: red=%u green=%u blue=%u white=%u", red, green, blue, white);
73 PUBLISH_STATE(this->red_sensor_, red);
74 PUBLISH_STATE(this->green_sensor_, green);
75 PUBLISH_STATE(this->blue_sensor_, blue);
76 PUBLISH_STATE(this->white_sensor_, white);
78 const bool saturated = red == MAX_COUNTS || green == MAX_COUNTS || blue == MAX_COUNTS;
80 ESP_LOGW(TAG,
"Sensor saturated; use a shorter integration time");
83 if (this->illuminance_sensor_ !=
nullptr) {
85 if (green != MAX_COUNTS) {
86 const float lux_per_count = LUX_PER_COUNT_40MS /
static_cast<float>(1u << this->
integration_time_);
87 lux = green * lux_per_count * this->glass_attenuation_factor_;
89 this->illuminance_sensor_->publish_state(lux);
92 if (this->color_temperature_sensor_ !=
nullptr) {
94 if (!saturated && green != 0) {
98 cct = CCT_A * powf(index, CCT_EXPONENT);
100 this->color_temperature_sensor_->publish_state(cct);