Compare commits
83 Commits
socket_lat
...
p4_remote_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
123d4c3e0d | ||
|
|
4f1953c581 | ||
|
|
a00fc75c77 | ||
|
|
80fd827f8b | ||
|
|
1dd3c6de90 | ||
|
|
c8c43f13fd | ||
|
|
518bce50a5 | ||
|
|
4f87bea788 | ||
|
|
8054c9b4f5 | ||
|
|
935e0a365f | ||
|
|
b39a9924d8 | ||
|
|
19ec922e28 | ||
|
|
a225d6881f | ||
|
|
6675e99862 | ||
|
|
8cbe2b41f6 | ||
|
|
6a225cb4c0 | ||
|
|
e62d8bfabe | ||
|
|
d4cea84b1b | ||
|
|
b63f90a6c0 | ||
|
|
4370b6695e | ||
|
|
589f13f0f7 | ||
|
|
367017b352 | ||
|
|
ec26d31499 | ||
|
|
1bbc6db1c3 | ||
|
|
162472bdc2 | ||
|
|
aecac15809 | ||
|
|
6554af21b9 | ||
|
|
8583466c6a | ||
|
|
6666604069 | ||
|
|
13e7aacc9d | ||
|
|
737d502614 | ||
|
|
67dd649d00 | ||
|
|
b2fc51367b | ||
|
|
5771bb4907 | ||
|
|
9ba9674437 | ||
|
|
acb1532e34 | ||
|
|
e2093c34da | ||
|
|
a2e4ad90ba | ||
|
|
32e69c67f2 | ||
|
|
df0b5a187e | ||
|
|
cee0e5379b | ||
|
|
daf2bd7e66 | ||
|
|
4031077f6d | ||
|
|
fd72a64053 | ||
|
|
959a8b91bd | ||
|
|
44f1ff10e6 | ||
|
|
64e4589f4e | ||
|
|
20aba45cbe | ||
|
|
0b1c5b825e | ||
|
|
455624105b | ||
|
|
7ac5746e0d | ||
|
|
12997451f6 | ||
|
|
8c77e40695 | ||
|
|
2ddd91acf2 | ||
|
|
729e49cdc3 | ||
|
|
d64b49cc13 | ||
|
|
cfa8b3b272 | ||
|
|
51981335d5 | ||
|
|
70c5e1bbf1 | ||
|
|
43e88af28a | ||
|
|
ffc66f539f | ||
|
|
c4cb694d77 | ||
|
|
3fb9577ad9 | ||
|
|
34169491ac | ||
|
|
8eac859bab | ||
|
|
d99e3237f9 | ||
|
|
d9a9e0aea3 | ||
|
|
0ce03ae26b | ||
|
|
18653f8f69 | ||
|
|
6e0523109a | ||
|
|
b6fa4f641d | ||
|
|
ca6295d1bd | ||
|
|
18a1d31845 | ||
|
|
c5239a63ab | ||
|
|
1911269dc9 | ||
|
|
04ee1a87e9 | ||
|
|
a8fdb6db4d | ||
|
|
8860c74f0c | ||
|
|
5bdf5c1bf3 | ||
|
|
fa27c0b8f1 | ||
|
|
69fec85cc1 | ||
|
|
aa26e2bffd | ||
|
|
af1a4d8a0a |
4
.github/actions/build-image/action.yaml
vendored
4
.github/actions/build-image/action.yaml
vendored
@@ -47,7 +47,7 @@ runs:
|
||||
|
||||
- name: Build and push to ghcr by digest
|
||||
id: build-ghcr
|
||||
uses: docker/build-push-action@v6.17.0
|
||||
uses: docker/build-push-action@v6.18.0
|
||||
env:
|
||||
DOCKER_BUILD_SUMMARY: false
|
||||
DOCKER_BUILD_RECORD_UPLOAD: false
|
||||
@@ -73,7 +73,7 @@ runs:
|
||||
|
||||
- name: Build and push to dockerhub by digest
|
||||
id: build-dockerhub
|
||||
uses: docker/build-push-action@v6.17.0
|
||||
uses: docker/build-push-action@v6.18.0
|
||||
env:
|
||||
DOCKER_BUILD_SUMMARY: false
|
||||
DOCKER_BUILD_RECORD_UPLOAD: false
|
||||
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -296,7 +296,7 @@ jobs:
|
||||
name: Run script/clang-tidy for ZEPHYR
|
||||
options: --environment nrf52-tidy --grep USE_ZEPHYR
|
||||
pio_cache_key: tidy-zephyr
|
||||
ignore_errors: true
|
||||
ignore_errors: false
|
||||
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
|
||||
@@ -139,12 +139,14 @@ esphome/components/es7210/* @kahrendt
|
||||
esphome/components/es7243e/* @kbx81
|
||||
esphome/components/es8156/* @kbx81
|
||||
esphome/components/es8311/* @kahrendt @kroimon
|
||||
esphome/components/es8388/* @P4uLT
|
||||
esphome/components/esp32/* @esphome/core
|
||||
esphome/components/esp32_ble/* @Rapsssito @jesserockz
|
||||
esphome/components/esp32_ble_client/* @jesserockz
|
||||
esphome/components/esp32_ble_server/* @Rapsssito @clydebarrow @jesserockz
|
||||
esphome/components/esp32_camera_web_server/* @ayufan
|
||||
esphome/components/esp32_can/* @Sympatron
|
||||
esphome/components/esp32_hosted/* @swoboda1337
|
||||
esphome/components/esp32_improv/* @jesserockz
|
||||
esphome/components/esp32_rmt/* @jesserockz
|
||||
esphome/components/esp32_rmt_led_strip/* @jesserockz
|
||||
@@ -234,6 +236,7 @@ esphome/components/kamstrup_kmp/* @cfeenstra1024
|
||||
esphome/components/key_collector/* @ssieb
|
||||
esphome/components/key_provider/* @ssieb
|
||||
esphome/components/kuntze/* @ssieb
|
||||
esphome/components/lc709203f/* @ilikecake
|
||||
esphome/components/lcd_menu/* @numo68
|
||||
esphome/components/ld2410/* @regevbr @sebcaps
|
||||
esphome/components/ld2420/* @descipher
|
||||
|
||||
@@ -593,15 +593,20 @@ def command_update_all(args):
|
||||
middle_text = f" {middle_text} "
|
||||
width = len(click.unstyle(middle_text))
|
||||
half_line = "=" * ((twidth - width) // 2)
|
||||
click.echo(f"{half_line}{middle_text}{half_line}")
|
||||
safe_print(f"{half_line}{middle_text}{half_line}")
|
||||
|
||||
for f in files:
|
||||
print(f"Updating {color(AnsiFore.CYAN, f)}")
|
||||
print("-" * twidth)
|
||||
print()
|
||||
rc = run_external_process(
|
||||
"esphome", "--dashboard", "run", f, "--no-logs", "--device", "OTA"
|
||||
)
|
||||
safe_print(f"Updating {color(AnsiFore.CYAN, f)}")
|
||||
safe_print("-" * twidth)
|
||||
safe_print()
|
||||
if CORE.dashboard:
|
||||
rc = run_external_process(
|
||||
"esphome", "--dashboard", "run", f, "--no-logs", "--device", "OTA"
|
||||
)
|
||||
else:
|
||||
rc = run_external_process(
|
||||
"esphome", "run", f, "--no-logs", "--device", "OTA"
|
||||
)
|
||||
if rc == 0:
|
||||
print_bar(f"[{color(AnsiFore.BOLD_GREEN, 'SUCCESS')}] {f}")
|
||||
success[f] = True
|
||||
@@ -609,17 +614,17 @@ def command_update_all(args):
|
||||
print_bar(f"[{color(AnsiFore.BOLD_RED, 'ERROR')}] {f}")
|
||||
success[f] = False
|
||||
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
safe_print()
|
||||
safe_print()
|
||||
safe_print()
|
||||
|
||||
print_bar(f"[{color(AnsiFore.BOLD_WHITE, 'SUMMARY')}]")
|
||||
failed = 0
|
||||
for f in files:
|
||||
if success[f]:
|
||||
print(f" - {f}: {color(AnsiFore.GREEN, 'SUCCESS')}")
|
||||
safe_print(f" - {f}: {color(AnsiFore.GREEN, 'SUCCESS')}")
|
||||
else:
|
||||
print(f" - {f}: {color(AnsiFore.BOLD_RED, 'FAILED')}")
|
||||
safe_print(f" - {f}: {color(AnsiFore.BOLD_RED, 'FAILED')}")
|
||||
failed += 1
|
||||
return failed
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace a4988 {
|
||||
static const char *const TAG = "a4988.stepper";
|
||||
|
||||
void A4988::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up A4988...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (this->sleep_pin_ != nullptr) {
|
||||
this->sleep_pin_->setup();
|
||||
this->sleep_pin_->digital_write(false);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace absolute_humidity {
|
||||
static const char *const TAG = "absolute_humidity.sensor";
|
||||
|
||||
void AbsoluteHumidityComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up absolute humidity '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
|
||||
ESP_LOGD(TAG, " Added callback for temperature '%s'", this->temperature_sensor_->get_name().c_str());
|
||||
this->temperature_sensor_->add_on_state_callback([this](float state) { this->temperature_callback_(state); });
|
||||
|
||||
@@ -22,7 +22,7 @@ static const int ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1;
|
||||
static const int ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1;
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
|
||||
if (this->channel1_ != ADC1_CHANNEL_MAX) {
|
||||
adc1_config_width(ADC_WIDTH_MAX_SOC_BITS);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace adc {
|
||||
static const char *const TAG = "adc.esp8266";
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
#ifndef USE_ADC_SENSOR_VCC
|
||||
this->pin_->setup();
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace adc {
|
||||
static const char *const TAG = "adc.libretiny";
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
#ifndef USE_ADC_SENSOR_VCC
|
||||
this->pin_->setup();
|
||||
#endif // !USE_ADC_SENSOR_VCC
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace adc {
|
||||
static const char *const TAG = "adc.rp2040";
|
||||
|
||||
void ADCSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADC '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
static bool initialized = false;
|
||||
if (!initialized) {
|
||||
adc_init();
|
||||
|
||||
@@ -9,7 +9,7 @@ static const char *const TAG = "adc128s102";
|
||||
float ADC128S102::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
|
||||
void ADC128S102::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up adc128s102");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->spi_setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,13 @@ static const uint8_t ADS1115_REGISTER_CONVERSION = 0x00;
|
||||
static const uint8_t ADS1115_REGISTER_CONFIG = 0x01;
|
||||
|
||||
void ADS1115Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADS1115...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint16_t value;
|
||||
if (!this->read_byte_16(ADS1115_REGISTER_CONVERSION, &value)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Configuring ADS1115...");
|
||||
|
||||
uint16_t config = 0;
|
||||
// Clear single-shot bit
|
||||
// 0b0xxxxxxxxxxxxxxx
|
||||
@@ -68,10 +66,10 @@ void ADS1115Component::setup() {
|
||||
this->prev_config_ = config;
|
||||
}
|
||||
void ADS1115Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ADS1115...");
|
||||
ESP_LOGCONFIG(TAG, "ADS1115:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with ADS1115 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
}
|
||||
float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1115Gain gain,
|
||||
|
||||
@@ -8,7 +8,7 @@ static const char *const TAG = "ads1118";
|
||||
static const uint8_t ADS1118_DATA_RATE_860_SPS = 0b111;
|
||||
|
||||
void ADS1118::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ads1118");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->spi_setup();
|
||||
|
||||
this->config_ = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@ static const uint16_t ZP_CURRENT = 0x0000;
|
||||
static const uint16_t ZP_DEFAULT = 0xFFFF;
|
||||
|
||||
void AGS10Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ags10...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
auto version = this->read_version_();
|
||||
if (version) {
|
||||
@@ -65,7 +65,7 @@ void AGS10Component::dump_config() {
|
||||
case NONE:
|
||||
break;
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with AGS10 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case CRC_CHECK_FAILED:
|
||||
ESP_LOGE(TAG, "The crc check failed");
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "aht10.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace aht10 {
|
||||
@@ -34,57 +35,59 @@ static const uint8_t AHT10_INIT_ATTEMPTS = 10;
|
||||
|
||||
static const uint8_t AHT10_STATUS_BUSY = 0x80;
|
||||
|
||||
static const float AHT10_DIVISOR = 1048576.0f; // 2^20, used for temperature and humidity calculations
|
||||
|
||||
void AHT10Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
if (this->write(AHT10_SOFTRESET_CMD, sizeof(AHT10_SOFTRESET_CMD)) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Reset AHT10 failed!");
|
||||
ESP_LOGE(TAG, "Reset failed");
|
||||
}
|
||||
delay(AHT10_SOFTRESET_DELAY);
|
||||
|
||||
i2c::ErrorCode error_code = i2c::ERROR_INVALID_ARGUMENT;
|
||||
switch (this->variant_) {
|
||||
case AHT10Variant::AHT20:
|
||||
ESP_LOGCONFIG(TAG, "Setting up AHT20");
|
||||
error_code = this->write(AHT20_INITIALIZE_CMD, sizeof(AHT20_INITIALIZE_CMD));
|
||||
break;
|
||||
case AHT10Variant::AHT10:
|
||||
ESP_LOGCONFIG(TAG, "Setting up AHT10");
|
||||
error_code = this->write(AHT10_INITIALIZE_CMD, sizeof(AHT10_INITIALIZE_CMD));
|
||||
break;
|
||||
}
|
||||
if (error_code != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Communication with AHT10 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
uint8_t cal_attempts = 0;
|
||||
uint8_t data = AHT10_STATUS_BUSY;
|
||||
int cal_attempts = 0;
|
||||
while (data & AHT10_STATUS_BUSY) {
|
||||
delay(AHT10_DEFAULT_DELAY);
|
||||
if (this->read(&data, 1) != i2c::ERROR_OK) {
|
||||
ESP_LOGE(TAG, "Communication with AHT10 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
++cal_attempts;
|
||||
if (cal_attempts > AHT10_INIT_ATTEMPTS) {
|
||||
ESP_LOGE(TAG, "AHT10 initialization timed out!");
|
||||
ESP_LOGE(TAG, "Initialization timed out");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((data & 0x68) != 0x08) { // Bit[6:5] = 0b00, NORMAL mode and Bit[3] = 0b1, CALIBRATED
|
||||
ESP_LOGE(TAG, "AHT10 initialization failed!");
|
||||
ESP_LOGE(TAG, "Initialization failed");
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "AHT10 initialization");
|
||||
ESP_LOGV(TAG, "Initialization complete");
|
||||
}
|
||||
|
||||
void AHT10Component::restart_read_() {
|
||||
if (this->read_count_ == AHT10_ATTEMPTS) {
|
||||
this->read_count_ = 0;
|
||||
this->status_set_error("Measurements reading timed-out!");
|
||||
this->status_set_error("Reading timed out");
|
||||
return;
|
||||
}
|
||||
this->read_count_++;
|
||||
@@ -97,24 +100,24 @@ void AHT10Component::read_data_() {
|
||||
ESP_LOGD(TAG, "Read attempt %d at %ums", this->read_count_, (unsigned) (millis() - this->start_time_));
|
||||
}
|
||||
if (this->read(data, 6) != i2c::ERROR_OK) {
|
||||
this->status_set_warning("AHT10 read failed, retrying soon");
|
||||
this->status_set_warning("Read failed, will retry");
|
||||
this->restart_read_();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((data[0] & 0x80) == 0x80) { // Bit[7] = 0b1, device is busy
|
||||
ESP_LOGD(TAG, "AHT10 is busy, waiting...");
|
||||
ESP_LOGD(TAG, "Device busy, will retry");
|
||||
this->restart_read_();
|
||||
return;
|
||||
}
|
||||
if (data[1] == 0x0 && data[2] == 0x0 && (data[3] >> 4) == 0x0) {
|
||||
// Unrealistic humidity (0x0)
|
||||
// Invalid humidity (0x0)
|
||||
if (this->humidity_sensor_ == nullptr) {
|
||||
ESP_LOGV(TAG, "ATH10 Unrealistic humidity (0x0), but humidity is not required");
|
||||
ESP_LOGV(TAG, "Invalid humidity (reading not required)");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "ATH10 Unrealistic humidity (0x0), retrying...");
|
||||
ESP_LOGD(TAG, "Invalid humidity, retrying");
|
||||
if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) {
|
||||
this->status_set_warning("Communication with AHT10 failed!");
|
||||
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
this->restart_read_();
|
||||
return;
|
||||
@@ -123,22 +126,17 @@ void AHT10Component::read_data_() {
|
||||
if (this->read_count_ > 1) {
|
||||
ESP_LOGD(TAG, "Success at %ums", (unsigned) (millis() - this->start_time_));
|
||||
}
|
||||
uint32_t raw_temperature = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
|
||||
uint32_t raw_humidity = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4;
|
||||
uint32_t raw_temperature = encode_uint24(data[3] & 0xF, data[4], data[5]);
|
||||
uint32_t raw_humidity = encode_uint24(data[1], data[2], data[3]) >> 4;
|
||||
|
||||
if (this->temperature_sensor_ != nullptr) {
|
||||
float temperature = ((200.0f * (float) raw_temperature) / 1048576.0f) - 50.0f;
|
||||
float temperature = ((200.0f * static_cast<float>(raw_temperature)) / AHT10_DIVISOR) - 50.0f;
|
||||
this->temperature_sensor_->publish_state(temperature);
|
||||
}
|
||||
if (this->humidity_sensor_ != nullptr) {
|
||||
float humidity;
|
||||
if (raw_humidity == 0) { // unrealistic value
|
||||
humidity = NAN;
|
||||
} else {
|
||||
humidity = (float) raw_humidity * 100.0f / 1048576.0f;
|
||||
}
|
||||
float humidity = raw_humidity == 0 ? NAN : static_cast<float>(raw_humidity) * 100.0f / AHT10_DIVISOR;
|
||||
if (std::isnan(humidity)) {
|
||||
ESP_LOGW(TAG, "Invalid humidity! Sensor reported 0%% Hum");
|
||||
ESP_LOGW(TAG, "Invalid humidity reading (0%%), ");
|
||||
}
|
||||
this->humidity_sensor_->publish_state(humidity);
|
||||
}
|
||||
@@ -150,7 +148,7 @@ void AHT10Component::update() {
|
||||
return;
|
||||
this->start_time_ = millis();
|
||||
if (this->write(AHT10_MEASURE_CMD, sizeof(AHT10_MEASURE_CMD)) != i2c::ERROR_OK) {
|
||||
this->status_set_warning("Communication with AHT10 failed!");
|
||||
this->status_set_warning(ESP_LOG_MSG_COMM_FAIL);
|
||||
return;
|
||||
}
|
||||
this->restart_read_();
|
||||
@@ -162,7 +160,7 @@ void AHT10Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "AHT10:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AHT10 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
|
||||
@@ -17,7 +17,7 @@ static const char *const TAG = "aic3204";
|
||||
}
|
||||
|
||||
void AIC3204::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AIC3204...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// Set register page to 0
|
||||
ERROR_CHECK(this->write_byte(AIC3204_PAGE_CTRL, 0x00), "Set page 0 failed");
|
||||
@@ -113,7 +113,7 @@ void AIC3204::dump_config() {
|
||||
LOG_I2C_DEVICE(this);
|
||||
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AIC3204 failed");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ bool AM2315C::convert_(uint8_t *data, float &humidity, float &temperature) {
|
||||
}
|
||||
|
||||
void AM2315C::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AM2315C...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// get status
|
||||
uint8_t status = 0;
|
||||
@@ -188,7 +188,7 @@ void AM2315C::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "AM2315C:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AM2315C failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
|
||||
@@ -34,7 +34,7 @@ void AM2320Component::update() {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
void AM2320Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AM2320...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t data[8];
|
||||
data[0] = 0;
|
||||
data[1] = 4;
|
||||
@@ -47,7 +47,7 @@ void AM2320Component::dump_config() {
|
||||
ESP_LOGD(TAG, "AM2320:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AM2320 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
|
||||
@@ -54,7 +54,7 @@ enum { // APDS9306 registers
|
||||
}
|
||||
|
||||
void APDS9306::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up APDS9306...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
uint8_t id;
|
||||
if (!this->read_byte(APDS9306_PART_ID, &id)) { // Part ID register
|
||||
@@ -97,7 +97,7 @@ void APDS9306::dump_config() {
|
||||
if (this->is_failed()) {
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with APDS9306 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case WRONG_ID:
|
||||
ESP_LOGE(TAG, "APDS9306 has invalid id!");
|
||||
|
||||
@@ -15,7 +15,7 @@ static const char *const TAG = "apds9960";
|
||||
#define APDS9960_WRITE_BYTE(reg, value) APDS9960_ERROR_CHECK(this->write_byte(reg, value));
|
||||
|
||||
void APDS9960::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up APDS9960...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t id;
|
||||
if (!this->read_byte(0x92, &id)) { // ID register
|
||||
this->error_code_ = COMMUNICATION_FAILED;
|
||||
@@ -141,7 +141,7 @@ void APDS9960::dump_config() {
|
||||
if (this->is_failed()) {
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with APDS9960 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case WRONG_ID:
|
||||
ESP_LOGE(TAG, "APDS9960 has invalid id!");
|
||||
|
||||
@@ -118,7 +118,7 @@ void APIConnection::loop() {
|
||||
// when network is disconnected force disconnect immediately
|
||||
// don't wait for timeout
|
||||
this->on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s: Network unavailable, disconnecting", this->client_combined_info_.c_str());
|
||||
ESP_LOGW(TAG, "%s: Network unavailable; disconnecting", this->client_combined_info_.c_str());
|
||||
return;
|
||||
}
|
||||
if (this->next_close_) {
|
||||
@@ -182,24 +182,23 @@ void APIConnection::loop() {
|
||||
// Disconnect if not responded within 2.5*keepalive
|
||||
if (now - this->last_traffic_ > (KEEPALIVE_TIMEOUT_MS * 5) / 2) {
|
||||
on_fatal_error();
|
||||
ESP_LOGW(TAG, "%s didn't respond to ping request in time. Disconnecting...", this->client_combined_info_.c_str());
|
||||
ESP_LOGW(TAG, "%s is unresponsive; disconnecting", this->client_combined_info_.c_str());
|
||||
}
|
||||
} else if (now - this->last_traffic_ > KEEPALIVE_TIMEOUT_MS && now > this->next_ping_retry_) {
|
||||
ESP_LOGVV(TAG, "Sending keepalive PING...");
|
||||
ESP_LOGVV(TAG, "Sending keepalive PING");
|
||||
this->sent_ping_ = this->send_ping_request(PingRequest());
|
||||
if (!this->sent_ping_) {
|
||||
char warn_str[38];
|
||||
this->next_ping_retry_ = now + ping_retry_interval;
|
||||
this->ping_retries_++;
|
||||
sprintf(warn_str, "Sending keepalive failed %u time(s); ", this->ping_retries_);
|
||||
if (this->ping_retries_ >= max_ping_retries) {
|
||||
on_fatal_error();
|
||||
ESP_LOGE(TAG, "%s: Sending keepalive failed %d time(s). Disconnecting...", this->client_combined_info_.c_str(),
|
||||
this->ping_retries_);
|
||||
ESP_LOGE(TAG, "%s: %sdisconnecting", this->client_combined_info_.c_str(), warn_str);
|
||||
} else if (this->ping_retries_ >= 10) {
|
||||
ESP_LOGW(TAG, "%s: Sending keepalive failed %d time(s), will retry in %d ms",
|
||||
this->client_combined_info_.c_str(), this->ping_retries_, ping_retry_interval);
|
||||
ESP_LOGW(TAG, "%s: %sretrying in %u ms", this->client_combined_info_.c_str(), warn_str, ping_retry_interval);
|
||||
} else {
|
||||
ESP_LOGD(TAG, "%s: Sending keepalive failed %d time(s), will retry in %d ms",
|
||||
this->client_combined_info_.c_str(), this->ping_retries_, ping_retry_interval);
|
||||
ESP_LOGD(TAG, "%s: %sretrying in %u ms", this->client_combined_info_.c_str(), warn_str, ping_retry_interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,7 +269,7 @@ DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) {
|
||||
// remote initiated disconnect_client
|
||||
// don't close yet, we still need to send the disconnect response
|
||||
// close will happen on next loop
|
||||
ESP_LOGD(TAG, "%s requested disconnected", this->client_combined_info_.c_str());
|
||||
ESP_LOGD(TAG, "%s disconnected", this->client_combined_info_.c_str());
|
||||
this->next_close_ = true;
|
||||
DisconnectResponse resp;
|
||||
return resp;
|
||||
@@ -1472,7 +1471,7 @@ void APIConnection::update_command(const UpdateCommandRequest &msg) {
|
||||
update->check();
|
||||
break;
|
||||
case enums::UPDATE_COMMAND_NONE:
|
||||
ESP_LOGE(TAG, "UPDATE_COMMAND_NONE not handled. Check client is sending the correct command");
|
||||
ESP_LOGE(TAG, "UPDATE_COMMAND_NONE not handled; confirm command is correct");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "Unknown update command: %" PRIu32, msg.command);
|
||||
@@ -1534,7 +1533,7 @@ ConnectResponse APIConnection::connect(const ConnectRequest &msg) {
|
||||
// bool invalid_password = 1;
|
||||
resp.invalid_password = !correct;
|
||||
if (correct) {
|
||||
ESP_LOGD(TAG, "%s: Connected successfully", this->client_combined_info_.c_str());
|
||||
ESP_LOGD(TAG, "%s connected", this->client_combined_info_.c_str());
|
||||
this->connection_state_ = ConnectionState::AUTHENTICATED;
|
||||
this->parent_->get_client_connected_trigger()->trigger(this->client_info_, this->client_peername_);
|
||||
#ifdef USE_HOMEASSISTANT_TIME
|
||||
@@ -1605,7 +1604,7 @@ void APIConnection::execute_service(const ExecuteServiceRequest &msg) {
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
ESP_LOGV(TAG, "Could not find matching service!");
|
||||
ESP_LOGV(TAG, "Could not find service");
|
||||
}
|
||||
}
|
||||
#ifdef USE_API_NOISE
|
||||
@@ -1674,11 +1673,11 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
|
||||
}
|
||||
void APIConnection::on_unauthenticated_access() {
|
||||
this->on_fatal_error();
|
||||
ESP_LOGD(TAG, "%s: tried to access without authentication.", this->client_combined_info_.c_str());
|
||||
ESP_LOGD(TAG, "%s requested access without authentication", this->client_combined_info_.c_str());
|
||||
}
|
||||
void APIConnection::on_no_setup_connection() {
|
||||
this->on_fatal_error();
|
||||
ESP_LOGD(TAG, "%s: tried to access without full connection.", this->client_combined_info_.c_str());
|
||||
ESP_LOGD(TAG, "%s requested access without full connection", this->client_combined_info_.c_str());
|
||||
}
|
||||
void APIConnection::on_fatal_error() {
|
||||
this->helper_->close();
|
||||
|
||||
@@ -780,7 +780,7 @@ extern "C" {
|
||||
// declare how noise generates random bytes (here with a good HWRNG based on the RF system)
|
||||
void noise_rand_bytes(void *output, size_t len) {
|
||||
if (!esphome::random_bytes(reinterpret_cast<uint8_t *>(output), len)) {
|
||||
ESP_LOGE(TAG, "Failed to acquire random bytes, rebooting!");
|
||||
ESP_LOGE(TAG, "Acquiring random bytes failed; rebooting");
|
||||
arch_restart();
|
||||
}
|
||||
}
|
||||
@@ -831,12 +831,15 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
|
||||
|
||||
// read header
|
||||
while (!rx_header_parsed_) {
|
||||
uint8_t data;
|
||||
// Reading one byte at a time is fastest in practice for ESP32 when
|
||||
// there is no data on the wire (which is the common case).
|
||||
// This results in faster failure detection compared to
|
||||
// attempting to read multiple bytes at once.
|
||||
ssize_t received = this->socket_->read(&data, 1);
|
||||
// Now that we know when the socket is ready, we can read up to 3 bytes
|
||||
// into the rx_header_buf_ before we have to switch back to reading
|
||||
// one byte at a time to ensure we don't read past the message and
|
||||
// into the next one.
|
||||
|
||||
// Read directly into rx_header_buf_ at the current position
|
||||
// Try to get to at least 3 bytes total (indicator + 2 varint bytes), then read one byte at a time
|
||||
ssize_t received =
|
||||
this->socket_->read(&rx_header_buf_[rx_header_buf_pos_], rx_header_buf_pos_ < 3 ? 3 - rx_header_buf_pos_ : 1);
|
||||
if (received == -1) {
|
||||
if (errno == EWOULDBLOCK || errno == EAGAIN) {
|
||||
return APIError::WOULD_BLOCK;
|
||||
@@ -850,51 +853,46 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
|
||||
return APIError::CONNECTION_CLOSED;
|
||||
}
|
||||
|
||||
// Successfully read a byte
|
||||
|
||||
// Process byte according to current buffer position
|
||||
if (rx_header_buf_pos_ == 0) { // Case 1: First byte (indicator byte)
|
||||
if (data != 0x00) {
|
||||
// If this was the first read, validate the indicator byte
|
||||
if (rx_header_buf_pos_ == 0 && received > 0) {
|
||||
if (rx_header_buf_[0] != 0x00) {
|
||||
state_ = State::FAILED;
|
||||
HELPER_LOG("Bad indicator byte %u", data);
|
||||
HELPER_LOG("Bad indicator byte %u", rx_header_buf_[0]);
|
||||
return APIError::BAD_INDICATOR;
|
||||
}
|
||||
// We don't store the indicator byte, just increment position
|
||||
rx_header_buf_pos_ = 1; // Set to 1 directly
|
||||
continue; // Need more bytes before we can parse
|
||||
}
|
||||
|
||||
// Check buffer overflow before storing
|
||||
if (rx_header_buf_pos_ == 5) { // Case 2: Buffer would overflow (5 bytes is max allowed)
|
||||
rx_header_buf_pos_ += received;
|
||||
|
||||
// Check for buffer overflow
|
||||
if (rx_header_buf_pos_ >= sizeof(rx_header_buf_)) {
|
||||
state_ = State::FAILED;
|
||||
HELPER_LOG("Header buffer overflow");
|
||||
return APIError::BAD_DATA_PACKET;
|
||||
}
|
||||
|
||||
// Store byte in buffer (adjust index to account for skipped indicator byte)
|
||||
rx_header_buf_[rx_header_buf_pos_ - 1] = data;
|
||||
|
||||
// Increment position after storing
|
||||
rx_header_buf_pos_++;
|
||||
|
||||
// Case 3: If we only have one varint byte, we need more
|
||||
if (rx_header_buf_pos_ == 2) { // Have read indicator + 1 byte
|
||||
continue; // Need more bytes before we can parse
|
||||
// Need at least 3 bytes total (indicator + 2 varint bytes) before trying to parse
|
||||
if (rx_header_buf_pos_ < 3) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// At this point, we have at least 3 bytes total:
|
||||
// - Validated indicator byte (0x00) but not stored
|
||||
// - Validated indicator byte (0x00) stored at position 0
|
||||
// - At least 2 bytes in the buffer for the varints
|
||||
// Buffer layout:
|
||||
// First 1-3 bytes: Message size varint (variable length)
|
||||
// [0]: indicator byte (0x00)
|
||||
// [1-3]: Message size varint (variable length)
|
||||
// - 2 bytes would only allow up to 16383, which is less than noise's UINT16_MAX (65535)
|
||||
// - 3 bytes allows up to 2097151, ensuring we support at least as much as noise
|
||||
// Remaining 1-2 bytes: Message type varint (variable length)
|
||||
// [2-5]: Message type varint (variable length)
|
||||
// We now attempt to parse both varints. If either is incomplete,
|
||||
// we'll continue reading more bytes.
|
||||
|
||||
// Skip indicator byte at position 0
|
||||
uint8_t varint_pos = 1;
|
||||
uint32_t consumed = 0;
|
||||
auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[0], rx_header_buf_pos_ - 1, &consumed);
|
||||
|
||||
auto msg_size_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed);
|
||||
if (!msg_size_varint.has_value()) {
|
||||
// not enough data there yet
|
||||
continue;
|
||||
@@ -908,7 +906,10 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
|
||||
}
|
||||
rx_header_parsed_len_ = msg_size_varint->as_uint16();
|
||||
|
||||
auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[consumed], rx_header_buf_pos_ - 1 - consumed, &consumed);
|
||||
// Move to next varint position
|
||||
varint_pos += consumed;
|
||||
|
||||
auto msg_type_varint = ProtoVarInt::parse(&rx_header_buf_[varint_pos], rx_header_buf_pos_ - varint_pos, &consumed);
|
||||
if (!msg_type_varint.has_value()) {
|
||||
// not enough data there yet
|
||||
continue;
|
||||
|
||||
@@ -233,14 +233,14 @@ class APIPlaintextFrameHelper : public APIFrameHelper {
|
||||
protected:
|
||||
APIError try_read_frame_(ParsedFrame *frame);
|
||||
// Fixed-size header buffer for plaintext protocol:
|
||||
// We only need space for the two varints since we validate the indicator byte separately.
|
||||
// We now store the indicator byte + the two varints.
|
||||
// To match noise protocol's maximum message size (UINT16_MAX = 65535), we need:
|
||||
// 3 bytes for message size varint (supports up to 2097151) + 2 bytes for message type varint
|
||||
// 1 byte for indicator + 3 bytes for message size varint (supports up to 2097151) + 2 bytes for message type varint
|
||||
//
|
||||
// While varints could theoretically be up to 10 bytes each for 64-bit values,
|
||||
// attempting to process messages with headers that large would likely crash the
|
||||
// ESP32 due to memory constraints.
|
||||
uint8_t rx_header_buf_[5]; // 5 bytes for varints (3 for size + 2 for type)
|
||||
uint8_t rx_header_buf_[6]; // 1 byte indicator + 5 bytes for varints (3 for size + 2 for type)
|
||||
uint8_t rx_header_buf_pos_ = 0;
|
||||
bool rx_header_parsed_ = false;
|
||||
uint16_t rx_header_parsed_type_ = 0;
|
||||
|
||||
@@ -27,7 +27,7 @@ APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-c
|
||||
APIServer::APIServer() { global_api_server = this; }
|
||||
|
||||
void APIServer::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Home Assistant API server...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->setup_controller();
|
||||
|
||||
#ifdef USE_API_NOISE
|
||||
@@ -157,7 +157,7 @@ void APIServer::loop() {
|
||||
const uint32_t now = millis();
|
||||
if (!this->is_connected()) {
|
||||
if (now - this->last_connected_ > this->reboot_timeout_) {
|
||||
ESP_LOGE(TAG, "No client connected to API. Rebooting...");
|
||||
ESP_LOGE(TAG, "No client connected; rebooting");
|
||||
App.reboot();
|
||||
}
|
||||
this->status_set_warning();
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace as3935 {
|
||||
static const char *const TAG = "as3935";
|
||||
|
||||
void AS3935Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AS3935...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
this->irq_pin_->setup();
|
||||
LOG_PIN(" IRQ Pin: ", this->irq_pin_);
|
||||
@@ -282,7 +282,7 @@ void AS3935Component::display_oscillator(bool state, uint8_t osc) {
|
||||
// based on the resonance frequency of the antenna and so it should be trimmed
|
||||
// before the calibration is done.
|
||||
bool AS3935Component::calibrate_oscillator() {
|
||||
ESP_LOGI(TAG, "Starting oscillators calibration...");
|
||||
ESP_LOGI(TAG, "Starting oscillators calibration");
|
||||
this->write_register(CALIB_RCO, WIPE_ALL, DIRECT_COMMAND, 0); // Send command to calibrate the oscillators
|
||||
|
||||
this->display_oscillator(true, 2);
|
||||
@@ -307,7 +307,7 @@ bool AS3935Component::calibrate_oscillator() {
|
||||
}
|
||||
|
||||
void AS3935Component::tune_antenna() {
|
||||
ESP_LOGI(TAG, "Starting antenna tuning...");
|
||||
ESP_LOGI(TAG, "Starting antenna tuning");
|
||||
uint8_t div_ratio = this->read_div_ratio();
|
||||
uint8_t tune_val = this->read_capacitance();
|
||||
ESP_LOGI(TAG, "Division Ratio is set to: %d", div_ratio);
|
||||
|
||||
@@ -23,7 +23,7 @@ static const uint8_t REGISTER_AGC = 0x1A; // 8 bytes / R
|
||||
static const uint8_t REGISTER_MAGNITUDE = 0x1B; // 16 bytes / R
|
||||
|
||||
void AS5600Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AS5600...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
if (!this->read_byte(REGISTER_STATUS).has_value()) {
|
||||
this->mark_failed();
|
||||
@@ -91,7 +91,7 @@ void AS5600Component::dump_config() {
|
||||
LOG_I2C_DEVICE(this);
|
||||
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AS5600 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace as7341 {
|
||||
static const char *const TAG = "as7341";
|
||||
|
||||
void AS7341Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AS7341...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
LOG_I2C_DEVICE(this);
|
||||
|
||||
// Verify device ID
|
||||
@@ -38,7 +38,7 @@ void AS7341Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "AS7341:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with AS7341 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
ESP_LOGCONFIG(TAG, " Gain: %u", get_gain());
|
||||
|
||||
@@ -71,11 +71,11 @@ bool AT581XComponent::i2c_read_reg(uint8_t addr, uint8_t &data) {
|
||||
return this->read_register(addr, &data, 1) == esphome::i2c::NO_ERROR;
|
||||
}
|
||||
|
||||
void AT581XComponent::setup() { ESP_LOGCONFIG(TAG, "Setting up AT581X..."); }
|
||||
void AT581XComponent::setup() { ESP_LOGCONFIG(TAG, "Running setup"); }
|
||||
void AT581XComponent::dump_config() { LOG_I2C_DEVICE(this); }
|
||||
#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
|
||||
bool AT581XComponent::i2c_write_config() {
|
||||
ESP_LOGCONFIG(TAG, "Writing new config for AT581X...");
|
||||
ESP_LOGCONFIG(TAG, "Writing new config for AT581X");
|
||||
ESP_LOGCONFIG(TAG, "Frequency: %dMHz", this->freq_);
|
||||
ESP_LOGCONFIG(TAG, "Sensing distance: %d", this->delta_);
|
||||
ESP_LOGCONFIG(TAG, "Power: %dµA", this->power_);
|
||||
|
||||
@@ -41,7 +41,7 @@ void ATM90E26Component::update() {
|
||||
}
|
||||
|
||||
void ATM90E26Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ATM90E26 Component...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->spi_setup();
|
||||
|
||||
uint16_t mmode = 0x422; // default values for everything but L/N line current gains
|
||||
@@ -135,7 +135,7 @@ void ATM90E26Component::dump_config() {
|
||||
ESP_LOGCONFIG("", "ATM90E26:");
|
||||
LOG_PIN(" CS Pin: ", this->cs_);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with ATM90E26 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Voltage A", this->voltage_sensor_);
|
||||
|
||||
@@ -108,7 +108,7 @@ void ATM90E32Component::update() {
|
||||
}
|
||||
|
||||
void ATM90E32Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ATM90E32 Component...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->spi_setup();
|
||||
|
||||
uint16_t mmode0 = 0x87; // 3P4W 50Hz
|
||||
@@ -217,7 +217,7 @@ void ATM90E32Component::dump_config() {
|
||||
ESP_LOGCONFIG("", "ATM90E32:");
|
||||
LOG_PIN(" CS Pin: ", this->cs_);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with ATM90E32 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Voltage A", this->phase_[PHASEA].voltage_sensor_);
|
||||
@@ -686,7 +686,7 @@ void ATM90E32Component::restore_power_offset_calibrations_() {
|
||||
}
|
||||
|
||||
void ATM90E32Component::clear_gain_calibrations() {
|
||||
ESP_LOGI(TAG, "[CALIBRATION] Clearing stored gain calibrations and restoring config-defined values...");
|
||||
ESP_LOGI(TAG, "[CALIBRATION] Clearing stored gain calibrations and restoring config-defined values");
|
||||
|
||||
for (int phase = 0; phase < 3; phase++) {
|
||||
gain_phase_[phase].voltage_gain = this->phase_[phase].voltage_gain_;
|
||||
|
||||
@@ -17,7 +17,7 @@ constexpr static const uint8_t AXS_READ_TOUCHPAD[11] = {0xb5, 0xab, 0xa5, 0x5a,
|
||||
}
|
||||
|
||||
void AXS15231Touchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up AXS15231 Touchscreen...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->setup();
|
||||
this->reset_pin_->digital_write(false);
|
||||
|
||||
@@ -527,7 +527,7 @@ void BedJetHub::dispatch_status_() {
|
||||
}
|
||||
|
||||
if (this->timeout_ > 0 && diff > this->timeout_ && this->parent()->enabled) {
|
||||
ESP_LOGW(TAG, "[%s] Timed out after %" PRId32 " sec. Retrying...", this->get_name().c_str(), this->timeout_);
|
||||
ESP_LOGW(TAG, "[%s] Timed out after %" PRId32 " sec. Retrying", this->get_name().c_str(), this->timeout_);
|
||||
// set_enabled(false) will only close the connection if state != IDLE.
|
||||
this->parent()->set_state(espbt::ClientState::CONNECTING);
|
||||
this->parent()->set_enabled(false);
|
||||
|
||||
@@ -119,7 +119,7 @@ void spi_dma_tx_finish_callback(unsigned int param) {
|
||||
}
|
||||
|
||||
void BekenSPILEDStripLightOutput::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Beken SPI LED Strip...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
size_t buffer_size = this->get_buffer_size_();
|
||||
size_t dma_buffer_size = (buffer_size * 8) + (2 * 64);
|
||||
@@ -256,7 +256,7 @@ void BekenSPILEDStripLightOutput::write_state(light::LightState *state) {
|
||||
this->last_refresh_ = now;
|
||||
this->mark_shown_();
|
||||
|
||||
ESP_LOGVV(TAG, "Writing RGB values to bus...");
|
||||
ESP_LOGVV(TAG, "Writing RGB values to bus");
|
||||
|
||||
if (spi_data == nullptr) {
|
||||
ESP_LOGE(TAG, "SPI not initialized");
|
||||
|
||||
@@ -38,7 +38,7 @@ MTreg:
|
||||
*/
|
||||
|
||||
void BH1750Sensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BH1750 '%s'...", this->name_.c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->name_.c_str());
|
||||
uint8_t turn_on = BH1750_COMMAND_POWER_ON;
|
||||
if (this->write(&turn_on, 1) != i2c::ERROR_OK) {
|
||||
this->mark_failed();
|
||||
@@ -118,7 +118,7 @@ void BH1750Sensor::dump_config() {
|
||||
LOG_SENSOR("", "BH1750", this);
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with BH1750 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL_FOR, this->get_name().c_str());
|
||||
}
|
||||
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
|
||||
@@ -68,8 +68,7 @@ void binary_sensor::MultiClickTrigger::on_state_(bool state) {
|
||||
*this->at_index_ = *this->at_index_ + 1;
|
||||
}
|
||||
void binary_sensor::MultiClickTrigger::schedule_cooldown_() {
|
||||
ESP_LOGV(TAG, "Multi Click: Invalid length of press, starting cooldown of %" PRIu32 " ms...",
|
||||
this->invalid_cooldown_);
|
||||
ESP_LOGV(TAG, "Multi Click: Invalid length of press, starting cooldown of %" PRIu32 " ms", this->invalid_cooldown_);
|
||||
this->is_in_cooldown_ = true;
|
||||
this->set_timeout("cooldown", this->invalid_cooldown_, [this]() {
|
||||
ESP_LOGV(TAG, "Multi Click: Cooldown ended, matching is now enabled again.");
|
||||
|
||||
@@ -100,7 +100,7 @@ void BL0906::handle_actions_() {
|
||||
for (int i = 0; i < this->action_queue_.size(); i++) {
|
||||
ptr_func = this->action_queue_[i];
|
||||
if (ptr_func) {
|
||||
ESP_LOGI(TAG, "HandleActionCallback[%d]...", i);
|
||||
ESP_LOGI(TAG, "HandleActionCallback[%d]", i);
|
||||
(this->*ptr_func)();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ const char *oversampling_to_str(BME280Oversampling oversampling) { // NOLINT
|
||||
}
|
||||
|
||||
void BME280Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BME280...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t chip_id = 0;
|
||||
|
||||
// Mark as not failed before initializing. Some devices will turn off sensors to save on batteries
|
||||
@@ -182,7 +182,7 @@ void BME280Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BME280:");
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with BME280 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case WRONG_CHIP_ID:
|
||||
ESP_LOGE(TAG, "BME280 has wrong chip ID! Is it a BME280?");
|
||||
@@ -207,7 +207,7 @@ inline uint8_t oversampling_to_time(BME280Oversampling over_sampling) { return (
|
||||
|
||||
void BME280Component::update() {
|
||||
// Enable sensor
|
||||
ESP_LOGV(TAG, "Sending conversion request...");
|
||||
ESP_LOGV(TAG, "Sending conversion request");
|
||||
uint8_t meas_value = 0;
|
||||
meas_value |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_value |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
|
||||
@@ -71,7 +71,7 @@ static const char *iir_filter_to_str(BME680IIRFilter filter) {
|
||||
}
|
||||
|
||||
void BME680Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BME680...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t chip_id;
|
||||
if (!this->read_byte(BME680_REGISTER_CHIPID, &chip_id) || chip_id != 0x61) {
|
||||
this->mark_failed();
|
||||
@@ -215,7 +215,7 @@ void BME680Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BME680:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with BME680 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " IIR Filter: %s", iir_filter_to_str(this->iir_filter_));
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
@@ -307,7 +307,7 @@ void BME680Component::read_data_() {
|
||||
this->humidity_sensor_->publish_state(NAN);
|
||||
if (this->gas_resistance_sensor_ != nullptr)
|
||||
this->gas_resistance_sensor_->publish_state(NAN);
|
||||
ESP_LOGW(TAG, "Communication with BME680 failed!");
|
||||
ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ from esphome.const import (
|
||||
CONF_PRESSURE,
|
||||
CONF_TEMPERATURE,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_ATMOSPHERIC_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
ICON_GAS_CYLINDER,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
@@ -71,7 +71,7 @@ CONFIG_SCHEMA = (
|
||||
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_HECTOPASCAL,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
device_class=DEVICE_CLASS_ATMOSPHERIC_PRESSURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
).extend(
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ std::vector<BME680BSECComponent *>
|
||||
uint8_t BME680BSECComponent::work_buffer_[BSEC_MAX_WORKBUFFER_SIZE] = {0};
|
||||
|
||||
void BME680BSECComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BME680(%s) via BSEC...", this->device_id_.c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->device_id_.c_str());
|
||||
|
||||
uint8_t new_idx = BME680BSECComponent::instances.size();
|
||||
BME680BSECComponent::instances.push_back(this);
|
||||
|
||||
@@ -15,6 +15,8 @@ from esphome.const import (
|
||||
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
|
||||
ICON_GAS_CYLINDER,
|
||||
ICON_GAUGE,
|
||||
ICON_THERMOMETER,
|
||||
ICON_WATER_PERCENT,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
UNIT_HECTOPASCAL,
|
||||
@@ -27,11 +29,11 @@ from . import CONF_BME680_BSEC_ID, SAMPLE_RATE_OPTIONS, BME680BSECComponent
|
||||
|
||||
DEPENDENCIES = ["bme680_bsec"]
|
||||
|
||||
CONF_IAQ = "iaq"
|
||||
CONF_CO2_EQUIVALENT = "co2_equivalent"
|
||||
CONF_BREATH_VOC_EQUIVALENT = "breath_voc_equivalent"
|
||||
UNIT_IAQ = "IAQ"
|
||||
CONF_CO2_EQUIVALENT = "co2_equivalent"
|
||||
CONF_IAQ = "iaq"
|
||||
ICON_ACCURACY = "mdi:checkbox-marked-circle-outline"
|
||||
UNIT_IAQ = "IAQ"
|
||||
|
||||
TYPES = [
|
||||
CONF_TEMPERATURE,
|
||||
@@ -49,6 +51,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.GenerateID(CONF_BME680_BSEC_ID): cv.use_id(BME680BSECComponent),
|
||||
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_CELSIUS,
|
||||
icon=ICON_THERMOMETER,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
@@ -65,6 +68,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
),
|
||||
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PERCENT,
|
||||
icon=ICON_WATER_PERCENT,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
|
||||
@@ -21,7 +21,7 @@ static const char *const TAG = "bme68x_bsec2.sensor";
|
||||
static const std::string IAQ_ACCURACY_STATES[4] = {"Stabilizing", "Uncertain", "Calibrating", "Calibrated"};
|
||||
|
||||
void BME68xBSEC2Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BME68X via BSEC2...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
this->bsec_status_ = bsec_init_m(&this->bsec_instance_);
|
||||
if (this->bsec_status_ != BSEC_OK) {
|
||||
|
||||
@@ -9,8 +9,10 @@ from esphome.const import (
|
||||
CONF_SAMPLE_RATE,
|
||||
CONF_TEMPERATURE,
|
||||
DEVICE_CLASS_ATMOSPHERIC_PRESSURE,
|
||||
DEVICE_CLASS_CARBON_DIOXIDE,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
|
||||
ICON_GAS_CYLINDER,
|
||||
ICON_GAUGE,
|
||||
ICON_THERMOMETER,
|
||||
@@ -32,7 +34,6 @@ CONF_CO2_EQUIVALENT = "co2_equivalent"
|
||||
CONF_IAQ = "iaq"
|
||||
CONF_IAQ_STATIC = "iaq_static"
|
||||
ICON_ACCURACY = "mdi:checkbox-marked-circle-outline"
|
||||
ICON_TEST_TUBE = "mdi:test-tube"
|
||||
UNIT_IAQ = "IAQ"
|
||||
|
||||
TYPES = [
|
||||
@@ -61,7 +62,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
),
|
||||
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_HECTOPASCAL,
|
||||
icon=ICON_GAUGE,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_ATMOSPHERIC_PRESSURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
@@ -102,14 +102,14 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
),
|
||||
cv.Optional(CONF_CO2_EQUIVALENT): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PARTS_PER_MILLION,
|
||||
icon=ICON_TEST_TUBE,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_CARBON_DIOXIDE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_BREATH_VOC_EQUIVALENT): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_PARTS_PER_MILLION,
|
||||
icon=ICON_TEST_TUBE,
|
||||
accuracy_decimals=1,
|
||||
device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS_PARTS,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
|
||||
@@ -119,44 +119,44 @@ const float GRAVITY_EARTH = 9.80665f;
|
||||
void BMI160Component::internal_setup_(int stage) {
|
||||
switch (stage) {
|
||||
case 0:
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMI160...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t chipid;
|
||||
if (!this->read_byte(BMI160_REGISTER_CHIPID, &chipid) || (chipid != 0b11010001)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Bringing accelerometer out of sleep...");
|
||||
ESP_LOGV(TAG, " Bringing accelerometer out of sleep");
|
||||
if (!this->write_byte(BMI160_REGISTER_CMD, (uint8_t) Cmd::ACCL_SET_PMU_MODE | (uint8_t) AcclPmuMode::NORMAL)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Waiting for accelerometer to wake up...");
|
||||
ESP_LOGV(TAG, " Waiting for accelerometer to wake up");
|
||||
// need to wait (max delay in datasheet) because we can't send commands while another is in progress
|
||||
// min 5ms, 10ms
|
||||
this->set_timeout(10, [this]() { this->internal_setup_(1); });
|
||||
break;
|
||||
|
||||
case 1:
|
||||
ESP_LOGV(TAG, " Bringing gyroscope out of sleep...");
|
||||
ESP_LOGV(TAG, " Bringing gyroscope out of sleep");
|
||||
if (!this->write_byte(BMI160_REGISTER_CMD, (uint8_t) Cmd::GYRO_SET_PMU_MODE | (uint8_t) GyroPmuMode::NORMAL)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Waiting for gyroscope to wake up...");
|
||||
ESP_LOGV(TAG, " Waiting for gyroscope to wake up");
|
||||
// wait between 51 & 81ms, doing 100 to be safe
|
||||
this->set_timeout(10, [this]() { this->internal_setup_(2); });
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ESP_LOGV(TAG, " Setting up Gyro Config...");
|
||||
ESP_LOGV(TAG, " Setting up Gyro Config");
|
||||
uint8_t gyro_config = (uint8_t) GyroBandwidth::OSR4 | (uint8_t) GyroOuputDataRate::HZ_25;
|
||||
ESP_LOGV(TAG, " Output gyro_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_config));
|
||||
if (!this->write_byte(BMI160_REGISTER_GYRO_CONFIG, gyro_config)) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Setting up Gyro Range...");
|
||||
ESP_LOGV(TAG, " Setting up Gyro Range");
|
||||
uint8_t gyro_range = (uint8_t) GyroRange::RANGE_2000_DPS;
|
||||
ESP_LOGV(TAG, " Output gyro_range: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(gyro_range));
|
||||
if (!this->write_byte(BMI160_REGISTER_GYRO_RANGE, gyro_range)) {
|
||||
@@ -164,7 +164,7 @@ void BMI160Component::internal_setup_(int stage) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Setting up Accel Config...");
|
||||
ESP_LOGV(TAG, " Setting up Accel Config");
|
||||
uint8_t accel_config =
|
||||
(uint8_t) AcclFilterMode::PERF | (uint8_t) AcclBandwidth::RES_AVG16 | (uint8_t) AccelOutputDataRate::HZ_25;
|
||||
ESP_LOGV(TAG, " Output accel_config: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_config));
|
||||
@@ -172,7 +172,7 @@ void BMI160Component::internal_setup_(int stage) {
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGV(TAG, " Setting up Accel Range...");
|
||||
ESP_LOGV(TAG, " Setting up Accel Range");
|
||||
uint8_t accel_range = (uint8_t) AccelRange::RANGE_16G;
|
||||
ESP_LOGV(TAG, " Output accel_range: 0b" BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(accel_range));
|
||||
if (!this->write_byte(BMI160_REGISTER_ACCEL_RANGE, accel_range)) {
|
||||
@@ -189,7 +189,7 @@ void BMI160Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BMI160:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with BMI160 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Acceleration X", this->accel_x_sensor_);
|
||||
@@ -219,7 +219,7 @@ void BMI160Component::update() {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, " Updating BMI160...");
|
||||
ESP_LOGV(TAG, " Updating BMI160");
|
||||
int16_t data[6];
|
||||
if (this->read_le_int16_(BMI160_REGISTER_DATA_GYRO_X_LSB, data, 6) != i2c::ERROR_OK) {
|
||||
this->status_set_warning();
|
||||
|
||||
@@ -20,7 +20,7 @@ void BMP085Component::update() {
|
||||
this->set_timeout("temperature", 5, [this]() { this->read_temperature_(); });
|
||||
}
|
||||
void BMP085Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMP085...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t data[22];
|
||||
if (!this->read_bytes(BMP085_REGISTER_AC1_H, data, 22)) {
|
||||
this->mark_failed();
|
||||
@@ -129,7 +129,7 @@ void BMP085Component::read_pressure_() {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
bool BMP085Component::set_mode_(uint8_t mode) {
|
||||
ESP_LOGV(TAG, "Setting mode to 0x%02X...", mode);
|
||||
ESP_LOGV(TAG, "Setting mode to 0x%02X", mode);
|
||||
return this->write_byte(BMP085_REGISTER_CONTROL, mode);
|
||||
}
|
||||
float BMP085Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
@@ -57,7 +57,7 @@ static const char *iir_filter_to_str(BMP280IIRFilter filter) {
|
||||
}
|
||||
|
||||
void BMP280Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMP280...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t chip_id = 0;
|
||||
|
||||
// Read the chip id twice, to work around a bug where the first read is 0.
|
||||
@@ -132,7 +132,7 @@ void BMP280Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "BMP280:");
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with BMP280 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case WRONG_CHIP_ID:
|
||||
ESP_LOGE(TAG, "BMP280 has wrong chip ID! Is it a BME280?");
|
||||
@@ -155,7 +155,7 @@ inline uint8_t oversampling_to_time(BMP280Oversampling over_sampling) { return (
|
||||
|
||||
void BMP280Component::update() {
|
||||
// Enable sensor
|
||||
ESP_LOGV(TAG, "Sending conversion request...");
|
||||
ESP_LOGV(TAG, "Sending conversion request");
|
||||
uint8_t meas_value = 0;
|
||||
meas_value |= (this->temperature_oversampling_ & 0b111) << 5;
|
||||
meas_value |= (this->pressure_oversampling_ & 0b111) << 2;
|
||||
|
||||
@@ -70,10 +70,10 @@ static const LogString *iir_filter_to_str(IIRFilter filter) {
|
||||
|
||||
void BMP3XXComponent::setup() {
|
||||
this->error_code_ = NONE;
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMP3XX...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
// Call the Device base class "initialise" function
|
||||
if (!reset()) {
|
||||
ESP_LOGE(TAG, "Failed to reset BMP3XX...");
|
||||
ESP_LOGE(TAG, "Failed to reset");
|
||||
this->error_code_ = ERROR_SENSOR_RESET;
|
||||
this->mark_failed();
|
||||
}
|
||||
@@ -154,19 +154,17 @@ void BMP3XXComponent::dump_config() {
|
||||
case NONE:
|
||||
break;
|
||||
case ERROR_COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with BMP3XX failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case ERROR_WRONG_CHIP_ID:
|
||||
ESP_LOGE(
|
||||
TAG,
|
||||
"BMP3XX has wrong chip ID (reported id: 0x%X) - please check if you are really using a BMP 388 or BMP 390",
|
||||
this->chip_id_.reg);
|
||||
ESP_LOGE(TAG, "Wrong chip ID (reported id: 0x%X) - please check if you are really using a BMP 388 or BMP 390",
|
||||
this->chip_id_.reg);
|
||||
break;
|
||||
case ERROR_SENSOR_RESET:
|
||||
ESP_LOGE(TAG, "BMP3XX failed to reset");
|
||||
ESP_LOGE(TAG, "Failed to reset");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "BMP3XX error code %d", (int) this->error_code_);
|
||||
ESP_LOGE(TAG, "Error code %d", (int) this->error_code_);
|
||||
break;
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " IIR Filter: %s", LOG_STR_ARG(iir_filter_to_str(this->iir_filter_)));
|
||||
@@ -186,7 +184,7 @@ inline uint8_t oversampling_to_time(Oversampling over_sampling) { return (1 << u
|
||||
|
||||
void BMP3XXComponent::update() {
|
||||
// Enable sensor
|
||||
ESP_LOGV(TAG, "Sending conversion request...");
|
||||
ESP_LOGV(TAG, "Sending conversion request");
|
||||
float meas_time = 1.0f;
|
||||
// Ref: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf 3.9.2
|
||||
meas_time += 2.02f * oversampling_to_time(this->temperature_oversampling_) + 0.163f;
|
||||
@@ -296,7 +294,7 @@ bool BMP3XXComponent::get_pressure(float &pressure) {
|
||||
bool BMP3XXComponent::get_measurements(float &temperature, float &pressure) {
|
||||
// Check if a measurement is ready
|
||||
if (!data_ready()) {
|
||||
ESP_LOGD(TAG, "BMP3XX Get measurement - data not ready skipping update");
|
||||
ESP_LOGD(TAG, "Get measurement - data not ready skipping update");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,22 +72,22 @@ void BMP581Component::dump_config() {
|
||||
case NONE:
|
||||
break;
|
||||
case ERROR_COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, " Communication with BMP581 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case ERROR_WRONG_CHIP_ID:
|
||||
ESP_LOGE(TAG, " BMP581 has wrong chip ID - please verify you are using a BMP 581");
|
||||
ESP_LOGE(TAG, "Unknown chip ID");
|
||||
break;
|
||||
case ERROR_SENSOR_RESET:
|
||||
ESP_LOGE(TAG, " BMP581 failed to reset");
|
||||
ESP_LOGE(TAG, "Reset failed");
|
||||
break;
|
||||
case ERROR_SENSOR_STATUS:
|
||||
ESP_LOGE(TAG, " BMP581 sensor status failed, there were NVM problems");
|
||||
ESP_LOGE(TAG, "Get status failed");
|
||||
break;
|
||||
case ERROR_PRIME_IIR_FAILED:
|
||||
ESP_LOGE(TAG, " BMP581's IIR Filter failed to prime with an initial measurement");
|
||||
ESP_LOGE(TAG, "IIR Filter failed to prime with initial measurement");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, " BMP581 error code %d", (int) this->error_code_);
|
||||
ESP_LOGE(TAG, "Error %d", (int) this->error_code_);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ void BMP581Component::setup() {
|
||||
*/
|
||||
|
||||
this->error_code_ = NONE;
|
||||
ESP_LOGCONFIG(TAG, "Setting up BMP581...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
////////////////////
|
||||
// 1) Soft reboot //
|
||||
@@ -130,7 +130,7 @@ void BMP581Component::setup() {
|
||||
|
||||
// Power-On-Reboot bit is asserted if sensor successfully reset
|
||||
if (!this->reset_()) {
|
||||
ESP_LOGE(TAG, "BMP581 failed to reset");
|
||||
ESP_LOGE(TAG, "Reset failed");
|
||||
|
||||
this->error_code_ = ERROR_SENSOR_RESET;
|
||||
this->mark_failed();
|
||||
@@ -146,7 +146,7 @@ void BMP581Component::setup() {
|
||||
|
||||
// read chip id from sensor
|
||||
if (!this->read_byte(BMP581_CHIP_ID, &chip_id)) {
|
||||
ESP_LOGE(TAG, "Failed to read chip id");
|
||||
ESP_LOGE(TAG, "Read chip ID failed");
|
||||
|
||||
this->error_code_ = ERROR_COMMUNICATION_FAILED;
|
||||
this->mark_failed();
|
||||
@@ -156,7 +156,7 @@ void BMP581Component::setup() {
|
||||
|
||||
// verify id
|
||||
if (chip_id != BMP581_ASIC_ID) {
|
||||
ESP_LOGE(TAG, "Unknown chip ID, is this a BMP581?");
|
||||
ESP_LOGE(TAG, "Unknown chip ID");
|
||||
|
||||
this->error_code_ = ERROR_WRONG_CHIP_ID;
|
||||
this->mark_failed();
|
||||
@@ -179,7 +179,7 @@ void BMP581Component::setup() {
|
||||
|
||||
// verify status_nvm_rdy bit (it is asserted if boot was successful)
|
||||
if (!(this->status_.bit.status_nvm_rdy)) {
|
||||
ESP_LOGE(TAG, "NVM not ready after boot");
|
||||
ESP_LOGE(TAG, "NVM not ready");
|
||||
|
||||
this->error_code_ = ERROR_SENSOR_STATUS;
|
||||
this->mark_failed();
|
||||
@@ -189,7 +189,7 @@ void BMP581Component::setup() {
|
||||
|
||||
// verify status_nvm_err bit (it is asserted if an error is detected)
|
||||
if (this->status_.bit.status_nvm_err) {
|
||||
ESP_LOGE(TAG, "NVM error detected on boot");
|
||||
ESP_LOGE(TAG, "NVM error detected");
|
||||
|
||||
this->error_code_ = ERROR_SENSOR_STATUS;
|
||||
this->mark_failed();
|
||||
@@ -254,7 +254,7 @@ void BMP581Component::setup() {
|
||||
}
|
||||
|
||||
if (!this->prime_iir_filter_()) {
|
||||
ESP_LOGE(TAG, "Failed to prime the IIR filter with an intiial measurement");
|
||||
ESP_LOGE(TAG, "Failed to prime the IIR filter with an initial measurement");
|
||||
|
||||
this->error_code_ = ERROR_PRIME_IIR_FAILED;
|
||||
this->mark_failed();
|
||||
@@ -286,10 +286,10 @@ void BMP581Component::update() {
|
||||
// 1) Request a measurement //
|
||||
//////////////////////////////
|
||||
|
||||
ESP_LOGVV(TAG, "Requesting a measurement from sensor");
|
||||
ESP_LOGVV(TAG, "Requesting measurement");
|
||||
|
||||
if (!this->start_measurement_()) {
|
||||
ESP_LOGW(TAG, "Failed to request forced measurement of sensor");
|
||||
ESP_LOGW(TAG, "Requesting forced measurement failed");
|
||||
this->status_set_warning();
|
||||
|
||||
return;
|
||||
@@ -299,7 +299,7 @@ void BMP581Component::update() {
|
||||
// 2) Wait for measurement to finish (based on oversampling rates) //
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
ESP_LOGVV(TAG, "Measurement is expected to take %d ms to complete", this->conversion_time_);
|
||||
ESP_LOGVV(TAG, "Measurement should take %d ms", this->conversion_time_);
|
||||
|
||||
this->set_timeout("measurement", this->conversion_time_, [this]() {
|
||||
float temperature = 0.0;
|
||||
@@ -311,14 +311,14 @@ void BMP581Component::update() {
|
||||
|
||||
if (this->pressure_sensor_) {
|
||||
if (!this->read_temperature_and_pressure_(temperature, pressure)) {
|
||||
ESP_LOGW(TAG, "Failed to read temperature and pressure measurements, skipping update");
|
||||
ESP_LOGW(TAG, "Failed to read temperature and pressure; skipping update");
|
||||
this->status_set_warning();
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!this->read_temperature_(temperature)) {
|
||||
ESP_LOGW(TAG, "Failed to read temperature measurement, skipping update");
|
||||
ESP_LOGW(TAG, "Failed to read temperature; skipping update");
|
||||
this->status_set_warning();
|
||||
|
||||
return;
|
||||
@@ -349,7 +349,7 @@ bool BMP581Component::check_data_readiness_() {
|
||||
// - returns data readiness state
|
||||
|
||||
if (this->odr_config_.bit.pwr_mode == STANDBY_MODE) {
|
||||
ESP_LOGD(TAG, "Data is not ready, sensor is in standby mode");
|
||||
ESP_LOGD(TAG, "Data not ready, sensor is in standby mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ bool BMP581Component::read_temperature_(float &temperature) {
|
||||
// - the measured temperature (in degrees Celsius)
|
||||
|
||||
if (!this->check_data_readiness_()) {
|
||||
ESP_LOGW(TAG, "Data from sensor isn't ready, skipping this update");
|
||||
ESP_LOGW(TAG, "Data not ready, skipping this update");
|
||||
this->status_set_warning();
|
||||
|
||||
return false;
|
||||
@@ -451,7 +451,7 @@ bool BMP581Component::read_temperature_(float &temperature) {
|
||||
|
||||
uint8_t data[3];
|
||||
if (!this->read_bytes(BMP581_MEASUREMENT_DATA, &data[0], 3)) {
|
||||
ESP_LOGW(TAG, "Failed to read sensor's measurement data");
|
||||
ESP_LOGW(TAG, "Failed to read measurement");
|
||||
this->status_set_warning();
|
||||
|
||||
return false;
|
||||
@@ -472,7 +472,7 @@ bool BMP581Component::read_temperature_and_pressure_(float &temperature, float &
|
||||
// - the measured pressure (in Pa)
|
||||
|
||||
if (!this->check_data_readiness_()) {
|
||||
ESP_LOGW(TAG, "Data from sensor isn't ready, skipping this update");
|
||||
ESP_LOGW(TAG, "Data not ready, skipping this update");
|
||||
this->status_set_warning();
|
||||
|
||||
return false;
|
||||
@@ -480,7 +480,7 @@ bool BMP581Component::read_temperature_and_pressure_(float &temperature, float &
|
||||
|
||||
uint8_t data[6];
|
||||
if (!this->read_bytes(BMP581_MEASUREMENT_DATA, &data[0], 6)) {
|
||||
ESP_LOGW(TAG, "Failed to read sensor's measurement data");
|
||||
ESP_LOGW(TAG, "Failed to read measurement");
|
||||
this->status_set_warning();
|
||||
|
||||
return false;
|
||||
|
||||
@@ -15,7 +15,7 @@ static const uint8_t BP1658CJ_ADDR_START_5CH = 0x30;
|
||||
static const uint8_t BP1658CJ_DELAY = 2;
|
||||
|
||||
void BP1658CJ::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BP1658CJ Output Component...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->data_pin_->setup();
|
||||
this->data_pin_->digital_write(false);
|
||||
this->clock_pin_->setup();
|
||||
|
||||
@@ -20,7 +20,7 @@ static const uint8_t BP5758D_ALL_DATA_CHANNEL_ENABLEMENT = 0b00011111;
|
||||
static const uint8_t BP5758D_DELAY = 2;
|
||||
|
||||
void BP5758D::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up BP5758D Output Component...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->data_pin_->setup();
|
||||
this->data_pin_->digital_write(false);
|
||||
delayMicroseconds(BP5758D_DELAY);
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace canbus {
|
||||
static const char *const TAG = "canbus";
|
||||
|
||||
void Canbus::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Canbus...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (!this->setup_internal()) {
|
||||
ESP_LOGE(TAG, "setup error!");
|
||||
this->mark_failed();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace cap1188 {
|
||||
static const char *const TAG = "cap1188";
|
||||
|
||||
void CAP1188Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CAP1188...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// Reset device using the reset pin
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
|
||||
@@ -29,7 +29,7 @@ void CaptivePortal::handle_config(AsyncWebServerRequest *request) {
|
||||
void CaptivePortal::handle_wifisave(AsyncWebServerRequest *request) {
|
||||
std::string ssid = request->arg("ssid").c_str();
|
||||
std::string psk = request->arg("psk").c_str();
|
||||
ESP_LOGI(TAG, "Captive Portal Requested WiFi Settings Change:");
|
||||
ESP_LOGI(TAG, "Requested WiFi Settings Change:");
|
||||
ESP_LOGI(TAG, " SSID='%s'", ssid.c_str());
|
||||
ESP_LOGI(TAG, " Password=" LOG_SECRET("'%s'"), psk.c_str());
|
||||
wifi::global_wifi_component->save_wifi_sta(ssid, psk);
|
||||
|
||||
@@ -163,7 +163,7 @@ void CCS811Component::dump_config() {
|
||||
if (this->is_failed()) {
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGW(TAG, "Communication failed! Is the sensor connected?");
|
||||
ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case INVALID_ID:
|
||||
ESP_LOGW(TAG, "Sensor reported an invalid ID. Is this a CCS811?");
|
||||
|
||||
@@ -10,7 +10,7 @@ static const char *const TAG = "cd74hc4067";
|
||||
float CD74HC4067Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
void CD74HC4067Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CD74HC4067...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
this->pin_s0_->setup();
|
||||
this->pin_s1_->setup();
|
||||
|
||||
@@ -14,7 +14,7 @@ static const uint8_t CH422G_REG_OUT_UPPER = 0x23; // write reg for output bit
|
||||
static const char *const TAG = "ch422g";
|
||||
|
||||
void CH422GComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CH422G...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
// set outputs before mode
|
||||
this->write_outputs_();
|
||||
// Set mode and check for errors
|
||||
@@ -37,7 +37,7 @@ void CH422GComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "CH422G:");
|
||||
LOG_I2C_DEVICE(this)
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with CH422G failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace esphome {
|
||||
namespace chsc6x {
|
||||
|
||||
void CHSC6XTouchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CHSC6X Touchscreen...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (this->interrupt_pin_ != nullptr) {
|
||||
this->interrupt_pin_->setup();
|
||||
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
||||
|
||||
@@ -20,10 +20,10 @@ uint8_t cm1106_checksum(const uint8_t *response, size_t len) {
|
||||
}
|
||||
|
||||
void CM1106Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CM1106...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t response[8] = {0};
|
||||
if (!this->cm1106_write_command_(C_M1106_CMD_GET_CO2, sizeof(C_M1106_CMD_GET_CO2), response, sizeof(response))) {
|
||||
ESP_LOGE(TAG, "Communication with CM1106 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void CM1106Component::update() {
|
||||
}
|
||||
|
||||
if (response[0] != 0x16 || response[1] != 0x05 || response[2] != 0x01) {
|
||||
ESP_LOGW(TAG, "Got wrong UART response from CM1106: %02X %02X %02X %02X...", response[0], response[1], response[2],
|
||||
ESP_LOGW(TAG, "Got wrong UART response from CM1106: %02X %02X %02X %02X", response[0], response[1], response[2],
|
||||
response[3]);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
@@ -104,7 +104,7 @@ void CM1106Component::dump_config() {
|
||||
LOG_SENSOR(" ", "CO2", this->co2_sensor_);
|
||||
this->check_uart_settings(9600);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with CM1106 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ bool CS5460AComponent::softreset_() {
|
||||
}
|
||||
|
||||
void CS5460AComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CS5460A...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
float current_full_scale = (pga_gain_ == CS5460A_PGA_GAIN_10X) ? 0.25 : 0.10;
|
||||
float voltage_full_scale = 0.25;
|
||||
|
||||
@@ -42,7 +42,7 @@ static const uint8_t CSE7761_CMD_ENABLE_WRITE = 0xE5; // Enable write operation
|
||||
enum CSE7761 { RMS_IAC, RMS_IBC, RMS_UC, POWER_PAC, POWER_PBC, POWER_SC, ENERGY_AC, ENERGY_BC };
|
||||
|
||||
void CSE7761Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CSE7761...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->write_(CSE7761_SPECIAL_COMMAND, CSE7761_CMD_RESET);
|
||||
uint16_t syscon = this->read_(0x00, 2); // Default 0x0A04
|
||||
if ((0x0A04 == syscon) && this->chip_init_()) {
|
||||
@@ -57,7 +57,7 @@ void CSE7761Component::setup() {
|
||||
void CSE7761Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "CSE7761:");
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with CSE7761 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
this->check_uart_settings(38400, 1, uart::UART_CONFIG_PARITY_EVEN, 8);
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace cst226 {
|
||||
static const char *const TAG = "cst226.touchscreen";
|
||||
|
||||
void CST226Touchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CST226 Touchscreen...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->setup();
|
||||
this->reset_pin_->digital_write(true);
|
||||
|
||||
@@ -38,7 +38,7 @@ void CST816Touchscreen::continue_setup_() {
|
||||
}
|
||||
|
||||
void CST816Touchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up CST816 Touchscreen...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (this->reset_pin_ != nullptr) {
|
||||
this->reset_pin_->setup();
|
||||
this->reset_pin_->digital_write(true);
|
||||
|
||||
@@ -20,9 +20,9 @@ static const uint8_t DAC7678_REG_INTERNAL_REF_0 = 0x80;
|
||||
static const uint8_t DAC7678_REG_INTERNAL_REF_1 = 0x90;
|
||||
|
||||
void DAC7678Output::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up DAC7678OutputComponent...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
ESP_LOGV(TAG, "Resetting device...");
|
||||
ESP_LOGV(TAG, "Resetting device");
|
||||
|
||||
// Reset device
|
||||
if (!this->write_byte_16(DAC7678_REG_SOFTWARE_RESET, 0x0000)) {
|
||||
|
||||
@@ -70,7 +70,7 @@ bool DallasTemperatureSensor::read_scratch_pad_() {
|
||||
}
|
||||
|
||||
void DallasTemperatureSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "setting up Dallas temperature sensor...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (!this->check_address_())
|
||||
return;
|
||||
if (!this->read_scratch_pad_())
|
||||
@@ -80,7 +80,7 @@ void DallasTemperatureSensor::setup() {
|
||||
|
||||
if ((this->address_ & 0xff) == DALLAS_MODEL_DS18S20) {
|
||||
// DS18S20 doesn't support resolution.
|
||||
ESP_LOGW(TAG, "DS18S20 doesn't support setting resolution.");
|
||||
ESP_LOGW(TAG, "DS18S20 doesn't support setting resolution");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,6 @@ bool DallasTemperatureSensor::check_scratch_pad_() {
|
||||
crc8(this->scratch_pad_, 8));
|
||||
#endif
|
||||
if (!chksum_validity) {
|
||||
ESP_LOGW(TAG, "'%s' - Scratch pad checksum invalid!", this->get_name().c_str());
|
||||
this->status_set_warning("scratch pad checksum invalid");
|
||||
ESP_LOGD(TAG, "Scratch pad: %02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X (%02X)", this->scratch_pad_[0],
|
||||
this->scratch_pad_[1], this->scratch_pad_[2], this->scratch_pad_[3], this->scratch_pad_[4],
|
||||
|
||||
@@ -15,10 +15,6 @@ namespace debug {
|
||||
static const char *const TAG = "debug";
|
||||
|
||||
void DebugComponent::dump_config() {
|
||||
#ifndef ESPHOME_LOG_HAS_DEBUG
|
||||
return; // Can't log below if debug logging is disabled
|
||||
#endif
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Debug component:");
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
LOG_TEXT_SENSOR(" ", "Device info", this->device_info_);
|
||||
|
||||
@@ -10,20 +10,20 @@ static const char *const TAG = "deep_sleep";
|
||||
bool global_has_deep_sleep = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
void DeepSleepComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Deep Sleep...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
global_has_deep_sleep = true;
|
||||
|
||||
const optional<uint32_t> run_duration = get_run_duration_();
|
||||
if (run_duration.has_value()) {
|
||||
ESP_LOGI(TAG, "Scheduling Deep Sleep to start in %" PRIu32 " ms", *run_duration);
|
||||
ESP_LOGI(TAG, "Scheduling in %" PRIu32 " ms", *run_duration);
|
||||
this->set_timeout(*run_duration, [this]() { this->begin_sleep(); });
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Not scheduling Deep Sleep, as no run duration is configured.");
|
||||
ESP_LOGD(TAG, "Not scheduling; no run duration configured");
|
||||
}
|
||||
}
|
||||
|
||||
void DeepSleepComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Deep Sleep...");
|
||||
ESP_LOGCONFIG(TAG, "Deep sleep:");
|
||||
if (this->sleep_duration_.has_value()) {
|
||||
uint32_t duration = *this->sleep_duration_ / 1000;
|
||||
ESP_LOGCONFIG(TAG, " Sleep Duration: %" PRIu32 " ms", duration);
|
||||
@@ -57,7 +57,7 @@ void DeepSleepComponent::begin_sleep(bool manual) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Beginning Deep Sleep");
|
||||
ESP_LOGI(TAG, "Beginning sleep");
|
||||
if (this->sleep_duration_.has_value()) {
|
||||
ESP_LOGI(TAG, "Sleeping for %" PRId64 "us", *this->sleep_duration_);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ bool DeepSleepComponent::prepare_to_sleep_() {
|
||||
// Defer deep sleep until inactive
|
||||
if (!this->next_enter_deep_sleep_) {
|
||||
this->status_set_warning();
|
||||
ESP_LOGW(TAG, "Waiting wakeup pin state change to enter deep sleep...");
|
||||
ESP_LOGW(TAG, "Waiting for wakeup pin state change");
|
||||
}
|
||||
this->next_enter_deep_sleep_ = true;
|
||||
return false;
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import (
|
||||
alarm_control_panel,
|
||||
binary_sensor,
|
||||
button,
|
||||
climate,
|
||||
cover,
|
||||
datetime,
|
||||
event,
|
||||
fan,
|
||||
light,
|
||||
lock,
|
||||
number,
|
||||
select,
|
||||
sensor,
|
||||
switch,
|
||||
text,
|
||||
text_sensor,
|
||||
valve,
|
||||
)
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
@@ -20,7 +28,9 @@ from esphome.const import (
|
||||
CONF_INVERTED,
|
||||
CONF_MAX_VALUE,
|
||||
CONF_MIN_VALUE,
|
||||
CONF_MODE,
|
||||
CONF_NAME,
|
||||
CONF_OPTIONS,
|
||||
CONF_OUTPUT_ID,
|
||||
CONF_SENSORS,
|
||||
CONF_STATE_CLASS,
|
||||
@@ -31,9 +41,11 @@ from esphome.const import (
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_IDENTIFY,
|
||||
DEVICE_CLASS_MOISTURE,
|
||||
DEVICE_CLASS_MOTION,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_UPDATE,
|
||||
ICON_BLUETOOTH,
|
||||
ICON_BLUR,
|
||||
ICON_THERMOMETER,
|
||||
@@ -45,38 +57,68 @@ from esphome.const import (
|
||||
)
|
||||
|
||||
AUTO_LOAD = [
|
||||
"alarm_control_panel",
|
||||
"binary_sensor",
|
||||
"button",
|
||||
"climate",
|
||||
"cover",
|
||||
"datetime",
|
||||
"event",
|
||||
"fan",
|
||||
"light",
|
||||
"lock",
|
||||
"number",
|
||||
"select",
|
||||
"sensor",
|
||||
"switch",
|
||||
"text",
|
||||
"text_sensor",
|
||||
"valve",
|
||||
]
|
||||
|
||||
demo_ns = cg.esphome_ns.namespace("demo")
|
||||
DemoAlarmControlPanel = demo_ns.class_(
|
||||
"DemoAlarmControlPanel", alarm_control_panel.AlarmControlPanel, cg.Component
|
||||
)
|
||||
DemoAlarmControlPanelType = demo_ns.enum("DemoAlarmControlPanelType", is_class=True)
|
||||
DemoBinarySensor = demo_ns.class_(
|
||||
"DemoBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent
|
||||
)
|
||||
DemoButton = demo_ns.class_("DemoButton", button.Button)
|
||||
DemoClimate = demo_ns.class_("DemoClimate", climate.Climate, cg.Component)
|
||||
DemoClimateType = demo_ns.enum("DemoClimateType", is_class=True)
|
||||
DemoCover = demo_ns.class_("DemoCover", cover.Cover, cg.Component)
|
||||
DemoCoverType = demo_ns.enum("DemoCoverType", is_class=True)
|
||||
DemoDate = demo_ns.class_("DemoDate", datetime.DateEntity, cg.Component)
|
||||
DemoDateTime = demo_ns.class_("DemoDateTime", datetime.DateTimeEntity, cg.Component)
|
||||
DemoTime = demo_ns.class_("DemoTime", datetime.TimeEntity, cg.Component)
|
||||
DemoEvent = demo_ns.class_("DemoEvent", event.Event, cg.Component)
|
||||
DemoFan = demo_ns.class_("DemoFan", fan.Fan, cg.Component)
|
||||
DemoFanType = demo_ns.enum("DemoFanType", is_class=True)
|
||||
DemoLight = demo_ns.class_("DemoLight", light.LightOutput, cg.Component)
|
||||
DemoLightType = demo_ns.enum("DemoLightType", is_class=True)
|
||||
DemoLock = demo_ns.class_("DemoLock", lock.Lock, cg.Component)
|
||||
DemoLockType = demo_ns.enum("DemoLockType", is_class=True)
|
||||
DemoNumber = demo_ns.class_("DemoNumber", number.Number, cg.Component)
|
||||
DemoNumberType = demo_ns.enum("DemoNumberType", is_class=True)
|
||||
DemoSelect = demo_ns.class_("DemoSelect", select.Select, cg.Component)
|
||||
DemoSelectType = demo_ns.enum("DemoSelectType", is_class=True)
|
||||
DemoSensor = demo_ns.class_("DemoSensor", sensor.Sensor, cg.PollingComponent)
|
||||
DemoSwitch = demo_ns.class_("DemoSwitch", switch.Switch, cg.Component)
|
||||
DemoText = demo_ns.class_("DemoText", text.Text, cg.Component)
|
||||
DemoTextType = demo_ns.enum("DemoTextType", is_class=True)
|
||||
DemoTextSensor = demo_ns.class_(
|
||||
"DemoTextSensor", text_sensor.TextSensor, cg.PollingComponent
|
||||
)
|
||||
DemoValve = demo_ns.class_("DemoValve", valve.Valve)
|
||||
DemoValveType = demo_ns.enum("DemoValveType", is_class=True)
|
||||
|
||||
|
||||
ALARM_CONTROL_PANEL_TYPES = {
|
||||
1: DemoAlarmControlPanelType.TYPE_1,
|
||||
2: DemoAlarmControlPanelType.TYPE_2,
|
||||
3: DemoAlarmControlPanelType.TYPE_3,
|
||||
}
|
||||
CLIMATE_TYPES = {
|
||||
1: DemoClimateType.TYPE_1,
|
||||
2: DemoClimateType.TYPE_2,
|
||||
@@ -103,21 +145,67 @@ LIGHT_TYPES = {
|
||||
6: DemoLightType.TYPE_6,
|
||||
7: DemoLightType.TYPE_7,
|
||||
}
|
||||
LOCK_TYPES = {
|
||||
1: DemoLockType.TYPE_1,
|
||||
2: DemoLockType.TYPE_2,
|
||||
}
|
||||
NUMBER_TYPES = {
|
||||
1: DemoNumberType.TYPE_1,
|
||||
2: DemoNumberType.TYPE_2,
|
||||
3: DemoNumberType.TYPE_3,
|
||||
}
|
||||
TEXT_TYPES = {
|
||||
1: DemoTextType.TYPE_1,
|
||||
2: DemoTextType.TYPE_2,
|
||||
}
|
||||
VALVE_TYPES = {
|
||||
1: DemoValveType.TYPE_1,
|
||||
2: DemoValveType.TYPE_2,
|
||||
}
|
||||
|
||||
|
||||
CONF_ALARM_CONTROL_PANELS = "alarm_control_panels"
|
||||
CONF_BUTTONS = "buttons"
|
||||
CONF_CLIMATES = "climates"
|
||||
CONF_COVERS = "covers"
|
||||
CONF_DATETIMES = "datetimes"
|
||||
CONF_FANS = "fans"
|
||||
CONF_LIGHTS = "lights"
|
||||
CONF_LOCKS = "locks"
|
||||
CONF_NUMBERS = "numbers"
|
||||
CONF_SELECTS = "selects"
|
||||
CONF_TEXTS = "texts"
|
||||
CONF_VALVES = "valves"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.Optional(
|
||||
CONF_ALARM_CONTROL_PANELS,
|
||||
default=[
|
||||
{
|
||||
CONF_NAME: "Demo Alarm Control Panel",
|
||||
CONF_TYPE: 1,
|
||||
},
|
||||
{
|
||||
CONF_NAME: "Demo Alarm Control Panel Code",
|
||||
CONF_TYPE: 2,
|
||||
},
|
||||
{
|
||||
CONF_NAME: "Demo Alarm Control Panel Code to Arm",
|
||||
CONF_TYPE: 3,
|
||||
},
|
||||
],
|
||||
): [
|
||||
alarm_control_panel.alarm_control_panel_schema(
|
||||
DemoAlarmControlPanel
|
||||
).extend(
|
||||
{
|
||||
cv.Required(CONF_TYPE): cv.enum(
|
||||
ALARM_CONTROL_PANEL_TYPES, int=True
|
||||
),
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_BINARY_SENSORS,
|
||||
default=[
|
||||
@@ -135,6 +223,21 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.polling_component_schema("60s")
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_BUTTONS,
|
||||
default=[
|
||||
{
|
||||
CONF_NAME: "Demo Update Button",
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_UPDATE,
|
||||
},
|
||||
{
|
||||
CONF_NAME: "Demo Button Identify",
|
||||
CONF_DEVICE_CLASS: DEVICE_CLASS_IDENTIFY,
|
||||
},
|
||||
],
|
||||
): [
|
||||
button.button_schema(DemoButton),
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_CLIMATES,
|
||||
default=[
|
||||
@@ -191,6 +294,20 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_DATETIMES,
|
||||
default=[
|
||||
{CONF_NAME: "Demo DateTime", CONF_TYPE: "DATETIME"},
|
||||
{CONF_NAME: "Demo Date", CONF_TYPE: "DATE"},
|
||||
{CONF_NAME: "Demo Time", CONF_TYPE: "TIME"},
|
||||
],
|
||||
): [
|
||||
cv.Any(
|
||||
datetime.date_schema(DemoDate),
|
||||
datetime.datetime_schema(DemoDateTime),
|
||||
datetime.time_schema(DemoTime),
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_FANS,
|
||||
default=[
|
||||
@@ -262,6 +379,19 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_LOCKS,
|
||||
default=[
|
||||
{CONF_NAME: "Demo Lock", CONF_TYPE: 1},
|
||||
{CONF_NAME: "Demo Lock and Open", CONF_TYPE: 2},
|
||||
],
|
||||
): [
|
||||
lock.lock_schema(DemoLock).extend(
|
||||
{
|
||||
cv.Required(CONF_TYPE): cv.enum(LOCK_TYPES, int=True),
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_NUMBERS,
|
||||
default=[
|
||||
@@ -299,6 +429,25 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_SELECTS,
|
||||
default=[
|
||||
{
|
||||
CONF_NAME: "Demo Select 1",
|
||||
CONF_OPTIONS: ["Option 1", "Option 2", "Option 3"],
|
||||
},
|
||||
{
|
||||
CONF_NAME: "Demo Select 2",
|
||||
CONF_OPTIONS: ["Option A", "Option B", "Option C"],
|
||||
},
|
||||
],
|
||||
): [
|
||||
select.select_schema(DemoSelect).extend(
|
||||
{
|
||||
cv.Required(CONF_OPTIONS): cv.ensure_list(cv.string_strict),
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_SENSORS,
|
||||
default=[
|
||||
@@ -355,6 +504,19 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
},
|
||||
],
|
||||
): [switch.switch_schema(DemoSwitch).extend(cv.COMPONENT_SCHEMA)],
|
||||
cv.Optional(
|
||||
CONF_TEXTS,
|
||||
default=[
|
||||
{CONF_NAME: "Demo Text 1", CONF_MODE: "TEXT", CONF_TYPE: 1},
|
||||
{CONF_NAME: "Demo Text 2", CONF_MODE: "PASSWORD", CONF_TYPE: 2},
|
||||
],
|
||||
): [
|
||||
text.text_schema(DemoText).extend(
|
||||
{
|
||||
cv.Required(CONF_TYPE): cv.enum(TEXT_TYPES, int=True),
|
||||
}
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_TEXT_SENSORS,
|
||||
default=[
|
||||
@@ -371,15 +533,36 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
cv.polling_component_schema("60s")
|
||||
)
|
||||
],
|
||||
cv.Optional(
|
||||
CONF_VALVES,
|
||||
default=[
|
||||
{CONF_NAME: "Demo Valve 1", CONF_TYPE: 1},
|
||||
{CONF_NAME: "Demo Valve 2", CONF_TYPE: 2},
|
||||
],
|
||||
): [
|
||||
valve.valve_schema(DemoValve).extend(
|
||||
{
|
||||
cv.Required(CONF_TYPE): cv.enum(VALVE_TYPES, int=True),
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
for conf in config[CONF_ALARM_CONTROL_PANELS]:
|
||||
var = await alarm_control_panel.new_alarm_control_panel(conf)
|
||||
cg.add(var.set_type(conf[CONF_TYPE]))
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_BINARY_SENSORS]:
|
||||
var = await binary_sensor.new_binary_sensor(conf)
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_BUTTONS]:
|
||||
await button.new_button(conf)
|
||||
|
||||
for conf in config[CONF_CLIMATES]:
|
||||
var = await climate.new_climate(conf)
|
||||
await cg.register_component(var, conf)
|
||||
@@ -390,6 +573,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, conf)
|
||||
cg.add(var.set_type(conf[CONF_TYPE]))
|
||||
|
||||
for conf in config[CONF_DATETIMES]:
|
||||
var = await datetime.new_datetime(conf)
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_FANS]:
|
||||
var = await fan.new_fan(conf)
|
||||
await cg.register_component(var, conf)
|
||||
@@ -400,6 +587,11 @@ async def to_code(config):
|
||||
await cg.register_component(var, conf)
|
||||
cg.add(var.set_type(conf[CONF_TYPE]))
|
||||
|
||||
for conf in config[CONF_LOCKS]:
|
||||
var = await lock.new_lock(conf)
|
||||
if conf[CONF_TYPE] == 2:
|
||||
cg.add(var.traits.set_supports_open(True))
|
||||
|
||||
for conf in config[CONF_NUMBERS]:
|
||||
var = await number.new_number(
|
||||
conf,
|
||||
@@ -410,6 +602,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, conf)
|
||||
cg.add(var.set_type(conf[CONF_TYPE]))
|
||||
|
||||
for conf in config[CONF_SELECTS]:
|
||||
var = await select.new_select(conf, options=conf[CONF_OPTIONS])
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_SENSORS]:
|
||||
var = await sensor.new_sensor(conf)
|
||||
await cg.register_component(var, conf)
|
||||
@@ -418,6 +614,16 @@ async def to_code(config):
|
||||
var = await switch.new_switch(conf)
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_TEXTS]:
|
||||
var = await text.new_text(conf)
|
||||
await cg.register_component(var, conf)
|
||||
if conf[CONF_TYPE] == 2:
|
||||
cg.add(var.traits.set_mode(text.TextMode.TEXT_MODE_PASSWORD))
|
||||
|
||||
for conf in config[CONF_TEXT_SENSORS]:
|
||||
var = await text_sensor.new_text_sensor(conf)
|
||||
await cg.register_component(var, conf)
|
||||
|
||||
for conf in config[CONF_VALVES]:
|
||||
var = await valve.new_valve(conf)
|
||||
cg.add(var.set_type(conf[CONF_TYPE]))
|
||||
|
||||
65
esphome/components/demo/demo_alarm_control_panel.h
Normal file
65
esphome/components/demo/demo_alarm_control_panel.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/alarm_control_panel/alarm_control_panel.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
using namespace alarm_control_panel;
|
||||
|
||||
enum class DemoAlarmControlPanelType {
|
||||
TYPE_1,
|
||||
TYPE_2,
|
||||
TYPE_3,
|
||||
};
|
||||
|
||||
class DemoAlarmControlPanel : public AlarmControlPanel, public Component {
|
||||
public:
|
||||
void setup() override {}
|
||||
|
||||
uint32_t get_supported_features() const override { return ACP_FEAT_ARM_AWAY | ACP_FEAT_TRIGGER; }
|
||||
|
||||
bool get_requires_code() const override { return this->type_ != DemoAlarmControlPanelType::TYPE_1; }
|
||||
|
||||
bool get_requires_code_to_arm() const override { return this->type_ == DemoAlarmControlPanelType::TYPE_3; }
|
||||
|
||||
void set_type(DemoAlarmControlPanelType type) { this->type_ = type; }
|
||||
|
||||
protected:
|
||||
void control(const AlarmControlPanelCall &call) override {
|
||||
auto state = call.get_state().value_or(ACP_STATE_DISARMED);
|
||||
switch (state) {
|
||||
case ACP_STATE_ARMED_AWAY:
|
||||
if (this->get_requires_code_to_arm() && call.get_code().has_value()) {
|
||||
if (call.get_code().value() != "1234") {
|
||||
this->status_momentary_error("Invalid code", 5000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->publish_state(ACP_STATE_ARMED_AWAY);
|
||||
break;
|
||||
case ACP_STATE_DISARMED:
|
||||
if (this->get_requires_code() && call.get_code().has_value()) {
|
||||
if (call.get_code().value() != "1234") {
|
||||
this->status_momentary_error("Invalid code", 5000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->publish_state(ACP_STATE_DISARMED);
|
||||
return;
|
||||
case ACP_STATE_TRIGGERED:
|
||||
this->publish_state(ACP_STATE_TRIGGERED);
|
||||
return;
|
||||
case ACP_STATE_PENDING:
|
||||
this->publish_state(ACP_STATE_PENDING);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
DemoAlarmControlPanelType type_{};
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
15
esphome/components/demo/demo_button.h
Normal file
15
esphome/components/demo/demo_button.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/button/button.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoButton : public button::Button {
|
||||
protected:
|
||||
void press_action() override {}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
34
esphome/components/demo/demo_date.h
Normal file
34
esphome/components/demo/demo_date.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_DATETIME_DATE
|
||||
|
||||
#include "esphome/components/datetime/date_entity.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoDate : public datetime::DateEntity, public Component {
|
||||
public:
|
||||
void setup() override {
|
||||
this->year_ = 2038;
|
||||
this->month_ = 01;
|
||||
this->day_ = 19;
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
protected:
|
||||
void control(const datetime::DateCall &call) override {
|
||||
this->year_ = call.get_year().value_or(this->year_);
|
||||
this->month_ = call.get_month().value_or(this->month_);
|
||||
this->day_ = call.get_day().value_or(this->day_);
|
||||
this->publish_state();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
40
esphome/components/demo/demo_datetime.h
Normal file
40
esphome/components/demo/demo_datetime.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_DATETIME_DATETIME
|
||||
|
||||
#include "esphome/components/datetime/datetime_entity.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoDateTime : public datetime::DateTimeEntity, public Component {
|
||||
public:
|
||||
void setup() override {
|
||||
this->year_ = 2038;
|
||||
this->month_ = 01;
|
||||
this->day_ = 19;
|
||||
this->hour_ = 3;
|
||||
this->minute_ = 14;
|
||||
this->second_ = 8;
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
protected:
|
||||
void control(const datetime::DateTimeCall &call) override {
|
||||
this->year_ = call.get_year().value_or(this->year_);
|
||||
this->month_ = call.get_month().value_or(this->month_);
|
||||
this->day_ = call.get_day().value_or(this->day_);
|
||||
this->hour_ = call.get_hour().value_or(this->hour_);
|
||||
this->minute_ = call.get_minute().value_or(this->minute_);
|
||||
this->second_ = call.get_second().value_or(this->second_);
|
||||
this->publish_state();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
17
esphome/components/demo/demo_lock.h
Normal file
17
esphome/components/demo/demo_lock.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/lock/lock.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoLock : public lock::Lock {
|
||||
protected:
|
||||
void control(const lock::LockCall &call) override {
|
||||
auto state = *call.get_state();
|
||||
this->publish_state(state);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
15
esphome/components/demo/demo_select.h
Normal file
15
esphome/components/demo/demo_select.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/select/select.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoSelect : public select::Select, public Component {
|
||||
protected:
|
||||
void control(const std::string &value) override { this->publish_state(value); }
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
18
esphome/components/demo/demo_text.h
Normal file
18
esphome/components/demo/demo_text.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/text/text.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoText : public text::Text, public Component {
|
||||
public:
|
||||
void setup() override { this->publish_state("I am a text entity"); }
|
||||
|
||||
protected:
|
||||
void control(const std::string &value) override { this->publish_state(value); }
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
34
esphome/components/demo/demo_time.h
Normal file
34
esphome/components/demo/demo_time.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
#ifdef USE_DATETIME_TIME
|
||||
|
||||
#include "esphome/components/datetime/time_entity.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
class DemoTime : public datetime::TimeEntity, public Component {
|
||||
public:
|
||||
void setup() override {
|
||||
this->hour_ = 3;
|
||||
this->minute_ = 14;
|
||||
this->second_ = 8;
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
protected:
|
||||
void control(const datetime::TimeCall &call) override {
|
||||
this->hour_ = call.get_hour().value_or(this->hour_);
|
||||
this->minute_ = call.get_minute().value_or(this->minute_);
|
||||
this->second_ = call.get_second().value_or(this->second_);
|
||||
this->publish_state();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
|
||||
#endif
|
||||
54
esphome/components/demo/demo_valve.h
Normal file
54
esphome/components/demo/demo_valve.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/valve/valve.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace demo {
|
||||
|
||||
enum class DemoValveType {
|
||||
TYPE_1,
|
||||
TYPE_2,
|
||||
};
|
||||
|
||||
class DemoValve : public valve::Valve {
|
||||
public:
|
||||
valve::ValveTraits get_traits() override {
|
||||
valve::ValveTraits traits;
|
||||
if (this->type_ == DemoValveType::TYPE_2) {
|
||||
traits.set_supports_position(true);
|
||||
traits.set_supports_toggle(true);
|
||||
traits.set_supports_stop(true);
|
||||
}
|
||||
return traits;
|
||||
}
|
||||
|
||||
void set_type(DemoValveType type) { this->type_ = type; }
|
||||
|
||||
protected:
|
||||
void control(const valve::ValveCall &call) override {
|
||||
if (call.get_position().has_value()) {
|
||||
this->position = *call.get_position();
|
||||
this->publish_state();
|
||||
return;
|
||||
} else if (call.get_toggle().has_value()) {
|
||||
if (call.get_toggle().value()) {
|
||||
if (this->position == valve::VALVE_OPEN) {
|
||||
this->position = valve::VALVE_CLOSED;
|
||||
this->publish_state();
|
||||
} else {
|
||||
this->position = valve::VALVE_OPEN;
|
||||
this->publish_state();
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (call.get_stop()) {
|
||||
this->current_operation = valve::VALVE_OPERATION_IDLE;
|
||||
this->publish_state(); // Keep the current position
|
||||
return;
|
||||
}
|
||||
}
|
||||
DemoValveType type_{};
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
} // namespace esphome
|
||||
@@ -21,7 +21,7 @@ uint8_t Command::execute(DfrobotSen0395Component *parent) {
|
||||
if (this->retries_left_ > 0) {
|
||||
this->retries_left_ -= 1;
|
||||
this->cmd_sent_ = false;
|
||||
ESP_LOGD(TAG, "Retrying...");
|
||||
ESP_LOGD(TAG, "Retrying");
|
||||
return 0;
|
||||
} else {
|
||||
this->parent_->find_prompt_();
|
||||
@@ -33,7 +33,7 @@ uint8_t Command::execute(DfrobotSen0395Component *parent) {
|
||||
if (this->retries_left_ > 0) {
|
||||
this->retries_left_ -= 1;
|
||||
this->cmd_sent_ = false;
|
||||
ESP_LOGD(TAG, "Retrying...");
|
||||
ESP_LOGD(TAG, "Retrying");
|
||||
return 0;
|
||||
} else {
|
||||
this->parent_->find_prompt_();
|
||||
@@ -51,7 +51,7 @@ uint8_t Command::execute(DfrobotSen0395Component *parent) {
|
||||
if (this->retries_left_ > 0) {
|
||||
this->retries_left_ -= 1;
|
||||
this->cmd_sent_ = false;
|
||||
ESP_LOGD(TAG, "Retrying...");
|
||||
ESP_LOGD(TAG, "Retrying");
|
||||
} else {
|
||||
return 1; // Command done
|
||||
}
|
||||
|
||||
@@ -8,25 +8,19 @@ namespace dht {
|
||||
static const char *const TAG = "dht";
|
||||
|
||||
void DHT::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up DHT...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->pin_->digital_write(true);
|
||||
this->pin_->setup();
|
||||
this->pin_->digital_write(true);
|
||||
}
|
||||
|
||||
void DHT::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "DHT:");
|
||||
LOG_PIN(" Pin: ", this->pin_);
|
||||
if (this->is_auto_detect_) {
|
||||
ESP_LOGCONFIG(TAG, " Auto-detected model: %s", this->model_ == DHT_MODEL_DHT11 ? "DHT11" : "DHT22");
|
||||
} else if (this->model_ == DHT_MODEL_DHT11) {
|
||||
ESP_LOGCONFIG(TAG, " Model: DHT11");
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Model: DHT22 (or equivalent)");
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Internal Pull-up: %s", ONOFF(this->pin_->get_flags() & gpio::FLAG_PULLUP));
|
||||
|
||||
ESP_LOGCONFIG(TAG, " %sModel: %s", this->is_auto_detect_ ? "Auto-detected " : "",
|
||||
this->model_ == DHT_MODEL_DHT11 ? "DHT11" : "DHT22 or equivalent");
|
||||
ESP_LOGCONFIG(TAG, " Internal pull-up: %s", ONOFF(this->pin_->get_flags() & gpio::FLAG_PULLUP));
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
}
|
||||
@@ -46,7 +40,7 @@ void DHT::update() {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
ESP_LOGD(TAG, "Got Temperature=%.1f°C Humidity=%.1f%%", temperature, humidity);
|
||||
ESP_LOGD(TAG, "Temperature %.1f°C Humidity %.1f%%", temperature, humidity);
|
||||
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(temperature);
|
||||
@@ -54,11 +48,8 @@ void DHT::update() {
|
||||
this->humidity_sensor_->publish_state(humidity);
|
||||
this->status_clear_warning();
|
||||
} else {
|
||||
const char *str = "";
|
||||
if (this->is_auto_detect_) {
|
||||
str = " and consider manually specifying the DHT model using the model option";
|
||||
}
|
||||
ESP_LOGW(TAG, "Invalid readings! Please check your wiring (pull-up resistor, pin number)%s.", str);
|
||||
ESP_LOGW(TAG, "Invalid readings! Check pin number and pull-up resistor%s.",
|
||||
this->is_auto_detect_ ? " and try manually specifying the model" : "");
|
||||
if (this->temperature_sensor_ != nullptr)
|
||||
this->temperature_sensor_->publish_state(NAN);
|
||||
if (this->humidity_sensor_ != nullptr)
|
||||
@@ -68,10 +59,12 @@ void DHT::update() {
|
||||
}
|
||||
|
||||
float DHT::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
void DHT::set_dht_model(DHTModel model) {
|
||||
this->model_ = model;
|
||||
this->is_auto_detect_ = model == DHT_MODEL_AUTO_DETECT;
|
||||
}
|
||||
|
||||
bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool report_errors) {
|
||||
*humidity = NAN;
|
||||
*temperature = NAN;
|
||||
@@ -121,9 +114,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
while (!this->pin_->digital_read()) {
|
||||
if (micros() - start_time > 90) {
|
||||
if (i < 0) {
|
||||
error_code = 1;
|
||||
error_code = 1; // line didn't clear
|
||||
} else {
|
||||
error_code = 2;
|
||||
error_code = 2; // rising edge for bit i timeout
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -139,9 +132,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
end_time = micros();
|
||||
if (end_time - start_time > 90) {
|
||||
if (i < 0) {
|
||||
error_code = 3;
|
||||
error_code = 3; // requesting data failed
|
||||
} else {
|
||||
error_code = 4;
|
||||
error_code = 4; // falling edge for bit i timeout
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -166,22 +159,9 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
if (!report_errors && error_code != 0)
|
||||
return false;
|
||||
|
||||
switch (error_code) {
|
||||
case 1:
|
||||
ESP_LOGW(TAG, "Waiting for DHT communication to clear failed!");
|
||||
return false;
|
||||
case 2:
|
||||
ESP_LOGW(TAG, "Rising edge for bit %d failed!", i);
|
||||
return false;
|
||||
case 3:
|
||||
ESP_LOGW(TAG, "Requesting data from DHT failed!");
|
||||
return false;
|
||||
case 4:
|
||||
ESP_LOGW(TAG, "Falling edge for bit %d failed!", i);
|
||||
return false;
|
||||
case 0:
|
||||
default:
|
||||
break;
|
||||
if (error_code) {
|
||||
ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGVV(TAG,
|
||||
@@ -206,15 +186,15 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
if (checksum_a == data[4]) {
|
||||
// Data format: 8bit integral RH data + 8bit decimal RH data + 8bit integral T data + 8bit decimal T data + 8bit
|
||||
// check sum - some models always have 0 in the decimal part
|
||||
const uint16_t raw_temperature = uint16_t(data[2]) * 10 + (data[3] & 0x7F);
|
||||
*temperature = raw_temperature / 10.0f;
|
||||
const uint16_t raw_temperature = static_cast<uint16_t>(data[2]) * 10 + (data[3] & 0x7F);
|
||||
*temperature = static_cast<float>(raw_temperature) / 10.0f;
|
||||
if ((data[3] & 0x80) != 0) {
|
||||
// negative
|
||||
*temperature *= -1;
|
||||
}
|
||||
|
||||
const uint16_t raw_humidity = uint16_t(data[0]) * 10 + data[1];
|
||||
*humidity = raw_humidity / 10.0f;
|
||||
const uint16_t raw_humidity = static_cast<uint16_t>(data[0]) * 10 + data[1];
|
||||
*humidity = static_cast<float>(raw_humidity) / 10.0f;
|
||||
} else {
|
||||
// For compatibility with DHT11 models which might only use 2 bytes checksums, only use the data from these two
|
||||
// bytes
|
||||
@@ -222,8 +202,8 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
*humidity = data[0];
|
||||
}
|
||||
} else {
|
||||
uint16_t raw_humidity = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
|
||||
uint16_t raw_temperature = (uint16_t(data[2] & 0xFF) << 8) | (data[3] & 0xFF);
|
||||
uint16_t raw_humidity = encode_uint16(data[0], data[1]);
|
||||
uint16_t raw_temperature = encode_uint16(data[2], data[3]);
|
||||
|
||||
if (raw_temperature & 0x8000) {
|
||||
if (!(raw_temperature & 0x4000))
|
||||
@@ -234,24 +214,23 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r
|
||||
|
||||
if (raw_temperature == 1 && raw_humidity == 10) {
|
||||
if (report_errors) {
|
||||
ESP_LOGW(TAG, "Invalid temperature+humidity! Sensor reported 1°C and 1%% Hum");
|
||||
ESP_LOGW(TAG, "Invalid data");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
*humidity = raw_humidity * 0.1f;
|
||||
if (*humidity > 100)
|
||||
*humidity = static_cast<float>(raw_humidity) * 0.1f;
|
||||
if (*humidity > 100.0f)
|
||||
*humidity = NAN;
|
||||
*temperature = int16_t(raw_temperature) * 0.1f;
|
||||
*temperature = static_cast<int16_t>(raw_temperature) * 0.1f;
|
||||
}
|
||||
|
||||
if (*temperature == 0.0f && (*humidity == 1.0f || *humidity == 2.0f)) {
|
||||
if (report_errors) {
|
||||
ESP_LOGW(TAG, "DHT reports invalid data. Is the update interval too high or the sensor damaged?");
|
||||
ESP_LOGW(TAG, "Invalid data");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ void DHT12Component::update() {
|
||||
this->status_clear_warning();
|
||||
}
|
||||
void DHT12Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up DHT12...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t data[5];
|
||||
if (!this->read_data_(data)) {
|
||||
this->mark_failed();
|
||||
@@ -45,7 +45,7 @@ void DHT12Component::dump_config() {
|
||||
ESP_LOGD(TAG, "DHT12:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with DHT12 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
LOG_SENSOR(" ", "Humidity", this->humidity_sensor_);
|
||||
|
||||
@@ -12,7 +12,7 @@ void DPS310Component::setup() {
|
||||
auto timer = DPS310_INIT_TIMEOUT;
|
||||
uint8_t reg = 0;
|
||||
|
||||
ESP_LOGCONFIG(TAG, "Setting up DPS310...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
// first, reset the sensor
|
||||
if (!this->write_byte(DPS310_REG_RESET, DPS310_CMD_RESET)) {
|
||||
this->mark_failed();
|
||||
@@ -91,7 +91,7 @@ void DPS310Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Revision ID: %u", (this->prod_rev_id_ >> 4) & 0x0F);
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with DPS310 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
LOG_SENSOR(" ", "Temperature", this->temperature_sensor_);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ds1307 {
|
||||
static const char *const TAG = "ds1307";
|
||||
|
||||
void DS1307Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up DS1307...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
if (!this->read_rtc_()) {
|
||||
this->mark_failed();
|
||||
}
|
||||
@@ -22,7 +22,7 @@ void DS1307Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "DS1307:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with DS1307 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace duty_cycle {
|
||||
static const char *const TAG = "duty_cycle";
|
||||
|
||||
void DutyCycleSensor::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Duty Cycle Sensor '%s'...", this->get_name().c_str());
|
||||
ESP_LOGCONFIG(TAG, "Running setup for '%s'", this->get_name().c_str());
|
||||
this->pin_->setup();
|
||||
this->store_.pin = this->pin_->to_isr();
|
||||
this->store_.last_level = this->pin_->digital_read();
|
||||
|
||||
@@ -16,7 +16,7 @@ static const uint16_t PRESSURE_ADDRESS = 0x04B0;
|
||||
|
||||
void EE895Component::setup() {
|
||||
uint16_t crc16_check = 0;
|
||||
ESP_LOGCONFIG(TAG, "Setting up EE895...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
write_command_(SERIAL_NUMBER, 8);
|
||||
uint8_t serial_number[20];
|
||||
this->read(serial_number, 20);
|
||||
@@ -35,7 +35,7 @@ void EE895Component::dump_config() {
|
||||
LOG_I2C_DEVICE(this);
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication with EE895 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case CRC_CHECK_FAILED:
|
||||
ESP_LOGE(TAG, "The crc check failed");
|
||||
|
||||
@@ -16,7 +16,7 @@ static const uint8_t GET_Y_RES[4] = {0x53, 0x63, 0x00, 0x00};
|
||||
static const uint8_t GET_POWER_STATE_CMD[4] = {0x53, 0x50, 0x00, 0x01};
|
||||
|
||||
void EKTF2232Touchscreen::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up EKT2232 Touchscreen...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP);
|
||||
this->interrupt_pin_->setup();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ static const uint8_t EMC2101_POLARITY_BIT = 1 << 4;
|
||||
float Emc2101Component::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
|
||||
void Emc2101Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up Emc2101 sensor...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// make sure we're talking to the right chip
|
||||
uint8_t chip_id = reg(EMC2101_REGISTER_WHOAMI).get();
|
||||
@@ -94,7 +94,7 @@ void Emc2101Component::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Emc2101 component:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Mode: %s", this->dac_mode_ ? "DAC" : "PWM");
|
||||
if (this->dac_mode_) {
|
||||
@@ -110,7 +110,7 @@ void Emc2101Component::set_duty_cycle(float value) {
|
||||
uint8_t duty_cycle = remap(value, 0.0f, 1.0f, (uint8_t) 0, this->max_output_value_);
|
||||
ESP_LOGD(TAG, "Setting duty fan setting to %02X", duty_cycle);
|
||||
if (!this->write_byte(EMC2101_REGISTER_FAN_SETTING, duty_cycle)) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ void Emc2101Component::set_duty_cycle(float value) {
|
||||
float Emc2101Component::get_duty_cycle() {
|
||||
uint8_t duty_cycle;
|
||||
if (!this->read_byte(EMC2101_REGISTER_FAN_SETTING, &duty_cycle)) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return NAN;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ float Emc2101Component::get_duty_cycle() {
|
||||
float Emc2101Component::get_internal_temperature() {
|
||||
uint8_t temperature;
|
||||
if (!this->read_byte(EMC2101_REGISTER_INTERNAL_TEMP, &temperature)) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return NAN;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ float Emc2101Component::get_external_temperature() {
|
||||
uint8_t lsb, msb;
|
||||
if (!this->read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_MSB, &msb) ||
|
||||
!this->read_byte(EMC2101_REGISTER_EXTERNAL_TEMP_LSB, &lsb)) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return NAN;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ float Emc2101Component::get_speed() {
|
||||
// Read **LSB** first to match 'Data Read Interlock' behavior from 6.1 of datasheet
|
||||
uint8_t lsb, msb;
|
||||
if (!this->read_byte(EMC2101_REGISTER_TACH_LSB, &lsb) || !this->read_byte(EMC2101_REGISTER_TACH_MSB, &msb)) {
|
||||
ESP_LOGE(TAG, "Communication with EMC2101 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return NAN;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ static const uint8_t ENS160_DATA_STATUS_NEWGPR = 0x01;
|
||||
static const uint8_t ENS160_DATA_AQI = 0x07;
|
||||
|
||||
void ENS160Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ENS160...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// check part_id
|
||||
uint16_t part_id;
|
||||
@@ -279,7 +279,7 @@ void ENS160Component::dump_config() {
|
||||
|
||||
switch (this->error_code_) {
|
||||
case COMMUNICATION_FAILED:
|
||||
ESP_LOGE(TAG, "Communication failed! Is the sensor connected?");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
break;
|
||||
case READ_FAILED:
|
||||
ESP_LOGE(TAG, "Error reading from register");
|
||||
|
||||
@@ -87,7 +87,7 @@ static uint32_t crc7(uint32_t value) {
|
||||
}
|
||||
|
||||
void ENS210Component::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ENS210...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
uint8_t data[2];
|
||||
uint16_t part_id = 0;
|
||||
// Reset
|
||||
@@ -163,7 +163,7 @@ void ENS210Component::update() {
|
||||
|
||||
// Read T_VAL and H_VAL
|
||||
if (!this->read_bytes(ENS210_REGISTER_T_VAL, data, 6)) {
|
||||
ESP_LOGE(TAG, "Communication with ENS210 failed!");
|
||||
ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
|
||||
this->status_set_warning();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ void ES7210::dump_config() {
|
||||
}
|
||||
|
||||
void ES7210::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ES7210...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// Software reset
|
||||
ES7210_ERROR_FAILED(this->write_byte(ES7210_RESET_REG00, 0xff));
|
||||
|
||||
@@ -34,7 +34,7 @@ void ES7243E::dump_config() {
|
||||
}
|
||||
|
||||
void ES7243E::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ES7243E...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
ES7243E_ERROR_FAILED(this->write_byte(ES7243E_CLOCK_MGR_REG01, 0x3A));
|
||||
ES7243E_ERROR_FAILED(this->write_byte(ES7243E_RESET_REG00, 0x80));
|
||||
|
||||
@@ -17,7 +17,7 @@ static const char *const TAG = "es8156";
|
||||
}
|
||||
|
||||
void ES8156::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ES8156...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
ES8156_ERROR_FAILED(this->write_byte(ES8156_REG02_SCLK_MODE, 0x04));
|
||||
ES8156_ERROR_FAILED(this->write_byte(ES8156_REG20_ANALOG_SYS1, 0x2A));
|
||||
|
||||
@@ -22,7 +22,7 @@ static const char *const TAG = "es8311";
|
||||
}
|
||||
|
||||
void ES8311::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ES8311...");
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// Reset
|
||||
ES8311_ERROR_FAILED(this->write_byte(ES8311_REG00_RESET, 0x1F));
|
||||
|
||||
0
esphome/components/es8388/__init__.py
Normal file
0
esphome/components/es8388/__init__.py
Normal file
26
esphome/components/es8388/audio_dac.py
Normal file
26
esphome/components/es8388/audio_dac.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import i2c
|
||||
from esphome.components.audio_dac import AudioDac
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
CODEOWNERS = ["@P4uLT"]
|
||||
CONF_ES8388_ID = "es8388_id"
|
||||
|
||||
es8388_ns = cg.esphome_ns.namespace("es8388")
|
||||
|
||||
ES8388 = es8388_ns.class_("ES8388", AudioDac, cg.Component, i2c.I2CDevice)
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema({cv.GenerateID(): cv.declare_id(ES8388)})
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(i2c.i2c_device_schema(0x10))
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
289
esphome/components/es8388/es8388.cpp
Normal file
289
esphome/components/es8388/es8388.cpp
Normal file
@@ -0,0 +1,289 @@
|
||||
#include "es8388.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace es8388 {
|
||||
|
||||
static const char *const TAG = "es8388";
|
||||
|
||||
// Mark the component as failed; use only in setup
|
||||
#define ES8388_ERROR_FAILED(func) \
|
||||
if (!(func)) { \
|
||||
this->mark_failed(); \
|
||||
return; \
|
||||
}
|
||||
|
||||
// Return false; use outside of setup
|
||||
#define ES8388_ERROR_CHECK(func) \
|
||||
if (!(func)) { \
|
||||
return false; \
|
||||
}
|
||||
|
||||
void ES8388::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Running setup");
|
||||
|
||||
// mute DAC
|
||||
this->set_mute_state_(true);
|
||||
|
||||
// I2S worker mode
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_MASTERMODE, 0x00));
|
||||
|
||||
/* Chip Control and Power Management */
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_CONTROL2, 0x50));
|
||||
// normal all and power up all
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0x00));
|
||||
|
||||
// vmidsel/500k
|
||||
// EnRef=0,Play&Record Mode,(0x17-both of mic&play)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_CONTROL1, 0x12));
|
||||
|
||||
// i2s 16 bits
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL1, 0x18));
|
||||
// sample freq 256
|
||||
// DACFsMode,SINGLE SPEED; DACFsRatio,256
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL2, 0x02));
|
||||
// 0x00 audio on LIN1&RIN1, 0x09 LIN2&RIN2
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL16, 0x00));
|
||||
// only left DAC to left mixer enable 0db
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL17, 0x90));
|
||||
// only right DAC to right mixer enable 0db
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL20, 0x90));
|
||||
// set internal ADC and DAC use the same LRCK clock, ADC LRCK as internal LRCK
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL21, 0x80));
|
||||
// vroi=0 - 1.5k VREF to analog output resistance (default)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL23, 0x00));
|
||||
|
||||
// power down adc and line in
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCPOWER, 0xFF));
|
||||
|
||||
//@nightdav
|
||||
ES8388_ERROR_FAILED(
|
||||
this->write_byte(ES8388_ADCCONTROL1, 0x00)); // +21dB : recommended value for ALC & voice recording
|
||||
|
||||
// set to Mono Right
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL3, 0x02));
|
||||
|
||||
// I2S 16 Bits length and I2S serial audio data format
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL4, 0x0d));
|
||||
// ADCFsMode,singel SPEED,RATIO=256
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL5, 0x02));
|
||||
|
||||
// ADC Volume
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL8, 0x00));
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL9, 0x00));
|
||||
|
||||
//@nightDav
|
||||
// ALC Config (as recommended by ES8388 user guide for voice recording)
|
||||
|
||||
// Reg 0x12 = 0xe2 (ALC enable, PGA Max. Gain=23.5dB, Min. Gain=0dB)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL10, 0xe2));
|
||||
|
||||
// Reg 0x13 = 0xa0 (ALC Target=-1.5dB, ALC Hold time =0 mS)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL11, 0xa0));
|
||||
// Reg 0x14 = 0x12(Decay time =820uS , Attack time = 416 uS)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL12, 0x12));
|
||||
|
||||
// Reg 0x15 = 0x06(ALC mode)
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL13, 0x06));
|
||||
|
||||
// Reg 0x16 = 0xc3(nose gate = -40.5dB, NGG = 0x01(mute ADC))
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL14, 0xc3));
|
||||
|
||||
// Power on ADC
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL21, 0x80));
|
||||
|
||||
// Start state machine
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0xF0));
|
||||
delay(1);
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_CHIPPOWER, 0x00));
|
||||
|
||||
// DAC volume max
|
||||
// Set initial volume
|
||||
// this->set_volume(0.75); // 0.75 = 0xBF = 0dB
|
||||
|
||||
this->set_mute_state_(false);
|
||||
|
||||
// unmute ADC with fade in
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCCONTROL7, 0x60));
|
||||
// unmute DAC with fade in
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_DACCONTROL3, 0x20));
|
||||
|
||||
// Power on ADC, Enable LIN&RIN, Power off MICBIAS, set int1lp to low power mode
|
||||
ES8388_ERROR_FAILED(this->write_byte(ES8388_ADCPOWER, 0x09));
|
||||
|
||||
#ifdef USE_SELECT
|
||||
if (this->dac_output_select_ != nullptr) {
|
||||
auto dac_power = this->get_dac_power();
|
||||
if (dac_power.has_value()) {
|
||||
auto dac_power_str = this->dac_output_select_->at(dac_power.value());
|
||||
if (dac_power_str.has_value()) {
|
||||
this->dac_output_select_->publish_state(dac_power_str.value());
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Unknown DAC output power value: %d", dac_power.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this->adc_input_mic_select_ != nullptr) {
|
||||
auto mic_input = this->get_mic_input();
|
||||
if (mic_input.has_value()) {
|
||||
auto mic_input_str = this->adc_input_mic_select_->at(mic_input.value());
|
||||
if (mic_input_str.has_value()) {
|
||||
this->adc_input_mic_select_->publish_state(mic_input_str.value());
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Unknown ADC input mic value: %d", mic_input.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ES8388::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "ES8388 Audio Codec:");
|
||||
LOG_I2C_DEVICE(this);
|
||||
#ifdef USE_SELECT
|
||||
LOG_SELECT(" ", "DacOutputSelect", this->dac_output_select_);
|
||||
LOG_SELECT(" ", "ADCInputMicSelect", this->adc_input_mic_select_);
|
||||
#endif
|
||||
|
||||
if (this->is_failed()) {
|
||||
ESP_LOGCONFIG(TAG, " Failed to initialize");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool ES8388::set_volume(float volume) {
|
||||
volume = clamp(volume, 0.0f, 1.0f);
|
||||
uint8_t value = remap<uint8_t, float>(volume, 0.0f, 1.0f, -96, 0);
|
||||
ESP_LOGD(TAG, "Setting ES8388_DACCONTROL4 / ES8388_DACCONTROL5 to 0x%02X (volume: %f)", value, volume);
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL4, value));
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL5, value));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float ES8388::volume() {
|
||||
uint8_t value;
|
||||
ES8388_ERROR_CHECK(this->read_byte(ES8388_DACCONTROL4, &value));
|
||||
return remap<float, uint8_t>(value, -96, 0, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
bool ES8388::set_mute_state_(bool mute_state) {
|
||||
uint8_t value = 0;
|
||||
|
||||
this->is_muted_ = mute_state;
|
||||
|
||||
ES8388_ERROR_CHECK(this->read_byte(ES8388_DACCONTROL3, &value));
|
||||
ESP_LOGV(TAG, "Read ES8388_DACCONTROL3: 0x%02X", value);
|
||||
|
||||
if (mute_state) {
|
||||
value = 0x3C;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Setting ES8388_DACCONTROL3 to 0x%02X (muted: %s)", value, YESNO(mute_state));
|
||||
return this->write_byte(ES8388_DACCONTROL3, value);
|
||||
}
|
||||
|
||||
// Set dac power output
|
||||
bool ES8388::set_dac_output(DacOutputLine line) {
|
||||
uint8_t reg_out1 = 0;
|
||||
uint8_t reg_out2 = 0;
|
||||
uint8_t dac_power = 0;
|
||||
|
||||
// 0x00: -30dB , 0x1E: 0dB
|
||||
switch (line) {
|
||||
case DAC_OUTPUT_LINE1:
|
||||
reg_out1 = 0x1E;
|
||||
dac_power = ES8388_DAC_OUTPUT_LOUT1_ROUT1;
|
||||
break;
|
||||
case DAC_OUTPUT_LINE2:
|
||||
reg_out2 = 0x1E;
|
||||
dac_power = ES8388_DAC_OUTPUT_LOUT2_ROUT2;
|
||||
break;
|
||||
case DAC_OUTPUT_BOTH:
|
||||
reg_out1 = 0x1E;
|
||||
reg_out2 = 0x1E;
|
||||
dac_power = ES8388_DAC_OUTPUT_BOTH;
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unknown DAC output line: %d", line);
|
||||
return false;
|
||||
};
|
||||
|
||||
ESP_LOGV(TAG, "Setting ES8388_DACPOWER to 0x%02X", dac_power);
|
||||
ESP_LOGV(TAG, "Setting ES8388_DACCONTROL24 / ES8388_DACCONTROL25 to 0x%02X", reg_out1);
|
||||
ESP_LOGV(TAG, "Setting ES8388_DACCONTROL26 / ES8388_DACCONTROL27 to 0x%02X", reg_out2);
|
||||
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL24, reg_out1)); // LOUT1VOL
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL25, reg_out1)); // ROUT1VOL
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL26, reg_out2)); // LOUT2VOL
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_DACCONTROL27, reg_out2)); // ROUT1VOL
|
||||
|
||||
return this->write_byte(ES8388_DACPOWER, dac_power);
|
||||
}
|
||||
|
||||
optional<DacOutputLine> ES8388::get_dac_power() {
|
||||
uint8_t dac_power;
|
||||
if (!this->read_byte(ES8388_DACPOWER, &dac_power)) {
|
||||
this->status_momentary_warning("Failed to read ES8388_DACPOWER");
|
||||
return {};
|
||||
}
|
||||
switch (dac_power) {
|
||||
case ES8388_DAC_OUTPUT_LOUT1_ROUT1:
|
||||
return DAC_OUTPUT_LINE1;
|
||||
case ES8388_DAC_OUTPUT_LOUT2_ROUT2:
|
||||
return DAC_OUTPUT_LINE2;
|
||||
case ES8388_DAC_OUTPUT_BOTH:
|
||||
return DAC_OUTPUT_BOTH;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// Set ADC input MIC
|
||||
bool ES8388::set_adc_input_mic(AdcInputMicLine line) {
|
||||
uint8_t mic_input = 0;
|
||||
|
||||
switch (line) {
|
||||
case ADC_INPUT_MIC_LINE1:
|
||||
mic_input = ES8388_ADC_INPUT_LINPUT1_RINPUT1;
|
||||
break;
|
||||
case ADC_INPUT_MIC_LINE2:
|
||||
mic_input = ES8388_ADC_INPUT_LINPUT2_RINPUT2;
|
||||
break;
|
||||
case ADC_INPUT_MIC_DIFFERENCE:
|
||||
mic_input = ES8388_ADC_INPUT_DIFFERENCE;
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "Unknown ADC input mic line: %d", line);
|
||||
return false;
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Setting ES8388_ADCCONTROL2 to 0x%02X", mic_input);
|
||||
ES8388_ERROR_CHECK(this->write_byte(ES8388_ADCCONTROL2, mic_input));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
optional<AdcInputMicLine> ES8388::get_mic_input() {
|
||||
uint8_t mic_input;
|
||||
if (!this->read_byte(ES8388_ADCCONTROL2, &mic_input)) {
|
||||
this->status_momentary_warning("Failed to read ES8388_ADCCONTROL2");
|
||||
return {};
|
||||
}
|
||||
switch (mic_input) {
|
||||
case ES8388_ADC_INPUT_LINPUT1_RINPUT1:
|
||||
return ADC_INPUT_MIC_LINE1;
|
||||
case ES8388_ADC_INPUT_LINPUT2_RINPUT2:
|
||||
return ADC_INPUT_MIC_LINE2;
|
||||
case ES8388_ADC_INPUT_DIFFERENCE:
|
||||
return ADC_INPUT_MIC_DIFFERENCE;
|
||||
default:
|
||||
return {};
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace es8388
|
||||
} // namespace esphome
|
||||
81
esphome/components/es8388/es8388.h
Normal file
81
esphome/components/es8388/es8388.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "esphome/components/audio_dac/audio_dac.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/core/component.h"
|
||||
#ifdef USE_SELECT
|
||||
#include "esphome/components/select/select.h"
|
||||
#endif
|
||||
|
||||
#include "es8388_const.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace es8388 {
|
||||
|
||||
enum DacOutputLine : uint8_t {
|
||||
DAC_OUTPUT_LINE1,
|
||||
DAC_OUTPUT_LINE2,
|
||||
DAC_OUTPUT_BOTH,
|
||||
};
|
||||
|
||||
enum AdcInputMicLine : uint8_t {
|
||||
ADC_INPUT_MIC_LINE1,
|
||||
ADC_INPUT_MIC_LINE2,
|
||||
ADC_INPUT_MIC_DIFFERENCE,
|
||||
};
|
||||
|
||||
class ES8388 : public audio_dac::AudioDac, public Component, public i2c::I2CDevice {
|
||||
#ifdef USE_SELECT
|
||||
SUB_SELECT(dac_output)
|
||||
SUB_SELECT(adc_input_mic)
|
||||
#endif
|
||||
|
||||
public:
|
||||
/////////////////////////
|
||||
// Component overrides //
|
||||
/////////////////////////
|
||||
|
||||
void setup() override;
|
||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||
void dump_config() override;
|
||||
|
||||
////////////////////////
|
||||
// AudioDac overrides //
|
||||
////////////////////////
|
||||
|
||||
/// @brief Writes the volume out to the DAC
|
||||
/// @param volume floating point between 0.0 and 1.0
|
||||
/// @return True if successful and false otherwise
|
||||
bool set_volume(float volume) override;
|
||||
|
||||
/// @brief Gets the current volume out from the DAC
|
||||
/// @return floating point between 0.0 and 1.0
|
||||
float volume() override;
|
||||
|
||||
/// @brief Disables mute for audio out
|
||||
/// @return True if successful and false otherwise
|
||||
bool set_mute_off() override { return this->set_mute_state_(false); }
|
||||
|
||||
/// @brief Enables mute for audio out
|
||||
/// @return True if successful and false otherwise
|
||||
bool set_mute_on() override { return this->set_mute_state_(true); }
|
||||
|
||||
bool is_muted() override { return this->is_muted_; }
|
||||
|
||||
optional<DacOutputLine> get_dac_power();
|
||||
optional<AdcInputMicLine> get_mic_input();
|
||||
|
||||
bool set_dac_output(DacOutputLine line);
|
||||
bool set_adc_input_mic(AdcInputMicLine line);
|
||||
|
||||
protected:
|
||||
/// @brief Mutes or unmutes the DAC audio out
|
||||
/// @param mute_state True to mute, false to unmute
|
||||
/// @return True if successful and false otherwise
|
||||
bool set_mute_state_(bool mute_state);
|
||||
};
|
||||
|
||||
} // namespace es8388
|
||||
} // namespace esphome
|
||||
83
esphome/components/es8388/es8388_const.h
Normal file
83
esphome/components/es8388/es8388_const.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace esphome {
|
||||
namespace es8388 {
|
||||
|
||||
/* ES8388 register */
|
||||
static const uint8_t ES8388_CONTROL1 = 0x00;
|
||||
static const uint8_t ES8388_CONTROL2 = 0x01;
|
||||
|
||||
static const uint8_t ES8388_CHIPPOWER = 0x02;
|
||||
|
||||
static const uint8_t ES8388_ADCPOWER = 0x03;
|
||||
static const uint8_t ES8388_DACPOWER = 0x04;
|
||||
|
||||
static const uint8_t ES8388_CHIPLOPOW1 = 0x05;
|
||||
static const uint8_t ES8388_CHIPLOPOW2 = 0x06;
|
||||
|
||||
static const uint8_t ES8388_ANAVOLMANAG = 0x07;
|
||||
|
||||
static const uint8_t ES8388_MASTERMODE = 0x08;
|
||||
|
||||
/* ADC */
|
||||
static const uint8_t ES8388_ADCCONTROL1 = 0x09;
|
||||
static const uint8_t ES8388_ADCCONTROL2 = 0x0a;
|
||||
static const uint8_t ES8388_ADCCONTROL3 = 0x0b;
|
||||
static const uint8_t ES8388_ADCCONTROL4 = 0x0c;
|
||||
static const uint8_t ES8388_ADCCONTROL5 = 0x0d;
|
||||
static const uint8_t ES8388_ADCCONTROL6 = 0x0e;
|
||||
static const uint8_t ES8388_ADCCONTROL7 = 0x0f;
|
||||
static const uint8_t ES8388_ADCCONTROL8 = 0x10;
|
||||
static const uint8_t ES8388_ADCCONTROL9 = 0x11;
|
||||
static const uint8_t ES8388_ADCCONTROL10 = 0x12;
|
||||
static const uint8_t ES8388_ADCCONTROL11 = 0x13;
|
||||
static const uint8_t ES8388_ADCCONTROL12 = 0x14;
|
||||
static const uint8_t ES8388_ADCCONTROL13 = 0x15;
|
||||
static const uint8_t ES8388_ADCCONTROL14 = 0x16;
|
||||
/* DAC */
|
||||
static const uint8_t ES8388_DACCONTROL1 = 0x17;
|
||||
static const uint8_t ES8388_DACCONTROL2 = 0x18;
|
||||
static const uint8_t ES8388_DACCONTROL3 = 0x19;
|
||||
static const uint8_t ES8388_DACCONTROL4 = 0x1a;
|
||||
static const uint8_t ES8388_DACCONTROL5 = 0x1b;
|
||||
static const uint8_t ES8388_DACCONTROL6 = 0x1c;
|
||||
static const uint8_t ES8388_DACCONTROL7 = 0x1d;
|
||||
static const uint8_t ES8388_DACCONTROL8 = 0x1e;
|
||||
static const uint8_t ES8388_DACCONTROL9 = 0x1f;
|
||||
static const uint8_t ES8388_DACCONTROL10 = 0x20;
|
||||
static const uint8_t ES8388_DACCONTROL11 = 0x21;
|
||||
static const uint8_t ES8388_DACCONTROL12 = 0x22;
|
||||
static const uint8_t ES8388_DACCONTROL13 = 0x23;
|
||||
static const uint8_t ES8388_DACCONTROL14 = 0x24;
|
||||
static const uint8_t ES8388_DACCONTROL15 = 0x25;
|
||||
static const uint8_t ES8388_DACCONTROL16 = 0x26;
|
||||
static const uint8_t ES8388_DACCONTROL17 = 0x27;
|
||||
static const uint8_t ES8388_DACCONTROL18 = 0x28;
|
||||
static const uint8_t ES8388_DACCONTROL19 = 0x29;
|
||||
static const uint8_t ES8388_DACCONTROL20 = 0x2a;
|
||||
static const uint8_t ES8388_DACCONTROL21 = 0x2b;
|
||||
static const uint8_t ES8388_DACCONTROL22 = 0x2c;
|
||||
static const uint8_t ES8388_DACCONTROL23 = 0x2d;
|
||||
static const uint8_t ES8388_DACCONTROL24 = 0x2e;
|
||||
static const uint8_t ES8388_DACCONTROL25 = 0x2f;
|
||||
static const uint8_t ES8388_DACCONTROL26 = 0x30;
|
||||
static const uint8_t ES8388_DACCONTROL27 = 0x31;
|
||||
static const uint8_t ES8388_DACCONTROL28 = 0x32;
|
||||
static const uint8_t ES8388_DACCONTROL29 = 0x33;
|
||||
static const uint8_t ES8388_DACCONTROL30 = 0x34;
|
||||
|
||||
static const uint8_t ES8388_DAC_OUTPUT_NONE = 0xC0; // ALL DAC DOWN
|
||||
|
||||
static const uint8_t ES8388_DAC_OUTPUT_LOUT1_ROUT1 = 0x30;
|
||||
static const uint8_t ES8388_DAC_OUTPUT_LOUT2_ROUT2 = 0x0C;
|
||||
static const uint8_t ES8388_DAC_OUTPUT_BOTH = 0x3C;
|
||||
|
||||
static const uint8_t ES8388_ADC_INPUT_LINPUT1_RINPUT1 = 0x00;
|
||||
static const uint8_t ES8388_ADC_INPUT_MIC1 = 0x05;
|
||||
static const uint8_t ES8388_ADC_INPUT_MIC2 = 0x06;
|
||||
static const uint8_t ES8388_ADC_INPUT_LINPUT2_RINPUT2 = 0x50;
|
||||
static const uint8_t ES8388_ADC_INPUT_DIFFERENCE = 0xf0;
|
||||
|
||||
} // namespace es8388
|
||||
} // namespace esphome
|
||||
47
esphome/components/es8388/select/__init__.py
Normal file
47
esphome/components/es8388/select/__init__.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import select
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import ENTITY_CATEGORY_CONFIG, ICON_CHIP # noqa: F401
|
||||
|
||||
from ..audio_dac import CONF_ES8388_ID, ES8388, es8388_ns
|
||||
|
||||
CONF_DAC_OUTPUT = "dac_output"
|
||||
CONF_ADC_INPUT_MIC = "adc_input_mic"
|
||||
|
||||
DacOutputSelect = es8388_ns.class_("DacOutputSelect", select.Select)
|
||||
ADCInputMicSelect = es8388_ns.class_("ADCInputMicSelect", select.Select)
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
{
|
||||
cv.GenerateID(CONF_ES8388_ID): cv.use_id(ES8388),
|
||||
cv.Optional(CONF_DAC_OUTPUT): select.select_schema(
|
||||
DacOutputSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_CHIP,
|
||||
),
|
||||
cv.Optional(CONF_ADC_INPUT_MIC): select.select_schema(
|
||||
ADCInputMicSelect,
|
||||
entity_category=ENTITY_CATEGORY_CONFIG,
|
||||
icon=ICON_CHIP,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_ES8388_ID])
|
||||
if dac_output_config := config.get(CONF_DAC_OUTPUT):
|
||||
s = await select.new_select(
|
||||
dac_output_config,
|
||||
options=["LINE1", "LINE2", "BOTH"],
|
||||
)
|
||||
await cg.register_parented(s, parent)
|
||||
cg.add(parent.set_dac_output_select(s))
|
||||
|
||||
if adc_input_mic_config := config.get(CONF_ADC_INPUT_MIC):
|
||||
s = await select.new_select(
|
||||
adc_input_mic_config,
|
||||
options=["LINE1", "LINE2", "DIFFERENCE"],
|
||||
)
|
||||
await cg.register_parented(s, parent)
|
||||
cg.add(parent.set_adc_input_mic_select(s))
|
||||
12
esphome/components/es8388/select/adc_input_mic_select.cpp
Normal file
12
esphome/components/es8388/select/adc_input_mic_select.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "adc_input_mic_select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace es8388 {
|
||||
|
||||
void ADCInputMicSelect::control(const std::string &value) {
|
||||
this->publish_state(value);
|
||||
this->parent_->set_adc_input_mic(static_cast<AdcInputMicLine>(this->index_of(value).value()));
|
||||
}
|
||||
|
||||
} // namespace es8388
|
||||
} // namespace esphome
|
||||
15
esphome/components/es8388/select/adc_input_mic_select.h
Normal file
15
esphome/components/es8388/select/adc_input_mic_select.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/es8388/es8388.h"
|
||||
#include "esphome/components/select/select.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace es8388 {
|
||||
|
||||
class ADCInputMicSelect : public select::Select, public Parented<ES8388> {
|
||||
protected:
|
||||
void control(const std::string &value) override;
|
||||
};
|
||||
|
||||
} // namespace es8388
|
||||
} // namespace esphome
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user