mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
Merge remote-tracking branch 'upstream/dev' into sx127x
This commit is contained in:
commit
ff6dd6ea9e
13 changed files with 103 additions and 8 deletions
|
@ -145,8 +145,9 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
|||
),
|
||||
)
|
||||
async def reset_energy_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
|
|
@ -147,6 +147,7 @@ void CSE7766Component::parse_data_() {
|
|||
float power = 0.0f;
|
||||
if (power_cycle_exceeds_range) {
|
||||
// Datasheet: power cycle exceeding range means active power is 0
|
||||
have_power = true;
|
||||
if (this->power_sensor_ != nullptr) {
|
||||
this->power_sensor_->publish_state(0.0f);
|
||||
}
|
||||
|
@ -178,6 +179,15 @@ void CSE7766Component::parse_data_() {
|
|||
if (this->apparent_power_sensor_ != nullptr) {
|
||||
this->apparent_power_sensor_->publish_state(apparent_power);
|
||||
}
|
||||
if (have_power && this->reactive_power_sensor_ != nullptr) {
|
||||
const float reactive_power = apparent_power - power;
|
||||
if (reactive_power < 0.0f) {
|
||||
ESP_LOGD(TAG, "Impossible reactive power: %.4f is negative", reactive_power);
|
||||
this->reactive_power_sensor_->publish_state(0.0f);
|
||||
} else {
|
||||
this->reactive_power_sensor_->publish_state(reactive_power);
|
||||
}
|
||||
}
|
||||
if (this->power_factor_sensor_ != nullptr && (have_power || power_cycle_exceeds_range)) {
|
||||
float pf = NAN;
|
||||
if (apparent_power > 0) {
|
||||
|
@ -232,6 +242,7 @@ void CSE7766Component::dump_config() {
|
|||
LOG_SENSOR(" ", "Power", this->power_sensor_);
|
||||
LOG_SENSOR(" ", "Energy", this->energy_sensor_);
|
||||
LOG_SENSOR(" ", "Apparent Power", this->apparent_power_sensor_);
|
||||
LOG_SENSOR(" ", "Reactive Power", this->reactive_power_sensor_);
|
||||
LOG_SENSOR(" ", "Power Factor", this->power_factor_sensor_);
|
||||
this->check_uart_settings(4800);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ class CSE7766Component : public Component, public uart::UARTDevice {
|
|||
void set_apparent_power_sensor(sensor::Sensor *apparent_power_sensor) {
|
||||
apparent_power_sensor_ = apparent_power_sensor;
|
||||
}
|
||||
void set_reactive_power_sensor(sensor::Sensor *reactive_power_sensor) {
|
||||
reactive_power_sensor_ = reactive_power_sensor;
|
||||
}
|
||||
void set_power_factor_sensor(sensor::Sensor *power_factor_sensor) { power_factor_sensor_ = power_factor_sensor; }
|
||||
|
||||
void loop() override;
|
||||
|
@ -35,6 +38,7 @@ class CSE7766Component : public Component, public uart::UARTDevice {
|
|||
sensor::Sensor *power_sensor_{nullptr};
|
||||
sensor::Sensor *energy_sensor_{nullptr};
|
||||
sensor::Sensor *apparent_power_sensor_{nullptr};
|
||||
sensor::Sensor *reactive_power_sensor_{nullptr};
|
||||
sensor::Sensor *power_factor_sensor_{nullptr};
|
||||
uint32_t cf_pulses_total_{0};
|
||||
uint16_t cf_pulses_last_{0};
|
||||
|
|
|
@ -8,18 +8,21 @@ from esphome.const import (
|
|||
CONF_ID,
|
||||
CONF_POWER,
|
||||
CONF_POWER_FACTOR,
|
||||
CONF_REACTIVE_POWER,
|
||||
CONF_VOLTAGE,
|
||||
DEVICE_CLASS_APPARENT_POWER,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_POWER_FACTOR,
|
||||
DEVICE_CLASS_REACTIVE_POWER,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
UNIT_AMPERE,
|
||||
UNIT_VOLT,
|
||||
UNIT_VOLT_AMPS,
|
||||
UNIT_VOLT_AMPS_REACTIVE,
|
||||
UNIT_WATT,
|
||||
UNIT_WATT_HOURS,
|
||||
)
|
||||
|
@ -62,6 +65,12 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
device_class=DEVICE_CLASS_APPARENT_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_REACTIVE_POWER): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_VOLT_AMPS_REACTIVE,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_REACTIVE_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_POWER_FACTOR,
|
||||
|
@ -94,6 +103,9 @@ async def to_code(config):
|
|||
if apparent_power_config := config.get(CONF_APPARENT_POWER):
|
||||
sens = await sensor.new_sensor(apparent_power_config)
|
||||
cg.add(var.set_apparent_power_sensor(sens))
|
||||
if reactive_power_config := config.get(CONF_REACTIVE_POWER):
|
||||
sens = await sensor.new_sensor(reactive_power_config)
|
||||
cg.add(var.set_reactive_power_sensor(sens))
|
||||
if power_factor_config := config.get(CONF_POWER_FACTOR):
|
||||
sens = await sensor.new_sensor(power_factor_config)
|
||||
cg.add(var.set_power_factor_sensor(sens))
|
||||
|
|
|
@ -53,6 +53,8 @@ MODELS = {
|
|||
"inkplate_10": InkplateModel.INKPLATE_10,
|
||||
"inkplate_6_plus": InkplateModel.INKPLATE_6_PLUS,
|
||||
"inkplate_6_v2": InkplateModel.INKPLATE_6_V2,
|
||||
"inkplate_5": InkplateModel.INKPLATE_5,
|
||||
"inkplate_5_v2": InkplateModel.INKPLATE_5_V2,
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
|
|
|
@ -15,6 +15,8 @@ enum InkplateModel : uint8_t {
|
|||
INKPLATE_10 = 1,
|
||||
INKPLATE_6_PLUS = 2,
|
||||
INKPLATE_6_V2 = 3,
|
||||
INKPLATE_5 = 4,
|
||||
INKPLATE_5_V2 = 5,
|
||||
};
|
||||
|
||||
class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
||||
|
@ -29,7 +31,7 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
|||
const uint8_t pixelMaskLUT[8] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
|
||||
const uint8_t pixelMaskGLUT[2] = {0x0F, 0xF0};
|
||||
|
||||
const uint8_t waveform3BitAll[4][8][9] = {// INKPLATE_6
|
||||
const uint8_t waveform3BitAll[6][8][9] = {// INKPLATE_6
|
||||
{{0, 1, 1, 0, 0, 1, 1, 0, 0},
|
||||
{0, 1, 2, 1, 1, 2, 1, 0, 0},
|
||||
{1, 1, 1, 2, 2, 1, 0, 0, 0},
|
||||
|
@ -64,7 +66,25 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
|||
{1, 1, 1, 1, 2, 2, 1, 0, 0},
|
||||
{0, 1, 1, 1, 2, 2, 1, 0, 0},
|
||||
{0, 0, 0, 0, 1, 1, 2, 0, 0},
|
||||
{0, 0, 0, 0, 0, 1, 2, 0, 0}}};
|
||||
{0, 0, 0, 0, 0, 1, 2, 0, 0}},
|
||||
// INKPLATE_5
|
||||
{{0, 0, 1, 1, 0, 1, 1, 1, 0},
|
||||
{0, 1, 1, 1, 1, 2, 0, 1, 0},
|
||||
{1, 2, 2, 0, 2, 1, 1, 1, 0},
|
||||
{1, 1, 1, 2, 0, 1, 1, 2, 0},
|
||||
{0, 1, 1, 1, 2, 0, 1, 2, 0},
|
||||
{0, 0, 0, 1, 1, 2, 1, 2, 0},
|
||||
{1, 1, 1, 2, 0, 2, 1, 2, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0}},
|
||||
// INKPLATE_5_V2
|
||||
{{0, 0, 1, 1, 2, 1, 1, 1, 0},
|
||||
{1, 1, 2, 2, 1, 2, 1, 1, 0},
|
||||
{0, 1, 2, 2, 1, 1, 2, 1, 0},
|
||||
{0, 0, 1, 1, 1, 1, 1, 2, 0},
|
||||
{1, 2, 1, 2, 1, 1, 1, 2, 0},
|
||||
{0, 1, 1, 1, 2, 0, 1, 2, 0},
|
||||
{1, 1, 1, 2, 2, 2, 1, 2, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0}}};
|
||||
|
||||
void set_greyscale(bool greyscale) {
|
||||
this->greyscale_ = greyscale;
|
||||
|
@ -146,6 +166,10 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
|||
return 800;
|
||||
} else if (this->model_ == INKPLATE_10) {
|
||||
return 1200;
|
||||
} else if (this->model_ == INKPLATE_5) {
|
||||
return 960;
|
||||
} else if (this->model_ == INKPLATE_5_V2) {
|
||||
return 1280;
|
||||
} else if (this->model_ == INKPLATE_6_PLUS) {
|
||||
return 1024;
|
||||
}
|
||||
|
@ -155,6 +179,10 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
|||
int get_height_internal() override {
|
||||
if (this->model_ == INKPLATE_6 || this->model_ == INKPLATE_6_V2) {
|
||||
return 600;
|
||||
} else if (this->model_ == INKPLATE_5) {
|
||||
return 540;
|
||||
} else if (this->model_ == INKPLATE_5_V2) {
|
||||
return 720;
|
||||
} else if (this->model_ == INKPLATE_10) {
|
||||
return 825;
|
||||
} else if (this->model_ == INKPLATE_6_PLUS) {
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
from esphome import automation, pins
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import esp32_rmt, remote_base
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import remote_base, esp32_rmt
|
||||
from esphome.const import CONF_CARRIER_DUTY_PERCENT, CONF_ID, CONF_PIN, CONF_RMT_CHANNEL
|
||||
|
||||
AUTO_LOAD = ["remote_base"]
|
||||
|
||||
CONF_ON_TRANSMIT = "on_transmit"
|
||||
CONF_ON_COMPLETE = "on_complete"
|
||||
|
||||
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
|
||||
RemoteTransmitterComponent = remote_transmitter_ns.class_(
|
||||
"RemoteTransmitterComponent", remote_base.RemoteTransmitterBase, cg.Component
|
||||
|
@ -19,6 +23,8 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
cv.percentage_int, cv.Range(min=1, max=100)
|
||||
),
|
||||
cv.Optional(CONF_RMT_CHANNEL): esp32_rmt.validate_rmt_channel(tx=True),
|
||||
cv.Optional(CONF_ON_TRANSMIT): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_ON_COMPLETE): automation.validate_automation(single=True),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
@ -32,3 +38,13 @@ async def to_code(config):
|
|||
await cg.register_component(var, config)
|
||||
|
||||
cg.add(var.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
|
||||
|
||||
if on_transmit_config := config.get(CONF_ON_TRANSMIT):
|
||||
await automation.build_automation(
|
||||
var.get_transmit_trigger(), [], on_transmit_config
|
||||
)
|
||||
|
||||
if on_complete_config := config.get(CONF_ON_COMPLETE):
|
||||
await automation.build_automation(
|
||||
var.get_complete_trigger(), [], on_complete_config
|
||||
)
|
||||
|
|
|
@ -33,6 +33,9 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
|
|||
|
||||
void set_carrier_duty_percent(uint8_t carrier_duty_percent) { this->carrier_duty_percent_ = carrier_duty_percent; }
|
||||
|
||||
Trigger<> *get_transmit_trigger() const { return this->transmit_trigger_; };
|
||||
Trigger<> *get_complete_trigger() const { return this->complete_trigger_; };
|
||||
|
||||
protected:
|
||||
void send_internal(uint32_t send_times, uint32_t send_wait) override;
|
||||
#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
|
||||
|
@ -57,6 +60,9 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
|
|||
bool inverted_{false};
|
||||
#endif
|
||||
uint8_t carrier_duty_percent_;
|
||||
|
||||
Trigger<> *transmit_trigger_{new Trigger<>()};
|
||||
Trigger<> *complete_trigger_{new Trigger<>()};
|
||||
};
|
||||
|
||||
} // namespace remote_transmitter
|
||||
|
|
|
@ -124,6 +124,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
ESP_LOGE(TAG, "Empty data");
|
||||
return;
|
||||
}
|
||||
this->transmit_trigger_->trigger();
|
||||
for (uint32_t i = 0; i < send_times; i++) {
|
||||
esp_err_t error = rmt_write_items(this->channel_, this->rmt_temp_.data(), this->rmt_temp_.size(), true);
|
||||
if (error != ESP_OK) {
|
||||
|
@ -135,6 +136,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
if (i + 1 < send_times)
|
||||
delayMicroseconds(send_wait);
|
||||
}
|
||||
this->complete_trigger_->trigger();
|
||||
}
|
||||
|
||||
} // namespace remote_transmitter
|
||||
|
|
|
@ -76,6 +76,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
uint32_t on_time, off_time;
|
||||
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
||||
this->target_time_ = 0;
|
||||
this->transmit_trigger_->trigger();
|
||||
for (uint32_t i = 0; i < send_times; i++) {
|
||||
for (int32_t item : this->temp_.get_data()) {
|
||||
if (item > 0) {
|
||||
|
@ -93,6 +94,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
if (i + 1 < send_times)
|
||||
this->target_time_ += send_wait;
|
||||
}
|
||||
this->complete_trigger_->trigger();
|
||||
}
|
||||
|
||||
} // namespace remote_transmitter
|
||||
|
|
|
@ -78,6 +78,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
uint32_t on_time, off_time;
|
||||
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
||||
this->target_time_ = 0;
|
||||
this->transmit_trigger_->trigger();
|
||||
for (uint32_t i = 0; i < send_times; i++) {
|
||||
InterruptLock lock;
|
||||
for (int32_t item : this->temp_.get_data()) {
|
||||
|
@ -96,6 +97,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
|||
if (i + 1 < send_times)
|
||||
this->target_time_ += send_wait;
|
||||
}
|
||||
this->complete_trigger_->trigger();
|
||||
}
|
||||
|
||||
} // namespace remote_transmitter
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "tcs34725.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace esphome {
|
||||
namespace tcs34725 {
|
||||
|
@ -211,7 +212,7 @@ void TCS34725Component::update() {
|
|||
if (raw_c == 0) {
|
||||
channel_c = channel_r = channel_g = channel_b = 0.0f;
|
||||
} else {
|
||||
float max_count = this->integration_time_ * 1024.0f / 2.4;
|
||||
float max_count = this->integration_time_ <= 153.6f ? this->integration_time_ * 1024.0f / 2.4f : 65535.0f;
|
||||
float sum = raw_c;
|
||||
channel_r = raw_r / sum * 100.0f;
|
||||
channel_g = raw_g / sum * 100.0f;
|
||||
|
@ -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
|
||||
|
|
|
@ -8,6 +8,7 @@ uart:
|
|||
|
||||
sensor:
|
||||
- platform: bl0906
|
||||
id: bl
|
||||
frequency:
|
||||
name: 'Frequency'
|
||||
temperature:
|
||||
|
@ -60,3 +61,9 @@ sensor:
|
|||
name: 'Total_Energy'
|
||||
total_power:
|
||||
name: 'Total_Power'
|
||||
|
||||
button:
|
||||
- platform: template
|
||||
id: reset
|
||||
on_press:
|
||||
- bl0906.reset_energy: bl
|
||||
|
|
Loading…
Reference in a new issue