1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-15 06:15:47 +00:00

Compare commits

...

17 Commits

Author SHA1 Message Date
Jesse Hills
48fa549042 Merge pull request #6660 from esphome/bump-2024.4.2
2024.4.2
2024-04-30 16:30:03 +12:00
Jesse Hills
516971a255 Bump version to 2024.4.2 2024-04-30 15:47:40 +12:00
Jesse Hills
4936cbec0d [i2s_audio.microphone] Fixing adc bug (#6654) 2024-04-30 15:47:40 +12:00
tronikos
9832fa4d76 Revert #6458 (#6650)
Reading the z-axis register is required.
2024-04-30 15:47:40 +12:00
Samuel Sieb
5838af646b allow defaults with no include vars (#6613) 2024-04-30 15:47:40 +12:00
mrtoy-me
33e9881830 Fix SHT3xd fails sometimes in 2024.4.0 (#6592)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2024-04-30 15:47:39 +12:00
Jesse Hills
fcd9e3cb5d Merge pull request #6607 from esphome/bump-2024.4.1
2024.4.1
2024-04-23 11:51:30 +12:00
Jesse Hills
7ae36b023c Bump version to 2024.4.1 2024-04-23 10:50:41 +12:00
Jonathan Swoboda
3e64876097 Fix or filter (#6574)
Co-authored-by: Jonathan Swoboda <jonathan.swoboda>
2024-04-23 10:50:41 +12:00
polyfloyd
44d13f2405 esp32_ble: Consider ESP_BT_STATUS_DONE a successful state (#6493)
Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
2024-04-23 10:50:41 +12:00
Clyde Stubbs
03d547d2c0 Disallow variant/family override for known boards (#6512) 2024-04-23 10:50:41 +12:00
Cody Cutrer
dd8be524b4 fix streaming logs from MQTT for ESP32 devices using TLS (#6605) 2024-04-23 10:50:41 +12:00
Mat931
a29e634af1 Calibrate Beken internal temperature (#6599) 2024-04-23 10:50:41 +12:00
Javier Peletier
1a152169e0 wifi: fix reconnect issue due to enablement of fast connect (#6598) 2024-04-23 10:50:40 +12:00
zry98
496b7f45db [Tuya Climate] Fix compilation error caused by codegen (#6568) 2024-04-23 10:50:40 +12:00
Jesse Hills
e1b861a0a1 Merge pull request #6547 from esphome/bump-2024.4.0
2024.4.0
2024-04-17 14:13:43 +12:00
Jesse Hills
f2a12589f3 Bump version to 2024.4.0 2024-04-17 13:08:27 +12:00
22 changed files with 201 additions and 85 deletions

View File

@@ -316,17 +316,26 @@ def _parse_platform_version(value):
def _detect_variant(value):
if CONF_VARIANT not in value:
board = value[CONF_BOARD]
if board not in BOARDS:
board = value[CONF_BOARD]
if board in BOARDS:
variant = BOARDS[board][KEY_VARIANT]
if CONF_VARIANT in value and variant != value[CONF_VARIANT]:
raise cv.Invalid(
"This board is unknown, please set the variant manually",
f"Option '{CONF_VARIANT}' does not match selected board.",
path=[CONF_VARIANT],
)
value = value.copy()
value[CONF_VARIANT] = variant
else:
if CONF_VARIANT not in value:
raise cv.Invalid(
"This board is unknown, if you are sure you want to compile with this board selection, "
f"override with option '{CONF_VARIANT}'",
path=[CONF_BOARD],
)
value = value.copy()
value[CONF_VARIANT] = BOARDS[board][KEY_VARIANT]
_LOGGER.warning(
"This board is unknown. Make sure the chosen chip component is correct.",
)
return value

View File

@@ -364,7 +364,11 @@ void ESP32BLETracker::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_ga
}
void ESP32BLETracker::gap_scan_set_param_complete_(const esp_ble_gap_cb_param_t::ble_scan_param_cmpl_evt_param &param) {
this->scan_set_param_failed_ = param.status;
if (param.status == ESP_BT_STATUS_DONE) {
this->scan_set_param_failed_ = ESP_BT_STATUS_SUCCESS;
} else {
this->scan_set_param_failed_ = param.status;
}
}
void ESP32BLETracker::gap_scan_start_complete_(const esp_ble_gap_cb_param_t::ble_scan_start_cmpl_evt_param &param) {

View File

@@ -61,28 +61,57 @@ void I2SAudioMicrophone::start_() {
.bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT,
};
esp_err_t err;
#if SOC_I2S_SUPPORTS_ADC
if (this->adc_) {
config.mode = (i2s_mode_t) (config.mode | I2S_MODE_ADC_BUILT_IN);
i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr);
err = i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error installing I2S driver: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
err = i2s_set_adc_mode(ADC_UNIT_1, this->adc_channel_);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error setting ADC mode: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
err = i2s_adc_enable(this->parent_->get_port());
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error enabling ADC: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
i2s_set_adc_mode(ADC_UNIT_1, this->adc_channel_);
i2s_adc_enable(this->parent_->get_port());
} else
#endif
{
if (this->pdm_)
config.mode = (i2s_mode_t) (config.mode | I2S_MODE_PDM);
i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr);
err = i2s_driver_install(this->parent_->get_port(), &config, 0, nullptr);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error installing I2S driver: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
i2s_pin_config_t pin_config = this->parent_->get_pin_config();
pin_config.data_in_num = this->din_pin_;
i2s_set_pin(this->parent_->get_port(), &pin_config);
err = i2s_set_pin(this->parent_->get_port(), &pin_config);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error setting I2S pin: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
}
this->state_ = microphone::STATE_RUNNING;
this->high_freq_.start();
this->status_clear_error();
}
void I2SAudioMicrophone::stop() {
@@ -96,11 +125,33 @@ void I2SAudioMicrophone::stop() {
}
void I2SAudioMicrophone::stop_() {
i2s_stop(this->parent_->get_port());
i2s_driver_uninstall(this->parent_->get_port());
esp_err_t err;
#if SOC_I2S_SUPPORTS_ADC
if (this->adc_) {
err = i2s_adc_disable(this->parent_->get_port());
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error disabling ADC: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
}
#endif
err = i2s_stop(this->parent_->get_port());
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error stopping I2S microphone: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
err = i2s_driver_uninstall(this->parent_->get_port());
if (err != ESP_OK) {
ESP_LOGW(TAG, "Error uninstalling I2S driver: %s", esp_err_to_name(err));
this->status_set_error();
return;
}
this->parent_->unlock();
this->state_ = microphone::STATE_STOPPED;
this->high_freq_.stop();
this->status_clear_error();
}
size_t I2SAudioMicrophone::read(int16_t *buf, size_t len) {

View File

@@ -55,11 +55,13 @@ void InternalTemperatureSensor::update() {
uint32_t raw, result;
result = temp_single_get_current_temperature(&raw);
success = (result == 0);
#ifdef USE_LIBRETINY_VARIANT_BK7231T
#if defined(USE_LIBRETINY_VARIANT_BK7231N)
temperature = raw * -0.38f + 156.0f;
#elif defined(USE_LIBRETINY_VARIANT_BK7231T)
temperature = raw * 0.04f;
#else
#else // USE_LIBRETINY_VARIANT
temperature = raw * 0.128f;
#endif // USE_LIBRETINY_VARIANT_BK7231T
#endif // USE_LIBRETINY_VARIANT
#endif // USE_BK72XX
if (success && std::isfinite(temperature)) {
this->publish_state(temperature);

View File

@@ -1,6 +1,10 @@
import json
import logging
from os.path import dirname, isfile, join
from os.path import (
dirname,
isfile,
join,
)
import esphome.codegen as cg
import esphome.config_validation as cv
@@ -55,15 +59,25 @@ def _detect_variant(value):
component: LibreTinyComponent = CORE.data[KEY_LIBRETINY][KEY_COMPONENT_DATA]
board = value[CONF_BOARD]
# read board-default family if not specified
if CONF_FAMILY not in value:
if board not in component.boards:
if board not in component.boards:
if CONF_FAMILY not in value:
raise cv.Invalid(
"This board is unknown, please set the family manually. "
"Also, make sure the chosen chip component is correct.",
"This board is unknown, if you are sure you want to compile with this board selection, "
f"override with option '{CONF_FAMILY}'",
path=[CONF_BOARD],
)
_LOGGER.warning(
"This board is unknown. Make sure the chosen chip component is correct.",
)
else:
family = component.boards[board][KEY_FAMILY]
if CONF_FAMILY in value and family != value[CONF_FAMILY]:
raise cv.Invalid(
f"Option '{CONF_FAMILY}' does not match selected board.",
path=[CONF_FAMILY],
)
value = value.copy()
value[CONF_FAMILY] = component.boards[board][KEY_FAMILY]
value[CONF_FAMILY] = family
# read component name matching this family
value[CONF_COMPONENT_ID] = FAMILY_COMPONENT[value[CONF_FAMILY]]
# make sure the chosen component matches the family
@@ -72,11 +86,6 @@ def _detect_variant(value):
f"The chosen family doesn't belong to '{component.name}' component. The correct component is '{value[CONF_COMPONENT_ID]}'",
path=[CONF_FAMILY],
)
# warn anyway if the board wasn't found
if board not in component.boards:
_LOGGER.warning(
"This board is unknown. Make sure the chosen chip component is correct.",
)
return value

View File

@@ -77,8 +77,17 @@ void QMC5883LComponent::dump_config() {
float QMC5883LComponent::get_setup_priority() const { return setup_priority::DATA; }
void QMC5883LComponent::update() {
uint8_t status = false;
if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG)
this->read_byte(QMC5883L_REGISTER_STATUS, &status);
this->read_byte(QMC5883L_REGISTER_STATUS, &status);
// Always request X,Y,Z regardless if there are sensors for them
// to avoid https://github.com/esphome/issues/issues/5731
uint16_t raw_x, raw_y, raw_z;
if (!this->read_byte_16_(QMC5883L_REGISTER_DATA_X_LSB, &raw_x) ||
!this->read_byte_16_(QMC5883L_REGISTER_DATA_Y_LSB, &raw_y) ||
!this->read_byte_16_(QMC5883L_REGISTER_DATA_Z_LSB, &raw_z)) {
this->status_set_warning();
return;
}
float mg_per_bit;
switch (this->range_) {
@@ -93,36 +102,11 @@ void QMC5883LComponent::update() {
}
// in µT
float x = NAN, y = NAN, z = NAN;
if (this->x_sensor_ != nullptr || this->heading_sensor_ != nullptr) {
uint16_t raw_x;
if (!this->read_byte_16_(QMC5883L_REGISTER_DATA_X_LSB, &raw_x)) {
this->status_set_warning();
return;
}
x = int16_t(raw_x) * mg_per_bit * 0.1f;
}
if (this->y_sensor_ != nullptr || this->heading_sensor_ != nullptr) {
uint16_t raw_y;
if (!this->read_byte_16_(QMC5883L_REGISTER_DATA_Y_LSB, &raw_y)) {
this->status_set_warning();
return;
}
y = int16_t(raw_y) * mg_per_bit * 0.1f;
}
if (this->z_sensor_ != nullptr) {
uint16_t raw_z;
if (!this->read_byte_16_(QMC5883L_REGISTER_DATA_Z_LSB, &raw_z)) {
this->status_set_warning();
return;
}
z = int16_t(raw_z) * mg_per_bit * 0.1f;
}
const float x = int16_t(raw_x) * mg_per_bit * 0.1f;
const float y = int16_t(raw_y) * mg_per_bit * 0.1f;
const float z = int16_t(raw_z) * mg_per_bit * 0.1f;
float heading = NAN;
if (this->heading_sensor_ != nullptr) {
heading = atan2f(0.0f - x, y) * 180.0f / M_PI;
}
float heading = atan2f(0.0f - x, y) * 180.0f / M_PI;
float temp = NAN;
if (this->temperature_sensor_ != nullptr) {

View File

@@ -359,11 +359,15 @@ OrFilter::OrFilter(std::vector<Filter *> filters) : filters_(std::move(filters))
OrFilter::PhiNode::PhiNode(OrFilter *or_parent) : or_parent_(or_parent) {}
optional<float> OrFilter::PhiNode::new_value(float value) {
this->or_parent_->output(value);
if (!this->or_parent_->has_value_) {
this->or_parent_->output(value);
this->or_parent_->has_value_ = true;
}
return {};
}
optional<float> OrFilter::new_value(float value) {
this->has_value_ = false;
for (Filter *filter : this->filters_)
filter->input(value);

View File

@@ -388,6 +388,7 @@ class OrFilter : public Filter {
};
std::vector<Filter *> filters_;
bool has_value_{false};
PhiNode phi_;
};

View File

@@ -6,9 +6,14 @@ namespace sht3xd {
static const char *const TAG = "sht3xd";
// use read serial number register with clock stretching disabled as per other SHT3XD_COMMAND registers
// which provides support for SHT85 sensor
// SHT85 does not support clock stretching and uses same registers as SHT3xd with clock stretching disabled
// https://sensirion.com/media/documents/E5762713/63D103C2/Sensirion_electronic_identification_code_SHT3x.pdf
// indicates two possible read serial number registers either with clock stretching enabled or disabled.
// Other SHT3XD_COMMAND registers use the clock stretching disabled register.
// To ensure compatibility, reading serial number using the register with clock stretching register enabled
// (used originally in this component) is tried first and if that fails the alternate register address
// with clock stretching disabled is read.
static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING = 0x3780;
static const uint16_t SHT3XD_COMMAND_READ_SERIAL_NUMBER = 0x3682;
static const uint16_t SHT3XD_COMMAND_READ_STATUS = 0xF32D;
@@ -22,13 +27,19 @@ static const uint16_t SHT3XD_COMMAND_FETCH_DATA = 0xE000;
void SHT3XDComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up SHT3xD...");
uint16_t raw_serial_number[2];
if (!this->get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER, raw_serial_number, 2)) {
this->mark_failed();
return;
if (!this->get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER_CLOCK_STRETCHING, raw_serial_number, 2)) {
this->error_code_ = READ_SERIAL_STRETCHED_FAILED;
if (!this->get_register(SHT3XD_COMMAND_READ_SERIAL_NUMBER, raw_serial_number, 2)) {
this->error_code_ = READ_SERIAL_FAILED;
this->mark_failed();
return;
}
}
this->serial_number_ = (uint32_t(raw_serial_number[0]) << 16) | uint32_t(raw_serial_number[1]);
if (!this->write_command(heater_enabled_ ? SHT3XD_COMMAND_HEATER_ENABLE : SHT3XD_COMMAND_HEATER_DISABLE)) {
this->error_code_ = WRITE_HEATER_MODE_FAILED;
this->mark_failed();
return;
}
@@ -36,10 +47,21 @@ void SHT3XDComponent::setup() {
void SHT3XDComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SHT3xD:");
switch (this->error_code_) {
case READ_SERIAL_FAILED:
ESP_LOGD(TAG, " Error reading serial number");
break;
case WRITE_HEATER_MODE_FAILED:
ESP_LOGD(TAG, " Error writing heater mode");
break;
default:
break;
}
if (this->is_failed()) {
ESP_LOGE(TAG, " Communication with SHT3xD failed!");
return;
}
ESP_LOGD(TAG, " Setup successful");
ESP_LOGD(TAG, " Serial Number: 0x%08" PRIX32, this->serial_number_);
ESP_LOGD(TAG, " Heater Enabled: %s", this->heater_enabled_ ? "true" : "false");

View File

@@ -22,6 +22,13 @@ class SHT3XDComponent : public PollingComponent, public sensirion_common::Sensir
void set_heater_enabled(bool heater_enabled) { heater_enabled_ = heater_enabled; }
protected:
enum ErrorCode {
NONE = 0,
READ_SERIAL_STRETCHED_FAILED,
READ_SERIAL_FAILED,
WRITE_HEATER_MODE_FAILED,
} error_code_{NONE};
sensor::Sensor *temperature_sensor_{nullptr};
sensor::Sensor *humidity_sensor_{nullptr};
bool heater_enabled_{true};

View File

@@ -208,7 +208,7 @@ async def to_code(config):
cg.add(var.set_switch_id(switch_datapoint))
if active_state_config := config.get(CONF_ACTIVE_STATE):
cg.add(var.set_active_state_id(CONF_DATAPOINT))
cg.add(var.set_active_state_id(active_state_config.get(CONF_DATAPOINT)))
if (heating_value := active_state_config.get(CONF_HEATING_VALUE)) is not None:
cg.add(var.set_active_state_heating_value(heating_value))
if (cooling_value := active_state_config.get(CONF_COOLING_VALUE)) is not None:
@@ -219,14 +219,10 @@ async def to_code(config):
cg.add(var.set_active_state_fanonly_value(fanonly_value))
else:
if heating_state_pin_config := config.get(CONF_HEATING_STATE_PIN):
heating_state_pin = await cg.gpio_pin_expression(
config(heating_state_pin_config)
)
heating_state_pin = await cg.gpio_pin_expression(heating_state_pin_config)
cg.add(var.set_heating_state_pin(heating_state_pin))
if cooling_state_pin_config := config.get(CONF_COOLING_STATE_PIN):
cooling_state_pin = await cg.gpio_pin_expression(
config(cooling_state_pin_config)
)
cooling_state_pin = await cg.gpio_pin_expression(cooling_state_pin_config)
cg.add(var.set_cooling_state_pin(cooling_state_pin))
if target_temperature_datapoint := config.get(CONF_TARGET_TEMPERATURE_DATAPOINT):
@@ -254,11 +250,11 @@ async def to_code(config):
if preset_config := config.get(CONF_PRESET, {}):
if eco_config := preset_config.get(CONF_ECO, {}):
cg.add(var.set_eco_id(CONF_DATAPOINT))
cg.add(var.set_eco_id(eco_config.get(CONF_DATAPOINT)))
if eco_temperature := eco_config.get(CONF_TEMPERATURE):
cg.add(var.set_eco_temperature(eco_temperature))
if CONF_SLEEP in preset_config:
cg.add(var.set_sleep_id(CONF_DATAPOINT))
if sleep_config := preset_config.get(CONF_SLEEP, {}):
cg.add(var.set_sleep_id(sleep_config.get(CONF_DATAPOINT)))
if swing_mode_config := config.get(CONF_SWING_MODE):
if swing_vertical_datapoint := swing_mode_config.get(CONF_VERTICAL_DATAPOINT):
@@ -268,7 +264,7 @@ async def to_code(config):
):
cg.add(var.set_swing_horizontal_id(swing_horizontal_datapoint))
if fan_mode_config := config.get(CONF_FAN_MODE):
cg.add(var.set_fan_speed_id(CONF_DATAPOINT))
cg.add(var.set_fan_speed_id(fan_mode_config.get(CONF_DATAPOINT)))
if (fan_auto_value := fan_mode_config.get(CONF_AUTO_VALUE)) is not None:
cg.add(var.set_fan_speed_auto_value(fan_auto_value))
if (fan_low_value := fan_mode_config.get(CONF_LOW_VALUE)) is not None:

View File

@@ -128,7 +128,7 @@ void WiFiComponent::loop() {
case WIFI_COMPONENT_STATE_COOLDOWN: {
this->status_set_warning();
if (millis() - this->action_started_ > 5000) {
if (this->fast_connect_) {
if (this->fast_connect_ || this->retry_hidden_) {
this->start_connecting(this->sta_[0], false);
} else {
this->start_scanning();
@@ -591,6 +591,9 @@ void WiFiComponent::check_connecting_finished() {
return;
}
// We won't retry hidden networks unless a reconnect fails more than three times again
this->retry_hidden_ = false;
ESP_LOGI(TAG, "WiFi Connected!");
this->print_connect_params_();
@@ -668,10 +671,11 @@ void WiFiComponent::retry_connect() {
this->wifi_mode_(false, {});
delay(100); // NOLINT
this->num_retried_ = 0;
this->retry_hidden_ = false;
} else {
// Try hidden networks after 3 failed retries
ESP_LOGD(TAG, "Retrying with hidden networks...");
this->fast_connect_ = true;
this->retry_hidden_ = true;
this->num_retried_++;
}
} else {

View File

@@ -371,6 +371,7 @@ class WiFiComponent : public Component {
std::vector<WiFiSTAPriority> sta_priorities_;
WiFiAP selected_ap_;
bool fast_connect_{false};
bool retry_hidden_{false};
bool has_ap_{false};
WiFiAP ap_;

View File

@@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2024.4.0b3"
__version__ = "2024.4.2"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = (

View File

@@ -10,6 +10,7 @@ import paho.mqtt.client as mqtt
from esphome.const import (
CONF_BROKER,
CONF_CERTIFICATE_AUTHORITY,
CONF_DISCOVERY_PREFIX,
CONF_ESPHOME,
CONF_LOG_TOPIC,
@@ -99,7 +100,9 @@ def prepare(
elif username:
client.username_pw_set(username, password)
if config[CONF_MQTT].get(CONF_SSL_FINGERPRINTS):
if config[CONF_MQTT].get(CONF_SSL_FINGERPRINTS) or config[CONF_MQTT].get(
CONF_CERTIFICATE_AUTHORITY
):
if sys.version_info >= (2, 7, 13):
tls_version = ssl.PROTOCOL_TLS # pylint: disable=no-member
else:

View File

@@ -321,8 +321,9 @@ class ESPHomeLoaderMixin:
file, vars = node.value, None
result = _load_yaml_internal(self._rel_path(file))
if vars:
result = substitute_vars(result, vars)
if not vars:
vars = {}
result = substitute_vars(result, vars)
return result
@_add_data_ref

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"

View File

@@ -0,0 +1,3 @@
sensor:
- platform: internal_temperature
name: "Internal Temperature"