From b61577b68b1e79595e751e158ee9873863b6d51c Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Wed, 25 Sep 2024 04:28:22 +0200 Subject: [PATCH] tcs34725: Add check for Division by Zero (#7485) --- esphome/components/tcs34725/tcs34725.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/tcs34725/tcs34725.cpp b/esphome/components/tcs34725/tcs34725.cpp index 9bb7c9a3b2..c9b2ae321a 100644 --- a/esphome/components/tcs34725/tcs34725.cpp +++ b/esphome/components/tcs34725/tcs34725.cpp @@ -1,6 +1,7 @@ #include "tcs34725.h" #include "esphome/core/log.h" #include "esphome/core/hal.h" +#include namespace esphome { namespace tcs34725 { @@ -254,7 +255,8 @@ void TCS34725Component::update() { // change integration time an gain to achieve maximum resolution an dynamic range // calculate optimal integration time to achieve 70% satuaration float integration_time_ideal; - integration_time_ideal = 60 / ((float) raw_c / 655.35) * this->integration_time_; + + integration_time_ideal = 60 / ((float) std::max((uint16_t) 1, raw_c) / 655.35f) * this->integration_time_; uint8_t gain_reg_val_new = this->gain_reg_; // increase gain if less than 20% of white channel used and high integration time