mirror of https://github.com/esphome/esphome.git
Merge ceae0cacab
into c7c0d97a5e
This commit is contained in:
commit
d838c02cc4
|
@ -24,6 +24,7 @@ esphome/components/ade7953_i2c/* @angelnu
|
|||
esphome/components/ade7953_spi/* @angelnu
|
||||
esphome/components/ads1118/* @solomondg1
|
||||
esphome/components/ags10/* @mak-42
|
||||
esphome/components/ain4_20ma/* @erikveg
|
||||
esphome/components/airthings_ble/* @jeromelaban
|
||||
esphome/components/airthings_wave_base/* @jeromelaban @kpfleming @ncareau
|
||||
esphome/components/airthings_wave_mini/* @ncareau
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
CODEOWNERS = ["@erikveg"]
|
||||
DEPENDENCIES = ["i2c"]
|
|
@ -0,0 +1,31 @@
|
|||
#include "ain4_20ma.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ain4_20ma {
|
||||
|
||||
static const char *const TAG = "ain4_20ma";
|
||||
|
||||
void Ain420maComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "AIN4-20mA Sensor:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Sensor:", this);
|
||||
}
|
||||
|
||||
void Ain420maComponent::update() {
|
||||
uint8_t data[2];
|
||||
|
||||
i2c::ErrorCode err = this->read_register(0x20, data, 2);
|
||||
if (err != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Error reading data from AIN4-20mA");
|
||||
this->publish_state(NAN);
|
||||
} else {
|
||||
uint16_t value;
|
||||
value = data[0] | (data[1] << 8);
|
||||
this->publish_state(value);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ain4_20ma
|
||||
} // namespace esphome
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ain4_20ma {
|
||||
|
||||
class Ain420maComponent : public i2c::I2CDevice, public PollingComponent, public sensor::Sensor {
|
||||
public:
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
void dump_config() override;
|
||||
void update() override;
|
||||
};
|
||||
|
||||
} // namespace ain4_20ma
|
||||
} // namespace esphome
|
|
@ -0,0 +1,33 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
from esphome.const import (
|
||||
DEVICE_CLASS_CURRENT,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
ain4_20ma_ns = cg.esphome_ns.namespace("ain4_20ma")
|
||||
|
||||
Ain420maComponent = ain4_20ma_ns.class_(
|
||||
"Ain420maComponent", cg.PollingComponent, i2c.I2CDevice, sensor.Sensor
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
sensor.sensor_schema(
|
||||
Ain420maComponent,
|
||||
unit_of_measurement="mA",
|
||||
accuracy_decimals=3,
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(default_address=0x55))
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await sensor.new_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 5
|
||||
sda: 4
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 5
|
||||
sda: 4
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 16
|
||||
sda: 17
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 16
|
||||
sda: 17
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 5
|
||||
sda: 4
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
|
@ -0,0 +1,9 @@
|
|||
i2c:
|
||||
- id: i2c_ain4_20ma
|
||||
scl: 5
|
||||
sda: 4
|
||||
|
||||
sensor:
|
||||
- platform: ain4_20ma
|
||||
name: "Current"
|
||||
update_interval: 60s
|
Loading…
Reference in New Issue