mirror of
https://github.com/esphome/esphome.git
synced 2025-08-02 16:37:46 +00:00
Merge branch 'proto_field_ifdefs' into integration
This commit is contained in:
commit
b497f11af0
2
.github/workflows/ci-docker.yml
vendored
2
.github/workflows/ci-docker.yml
vendored
@ -47,7 +47,7 @@ jobs:
|
|||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.6.0
|
uses: actions/setup-python@v5.6.0
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.11"
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3.11.1
|
uses: docker/setup-buildx-action@v3.11.1
|
||||||
|
|
||||||
|
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@ -20,8 +20,8 @@ permissions:
|
|||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
DEFAULT_PYTHON: "3.10"
|
DEFAULT_PYTHON: "3.11"
|
||||||
PYUPGRADE_TARGET: "--py310-plus"
|
PYUPGRADE_TARGET: "--py311-plus"
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
# yamllint disable-line rule:line-length
|
# yamllint disable-line rule:line-length
|
||||||
@ -112,7 +112,6 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version:
|
python-version:
|
||||||
- "3.10"
|
|
||||||
- "3.11"
|
- "3.11"
|
||||||
- "3.12"
|
- "3.12"
|
||||||
- "3.13"
|
- "3.13"
|
||||||
@ -128,14 +127,10 @@ jobs:
|
|||||||
os: windows-latest
|
os: windows-latest
|
||||||
- python-version: "3.12"
|
- python-version: "3.12"
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
- python-version: "3.10"
|
|
||||||
os: windows-latest
|
|
||||||
- python-version: "3.13"
|
- python-version: "3.13"
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
- python-version: "3.12"
|
- python-version: "3.12"
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
- python-version: "3.10"
|
|
||||||
os: macOS-latest
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
needs:
|
needs:
|
||||||
- common
|
- common
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -96,7 +96,7 @@ jobs:
|
|||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v5.6.0
|
uses: actions/setup-python@v5.6.0
|
||||||
with:
|
with:
|
||||||
python-version: "3.10"
|
python-version: "3.11"
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3.11.1
|
uses: docker/setup-buildx-action@v3.11.1
|
||||||
|
@ -40,7 +40,7 @@ repos:
|
|||||||
rev: v3.20.0
|
rev: v3.20.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py310-plus]
|
args: [--py311-plus]
|
||||||
- repo: https://github.com/adrienverge/yamllint.git
|
- repo: https://github.com/adrienverge/yamllint.git
|
||||||
rev: v1.37.1
|
rev: v1.37.1
|
||||||
hooks:
|
hooks:
|
||||||
|
@ -277,6 +277,34 @@ class APIConnection : public APIServerConnection {
|
|||||||
// Helper function to handle authentication completion
|
// Helper function to handle authentication completion
|
||||||
void complete_authentication_();
|
void complete_authentication_();
|
||||||
|
|
||||||
|
// Helper function to fill common entity info fields
|
||||||
|
static void fill_entity_info_base(esphome::EntityBase *entity, InfoResponseProtoMessage &response) {
|
||||||
|
// Set common fields that are shared by all entity types
|
||||||
|
response.key = entity->get_object_id_hash();
|
||||||
|
response.object_id = entity->get_object_id();
|
||||||
|
|
||||||
|
if (entity->has_own_name())
|
||||||
|
response.name = entity->get_name();
|
||||||
|
|
||||||
|
// Set common EntityBase properties
|
||||||
|
#ifdef USE_ENTITY_ICON
|
||||||
|
response.icon = entity->get_icon();
|
||||||
|
#endif
|
||||||
|
response.disabled_by_default = entity->is_disabled_by_default();
|
||||||
|
response.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category());
|
||||||
|
#ifdef USE_DEVICES
|
||||||
|
response.device_id = entity->get_device_id();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to fill common entity state fields
|
||||||
|
static void fill_entity_state_base(esphome::EntityBase *entity, StateResponseProtoMessage &response) {
|
||||||
|
response.key = entity->get_object_id_hash();
|
||||||
|
#ifdef USE_DEVICES
|
||||||
|
response.device_id = entity->get_device_id();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Non-template helper to encode any ProtoMessage
|
// Non-template helper to encode any ProtoMessage
|
||||||
static uint16_t encode_message_to_buffer(ProtoMessage &msg, uint8_t message_type, APIConnection *conn,
|
static uint16_t encode_message_to_buffer(ProtoMessage &msg, uint8_t message_type, APIConnection *conn,
|
||||||
uint32_t remaining_size, bool is_single);
|
uint32_t remaining_size, bool is_single);
|
||||||
|
@ -189,9 +189,9 @@ class ProtoWriteBuffer {
|
|||||||
* @param field_id Field number (tag) in the protobuf message
|
* @param field_id Field number (tag) in the protobuf message
|
||||||
* @param type Wire type value:
|
* @param type Wire type value:
|
||||||
* - 0: Varint (int32, int64, uint32, uint64, sint32, sint64, bool, enum)
|
* - 0: Varint (int32, int64, uint32, uint64, sint32, sint64, bool, enum)
|
||||||
* - 1: 64-bit (fixed64, sfixed64, double)
|
|
||||||
* - 2: Length-delimited (string, bytes, embedded messages, packed repeated fields)
|
* - 2: Length-delimited (string, bytes, embedded messages, packed repeated fields)
|
||||||
* - 5: 32-bit (fixed32, sfixed32, float)
|
* - 5: 32-bit (fixed32, sfixed32, float)
|
||||||
|
* - Note: Wire type 1 (64-bit fixed) is not supported
|
||||||
*
|
*
|
||||||
* Following https://protobuf.dev/programming-guides/encoding/#structure
|
* Following https://protobuf.dev/programming-guides/encoding/#structure
|
||||||
*/
|
*/
|
||||||
@ -549,14 +549,8 @@ class ProtoSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// NOTE: add_double_field removed - wire type 1 (64-bit: double) not supported
|
||||||
* @brief Calculates and adds the size of a double field to the total message size
|
// to reduce overhead on embedded systems
|
||||||
*/
|
|
||||||
static inline void add_double_field(uint32_t &total_size, uint32_t field_id_size, double value) {
|
|
||||||
if (value != 0.0) {
|
|
||||||
total_size += field_id_size + 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates and adds the size of a fixed32 field to the total message size
|
* @brief Calculates and adds the size of a fixed32 field to the total message size
|
||||||
@ -567,14 +561,8 @@ class ProtoSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// NOTE: add_fixed64_field removed - wire type 1 (64-bit: fixed64) not supported
|
||||||
* @brief Calculates and adds the size of a fixed64 field to the total message size
|
// to reduce overhead on embedded systems
|
||||||
*/
|
|
||||||
static inline void add_fixed64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value) {
|
|
||||||
if (value != 0) {
|
|
||||||
total_size += field_id_size + 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates and adds the size of a sfixed32 field to the total message size
|
* @brief Calculates and adds the size of a sfixed32 field to the total message size
|
||||||
@ -585,14 +573,8 @@ class ProtoSize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// NOTE: add_sfixed64_field removed - wire type 1 (64-bit: sfixed64) not supported
|
||||||
* @brief Calculates and adds the size of a sfixed64 field to the total message size
|
// to reduce overhead on embedded systems
|
||||||
*/
|
|
||||||
static inline void add_sfixed64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) {
|
|
||||||
if (value != 0) {
|
|
||||||
total_size += field_id_size + 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Calculates and adds the size of an enum field to the total message size
|
* @brief Calculates and adds the size of an enum field to the total message size
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
|
||||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0)
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0)
|
||||||
#define SOC_HP_I2C_NUM SOC_I2C_NUM
|
#define SOC_HP_I2C_NUM SOC_I2C_NUM
|
||||||
@ -20,21 +21,72 @@ static const char *const TAG = "i2c.idf";
|
|||||||
void IDFI2CBus::setup() {
|
void IDFI2CBus::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Running setup");
|
ESP_LOGCONFIG(TAG, "Running setup");
|
||||||
static i2c_port_t next_port = I2C_NUM_0;
|
static i2c_port_t next_port = I2C_NUM_0;
|
||||||
port_ = next_port;
|
this->port_ = next_port;
|
||||||
|
if (this->port_ == I2C_NUM_MAX) {
|
||||||
|
ESP_LOGE(TAG, "No more than %u buses supported", I2C_NUM_MAX);
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->timeout_ > 13000) {
|
||||||
|
ESP_LOGW(TAG, "Using max allowed timeout: 13 ms");
|
||||||
|
this->timeout_ = 13000;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->recover_();
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||||
|
next_port = (i2c_port_t) (next_port + 1);
|
||||||
|
|
||||||
|
i2c_master_bus_config_t bus_conf{};
|
||||||
|
memset(&bus_conf, 0, sizeof(bus_conf));
|
||||||
|
bus_conf.sda_io_num = gpio_num_t(sda_pin_);
|
||||||
|
bus_conf.scl_io_num = gpio_num_t(scl_pin_);
|
||||||
|
bus_conf.i2c_port = this->port_;
|
||||||
|
bus_conf.glitch_ignore_cnt = 7;
|
||||||
|
#if SOC_LP_I2C_SUPPORTED
|
||||||
|
if (this->port_ < SOC_HP_I2C_NUM) {
|
||||||
|
bus_conf.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||||
|
} else {
|
||||||
|
bus_conf.lp_source_clk = LP_I2C_SCLK_DEFAULT;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
bus_conf.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||||
|
#endif
|
||||||
|
bus_conf.flags.enable_internal_pullup = sda_pullup_enabled_ || scl_pullup_enabled_;
|
||||||
|
esp_err_t err = i2c_new_master_bus(&bus_conf, &this->bus_);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "i2c_new_master_bus failed: %s", esp_err_to_name(err));
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_device_config_t dev_conf{};
|
||||||
|
memset(&dev_conf, 0, sizeof(dev_conf));
|
||||||
|
dev_conf.dev_addr_length = I2C_ADDR_BIT_LEN_7;
|
||||||
|
dev_conf.device_address = I2C_DEVICE_ADDRESS_NOT_USED;
|
||||||
|
dev_conf.scl_speed_hz = this->frequency_;
|
||||||
|
dev_conf.scl_wait_us = this->timeout_;
|
||||||
|
err = i2c_master_bus_add_device(this->bus_, &dev_conf, &this->dev_);
|
||||||
|
if (err != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "i2c_master_bus_add_device failed: %s", esp_err_to_name(err));
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->initialized_ = true;
|
||||||
|
|
||||||
|
if (this->scan_) {
|
||||||
|
ESP_LOGV(TAG, "Scanning for devices");
|
||||||
|
this->i2c_scan_();
|
||||||
|
}
|
||||||
|
#else
|
||||||
#if SOC_HP_I2C_NUM > 1
|
#if SOC_HP_I2C_NUM > 1
|
||||||
next_port = (next_port == I2C_NUM_0) ? I2C_NUM_1 : I2C_NUM_MAX;
|
next_port = (next_port == I2C_NUM_0) ? I2C_NUM_1 : I2C_NUM_MAX;
|
||||||
#else
|
#else
|
||||||
next_port = I2C_NUM_MAX;
|
next_port = I2C_NUM_MAX;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (port_ == I2C_NUM_MAX) {
|
|
||||||
ESP_LOGE(TAG, "No more than %u buses supported", SOC_HP_I2C_NUM);
|
|
||||||
this->mark_failed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
recover_();
|
|
||||||
|
|
||||||
i2c_config_t conf{};
|
i2c_config_t conf{};
|
||||||
memset(&conf, 0, sizeof(conf));
|
memset(&conf, 0, sizeof(conf));
|
||||||
conf.mode = I2C_MODE_MASTER;
|
conf.mode = I2C_MODE_MASTER;
|
||||||
@ -53,11 +105,7 @@ void IDFI2CBus::setup() {
|
|||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (timeout_ > 0) { // if timeout specified in yaml:
|
if (timeout_ > 0) {
|
||||||
if (timeout_ > 13000) {
|
|
||||||
ESP_LOGW(TAG, "i2c timeout of %" PRIu32 "us greater than max of 13ms on esp-idf, setting to max", timeout_);
|
|
||||||
timeout_ = 13000;
|
|
||||||
}
|
|
||||||
err = i2c_set_timeout(port_, timeout_ * 80); // unit: APB 80MHz clock cycle
|
err = i2c_set_timeout(port_, timeout_ * 80); // unit: APB 80MHz clock cycle
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGW(TAG, "i2c_set_timeout failed: %s", esp_err_to_name(err));
|
ESP_LOGW(TAG, "i2c_set_timeout failed: %s", esp_err_to_name(err));
|
||||||
@ -73,12 +121,15 @@ void IDFI2CBus::setup() {
|
|||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
if (this->scan_) {
|
if (this->scan_) {
|
||||||
ESP_LOGV(TAG, "Scanning bus for active devices");
|
ESP_LOGV(TAG, "Scanning bus for active devices");
|
||||||
this->i2c_scan_();
|
this->i2c_scan_();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDFI2CBus::dump_config() {
|
void IDFI2CBus::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, "I2C Bus:");
|
ESP_LOGCONFIG(TAG, "I2C Bus:");
|
||||||
ESP_LOGCONFIG(TAG,
|
ESP_LOGCONFIG(TAG,
|
||||||
@ -123,6 +174,74 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
|||||||
ESP_LOGVV(TAG, "i2c bus not initialized!");
|
ESP_LOGVV(TAG, "i2c bus not initialized!");
|
||||||
return ERROR_NOT_INITIALIZED;
|
return ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||||
|
i2c_operation_job_t jobs[cnt + 4];
|
||||||
|
uint8_t read = (address << 1) | I2C_MASTER_READ;
|
||||||
|
size_t last = 0, num = 0;
|
||||||
|
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_START;
|
||||||
|
num++;
|
||||||
|
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||||
|
jobs[num].write.ack_check = true;
|
||||||
|
jobs[num].write.data = &read;
|
||||||
|
jobs[num].write.total_bytes = 1;
|
||||||
|
num++;
|
||||||
|
|
||||||
|
// find the last valid index
|
||||||
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
const auto &buf = buffers[i];
|
||||||
|
if (buf.len == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
last = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
const auto &buf = buffers[i];
|
||||||
|
if (buf.len == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i == last) {
|
||||||
|
// the last byte read before stop should always be a nack,
|
||||||
|
// split the last read if len is larger than 1
|
||||||
|
if (buf.len > 1) {
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||||
|
jobs[num].read.ack_value = I2C_ACK_VAL;
|
||||||
|
jobs[num].read.data = (uint8_t *) buf.data;
|
||||||
|
jobs[num].read.total_bytes = buf.len - 1;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||||
|
jobs[num].read.ack_value = I2C_NACK_VAL;
|
||||||
|
jobs[num].read.data = (uint8_t *) buf.data + buf.len - 1;
|
||||||
|
jobs[num].read.total_bytes = 1;
|
||||||
|
num++;
|
||||||
|
} else {
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_READ;
|
||||||
|
jobs[num].read.ack_value = I2C_ACK_VAL;
|
||||||
|
jobs[num].read.data = (uint8_t *) buf.data;
|
||||||
|
jobs[num].read.total_bytes = buf.len;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_STOP;
|
||||||
|
num++;
|
||||||
|
|
||||||
|
esp_err_t err = i2c_master_execute_defined_operations(this->dev_, jobs, num, 20);
|
||||||
|
if (err == ESP_ERR_INVALID_STATE) {
|
||||||
|
ESP_LOGVV(TAG, "RX from %02X failed: not acked", address);
|
||||||
|
return ERROR_NOT_ACKNOWLEDGED;
|
||||||
|
} else if (err == ESP_ERR_TIMEOUT) {
|
||||||
|
ESP_LOGVV(TAG, "RX from %02X failed: timeout", address);
|
||||||
|
return ERROR_TIMEOUT;
|
||||||
|
} else if (err != ESP_OK) {
|
||||||
|
ESP_LOGVV(TAG, "RX from %02X failed: %s", address, esp_err_to_name(err));
|
||||||
|
return ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
#else
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
esp_err_t err = i2c_master_start(cmd);
|
esp_err_t err = i2c_master_start(cmd);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
@ -168,6 +287,7 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
|||||||
ESP_LOGVV(TAG, "RX from %02X failed: %s", address, esp_err_to_name(err));
|
ESP_LOGVV(TAG, "RX from %02X failed: %s", address, esp_err_to_name(err));
|
||||||
return ERROR_UNKNOWN;
|
return ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
||||||
char debug_buf[4];
|
char debug_buf[4];
|
||||||
@ -185,6 +305,7 @@ ErrorCode IDFI2CBus::readv(uint8_t address, ReadBuffer *buffers, size_t cnt) {
|
|||||||
|
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) {
|
ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, bool stop) {
|
||||||
// logging is only enabled with vv level, if warnings are shown the caller
|
// logging is only enabled with vv level, if warnings are shown the caller
|
||||||
// should log them
|
// should log them
|
||||||
@ -207,6 +328,49 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b
|
|||||||
ESP_LOGVV(TAG, "0x%02X TX %s", address, debug_hex.c_str());
|
ESP_LOGVV(TAG, "0x%02X TX %s", address, debug_hex.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||||
|
i2c_operation_job_t jobs[cnt + 3];
|
||||||
|
uint8_t write = (address << 1) | I2C_MASTER_WRITE;
|
||||||
|
size_t num = 0;
|
||||||
|
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_START;
|
||||||
|
num++;
|
||||||
|
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||||
|
jobs[num].write.ack_check = true;
|
||||||
|
jobs[num].write.data = &write;
|
||||||
|
jobs[num].write.total_bytes = 1;
|
||||||
|
num++;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < cnt; i++) {
|
||||||
|
const auto &buf = buffers[i];
|
||||||
|
if (buf.len == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_WRITE;
|
||||||
|
jobs[num].write.ack_check = true;
|
||||||
|
jobs[num].write.data = (uint8_t *) buf.data;
|
||||||
|
jobs[num].write.total_bytes = buf.len;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stop) {
|
||||||
|
jobs[num].command = I2C_MASTER_CMD_STOP;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t err = i2c_master_execute_defined_operations(this->dev_, jobs, num, 20);
|
||||||
|
if (err == ESP_ERR_INVALID_STATE) {
|
||||||
|
ESP_LOGVV(TAG, "TX to %02X failed: not acked", address);
|
||||||
|
return ERROR_NOT_ACKNOWLEDGED;
|
||||||
|
} else if (err == ESP_ERR_TIMEOUT) {
|
||||||
|
ESP_LOGVV(TAG, "TX to %02X failed: timeout", address);
|
||||||
|
return ERROR_TIMEOUT;
|
||||||
|
} else if (err != ESP_OK) {
|
||||||
|
ESP_LOGVV(TAG, "TX to %02X failed: %s", address, esp_err_to_name(err));
|
||||||
|
return ERROR_UNKNOWN;
|
||||||
|
}
|
||||||
|
#else
|
||||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||||
esp_err_t err = i2c_master_start(cmd);
|
esp_err_t err = i2c_master_start(cmd);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
@ -252,6 +416,7 @@ ErrorCode IDFI2CBus::writev(uint8_t address, WriteBuffer *buffers, size_t cnt, b
|
|||||||
ESP_LOGVV(TAG, "TX to %02X failed: %s", address, esp_err_to_name(err));
|
ESP_LOGVV(TAG, "TX to %02X failed: %s", address, esp_err_to_name(err));
|
||||||
return ERROR_UNKNOWN;
|
return ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
|
|
||||||
#include <driver/i2c.h>
|
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "i2c_bus.h"
|
#include "i2c_bus.h"
|
||||||
|
#include "esp_idf_version.h"
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||||
|
#include <driver/i2c_master.h>
|
||||||
|
#else
|
||||||
|
#include <driver/i2c.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace i2c {
|
namespace i2c {
|
||||||
@ -38,6 +43,10 @@ class IDFI2CBus : public InternalI2CBus, public Component {
|
|||||||
RecoveryCode recovery_result_;
|
RecoveryCode recovery_result_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 2)
|
||||||
|
i2c_master_dev_handle_t dev_;
|
||||||
|
i2c_master_bus_handle_t bus_;
|
||||||
|
#endif
|
||||||
i2c_port_t port_;
|
i2c_port_t port_;
|
||||||
uint8_t sda_pin_;
|
uint8_t sda_pin_;
|
||||||
bool sda_pullup_enabled_;
|
bool sda_pullup_enabled_;
|
||||||
|
@ -76,6 +76,7 @@ async def theme_to_code(config):
|
|||||||
for w_name, style in theme.items():
|
for w_name, style in theme.items():
|
||||||
# Work around Python 3.10 bug with nested async comprehensions
|
# Work around Python 3.10 bug with nested async comprehensions
|
||||||
# With Python 3.11 this could be simplified
|
# With Python 3.11 this could be simplified
|
||||||
|
# TODO: Now that we require Python 3.11+, this can be updated to use nested comprehensions
|
||||||
styles = {}
|
styles = {}
|
||||||
for part, states in collect_parts(style).items():
|
for part, states in collect_parts(style).items():
|
||||||
styles[part] = {
|
styles[part] = {
|
||||||
|
@ -50,6 +50,7 @@ optional<float> MedianFilter::new_value(float value) {
|
|||||||
if (!this->queue_.empty()) {
|
if (!this->queue_.empty()) {
|
||||||
// Copy queue without NaN values
|
// Copy queue without NaN values
|
||||||
std::vector<float> median_queue;
|
std::vector<float> median_queue;
|
||||||
|
median_queue.reserve(this->queue_.size());
|
||||||
for (auto v : this->queue_) {
|
for (auto v : this->queue_) {
|
||||||
if (!std::isnan(v)) {
|
if (!std::isnan(v)) {
|
||||||
median_queue.push_back(v);
|
median_queue.push_back(v);
|
||||||
|
@ -3,15 +3,9 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
import sys
|
|
||||||
|
|
||||||
from icmplib import NameLookupError, async_resolve
|
from icmplib import NameLookupError, async_resolve
|
||||||
|
|
||||||
if sys.version_info >= (3, 11):
|
|
||||||
from asyncio import timeout as async_timeout
|
|
||||||
else:
|
|
||||||
from async_timeout import timeout as async_timeout
|
|
||||||
|
|
||||||
RESOLVE_TIMEOUT = 3.0
|
RESOLVE_TIMEOUT = 3.0
|
||||||
|
|
||||||
|
|
||||||
@ -20,9 +14,9 @@ async def _async_resolve_wrapper(hostname: str) -> list[str] | Exception:
|
|||||||
with suppress(ValueError):
|
with suppress(ValueError):
|
||||||
return [str(ip_address(hostname))]
|
return [str(ip_address(hostname))]
|
||||||
try:
|
try:
|
||||||
async with async_timeout(RESOLVE_TIMEOUT):
|
async with asyncio.timeout(RESOLVE_TIMEOUT):
|
||||||
return await async_resolve(hostname)
|
return await async_resolve(hostname)
|
||||||
except (asyncio.TimeoutError, NameLookupError, UnicodeError) as ex:
|
except (TimeoutError, NameLookupError, UnicodeError) as ex:
|
||||||
return ex
|
return ex
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ classifiers = [
|
|||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Topic :: Home Automation",
|
"Topic :: Home Automation",
|
||||||
]
|
]
|
||||||
requires-python = ">=3.10.0"
|
requires-python = ">=3.11.0"
|
||||||
|
|
||||||
dynamic = ["dependencies", "optional-dependencies", "version"]
|
dynamic = ["dependencies", "optional-dependencies", "version"]
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ addopts = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[tool.pylint.MAIN]
|
[tool.pylint.MAIN]
|
||||||
py-version = "3.10"
|
py-version = "3.11"
|
||||||
ignore = [
|
ignore = [
|
||||||
"api_pb2.py",
|
"api_pb2.py",
|
||||||
]
|
]
|
||||||
@ -106,7 +106,7 @@ expected-line-ending-format = "LF"
|
|||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
required-version = ">=0.5.0"
|
required-version = ">=0.5.0"
|
||||||
target-version = "py310"
|
target-version = "py311"
|
||||||
exclude = ['generated']
|
exclude = ['generated']
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
async_timeout==5.0.1; python_version <= "3.10"
|
|
||||||
cryptography==45.0.1
|
cryptography==45.0.1
|
||||||
voluptuous==0.15.2
|
voluptuous==0.15.2
|
||||||
PyYAML==6.0.2
|
PyYAML==6.0.2
|
||||||
|
@ -137,7 +137,7 @@ def main():
|
|||||||
print()
|
print()
|
||||||
print("Running pyupgrade...")
|
print("Running pyupgrade...")
|
||||||
print()
|
print()
|
||||||
PYUPGRADE_TARGET = "--py310-plus"
|
PYUPGRADE_TARGET = "--py311-plus"
|
||||||
for files in filesets:
|
for files in filesets:
|
||||||
cmd = ["pyupgrade", PYUPGRADE_TARGET] + files
|
cmd = ["pyupgrade", PYUPGRADE_TARGET] + files
|
||||||
log = get_err(*cmd)
|
log = get_err(*cmd)
|
||||||
|
@ -395,7 +395,7 @@ async def wait_and_connect_api_client(
|
|||||||
# Wait for connection with timeout
|
# Wait for connection with timeout
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(connected_future, timeout=timeout)
|
await asyncio.wait_for(connected_future, timeout=timeout)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
raise TimeoutError(f"Failed to connect to API after {timeout} seconds")
|
raise TimeoutError(f"Failed to connect to API after {timeout} seconds")
|
||||||
|
|
||||||
yield client
|
yield client
|
||||||
@ -575,12 +575,12 @@ async def run_binary_and_wait_for_port(
|
|||||||
process.send_signal(signal.SIGINT)
|
process.send_signal(signal.SIGINT)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(process.wait(), timeout=SIGINT_TIMEOUT)
|
await asyncio.wait_for(process.wait(), timeout=SIGINT_TIMEOUT)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
# If SIGINT didn't work, try SIGTERM
|
# If SIGINT didn't work, try SIGTERM
|
||||||
process.terminate()
|
process.terminate()
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(process.wait(), timeout=SIGTERM_TIMEOUT)
|
await asyncio.wait_for(process.wait(), timeout=SIGTERM_TIMEOUT)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
# Last resort: SIGKILL
|
# Last resort: SIGKILL
|
||||||
process.kill()
|
process.kill()
|
||||||
await process.wait()
|
await process.wait()
|
||||||
|
@ -177,7 +177,7 @@ async def test_api_message_size_batching(
|
|||||||
# Wait for states with timeout
|
# Wait for states with timeout
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(states_future, timeout=5.0)
|
await asyncio.wait_for(states_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
missing_keys = expected_keys - received_keys
|
missing_keys = expected_keys - received_keys
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive states from all entities within 5 seconds. "
|
f"Did not receive states from all entities within 5 seconds. "
|
||||||
|
@ -29,7 +29,7 @@ async def test_api_reboot_timeout(
|
|||||||
# (0.5s reboot timeout + some margin for processing)
|
# (0.5s reboot timeout + some margin for processing)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(reboot_future, timeout=2.0)
|
await asyncio.wait_for(reboot_future, timeout=2.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Device did not reboot within expected timeout")
|
pytest.fail("Device did not reboot within expected timeout")
|
||||||
|
|
||||||
# Test passes if we get here - reboot was detected
|
# Test passes if we get here - reboot was detected
|
||||||
|
@ -98,7 +98,7 @@ async def test_areas_and_devices(
|
|||||||
# Wait for sensor states
|
# Wait for sensor states
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(states_future, timeout=10.0)
|
await asyncio.wait_for(states_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive all sensor states within 10 seconds. "
|
f"Did not receive all sensor states within 10 seconds. "
|
||||||
f"Received {len(states)} states"
|
f"Received {len(states)} states"
|
||||||
|
@ -77,7 +77,7 @@ async def test_device_id_in_state(
|
|||||||
# Wait for states
|
# Wait for states
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(states_future, timeout=10.0)
|
await asyncio.wait_for(states_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive all entity states within 10 seconds. "
|
f"Did not receive all entity states within 10 seconds. "
|
||||||
f"Received {len(states)} states, expected {len(entity_device_mapping)}"
|
f"Received {len(states)} states, expected {len(entity_device_mapping)}"
|
||||||
|
@ -206,7 +206,7 @@ async def test_duplicate_entities_not_allowed_on_different_devices(
|
|||||||
# Wait for all entity states
|
# Wait for all entity states
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(states_future, timeout=10.0)
|
await asyncio.wait_for(states_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive all entity states within 10 seconds. "
|
f"Did not receive all entity states within 10 seconds. "
|
||||||
f"Expected {expected_count}, received {state_count}"
|
f"Expected {expected_count}, received {state_count}"
|
||||||
|
@ -82,7 +82,7 @@ async def test_entity_icon(
|
|||||||
# Wait for states
|
# Wait for states
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(state_received.wait(), timeout=5.0)
|
await asyncio.wait_for(state_received.wait(), timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("No states received within 5 seconds")
|
pytest.fail("No states received within 5 seconds")
|
||||||
|
|
||||||
# Verify we received states
|
# Verify we received states
|
||||||
|
@ -44,7 +44,7 @@ async def test_host_mode_batch_delay(
|
|||||||
# Wait for states from all entities with timeout
|
# Wait for states from all entities with timeout
|
||||||
try:
|
try:
|
||||||
entity_count = await asyncio.wait_for(entity_count_future, timeout=5.0)
|
entity_count = await asyncio.wait_for(entity_count_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive states from at least 7 entities within 5 seconds. "
|
f"Did not receive states from at least 7 entities within 5 seconds. "
|
||||||
f"Received {len(states)} states"
|
f"Received {len(states)} states"
|
||||||
|
@ -99,7 +99,7 @@ async def test_host_mode_empty_string_options(
|
|||||||
# Wait for initial states with timeout
|
# Wait for initial states with timeout
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(states_received_future, timeout=5.0)
|
await asyncio.wait_for(states_received_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Did not receive states for all select entities. "
|
f"Did not receive states for all select entities. "
|
||||||
f"Expected keys: {expected_select_keys}, Received: {received_select_keys}"
|
f"Expected keys: {expected_select_keys}, Received: {received_select_keys}"
|
||||||
|
@ -86,7 +86,7 @@ async def test_host_mode_entity_fields(
|
|||||||
# Wait for at least one state
|
# Wait for at least one state
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(state_received.wait(), timeout=5.0)
|
await asyncio.wait_for(state_received.wait(), timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("No states received within 5 seconds")
|
pytest.fail("No states received within 5 seconds")
|
||||||
|
|
||||||
# Verify we received states (which means has_state flag is working)
|
# Verify we received states (which means has_state flag is working)
|
||||||
|
@ -41,7 +41,7 @@ async def test_host_mode_many_entities(
|
|||||||
# Wait for states from at least 50 sensors with timeout
|
# Wait for states from at least 50 sensors with timeout
|
||||||
try:
|
try:
|
||||||
sensor_count = await asyncio.wait_for(sensor_count_future, timeout=10.0)
|
sensor_count = await asyncio.wait_for(sensor_count_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
sensor_states = [
|
sensor_states = [
|
||||||
s
|
s
|
||||||
for s in states.values()
|
for s in states.values()
|
||||||
|
@ -50,7 +50,7 @@ async def test_host_mode_many_entities_multiple_connections(
|
|||||||
asyncio.wait_for(client1_ready, timeout=10.0),
|
asyncio.wait_for(client1_ready, timeout=10.0),
|
||||||
asyncio.wait_for(client2_ready, timeout=10.0),
|
asyncio.wait_for(client2_ready, timeout=10.0),
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"One or both clients did not receive enough states within 10 seconds. "
|
f"One or both clients did not receive enough states within 10 seconds. "
|
||||||
f"Client1: {len(states1)}, Client2: {len(states2)}"
|
f"Client1: {len(states1)}, Client2: {len(states2)}"
|
||||||
|
@ -40,7 +40,7 @@ async def test_host_mode_with_sensor(
|
|||||||
# Wait for sensor with specific value (42.0) with timeout
|
# Wait for sensor with specific value (42.0) with timeout
|
||||||
try:
|
try:
|
||||||
test_sensor_state = await asyncio.wait_for(sensor_future, timeout=5.0)
|
test_sensor_state = await asyncio.wait_for(sensor_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Sensor with value 42.0 not received within 5 seconds. "
|
f"Sensor with value 42.0 not received within 5 seconds. "
|
||||||
f"Received states: {list(states.values())}"
|
f"Received states: {list(states.values())}"
|
||||||
|
@ -150,7 +150,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for self_disable_10 to disable itself
|
# Wait for self_disable_10 to disable itself
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self_disable_10_disabled.wait(), timeout=10.0)
|
await asyncio.wait_for(self_disable_10_disabled.wait(), timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("self_disable_10 did not disable itself within 10 seconds")
|
pytest.fail("self_disable_10 did not disable itself within 10 seconds")
|
||||||
|
|
||||||
# Verify it ran at least 10 times before disabling
|
# Verify it ran at least 10 times before disabling
|
||||||
@ -164,7 +164,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for normal_component to run at least 10 times
|
# Wait for normal_component to run at least 10 times
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(normal_component_10_loops.wait(), timeout=10.0)
|
await asyncio.wait_for(normal_component_10_loops.wait(), timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"normal_component did not reach 10 loops within timeout, got {len(normal_component_counts)}"
|
f"normal_component did not reach 10 loops within timeout, got {len(normal_component_counts)}"
|
||||||
)
|
)
|
||||||
@ -172,12 +172,12 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for redundant operation tests
|
# Wait for redundant operation tests
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(redundant_enable_tested.wait(), timeout=10.0)
|
await asyncio.wait_for(redundant_enable_tested.wait(), timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("redundant_enable did not test enabling when already enabled")
|
pytest.fail("redundant_enable did not test enabling when already enabled")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(redundant_disable_tested.wait(), timeout=10.0)
|
await asyncio.wait_for(redundant_disable_tested.wait(), timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
"redundant_disable did not test disabling when will be disabled"
|
"redundant_disable did not test disabling when will be disabled"
|
||||||
)
|
)
|
||||||
@ -185,7 +185,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait to see if self_disable_10 gets re-enabled
|
# Wait to see if self_disable_10 gets re-enabled
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self_disable_10_re_enabled.wait(), timeout=5.0)
|
await asyncio.wait_for(self_disable_10_re_enabled.wait(), timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("self_disable_10 was not re-enabled within 5 seconds")
|
pytest.fail("self_disable_10 was not re-enabled within 5 seconds")
|
||||||
|
|
||||||
# Component was re-enabled - verify it ran more times
|
# Component was re-enabled - verify it ran more times
|
||||||
@ -198,7 +198,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for ISR component to disable itself after 5 loops
|
# Wait for ISR component to disable itself after 5 loops
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(isr_component_disabled.wait(), timeout=3.0)
|
await asyncio.wait_for(isr_component_disabled.wait(), timeout=3.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("ISR component did not disable itself within 3 seconds")
|
pytest.fail("ISR component did not disable itself within 3 seconds")
|
||||||
|
|
||||||
# Verify it ran exactly 5 times before disabling
|
# Verify it ran exactly 5 times before disabling
|
||||||
@ -210,7 +210,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for component to be re-enabled by periodic ISR simulation and run again
|
# Wait for component to be re-enabled by periodic ISR simulation and run again
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(isr_component_re_enabled.wait(), timeout=2.0)
|
await asyncio.wait_for(isr_component_re_enabled.wait(), timeout=2.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("ISR component was not re-enabled after ISR call")
|
pytest.fail("ISR component was not re-enabled after ISR call")
|
||||||
|
|
||||||
# Verify it's running again after ISR enable
|
# Verify it's running again after ISR enable
|
||||||
@ -222,7 +222,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for pure ISR enable (no main loop enable) to work
|
# Wait for pure ISR enable (no main loop enable) to work
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(isr_component_pure_re_enabled.wait(), timeout=2.0)
|
await asyncio.wait_for(isr_component_pure_re_enabled.wait(), timeout=2.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("ISR component was not re-enabled by pure ISR call")
|
pytest.fail("ISR component was not re-enabled by pure ISR call")
|
||||||
|
|
||||||
# Verify it ran after pure ISR enable
|
# Verify it ran after pure ISR enable
|
||||||
@ -235,7 +235,7 @@ async def test_loop_disable_enable(
|
|||||||
# Wait for update component to disable its loop
|
# Wait for update component to disable its loop
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(update_component_loop_disabled.wait(), timeout=3.0)
|
await asyncio.wait_for(update_component_loop_disabled.wait(), timeout=3.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Update component did not disable its loop within 3 seconds")
|
pytest.fail("Update component did not disable its loop within 3 seconds")
|
||||||
|
|
||||||
# Verify it ran exactly 3 loops before disabling
|
# Verify it ran exactly 3 loops before disabling
|
||||||
@ -248,7 +248,7 @@ async def test_loop_disable_enable(
|
|||||||
await asyncio.wait_for(
|
await asyncio.wait_for(
|
||||||
update_component_manual_update_called.wait(), timeout=5.0
|
update_component_manual_update_called.wait(), timeout=5.0
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Manual component.update was not called within 5 seconds")
|
pytest.fail("Manual component.update was not called within 5 seconds")
|
||||||
|
|
||||||
# The key test: verify that manual component.update worked after loop was disabled
|
# The key test: verify that manual component.update worked after loop was disabled
|
||||||
|
@ -103,7 +103,7 @@ async def test_scheduler_bulk_cleanup(
|
|||||||
# Wait for test completion
|
# Wait for test completion
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Bulk cleanup test timed out")
|
pytest.fail("Bulk cleanup test timed out")
|
||||||
|
|
||||||
# Verify bulk cleanup was triggered
|
# Verify bulk cleanup was triggered
|
||||||
|
@ -85,7 +85,7 @@ async def test_scheduler_defer_cancel(
|
|||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
executed_defer = await asyncio.wait_for(test_result_future, timeout=1.0)
|
executed_defer = await asyncio.wait_for(test_result_future, timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Test did not complete within timeout")
|
pytest.fail("Test did not complete within timeout")
|
||||||
|
|
||||||
# Verify that only defer 10 was executed
|
# Verify that only defer 10 was executed
|
||||||
|
@ -64,7 +64,7 @@ async def test_scheduler_defer_cancels_regular(
|
|||||||
# Wait for test completion
|
# Wait for test completion
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(f"Test timed out. Log messages: {log_messages}")
|
pytest.fail(f"Test timed out. Log messages: {log_messages}")
|
||||||
|
|
||||||
# Verify results
|
# Verify results
|
||||||
|
@ -90,7 +90,7 @@ async def test_scheduler_defer_fifo_simple(
|
|||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
||||||
test1_passed = await asyncio.wait_for(test_result_future, timeout=1.0)
|
test1_passed = await asyncio.wait_for(test_result_future, timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Test set_timeout(0) did not complete within 5 seconds")
|
pytest.fail("Test set_timeout(0) did not complete within 5 seconds")
|
||||||
|
|
||||||
assert test1_passed is True, (
|
assert test1_passed is True, (
|
||||||
@ -108,7 +108,7 @@ async def test_scheduler_defer_fifo_simple(
|
|||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
||||||
test2_passed = await asyncio.wait_for(test_result_future, timeout=1.0)
|
test2_passed = await asyncio.wait_for(test_result_future, timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Test defer() did not complete within 5 seconds")
|
pytest.fail("Test defer() did not complete within 5 seconds")
|
||||||
|
|
||||||
# Verify the test passed
|
# Verify the test passed
|
||||||
|
@ -97,7 +97,7 @@ async def test_scheduler_defer_stress(
|
|||||||
# Wait for all defers to execute (should be quick)
|
# Wait for all defers to execute (should be quick)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
await asyncio.wait_for(test_complete_future, timeout=5.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
# Report how many we got
|
# Report how many we got
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Stress test timed out. Only {len(executed_defers)} of "
|
f"Stress test timed out. Only {len(executed_defers)} of "
|
||||||
|
@ -104,7 +104,7 @@ async def test_scheduler_heap_stress(
|
|||||||
# Wait for all callbacks to execute (should be quick, but give more time for scheduling)
|
# Wait for all callbacks to execute (should be quick, but give more time for scheduling)
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=60.0)
|
await asyncio.wait_for(test_complete_future, timeout=60.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
# Report how many we got
|
# Report how many we got
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Stress test timed out. Only {len(executed_callbacks)} of "
|
f"Stress test timed out. Only {len(executed_callbacks)} of "
|
||||||
|
@ -53,7 +53,7 @@ async def test_scheduler_null_name(
|
|||||||
# Wait for test completion
|
# Wait for test completion
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
"Test did not complete within timeout - likely crashed due to NULL name"
|
"Test did not complete within timeout - likely crashed due to NULL name"
|
||||||
)
|
)
|
||||||
|
@ -112,7 +112,7 @@ async def test_scheduler_rapid_cancellation(
|
|||||||
# Wait for test to complete with timeout
|
# Wait for test to complete with timeout
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(f"Test timed out. Stats: {test_stats}")
|
pytest.fail(f"Test timed out. Stats: {test_stats}")
|
||||||
|
|
||||||
# Check for any errors
|
# Check for any errors
|
||||||
|
@ -84,7 +84,7 @@ async def test_scheduler_recursive_timeout(
|
|||||||
# Wait for test to complete
|
# Wait for test to complete
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
await asyncio.wait_for(test_complete_future, timeout=10.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"Recursive timeout test timed out. Got sequence: {execution_sequence}"
|
f"Recursive timeout test timed out. Got sequence: {execution_sequence}"
|
||||||
)
|
)
|
||||||
|
@ -103,7 +103,7 @@ async def test_scheduler_simultaneous_callbacks(
|
|||||||
# Wait for test to complete
|
# Wait for test to complete
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=30.0)
|
await asyncio.wait_for(test_complete_future, timeout=30.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(f"Simultaneous callbacks test timed out. Stats: {test_stats}")
|
pytest.fail(f"Simultaneous callbacks test timed out. Stats: {test_stats}")
|
||||||
|
|
||||||
# Check for any errors
|
# Check for any errors
|
||||||
|
@ -157,7 +157,7 @@ async def test_scheduler_string_lifetime(
|
|||||||
client.execute_service(test_services["final"], {})
|
client.execute_service(test_services["final"], {})
|
||||||
await asyncio.wait_for(all_tests_complete.wait(), timeout=5.0)
|
await asyncio.wait_for(all_tests_complete.wait(), timeout=5.0)
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(f"String lifetime test timed out. Stats: {test_stats}")
|
pytest.fail(f"String lifetime test timed out. Stats: {test_stats}")
|
||||||
|
|
||||||
# Check for any errors
|
# Check for any errors
|
||||||
|
@ -97,7 +97,7 @@ async def test_scheduler_string_name_stress(
|
|||||||
# Wait for test to complete or crash
|
# Wait for test to complete or crash
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(test_complete_future, timeout=30.0)
|
await asyncio.wait_for(test_complete_future, timeout=30.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail(
|
pytest.fail(
|
||||||
f"String name stress test timed out. Executed {len(executed_callbacks)} callbacks. "
|
f"String name stress test timed out. Executed {len(executed_callbacks)} callbacks. "
|
||||||
f"This might indicate a deadlock."
|
f"This might indicate a deadlock."
|
||||||
|
@ -122,22 +122,22 @@ async def test_scheduler_string_test(
|
|||||||
# Wait for static string tests
|
# Wait for static string tests
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_timeout_1_fired.wait(), timeout=0.5)
|
await asyncio.wait_for(static_timeout_1_fired.wait(), timeout=0.5)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static timeout 1 did not fire within 0.5 seconds")
|
pytest.fail("Static timeout 1 did not fire within 0.5 seconds")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_timeout_2_fired.wait(), timeout=0.5)
|
await asyncio.wait_for(static_timeout_2_fired.wait(), timeout=0.5)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static timeout 2 did not fire within 0.5 seconds")
|
pytest.fail("Static timeout 2 did not fire within 0.5 seconds")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_interval_fired.wait(), timeout=1.0)
|
await asyncio.wait_for(static_interval_fired.wait(), timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static interval did not fire within 1 second")
|
pytest.fail("Static interval did not fire within 1 second")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_interval_cancelled.wait(), timeout=2.0)
|
await asyncio.wait_for(static_interval_cancelled.wait(), timeout=2.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static interval was not cancelled within 2 seconds")
|
pytest.fail("Static interval was not cancelled within 2 seconds")
|
||||||
|
|
||||||
# Verify static interval ran at least 3 times
|
# Verify static interval ran at least 3 times
|
||||||
@ -153,41 +153,41 @@ async def test_scheduler_string_test(
|
|||||||
# Wait for static defer tests
|
# Wait for static defer tests
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_defer_1_fired.wait(), timeout=0.5)
|
await asyncio.wait_for(static_defer_1_fired.wait(), timeout=0.5)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static defer 1 did not fire within 0.5 seconds")
|
pytest.fail("Static defer 1 did not fire within 0.5 seconds")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(static_defer_2_fired.wait(), timeout=0.5)
|
await asyncio.wait_for(static_defer_2_fired.wait(), timeout=0.5)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Static defer 2 did not fire within 0.5 seconds")
|
pytest.fail("Static defer 2 did not fire within 0.5 seconds")
|
||||||
|
|
||||||
# Wait for dynamic string tests
|
# Wait for dynamic string tests
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(dynamic_timeout_fired.wait(), timeout=1.0)
|
await asyncio.wait_for(dynamic_timeout_fired.wait(), timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Dynamic timeout did not fire within 1 second")
|
pytest.fail("Dynamic timeout did not fire within 1 second")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(dynamic_interval_fired.wait(), timeout=1.5)
|
await asyncio.wait_for(dynamic_interval_fired.wait(), timeout=1.5)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Dynamic interval did not fire within 1.5 seconds")
|
pytest.fail("Dynamic interval did not fire within 1.5 seconds")
|
||||||
|
|
||||||
# Wait for dynamic defer test
|
# Wait for dynamic defer test
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(dynamic_defer_fired.wait(), timeout=1.0)
|
await asyncio.wait_for(dynamic_defer_fired.wait(), timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Dynamic defer did not fire within 1 second")
|
pytest.fail("Dynamic defer did not fire within 1 second")
|
||||||
|
|
||||||
# Wait for cancel test
|
# Wait for cancel test
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(cancel_test_done.wait(), timeout=1.0)
|
await asyncio.wait_for(cancel_test_done.wait(), timeout=1.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Cancel test did not complete within 1 second")
|
pytest.fail("Cancel test did not complete within 1 second")
|
||||||
|
|
||||||
# Wait for final results
|
# Wait for final results
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(final_results_logged.wait(), timeout=4.0)
|
await asyncio.wait_for(final_results_logged.wait(), timeout=4.0)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
pytest.fail("Final results were not logged within 4 seconds")
|
pytest.fail("Final results were not logged within 4 seconds")
|
||||||
|
|
||||||
# Verify results
|
# Verify results
|
||||||
|
Loading…
x
Reference in New Issue
Block a user