1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-20 00:35:44 +00:00

ads1115: remove auto-load and split sensor into platform folder (#5981)

This commit is contained in:
Jesse Hills
2024-04-11 10:09:25 +12:00
parent 68b4d8865c
commit 1d4c074ee6
6 changed files with 82 additions and 69 deletions

View File

@@ -0,0 +1,30 @@
#include "ads1115_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ads1115 {
static const char *const TAG = "ads1115.sensor";
float ADS1115Sensor::sample() {
return this->parent_->request_measurement(this->multiplexer_, this->gain_, this->resolution_);
}
void ADS1115Sensor::update() {
float v = this->sample();
if (!std::isnan(v)) {
ESP_LOGD(TAG, "'%s': Got Voltage=%fV", this->get_name().c_str(), v);
this->publish_state(v);
}
}
void ADS1115Sensor::dump_config() {
LOG_SENSOR(" ", "ADS1115 Sensor", this);
ESP_LOGCONFIG(TAG, " Multiplexer: %u", this->multiplexer_);
ESP_LOGCONFIG(TAG, " Gain: %u", this->gain_);
ESP_LOGCONFIG(TAG, " Resolution: %u", this->resolution_);
}
} // namespace ads1115
} // namespace esphome