Fix more linting errors

This commit is contained in:
Stephen Tierney 2021-02-01 21:43:50 +11:00 committed by steve
parent 7d13d6aa50
commit 8d08c82132
3 changed files with 54 additions and 58 deletions

View file

@ -49,9 +49,7 @@ ltr390_mode_t LTR390Component::get_mode_(void) {
return (ltr390_mode_t)(int) crtl_value[LTR390_CTRL_MODE];
}
void LTR390Component::set_gain_(ltr390_gain_t gain) {
*this->gain_reg_ = gain;
}
void LTR390Component::set_gain_(ltr390_gain_t gain) { *this->gain_reg_ = gain; }
ltr390_gain_t LTR390Component::get_gain_(void) {
std::bitset<8> gain_value(this->gain_reg_->get());
@ -111,6 +109,50 @@ uint32_t LTR390Component::read_sensor_data_(ltr390_mode_t mode) {
return little_endian_bytes_to_int(buffer, num_bytes);
}
void LTR390Component::read_als_() {
uint32_t als = this->read_sensor_data(LTR390_MODE_ALS);
if (this->light_sensor_ != nullptr) {
float lux = (0.6 * als) / (gain_values_[this->gain_] * resolution_values_[this->res_]) * this->wfac_;
this->light_sensor_->publish_state(lux);
}
if (this->als_sensor_ != nullptr) {
this->als_sensor_->publish_state(als);
}
}
void LTR390Component::read_uvs_() {
uint32_t uv = this->read_sensor_data(LTR390_MODE_UVS);
if (this->uvi_sensor_ != nullptr) {
this->uvi_sensor_->publish_state(uv / LTR390_SENSITIVITY * this->wfac_);
}
if (this->uv_sensor_ != nullptr) {
this->uv_sensor_->publish_state(uv);
}
}
void LTR390Component::read_mode_(int mode_index) {
// Set mode
this->set_mode(std::get<0>(this->mode_funcs_->at(mode_index)));
// After the sensor integration time do the following
this->set_timeout(resolution_values_[this->res_] * 100, [this, mode_index]() {
// Read from the sensor
std::get<1>(this->mode_funcs_->at(mode_index))();
// If there are more modes to read then begin the next
// otherwise stop
if (mode_index + 1 < this->mode_funcs_->size()) {
this->read_mode(mode_index + 1);
} else {
this->reading = false;
}
});
}
void LTR390Component::setup() {
ESP_LOGCONFIG(TAG, "Setting up ltr390...");
@ -151,57 +193,9 @@ void LTR390Component::setup() {
}
}
void LTR390Component::dump_config() {
LOG_I2C_DEVICE(this);
}
void LTR390Component::read_als_() {
uint32_t als = this->read_sensor_data(LTR390_MODE_ALS);
if (this->light_sensor_ != nullptr) {
float lux = (0.6 * als) / (gain_values_[this->gain_] * resolution_values_[this->res_]) * this->wfac_;
this->light_sensor_->publish_state(lux);
}
if (this->als_sensor_ != nullptr) {
this->als_sensor_->publish_state(als);
}
}
void LTR390Component::read_uvs_() {
uint32_t uv = this->read_sensor_data(LTR390_MODE_UVS);
if (this->uvi_sensor_ != nullptr) {
this->uvi_sensor_->publish_state(uv / LTR390_SENSITIVITY * this->wfac_);
}
if (this->uv_sensor_ != nullptr) {
this->uv_sensor_->publish_state(uv);
}
}
void LTR390Component::read_mode_(int mode_index) {
// Set mode
this->set_mode(std::get<0>(this->mode_funcs_->at(mode_index)));
// After the sensor integration time do the following
this->set_timeout(resolution_values_[this->res_] * 100, [this, mode_index]() {
// Read from the sensor
std::get<1>(this->mode_funcs_->at(mode_index))();
// If there are more modes to read then begin the next
// otherwise stop
if (mode_index + 1 < this->mode_funcs_->size()) {
this->read_mode(mode_index + 1);
} else {
this->reading = false;
}
});
}
void LTR390Component::dump_config() { LOG_I2C_DEVICE(this); }
void LTR390Component::update() {
if (!this->reading) {
this->reading = true;
this->read_mode(0);

View file

@ -53,10 +53,10 @@ enum ltr390_resolution_t {
class LTR390Component : public PollingComponent, public i2c::I2CDevice {
public:
float get_setup_priority() const override { return setup_priority::DATA; }
void setup() override;
void dump_config() override;
void update() override;
float get_setup_priority() const override { return setup_priority::DATA; }
void set_gain_value(ltr390_gain_t gain) { this->gain_ = gain; }
void set_res_value(ltr390_resolution_t res) { this->res_ = res; }

View file

@ -1,7 +1,8 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import CONF_ID, CONF_GAIN, CONF_LIGHT, CONF_RESOLUTION, UNIT_LUX, ICON_BRIGHTNESS_5
from esphome.const import CONF_ID, CONF_GAIN, CONF_LIGHT, CONF_RESOLUTION,
UNIT_LUX, ICON_BRIGHTNESS_5
DEPENDENCIES = ['i2c']
@ -58,6 +59,7 @@ TYPES = {
CONF_UV: 'set_uv_sensor',
}
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)