mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 19:54:14 +01:00
a919b015b4
* Add support for INA226 Current/Power Monitor * fix lint errors * fix narrowing conversion * Remove useless code Co-authored-by: Sergio Muñoz <sergio@iMac-de-Sergio.local>
35 lines
1.3 KiB
C++
35 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
#include "esphome/components/i2c/i2c.h"
|
|
|
|
namespace esphome {
|
|
namespace ina226 {
|
|
|
|
class INA226Component : public PollingComponent, public i2c::I2CDevice {
|
|
public:
|
|
void setup() override;
|
|
void dump_config() override;
|
|
float get_setup_priority() const override;
|
|
void update() override;
|
|
|
|
void set_shunt_resistance_ohm(float shunt_resistance_ohm) { shunt_resistance_ohm_ = shunt_resistance_ohm; }
|
|
void set_max_current_a(float max_current_a) { max_current_a_ = max_current_a; }
|
|
void set_bus_voltage_sensor(sensor::Sensor *bus_voltage_sensor) { bus_voltage_sensor_ = bus_voltage_sensor; }
|
|
void set_shunt_voltage_sensor(sensor::Sensor *shunt_voltage_sensor) { shunt_voltage_sensor_ = shunt_voltage_sensor; }
|
|
void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
|
|
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
|
|
|
|
protected:
|
|
float shunt_resistance_ohm_;
|
|
float max_current_a_;
|
|
uint32_t calibration_lsb_;
|
|
sensor::Sensor *bus_voltage_sensor_{nullptr};
|
|
sensor::Sensor *shunt_voltage_sensor_{nullptr};
|
|
sensor::Sensor *current_sensor_{nullptr};
|
|
sensor::Sensor *power_sensor_{nullptr};
|
|
};
|
|
|
|
} // namespace ina226
|
|
} // namespace esphome
|