mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 15:04:54 +01:00
Merge branch 'dev' of github.com:esphome/esphome into hbridge-switch
This commit is contained in:
commit
a1a00620f4
22 changed files with 309 additions and 17 deletions
2
.github/workflows/sync-device-classes.yml
vendored
2
.github/workflows/sync-device-classes.yml
vendored
|
@ -36,7 +36,7 @@ jobs:
|
||||||
python ./script/sync-device_class.py
|
python ./script/sync-device_class.py
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
uses: peter-evans/create-pull-request@v7.0.3
|
uses: peter-evans/create-pull-request@v7.0.5
|
||||||
with:
|
with:
|
||||||
commit-message: "Synchronise Device Classes from Home Assistant"
|
commit-message: "Synchronise Device Classes from Home Assistant"
|
||||||
committer: esphomebot <esphome@nabucasa.com>
|
committer: esphomebot <esphome@nabucasa.com>
|
||||||
|
|
|
@ -1242,6 +1242,9 @@ VoiceAssistantConfigurationResponse APIConnection::voice_assistant_get_configura
|
||||||
}
|
}
|
||||||
resp.available_wake_words.push_back(std::move(resp_wake_word));
|
resp.available_wake_words.push_back(std::move(resp_wake_word));
|
||||||
}
|
}
|
||||||
|
for (auto &wake_word_id : config.active_wake_words) {
|
||||||
|
resp.active_wake_words.push_back(wake_word_id);
|
||||||
|
}
|
||||||
resp.max_active_wake_words = config.max_active_wake_words;
|
resp.max_active_wake_words = config.max_active_wake_words;
|
||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
|
|
|
@ -145,8 +145,9 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
async def reset_energy_to_code(config, action_id, template_arg, args):
|
async def reset_energy_to_code(config, action_id, template_arg, args):
|
||||||
paren = await cg.get_variable(config[CONF_ID])
|
var = cg.new_Pvariable(action_id, template_arg)
|
||||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
await cg.register_parented(var, config[CONF_ID])
|
||||||
|
return var
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
|
|
@ -147,6 +147,7 @@ void CSE7766Component::parse_data_() {
|
||||||
float power = 0.0f;
|
float power = 0.0f;
|
||||||
if (power_cycle_exceeds_range) {
|
if (power_cycle_exceeds_range) {
|
||||||
// Datasheet: power cycle exceeding range means active power is 0
|
// Datasheet: power cycle exceeding range means active power is 0
|
||||||
|
have_power = true;
|
||||||
if (this->power_sensor_ != nullptr) {
|
if (this->power_sensor_ != nullptr) {
|
||||||
this->power_sensor_->publish_state(0.0f);
|
this->power_sensor_->publish_state(0.0f);
|
||||||
}
|
}
|
||||||
|
@ -178,6 +179,15 @@ void CSE7766Component::parse_data_() {
|
||||||
if (this->apparent_power_sensor_ != nullptr) {
|
if (this->apparent_power_sensor_ != nullptr) {
|
||||||
this->apparent_power_sensor_->publish_state(apparent_power);
|
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)) {
|
if (this->power_factor_sensor_ != nullptr && (have_power || power_cycle_exceeds_range)) {
|
||||||
float pf = NAN;
|
float pf = NAN;
|
||||||
if (apparent_power > 0) {
|
if (apparent_power > 0) {
|
||||||
|
@ -232,6 +242,7 @@ void CSE7766Component::dump_config() {
|
||||||
LOG_SENSOR(" ", "Power", this->power_sensor_);
|
LOG_SENSOR(" ", "Power", this->power_sensor_);
|
||||||
LOG_SENSOR(" ", "Energy", this->energy_sensor_);
|
LOG_SENSOR(" ", "Energy", this->energy_sensor_);
|
||||||
LOG_SENSOR(" ", "Apparent Power", this->apparent_power_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_);
|
LOG_SENSOR(" ", "Power Factor", this->power_factor_sensor_);
|
||||||
this->check_uart_settings(4800);
|
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) {
|
void set_apparent_power_sensor(sensor::Sensor *apparent_power_sensor) {
|
||||||
apparent_power_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 set_power_factor_sensor(sensor::Sensor *power_factor_sensor) { power_factor_sensor_ = power_factor_sensor; }
|
||||||
|
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
@ -35,6 +38,7 @@ class CSE7766Component : public Component, public uart::UARTDevice {
|
||||||
sensor::Sensor *power_sensor_{nullptr};
|
sensor::Sensor *power_sensor_{nullptr};
|
||||||
sensor::Sensor *energy_sensor_{nullptr};
|
sensor::Sensor *energy_sensor_{nullptr};
|
||||||
sensor::Sensor *apparent_power_sensor_{nullptr};
|
sensor::Sensor *apparent_power_sensor_{nullptr};
|
||||||
|
sensor::Sensor *reactive_power_sensor_{nullptr};
|
||||||
sensor::Sensor *power_factor_sensor_{nullptr};
|
sensor::Sensor *power_factor_sensor_{nullptr};
|
||||||
uint32_t cf_pulses_total_{0};
|
uint32_t cf_pulses_total_{0};
|
||||||
uint16_t cf_pulses_last_{0};
|
uint16_t cf_pulses_last_{0};
|
||||||
|
|
|
@ -8,18 +8,21 @@ from esphome.const import (
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_POWER,
|
CONF_POWER,
|
||||||
CONF_POWER_FACTOR,
|
CONF_POWER_FACTOR,
|
||||||
|
CONF_REACTIVE_POWER,
|
||||||
CONF_VOLTAGE,
|
CONF_VOLTAGE,
|
||||||
DEVICE_CLASS_APPARENT_POWER,
|
DEVICE_CLASS_APPARENT_POWER,
|
||||||
DEVICE_CLASS_CURRENT,
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
DEVICE_CLASS_POWER_FACTOR,
|
DEVICE_CLASS_POWER_FACTOR,
|
||||||
|
DEVICE_CLASS_REACTIVE_POWER,
|
||||||
DEVICE_CLASS_VOLTAGE,
|
DEVICE_CLASS_VOLTAGE,
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
UNIT_AMPERE,
|
UNIT_AMPERE,
|
||||||
UNIT_VOLT,
|
UNIT_VOLT,
|
||||||
UNIT_VOLT_AMPS,
|
UNIT_VOLT_AMPS,
|
||||||
|
UNIT_VOLT_AMPS_REACTIVE,
|
||||||
UNIT_WATT,
|
UNIT_WATT,
|
||||||
UNIT_WATT_HOURS,
|
UNIT_WATT_HOURS,
|
||||||
)
|
)
|
||||||
|
@ -62,6 +65,12 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
device_class=DEVICE_CLASS_APPARENT_POWER,
|
device_class=DEVICE_CLASS_APPARENT_POWER,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
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(
|
cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(
|
||||||
accuracy_decimals=2,
|
accuracy_decimals=2,
|
||||||
device_class=DEVICE_CLASS_POWER_FACTOR,
|
device_class=DEVICE_CLASS_POWER_FACTOR,
|
||||||
|
@ -94,6 +103,9 @@ async def to_code(config):
|
||||||
if apparent_power_config := config.get(CONF_APPARENT_POWER):
|
if apparent_power_config := config.get(CONF_APPARENT_POWER):
|
||||||
sens = await sensor.new_sensor(apparent_power_config)
|
sens = await sensor.new_sensor(apparent_power_config)
|
||||||
cg.add(var.set_apparent_power_sensor(sens))
|
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):
|
if power_factor_config := config.get(CONF_POWER_FACTOR):
|
||||||
sens = await sensor.new_sensor(power_factor_config)
|
sens = await sensor.new_sensor(power_factor_config)
|
||||||
cg.add(var.set_power_factor_sensor(sens))
|
cg.add(var.set_power_factor_sensor(sens))
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
from esphome import automation
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
from esphome.components import binary_sensor, esp32_ble_server, output
|
from esphome.components import binary_sensor, esp32_ble_server, output
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ID
|
from esphome.const import CONF_ID, CONF_ON_STATE, CONF_TRIGGER_ID
|
||||||
|
|
||||||
AUTO_LOAD = ["esp32_ble_server"]
|
AUTO_LOAD = ["esp32_ble_server"]
|
||||||
CODEOWNERS = ["@jesserockz"]
|
CODEOWNERS = ["@jesserockz"]
|
||||||
|
@ -11,13 +12,36 @@ CONF_AUTHORIZED_DURATION = "authorized_duration"
|
||||||
CONF_AUTHORIZER = "authorizer"
|
CONF_AUTHORIZER = "authorizer"
|
||||||
CONF_BLE_SERVER_ID = "ble_server_id"
|
CONF_BLE_SERVER_ID = "ble_server_id"
|
||||||
CONF_IDENTIFY_DURATION = "identify_duration"
|
CONF_IDENTIFY_DURATION = "identify_duration"
|
||||||
|
CONF_ON_PROVISIONED = "on_provisioned"
|
||||||
|
CONF_ON_PROVISIONING = "on_provisioning"
|
||||||
|
CONF_ON_START = "on_start"
|
||||||
|
CONF_ON_STOP = "on_stop"
|
||||||
CONF_STATUS_INDICATOR = "status_indicator"
|
CONF_STATUS_INDICATOR = "status_indicator"
|
||||||
CONF_WIFI_TIMEOUT = "wifi_timeout"
|
CONF_WIFI_TIMEOUT = "wifi_timeout"
|
||||||
|
|
||||||
|
improv_ns = cg.esphome_ns.namespace("improv")
|
||||||
|
Error = improv_ns.enum("Error")
|
||||||
|
State = improv_ns.enum("State")
|
||||||
|
|
||||||
esp32_improv_ns = cg.esphome_ns.namespace("esp32_improv")
|
esp32_improv_ns = cg.esphome_ns.namespace("esp32_improv")
|
||||||
ESP32ImprovComponent = esp32_improv_ns.class_(
|
ESP32ImprovComponent = esp32_improv_ns.class_(
|
||||||
"ESP32ImprovComponent", cg.Component, esp32_ble_server.BLEServiceComponent
|
"ESP32ImprovComponent", cg.Component, esp32_ble_server.BLEServiceComponent
|
||||||
)
|
)
|
||||||
|
ESP32ImprovProvisionedTrigger = esp32_improv_ns.class_(
|
||||||
|
"ESP32ImprovProvisionedTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
ESP32ImprovProvisioningTrigger = esp32_improv_ns.class_(
|
||||||
|
"ESP32ImprovProvisioningTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
ESP32ImprovStartTrigger = esp32_improv_ns.class_(
|
||||||
|
"ESP32ImprovStartTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
ESP32ImprovStateTrigger = esp32_improv_ns.class_(
|
||||||
|
"ESP32ImprovStateTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
ESP32ImprovStoppedTrigger = esp32_improv_ns.class_(
|
||||||
|
"ESP32ImprovStoppedTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema(
|
CONFIG_SCHEMA = cv.Schema(
|
||||||
|
@ -37,6 +61,37 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
cv.Optional(
|
cv.Optional(
|
||||||
CONF_WIFI_TIMEOUT, default="1min"
|
CONF_WIFI_TIMEOUT, default="1min"
|
||||||
): cv.positive_time_period_milliseconds,
|
): cv.positive_time_period_milliseconds,
|
||||||
|
cv.Optional(CONF_ON_PROVISIONED): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||||
|
ESP32ImprovProvisionedTrigger
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_PROVISIONING): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||||
|
ESP32ImprovProvisioningTrigger
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_START): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ESP32ImprovStartTrigger),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STATE): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ESP32ImprovStateTrigger),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
cv.Optional(CONF_ON_STOP): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
||||||
|
ESP32ImprovStoppedTrigger
|
||||||
|
),
|
||||||
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA)
|
).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
|
@ -63,3 +118,29 @@ async def to_code(config):
|
||||||
if CONF_STATUS_INDICATOR in config:
|
if CONF_STATUS_INDICATOR in config:
|
||||||
status_indicator = await cg.get_variable(config[CONF_STATUS_INDICATOR])
|
status_indicator = await cg.get_variable(config[CONF_STATUS_INDICATOR])
|
||||||
cg.add(var.set_status_indicator(status_indicator))
|
cg.add(var.set_status_indicator(status_indicator))
|
||||||
|
|
||||||
|
use_state_callback = False
|
||||||
|
for conf in config.get(CONF_ON_PROVISIONED, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
use_state_callback = True
|
||||||
|
for conf in config.get(CONF_ON_PROVISIONING, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
use_state_callback = True
|
||||||
|
for conf in config.get(CONF_ON_START, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
use_state_callback = True
|
||||||
|
for conf in config.get(CONF_ON_STATE, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(
|
||||||
|
trigger, [(State, "state"), (Error, "error")], conf
|
||||||
|
)
|
||||||
|
use_state_callback = True
|
||||||
|
for conf in config.get(CONF_ON_STOP, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
use_state_callback = True
|
||||||
|
if use_state_callback:
|
||||||
|
cg.add_define("USE_ESP32_IMPROV_STATE_CALLBACK")
|
||||||
|
|
72
esphome/components/esp32_improv/automation.h
Normal file
72
esphome/components/esp32_improv/automation.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
#pragma once
|
||||||
|
#ifdef USE_ESP32
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
#include "esp32_improv_component.h"
|
||||||
|
|
||||||
|
#include "esphome/core/automation.h"
|
||||||
|
|
||||||
|
#include <improv.h>
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace esp32_improv {
|
||||||
|
|
||||||
|
class ESP32ImprovProvisionedTrigger : public Trigger<> {
|
||||||
|
public:
|
||||||
|
explicit ESP32ImprovProvisionedTrigger(ESP32ImprovComponent *parent) {
|
||||||
|
parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
|
||||||
|
if (state == improv::STATE_PROVISIONED && !parent->is_failed()) {
|
||||||
|
trigger();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ESP32ImprovProvisioningTrigger : public Trigger<> {
|
||||||
|
public:
|
||||||
|
explicit ESP32ImprovProvisioningTrigger(ESP32ImprovComponent *parent) {
|
||||||
|
parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
|
||||||
|
if (state == improv::STATE_PROVISIONING && !parent->is_failed()) {
|
||||||
|
trigger();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ESP32ImprovStartTrigger : public Trigger<> {
|
||||||
|
public:
|
||||||
|
explicit ESP32ImprovStartTrigger(ESP32ImprovComponent *parent) {
|
||||||
|
parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
|
||||||
|
if ((state == improv::STATE_AUTHORIZED || state == improv::STATE_AWAITING_AUTHORIZATION) &&
|
||||||
|
!parent->is_failed()) {
|
||||||
|
trigger();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ESP32ImprovStateTrigger : public Trigger<improv::State, improv::Error> {
|
||||||
|
public:
|
||||||
|
explicit ESP32ImprovStateTrigger(ESP32ImprovComponent *parent) {
|
||||||
|
parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
|
||||||
|
if (!parent->is_failed()) {
|
||||||
|
trigger(state, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ESP32ImprovStoppedTrigger : public Trigger<> {
|
||||||
|
public:
|
||||||
|
explicit ESP32ImprovStoppedTrigger(ESP32ImprovComponent *parent) {
|
||||||
|
parent->add_on_state_callback([this, parent](improv::State state, improv::Error error) {
|
||||||
|
if (state == improv::STATE_STOPPED && !parent->is_failed()) {
|
||||||
|
trigger();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace esp32_improv
|
||||||
|
} // namespace esphome
|
||||||
|
#endif
|
||||||
|
#endif
|
|
@ -68,7 +68,12 @@ void ESP32ImprovComponent::setup_characteristics() {
|
||||||
|
|
||||||
void ESP32ImprovComponent::loop() {
|
void ESP32ImprovComponent::loop() {
|
||||||
if (!global_ble_server->is_running()) {
|
if (!global_ble_server->is_running()) {
|
||||||
this->state_ = improv::STATE_STOPPED;
|
if (this->state_ != improv::STATE_STOPPED) {
|
||||||
|
this->state_ = improv::STATE_STOPPED;
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
this->state_callback_.call(this->state_, this->error_state_);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
this->incoming_data_.clear();
|
this->incoming_data_.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -217,6 +222,9 @@ void ESP32ImprovComponent::set_state_(improv::State state) {
|
||||||
service_data[7] = 0x00; // Reserved
|
service_data[7] = 0x00; // Reserved
|
||||||
|
|
||||||
esp32_ble::global_ble->advertising_set_service_data(service_data);
|
esp32_ble::global_ble->advertising_set_service_data(service_data);
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
this->state_callback_.call(this->state_, this->error_state_);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP32ImprovComponent::set_error_(improv::Error error) {
|
void ESP32ImprovComponent::set_error_(improv::Error error) {
|
||||||
|
@ -270,7 +278,7 @@ void ESP32ImprovComponent::dump_config() {
|
||||||
void ESP32ImprovComponent::process_incoming_data_() {
|
void ESP32ImprovComponent::process_incoming_data_() {
|
||||||
uint8_t length = this->incoming_data_[1];
|
uint8_t length = this->incoming_data_[1];
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Processing bytes - %s", format_hex_pretty(this->incoming_data_).c_str());
|
ESP_LOGV(TAG, "Processing bytes - %s", format_hex_pretty(this->incoming_data_).c_str());
|
||||||
if (this->incoming_data_.size() - 3 == length) {
|
if (this->incoming_data_.size() - 3 == length) {
|
||||||
this->set_error_(improv::ERROR_NONE);
|
this->set_error_(improv::ERROR_NONE);
|
||||||
improv::ImprovCommand command = improv::parse_improv_data(this->incoming_data_);
|
improv::ImprovCommand command = improv::parse_improv_data(this->incoming_data_);
|
||||||
|
@ -295,7 +303,7 @@ void ESP32ImprovComponent::process_incoming_data_() {
|
||||||
wifi::global_wifi_component->set_sta(sta);
|
wifi::global_wifi_component->set_sta(sta);
|
||||||
wifi::global_wifi_component->start_connecting(sta, false);
|
wifi::global_wifi_component->start_connecting(sta, false);
|
||||||
this->set_state_(improv::STATE_PROVISIONING);
|
this->set_state_(improv::STATE_PROVISIONING);
|
||||||
ESP_LOGD(TAG, "Received Improv wifi settings ssid=%s, password=" LOG_SECRET("%s"), command.ssid.c_str(),
|
ESP_LOGD(TAG, "Received Improv Wi-Fi settings ssid=%s, password=" LOG_SECRET("%s"), command.ssid.c_str(),
|
||||||
command.password.c_str());
|
command.password.c_str());
|
||||||
|
|
||||||
auto f = std::bind(&ESP32ImprovComponent::on_wifi_connect_timeout_, this);
|
auto f = std::bind(&ESP32ImprovComponent::on_wifi_connect_timeout_, this);
|
||||||
|
@ -313,7 +321,7 @@ void ESP32ImprovComponent::process_incoming_data_() {
|
||||||
this->incoming_data_.clear();
|
this->incoming_data_.clear();
|
||||||
}
|
}
|
||||||
} else if (this->incoming_data_.size() - 2 > length) {
|
} else if (this->incoming_data_.size() - 2 > length) {
|
||||||
ESP_LOGV(TAG, "Too much data came in, or malformed resetting buffer...");
|
ESP_LOGV(TAG, "Too much data received or data malformed; resetting buffer...");
|
||||||
this->incoming_data_.clear();
|
this->incoming_data_.clear();
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGV(TAG, "Waiting for split data packets...");
|
ESP_LOGV(TAG, "Waiting for split data packets...");
|
||||||
|
@ -327,7 +335,7 @@ void ESP32ImprovComponent::on_wifi_connect_timeout_() {
|
||||||
if (this->authorizer_ != nullptr)
|
if (this->authorizer_ != nullptr)
|
||||||
this->authorized_start_ = millis();
|
this->authorized_start_ = millis();
|
||||||
#endif
|
#endif
|
||||||
ESP_LOGW(TAG, "Timed out trying to connect to given WiFi network");
|
ESP_LOGW(TAG, "Timed out while connecting to Wi-Fi network");
|
||||||
wifi::global_wifi_component->clear_sta();
|
wifi::global_wifi_component->clear_sta();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
#include "esphome/components/esp32_ble_server/ble_server.h"
|
#include "esphome/components/esp32_ble_server/ble_server.h"
|
||||||
#include "esphome/components/wifi/wifi_component.h"
|
#include "esphome/components/wifi/wifi_component.h"
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
#include "esphome/core/automation.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,6 +46,11 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
|
||||||
void stop() override;
|
void stop() override;
|
||||||
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
|
bool is_active() const { return this->state_ != improv::STATE_STOPPED; }
|
||||||
|
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
void add_on_state_callback(std::function<void(improv::State, improv::Error)> &&callback) {
|
||||||
|
this->state_callback_.add(std::move(callback));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef USE_BINARY_SENSOR
|
#ifdef USE_BINARY_SENSOR
|
||||||
void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
|
void set_authorizer(binary_sensor::BinarySensor *authorizer) { this->authorizer_ = authorizer; }
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,6 +63,9 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
|
||||||
void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
|
void set_wifi_timeout(uint32_t wifi_timeout) { this->wifi_timeout_ = wifi_timeout; }
|
||||||
uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
|
uint32_t get_wifi_timeout() const { return this->wifi_timeout_; }
|
||||||
|
|
||||||
|
improv::State get_improv_state() const { return this->state_; }
|
||||||
|
improv::Error get_improv_error_state() const { return this->error_state_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool should_start_{false};
|
bool should_start_{false};
|
||||||
bool setup_complete_{false};
|
bool setup_complete_{false};
|
||||||
|
@ -84,6 +96,9 @@ class ESP32ImprovComponent : public Component, public BLEServiceComponent {
|
||||||
|
|
||||||
improv::State state_{improv::STATE_STOPPED};
|
improv::State state_{improv::STATE_STOPPED};
|
||||||
improv::Error error_state_{improv::ERROR_NONE};
|
improv::Error error_state_{improv::ERROR_NONE};
|
||||||
|
#ifdef USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
|
CallbackManager<void(improv::State, improv::Error)> state_callback_{};
|
||||||
|
#endif
|
||||||
|
|
||||||
bool status_indicator_state_{false};
|
bool status_indicator_state_{false};
|
||||||
void set_status_indicator_state_(bool state);
|
void set_status_indicator_state_(bool state);
|
||||||
|
|
|
@ -53,6 +53,8 @@ MODELS = {
|
||||||
"inkplate_10": InkplateModel.INKPLATE_10,
|
"inkplate_10": InkplateModel.INKPLATE_10,
|
||||||
"inkplate_6_plus": InkplateModel.INKPLATE_6_PLUS,
|
"inkplate_6_plus": InkplateModel.INKPLATE_6_PLUS,
|
||||||
"inkplate_6_v2": InkplateModel.INKPLATE_6_V2,
|
"inkplate_6_v2": InkplateModel.INKPLATE_6_V2,
|
||||||
|
"inkplate_5": InkplateModel.INKPLATE_5,
|
||||||
|
"inkplate_5_v2": InkplateModel.INKPLATE_5_V2,
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
|
|
|
@ -15,6 +15,8 @@ enum InkplateModel : uint8_t {
|
||||||
INKPLATE_10 = 1,
|
INKPLATE_10 = 1,
|
||||||
INKPLATE_6_PLUS = 2,
|
INKPLATE_6_PLUS = 2,
|
||||||
INKPLATE_6_V2 = 3,
|
INKPLATE_6_V2 = 3,
|
||||||
|
INKPLATE_5 = 4,
|
||||||
|
INKPLATE_5_V2 = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
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 pixelMaskLUT[8] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80};
|
||||||
const uint8_t pixelMaskGLUT[2] = {0x0F, 0xF0};
|
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, 1, 0, 0, 1, 1, 0, 0},
|
||||||
{0, 1, 2, 1, 1, 2, 1, 0, 0},
|
{0, 1, 2, 1, 1, 2, 1, 0, 0},
|
||||||
{1, 1, 1, 2, 2, 1, 0, 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},
|
{1, 1, 1, 1, 2, 2, 1, 0, 0},
|
||||||
{0, 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, 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) {
|
void set_greyscale(bool greyscale) {
|
||||||
this->greyscale_ = greyscale;
|
this->greyscale_ = greyscale;
|
||||||
|
@ -146,6 +166,10 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
||||||
return 800;
|
return 800;
|
||||||
} else if (this->model_ == INKPLATE_10) {
|
} else if (this->model_ == INKPLATE_10) {
|
||||||
return 1200;
|
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) {
|
} else if (this->model_ == INKPLATE_6_PLUS) {
|
||||||
return 1024;
|
return 1024;
|
||||||
}
|
}
|
||||||
|
@ -155,6 +179,10 @@ class Inkplate6 : public display::DisplayBuffer, public i2c::I2CDevice {
|
||||||
int get_height_internal() override {
|
int get_height_internal() override {
|
||||||
if (this->model_ == INKPLATE_6 || this->model_ == INKPLATE_6_V2) {
|
if (this->model_ == INKPLATE_6 || this->model_ == INKPLATE_6_V2) {
|
||||||
return 600;
|
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) {
|
} else if (this->model_ == INKPLATE_10) {
|
||||||
return 825;
|
return 825;
|
||||||
} else if (this->model_ == INKPLATE_6_PLUS) {
|
} else if (this->model_ == INKPLATE_6_PLUS) {
|
||||||
|
|
|
@ -419,6 +419,13 @@ async def to_code(config):
|
||||||
repo="https://github.com/espressif/esp-tflite-micro",
|
repo="https://github.com/espressif/esp-tflite-micro",
|
||||||
ref="v1.3.1",
|
ref="v1.3.1",
|
||||||
)
|
)
|
||||||
|
# add esp-nn dependency for tflite-micro to work around https://github.com/espressif/esp-nn/issues/17
|
||||||
|
# ...remove after switching to IDF 5.1.4+
|
||||||
|
esp32.add_idf_component(
|
||||||
|
name="esp-nn",
|
||||||
|
repo="https://github.com/espressif/esp-nn",
|
||||||
|
ref="v1.1.0",
|
||||||
|
)
|
||||||
|
|
||||||
cg.add_build_flag("-DTF_LITE_STATIC_MEMORY")
|
cg.add_build_flag("-DTF_LITE_STATIC_MEMORY")
|
||||||
cg.add_build_flag("-DTF_LITE_DISABLE_X86_NEON")
|
cg.add_build_flag("-DTF_LITE_DISABLE_X86_NEON")
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
from esphome import automation, pins
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
from esphome.components import esp32_rmt, remote_base
|
||||||
import esphome.config_validation as cv
|
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
|
from esphome.const import CONF_CARRIER_DUTY_PERCENT, CONF_ID, CONF_PIN, CONF_RMT_CHANNEL
|
||||||
|
|
||||||
AUTO_LOAD = ["remote_base"]
|
AUTO_LOAD = ["remote_base"]
|
||||||
|
|
||||||
|
CONF_ON_TRANSMIT = "on_transmit"
|
||||||
|
CONF_ON_COMPLETE = "on_complete"
|
||||||
|
|
||||||
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
|
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
|
||||||
RemoteTransmitterComponent = remote_transmitter_ns.class_(
|
RemoteTransmitterComponent = remote_transmitter_ns.class_(
|
||||||
"RemoteTransmitterComponent", remote_base.RemoteTransmitterBase, cg.Component
|
"RemoteTransmitterComponent", remote_base.RemoteTransmitterBase, cg.Component
|
||||||
|
@ -19,6 +23,8 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
cv.percentage_int, cv.Range(min=1, max=100)
|
cv.percentage_int, cv.Range(min=1, max=100)
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_RMT_CHANNEL): esp32_rmt.validate_rmt_channel(tx=True),
|
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)
|
).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
|
@ -32,3 +38,13 @@ async def to_code(config):
|
||||||
await cg.register_component(var, config)
|
await cg.register_component(var, config)
|
||||||
|
|
||||||
cg.add(var.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
|
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; }
|
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:
|
protected:
|
||||||
void send_internal(uint32_t send_times, uint32_t send_wait) override;
|
void send_internal(uint32_t send_times, uint32_t send_wait) override;
|
||||||
#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
|
#if defined(USE_ESP8266) || defined(USE_LIBRETINY)
|
||||||
|
@ -57,6 +60,9 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
|
||||||
bool inverted_{false};
|
bool inverted_{false};
|
||||||
#endif
|
#endif
|
||||||
uint8_t carrier_duty_percent_;
|
uint8_t carrier_duty_percent_;
|
||||||
|
|
||||||
|
Trigger<> *transmit_trigger_{new Trigger<>()};
|
||||||
|
Trigger<> *complete_trigger_{new Trigger<>()};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace remote_transmitter
|
} // namespace remote_transmitter
|
||||||
|
|
|
@ -124,6 +124,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||||
ESP_LOGE(TAG, "Empty data");
|
ESP_LOGE(TAG, "Empty data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this->transmit_trigger_->trigger();
|
||||||
for (uint32_t i = 0; i < send_times; i++) {
|
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);
|
esp_err_t error = rmt_write_items(this->channel_, this->rmt_temp_.data(), this->rmt_temp_.size(), true);
|
||||||
if (error != ESP_OK) {
|
if (error != ESP_OK) {
|
||||||
|
@ -135,6 +136,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||||
if (i + 1 < send_times)
|
if (i + 1 < send_times)
|
||||||
delayMicroseconds(send_wait);
|
delayMicroseconds(send_wait);
|
||||||
}
|
}
|
||||||
|
this->complete_trigger_->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace remote_transmitter
|
} // namespace remote_transmitter
|
||||||
|
|
|
@ -76,6 +76,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||||
uint32_t on_time, off_time;
|
uint32_t on_time, off_time;
|
||||||
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
||||||
this->target_time_ = 0;
|
this->target_time_ = 0;
|
||||||
|
this->transmit_trigger_->trigger();
|
||||||
for (uint32_t i = 0; i < send_times; i++) {
|
for (uint32_t i = 0; i < send_times; i++) {
|
||||||
for (int32_t item : this->temp_.get_data()) {
|
for (int32_t item : this->temp_.get_data()) {
|
||||||
if (item > 0) {
|
if (item > 0) {
|
||||||
|
@ -93,6 +94,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||||
if (i + 1 < send_times)
|
if (i + 1 < send_times)
|
||||||
this->target_time_ += send_wait;
|
this->target_time_ += send_wait;
|
||||||
}
|
}
|
||||||
|
this->complete_trigger_->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace remote_transmitter
|
} // namespace remote_transmitter
|
||||||
|
|
|
@ -78,6 +78,7 @@ void RemoteTransmitterComponent::send_internal(uint32_t send_times, uint32_t sen
|
||||||
uint32_t on_time, off_time;
|
uint32_t on_time, off_time;
|
||||||
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
|
||||||
this->target_time_ = 0;
|
this->target_time_ = 0;
|
||||||
|
this->transmit_trigger_->trigger();
|
||||||
for (uint32_t i = 0; i < send_times; i++) {
|
for (uint32_t i = 0; i < send_times; i++) {
|
||||||
InterruptLock lock;
|
InterruptLock lock;
|
||||||
for (int32_t item : this->temp_.get_data()) {
|
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)
|
if (i + 1 < send_times)
|
||||||
this->target_time_ += send_wait;
|
this->target_time_ += send_wait;
|
||||||
}
|
}
|
||||||
|
this->complete_trigger_->trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace remote_transmitter
|
} // namespace remote_transmitter
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "tcs34725.h"
|
#include "tcs34725.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace tcs34725 {
|
namespace tcs34725 {
|
||||||
|
@ -211,7 +212,7 @@ void TCS34725Component::update() {
|
||||||
if (raw_c == 0) {
|
if (raw_c == 0) {
|
||||||
channel_c = channel_r = channel_g = channel_b = 0.0f;
|
channel_c = channel_r = channel_g = channel_b = 0.0f;
|
||||||
} else {
|
} 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;
|
float sum = raw_c;
|
||||||
channel_r = raw_r / sum * 100.0f;
|
channel_r = raw_r / sum * 100.0f;
|
||||||
channel_g = raw_g / 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
|
// change integration time an gain to achieve maximum resolution an dynamic range
|
||||||
// calculate optimal integration time to achieve 70% satuaration
|
// calculate optimal integration time to achieve 70% satuaration
|
||||||
float integration_time_ideal;
|
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_;
|
uint8_t gain_reg_val_new = this->gain_reg_;
|
||||||
// increase gain if less than 20% of white channel used and high integration time
|
// increase gain if less than 20% of white channel used and high integration time
|
||||||
|
|
|
@ -1012,6 +1012,16 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url
|
||||||
call.set_mode(mode.c_str());
|
call.set_mode(mode.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request->hasParam("fan_mode")) {
|
||||||
|
auto mode = request->getParam("fan_mode")->value();
|
||||||
|
call.set_fan_mode(mode.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->hasParam("swing_mode")) {
|
||||||
|
auto mode = request->getParam("swing_mode")->value();
|
||||||
|
call.set_swing_mode(mode.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
if (request->hasParam("target_temperature_high")) {
|
if (request->hasParam("target_temperature_high")) {
|
||||||
auto target_temperature_high = parse_number<float>(request->getParam("target_temperature_high")->value().c_str());
|
auto target_temperature_high = parse_number<float>(request->getParam("target_temperature_high")->value().c_str());
|
||||||
if (target_temperature_high.has_value())
|
if (target_temperature_high.has_value())
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#define USE_DATETIME_TIME
|
#define USE_DATETIME_TIME
|
||||||
#define USE_DEEP_SLEEP
|
#define USE_DEEP_SLEEP
|
||||||
#define USE_DISPLAY
|
#define USE_DISPLAY
|
||||||
|
#define USE_ESP32_IMPROV_STATE_CALLBACK
|
||||||
#define USE_EVENT
|
#define USE_EVENT
|
||||||
#define USE_FAN
|
#define USE_FAN
|
||||||
#define USE_GRAPH
|
#define USE_GRAPH
|
||||||
|
@ -45,10 +46,10 @@
|
||||||
#define USE_LVGL_BUTTONMATRIX
|
#define USE_LVGL_BUTTONMATRIX
|
||||||
#define USE_LVGL_FONT
|
#define USE_LVGL_FONT
|
||||||
#define USE_LVGL_IMAGE
|
#define USE_LVGL_IMAGE
|
||||||
#define USE_LVGL_KEYBOARD
|
|
||||||
#define USE_LVGL_KEY_LISTENER
|
#define USE_LVGL_KEY_LISTENER
|
||||||
#define USE_LVGL_TOUCHSCREEN
|
#define USE_LVGL_KEYBOARD
|
||||||
#define USE_LVGL_ROTARY_ENCODER
|
#define USE_LVGL_ROTARY_ENCODER
|
||||||
|
#define USE_LVGL_TOUCHSCREEN
|
||||||
#define USE_MDNS
|
#define USE_MDNS
|
||||||
#define USE_MEDIA_PLAYER
|
#define USE_MEDIA_PLAYER
|
||||||
#define USE_MQTT
|
#define USE_MQTT
|
||||||
|
|
|
@ -8,6 +8,7 @@ uart:
|
||||||
|
|
||||||
sensor:
|
sensor:
|
||||||
- platform: bl0906
|
- platform: bl0906
|
||||||
|
id: bl
|
||||||
frequency:
|
frequency:
|
||||||
name: 'Frequency'
|
name: 'Frequency'
|
||||||
temperature:
|
temperature:
|
||||||
|
@ -60,3 +61,9 @@ sensor:
|
||||||
name: 'Total_Energy'
|
name: 'Total_Energy'
|
||||||
total_power:
|
total_power:
|
||||||
name: 'Total_Power'
|
name: 'Total_Power'
|
||||||
|
|
||||||
|
button:
|
||||||
|
- platform: template
|
||||||
|
id: reset
|
||||||
|
on_press:
|
||||||
|
- bl0906.reset_energy: bl
|
||||||
|
|
Loading…
Reference in a new issue