From 833d31ef7a0fdef1c434ec1d188b13a9e74d0091 Mon Sep 17 00:00:00 2001 From: mkmer Date: Sun, 5 May 2024 18:48:09 -0400 Subject: [PATCH 1/5] Add fast update to HMC5883L (#6669) --- esphome/components/hmc5883l/hmc5883l.cpp | 5 +++++ esphome/components/hmc5883l/hmc5883l.h | 1 + 2 files changed, 6 insertions(+) diff --git a/esphome/components/hmc5883l/hmc5883l.cpp b/esphome/components/hmc5883l/hmc5883l.cpp index de3903d7e2..24f4b3f8f1 100644 --- a/esphome/components/hmc5883l/hmc5883l.cpp +++ b/esphome/components/hmc5883l/hmc5883l.cpp @@ -1,5 +1,6 @@ #include "hmc5883l.h" #include "esphome/core/log.h" +#include "esphome/core/application.h" namespace esphome { namespace hmc5883l { @@ -31,6 +32,10 @@ void HMC5883LComponent::setup() { return; } + if (this->get_update_interval() < App.get_loop_interval()) { + high_freq_.start(); + } + if (id[0] != 0x48 || id[1] != 0x34 || id[2] != 0x33) { this->error_code_ = ID_REGISTERS; this->mark_failed(); diff --git a/esphome/components/hmc5883l/hmc5883l.h b/esphome/components/hmc5883l/hmc5883l.h index 3481f45dc8..06fba2af9d 100644 --- a/esphome/components/hmc5883l/hmc5883l.h +++ b/esphome/components/hmc5883l/hmc5883l.h @@ -63,6 +63,7 @@ class HMC5883LComponent : public PollingComponent, public i2c::I2CDevice { COMMUNICATION_FAILED, ID_REGISTERS, } error_code_; + HighFrequencyLoopRequester high_freq_; }; } // namespace hmc5883l From 599dbf27e068e4c69ad60b78ec11c5e46bb32992 Mon Sep 17 00:00:00 2001 From: Anton Viktorov Date: Mon, 6 May 2024 04:19:25 +0200 Subject: [PATCH 2/5] Minor tidy up of BME280 code (#6672) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/bme280_base/__init__.py | 107 ++++++++++++++++++ esphome/components/bme280_base/sensor.py | 106 ----------------- esphome/components/bme280_i2c/sensor.py | 8 +- esphome/components/bme280_spi/__init__.py | 1 - esphome/components/bme280_spi/bme280_spi.cpp | 29 +++-- esphome/components/bme280_spi/sensor.py | 13 +-- tests/components/bme280_i2c/common.yaml | 19 ++++ .../bme280_i2c/test.esp32-c3-idf.yaml | 21 +--- .../components/bme280_i2c/test.esp32-c3.yaml | 21 +--- .../components/bme280_i2c/test.esp32-idf.yaml | 21 +--- tests/components/bme280_i2c/test.esp32.yaml | 21 +--- tests/components/bme280_i2c/test.esp8266.yaml | 21 +--- tests/components/bme280_i2c/test.rp2040.yaml | 21 +--- tests/components/bme280_spi/common.yaml | 20 ++++ .../bme280_spi/test.esp32-c3-idf.yaml | 24 +--- .../components/bme280_spi/test.esp32-c3.yaml | 24 +--- .../components/bme280_spi/test.esp32-idf.yaml | 24 +--- tests/components/bme280_spi/test.esp32.yaml | 24 +--- tests/components/bme280_spi/test.esp8266.yaml | 24 +--- tests/components/bme280_spi/test.rp2040.yaml | 24 +--- tests/test1.yaml | 29 ----- 21 files changed, 231 insertions(+), 371 deletions(-) delete mode 100644 esphome/components/bme280_base/sensor.py create mode 100644 tests/components/bme280_i2c/common.yaml create mode 100644 tests/components/bme280_spi/common.yaml diff --git a/esphome/components/bme280_base/__init__.py b/esphome/components/bme280_base/__init__.py index f70ffa9520..6a5f7e1127 100644 --- a/esphome/components/bme280_base/__init__.py +++ b/esphome/components/bme280_base/__init__.py @@ -1 +1,108 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import sensor +from esphome.const import ( + CONF_HUMIDITY, + CONF_ID, + CONF_IIR_FILTER, + CONF_OVERSAMPLING, + CONF_PRESSURE, + CONF_TEMPERATURE, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_PRESSURE, + DEVICE_CLASS_TEMPERATURE, + STATE_CLASS_MEASUREMENT, + UNIT_CELSIUS, + UNIT_HECTOPASCAL, + UNIT_PERCENT, +) + CODEOWNERS = ["@esphome/core"] + +bme280_ns = cg.esphome_ns.namespace("bme280_base") +BME280Oversampling = bme280_ns.enum("BME280Oversampling") +OVERSAMPLING_OPTIONS = { + "NONE": BME280Oversampling.BME280_OVERSAMPLING_NONE, + "1X": BME280Oversampling.BME280_OVERSAMPLING_1X, + "2X": BME280Oversampling.BME280_OVERSAMPLING_2X, + "4X": BME280Oversampling.BME280_OVERSAMPLING_4X, + "8X": BME280Oversampling.BME280_OVERSAMPLING_8X, + "16X": BME280Oversampling.BME280_OVERSAMPLING_16X, +} + +BME280IIRFilter = bme280_ns.enum("BME280IIRFilter") +IIR_FILTER_OPTIONS = { + "OFF": BME280IIRFilter.BME280_IIR_FILTER_OFF, + "2X": BME280IIRFilter.BME280_IIR_FILTER_2X, + "4X": BME280IIRFilter.BME280_IIR_FILTER_4X, + "8X": BME280IIRFilter.BME280_IIR_FILTER_8X, + "16X": BME280IIRFilter.BME280_IIR_FILTER_16X, +} + +CONFIG_SCHEMA_BASE = cv.Schema( + { + cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( + unit_of_measurement=UNIT_CELSIUS, + accuracy_decimals=1, + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ).extend( + { + cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( + OVERSAMPLING_OPTIONS, upper=True + ), + } + ), + cv.Optional(CONF_PRESSURE): sensor.sensor_schema( + unit_of_measurement=UNIT_HECTOPASCAL, + accuracy_decimals=1, + device_class=DEVICE_CLASS_PRESSURE, + state_class=STATE_CLASS_MEASUREMENT, + ).extend( + { + cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( + OVERSAMPLING_OPTIONS, upper=True + ), + } + ), + cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( + unit_of_measurement=UNIT_PERCENT, + accuracy_decimals=1, + device_class=DEVICE_CLASS_HUMIDITY, + state_class=STATE_CLASS_MEASUREMENT, + ).extend( + { + cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( + OVERSAMPLING_OPTIONS, upper=True + ), + } + ), + cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum( + IIR_FILTER_OPTIONS, upper=True + ), + } +).extend(cv.polling_component_schema("60s")) + + +async def to_code_base(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cg.register_component(var, config) + + if temperature_config := config.get(CONF_TEMPERATURE): + sens = await sensor.new_sensor(temperature_config) + cg.add(var.set_temperature_sensor(sens)) + cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING])) + + if pressure_config := config.get(CONF_PRESSURE): + sens = await sensor.new_sensor(pressure_config) + cg.add(var.set_pressure_sensor(sens)) + cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING])) + + if humidity_config := config.get(CONF_HUMIDITY): + sens = await sensor.new_sensor(humidity_config) + cg.add(var.set_humidity_sensor(sens)) + cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING])) + + cg.add(var.set_iir_filter(config[CONF_IIR_FILTER])) + + return var diff --git a/esphome/components/bme280_base/sensor.py b/esphome/components/bme280_base/sensor.py deleted file mode 100644 index 3a745ed348..0000000000 --- a/esphome/components/bme280_base/sensor.py +++ /dev/null @@ -1,106 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor -from esphome.const import ( - CONF_HUMIDITY, - CONF_ID, - CONF_IIR_FILTER, - CONF_OVERSAMPLING, - CONF_PRESSURE, - CONF_TEMPERATURE, - DEVICE_CLASS_HUMIDITY, - DEVICE_CLASS_PRESSURE, - DEVICE_CLASS_TEMPERATURE, - STATE_CLASS_MEASUREMENT, - UNIT_CELSIUS, - UNIT_HECTOPASCAL, - UNIT_PERCENT, -) - -bme280_ns = cg.esphome_ns.namespace("bme280_base") -BME280Oversampling = bme280_ns.enum("BME280Oversampling") -OVERSAMPLING_OPTIONS = { - "NONE": BME280Oversampling.BME280_OVERSAMPLING_NONE, - "1X": BME280Oversampling.BME280_OVERSAMPLING_1X, - "2X": BME280Oversampling.BME280_OVERSAMPLING_2X, - "4X": BME280Oversampling.BME280_OVERSAMPLING_4X, - "8X": BME280Oversampling.BME280_OVERSAMPLING_8X, - "16X": BME280Oversampling.BME280_OVERSAMPLING_16X, -} - -BME280IIRFilter = bme280_ns.enum("BME280IIRFilter") -IIR_FILTER_OPTIONS = { - "OFF": BME280IIRFilter.BME280_IIR_FILTER_OFF, - "2X": BME280IIRFilter.BME280_IIR_FILTER_2X, - "4X": BME280IIRFilter.BME280_IIR_FILTER_4X, - "8X": BME280IIRFilter.BME280_IIR_FILTER_8X, - "16X": BME280IIRFilter.BME280_IIR_FILTER_16X, -} - -CONFIG_SCHEMA_BASE = cv.Schema( - { - cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ).extend( - { - cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( - OVERSAMPLING_OPTIONS, upper=True - ), - } - ), - cv.Optional(CONF_PRESSURE): sensor.sensor_schema( - unit_of_measurement=UNIT_HECTOPASCAL, - accuracy_decimals=1, - device_class=DEVICE_CLASS_PRESSURE, - state_class=STATE_CLASS_MEASUREMENT, - ).extend( - { - cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( - OVERSAMPLING_OPTIONS, upper=True - ), - } - ), - cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - accuracy_decimals=1, - device_class=DEVICE_CLASS_HUMIDITY, - state_class=STATE_CLASS_MEASUREMENT, - ).extend( - { - cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum( - OVERSAMPLING_OPTIONS, upper=True - ), - } - ), - cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum( - IIR_FILTER_OPTIONS, upper=True - ), - } -).extend(cv.polling_component_schema("60s")) - - -async def to_code(config, func=None): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - if func is not None: - await func(var, config) - - if temperature_config := config.get(CONF_TEMPERATURE): - sens = await sensor.new_sensor(temperature_config) - cg.add(var.set_temperature_sensor(sens)) - cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING])) - - if pressure_config := config.get(CONF_PRESSURE): - sens = await sensor.new_sensor(pressure_config) - cg.add(var.set_pressure_sensor(sens)) - cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING])) - - if humidity_config := config.get(CONF_HUMIDITY): - sens = await sensor.new_sensor(humidity_config) - cg.add(var.set_humidity_sensor(sens)) - cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING])) - - cg.add(var.set_iir_filter(config[CONF_IIR_FILTER])) diff --git a/esphome/components/bme280_i2c/sensor.py b/esphome/components/bme280_i2c/sensor.py index 489c52969d..f3007ebaac 100644 --- a/esphome/components/bme280_i2c/sensor.py +++ b/esphome/components/bme280_i2c/sensor.py @@ -1,9 +1,10 @@ import esphome.codegen as cg +import esphome.config_validation as cv from esphome.components import i2c -from ..bme280_base.sensor import to_code as to_code_base, cv, CONFIG_SCHEMA_BASE +from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE -DEPENDENCIES = ["i2c"] AUTO_LOAD = ["bme280_base"] +DEPENDENCIES = ["i2c"] bme280_ns = cg.esphome_ns.namespace("bme280_i2c") BME280I2CComponent = bme280_ns.class_( @@ -16,4 +17,5 @@ CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend( async def to_code(config): - await to_code_base(config, func=i2c.register_i2c_device) + var = await to_code_base(config) + await i2c.register_i2c_device(var, config) diff --git a/esphome/components/bme280_spi/__init__.py b/esphome/components/bme280_spi/__init__.py index a1d33e4d7a..e69de29bb2 100644 --- a/esphome/components/bme280_spi/__init__.py +++ b/esphome/components/bme280_spi/__init__.py @@ -1 +0,0 @@ -CODEOWNERS = ["@apbodrov"] diff --git a/esphome/components/bme280_spi/bme280_spi.cpp b/esphome/components/bme280_spi/bme280_spi.cpp index 921128c8f5..c6ebfdfd0b 100644 --- a/esphome/components/bme280_spi/bme280_spi.cpp +++ b/esphome/components/bme280_spi/bme280_spi.cpp @@ -4,19 +4,19 @@ #include "bme280_spi.h" #include -int set_bit(uint8_t num, int position) { +namespace esphome { +namespace bme280_spi { + +uint8_t set_bit(uint8_t num, int position) { int mask = 1 << position; return num | mask; } -int clear_bit(uint8_t num, int position) { +uint8_t clear_bit(uint8_t num, int position) { int mask = 1 << position; return num & ~mask; } -namespace esphome { -namespace bme280_spi { - void BME280SPIComponent::setup() { this->spi_setup(); BME280Component::setup(); @@ -30,34 +30,33 @@ void BME280SPIComponent::setup() { bool BME280SPIComponent::read_byte(uint8_t a_register, uint8_t *data) { this->enable(); - // cause: *data = this->delegate_->transfer(tmp) doesnt work - this->delegate_->transfer(set_bit(a_register, 7)); - *data = this->delegate_->transfer(0); + this->transfer_byte(set_bit(a_register, 7)); + *data = this->transfer_byte(0); this->disable(); return true; } bool BME280SPIComponent::write_byte(uint8_t a_register, uint8_t data) { this->enable(); - this->delegate_->transfer(clear_bit(a_register, 7)); - this->delegate_->transfer(data); + this->transfer_byte(clear_bit(a_register, 7)); + this->transfer_byte(data); this->disable(); return true; } bool BME280SPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) { this->enable(); - this->delegate_->transfer(set_bit(a_register, 7)); - this->delegate_->read_array(data, len); + this->transfer_byte(set_bit(a_register, 7)); + this->read_array(data, len); this->disable(); return true; } bool BME280SPIComponent::read_byte_16(uint8_t a_register, uint16_t *data) { this->enable(); - this->delegate_->transfer(set_bit(a_register, 7)); - ((uint8_t *) data)[1] = this->delegate_->transfer(0); - ((uint8_t *) data)[0] = this->delegate_->transfer(0); + this->transfer_byte(set_bit(a_register, 7)); + ((uint8_t *) data)[1] = this->transfer_byte(0); + ((uint8_t *) data)[0] = this->transfer_byte(0); this->disable(); return true; } diff --git a/esphome/components/bme280_spi/sensor.py b/esphome/components/bme280_spi/sensor.py index 3cfe1b3cdd..33a12318a5 100644 --- a/esphome/components/bme280_spi/sensor.py +++ b/esphome/components/bme280_spi/sensor.py @@ -1,13 +1,11 @@ import esphome.codegen as cg +import esphome.config_validation as cv from esphome.components import spi -from esphome.components.bme280_base.sensor import ( - to_code as to_code_base, - cv, - CONFIG_SCHEMA_BASE, -) +from ..bme280_base import to_code_base, CONFIG_SCHEMA_BASE -DEPENDENCIES = ["spi"] AUTO_LOAD = ["bme280_base"] +CODEOWNERS = ["@apbodrov"] +DEPENDENCIES = ["spi"] bme280_spi_ns = cg.esphome_ns.namespace("bme280_spi") @@ -21,4 +19,5 @@ CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend(spi.spi_device_schema()).extend( async def to_code(config): - await to_code_base(config, func=spi.register_spi_device) + var = await to_code_base(config) + await spi.register_spi_device(var, config) diff --git a/tests/components/bme280_i2c/common.yaml b/tests/components/bme280_i2c/common.yaml new file mode 100644 index 0000000000..e74ce9bf6d --- /dev/null +++ b/tests/components/bme280_i2c/common.yaml @@ -0,0 +1,19 @@ +i2c: + - id: i2c_bme280 + scl: ${scl_pin} + sda: ${sda_pin} + +sensor: + - platform: bme280_i2c + i2c_id: i2c_bme280 + address: 0x76 + temperature: + id: bme280_temperature + name: BME280 Temperature + humidity: + id: bme280_humidity + name: BME280 Humidity + pressure: + id: bme280_pressure + name: BME280 Pressure + update_interval: 15s diff --git a/tests/components/bme280_i2c/test.esp32-c3-idf.yaml b/tests/components/bme280_i2c/test.esp32-c3-idf.yaml index 070c2845d9..ee2c29ca4e 100644 --- a/tests/components/bme280_i2c/test.esp32-c3-idf.yaml +++ b/tests/components/bme280_i2c/test.esp32-c3-idf.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 5 - sda: 4 +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_i2c/test.esp32-c3.yaml b/tests/components/bme280_i2c/test.esp32-c3.yaml index 070c2845d9..ee2c29ca4e 100644 --- a/tests/components/bme280_i2c/test.esp32-c3.yaml +++ b/tests/components/bme280_i2c/test.esp32-c3.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 5 - sda: 4 +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_i2c/test.esp32-idf.yaml b/tests/components/bme280_i2c/test.esp32-idf.yaml index e379b98874..63c3bd6afd 100644 --- a/tests/components/bme280_i2c/test.esp32-idf.yaml +++ b/tests/components/bme280_i2c/test.esp32-idf.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 16 - sda: 17 +substitutions: + scl_pin: GPIO16 + sda_pin: GPIO17 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_i2c/test.esp32.yaml b/tests/components/bme280_i2c/test.esp32.yaml index e379b98874..63c3bd6afd 100644 --- a/tests/components/bme280_i2c/test.esp32.yaml +++ b/tests/components/bme280_i2c/test.esp32.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 16 - sda: 17 +substitutions: + scl_pin: GPIO16 + sda_pin: GPIO17 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_i2c/test.esp8266.yaml b/tests/components/bme280_i2c/test.esp8266.yaml index 070c2845d9..ee2c29ca4e 100644 --- a/tests/components/bme280_i2c/test.esp8266.yaml +++ b/tests/components/bme280_i2c/test.esp8266.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 5 - sda: 4 +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_i2c/test.rp2040.yaml b/tests/components/bme280_i2c/test.rp2040.yaml index 070c2845d9..ee2c29ca4e 100644 --- a/tests/components/bme280_i2c/test.rp2040.yaml +++ b/tests/components/bme280_i2c/test.rp2040.yaml @@ -1,18 +1,5 @@ -i2c: - - id: i2c_bme280 - scl: 5 - sda: 4 +substitutions: + scl_pin: GPIO5 + sda_pin: GPIO4 -sensor: - - platform: bme280_i2c - address: 0x76 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/common.yaml b/tests/components/bme280_spi/common.yaml new file mode 100644 index 0000000000..303ecf9f73 --- /dev/null +++ b/tests/components/bme280_spi/common.yaml @@ -0,0 +1,20 @@ +spi: + - id: spi_bme280 + clk_pin: ${clk_pin} + mosi_pin: ${mosi_pin} + miso_pin: ${miso_pin} + +sensor: + - platform: bme280_spi + spi_id: spi_bme280 + cs_pin: ${cs_pin} + temperature: + id: bme280_temperature + name: BME280 Temperature + humidity: + id: bme280_humidity + name: BME280 Humidity + pressure: + id: bme280_pressure + name: BME280 Pressure + update_interval: 15s diff --git a/tests/components/bme280_spi/test.esp32-c3-idf.yaml b/tests/components/bme280_spi/test.esp32-c3-idf.yaml index 4bc7c14e6c..2415ba5dc6 100644 --- a/tests/components/bme280_spi/test.esp32-c3-idf.yaml +++ b/tests/components/bme280_spi/test.esp32-c3-idf.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 6 - mosi_pin: 7 - miso_pin: 5 +substitutions: + clk_pin: GPIO6 + mosi_pin: GPIO7 + miso_pin: GPIO5 + cs_pin: GPIO8 -sensor: - - platform: bme280_spi - cs_pin: 8 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/test.esp32-c3.yaml b/tests/components/bme280_spi/test.esp32-c3.yaml index 4bc7c14e6c..2415ba5dc6 100644 --- a/tests/components/bme280_spi/test.esp32-c3.yaml +++ b/tests/components/bme280_spi/test.esp32-c3.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 6 - mosi_pin: 7 - miso_pin: 5 +substitutions: + clk_pin: GPIO6 + mosi_pin: GPIO7 + miso_pin: GPIO5 + cs_pin: GPIO8 -sensor: - - platform: bme280_spi - cs_pin: 8 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/test.esp32-idf.yaml b/tests/components/bme280_spi/test.esp32-idf.yaml index ebb3d98213..54e027a614 100644 --- a/tests/components/bme280_spi/test.esp32-idf.yaml +++ b/tests/components/bme280_spi/test.esp32-idf.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 16 - mosi_pin: 17 - miso_pin: 15 +substitutions: + clk_pin: GPIO16 + mosi_pin: GPIO17 + miso_pin: GPIO15 + cs_pin: GPIO5 -sensor: - - platform: bme280_spi - cs_pin: 12 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/test.esp32.yaml b/tests/components/bme280_spi/test.esp32.yaml index ebb3d98213..54e027a614 100644 --- a/tests/components/bme280_spi/test.esp32.yaml +++ b/tests/components/bme280_spi/test.esp32.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 16 - mosi_pin: 17 - miso_pin: 15 +substitutions: + clk_pin: GPIO16 + mosi_pin: GPIO17 + miso_pin: GPIO15 + cs_pin: GPIO5 -sensor: - - platform: bme280_spi - cs_pin: 12 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/test.esp8266.yaml b/tests/components/bme280_spi/test.esp8266.yaml index 63013abb87..dbd158d030 100644 --- a/tests/components/bme280_spi/test.esp8266.yaml +++ b/tests/components/bme280_spi/test.esp8266.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 14 - mosi_pin: 13 - miso_pin: 12 +substitutions: + clk_pin: GPIO14 + mosi_pin: GPIO13 + miso_pin: GPIO12 + cs_pin: GPIO15 -sensor: - - platform: bme280_spi - cs_pin: 15 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/components/bme280_spi/test.rp2040.yaml b/tests/components/bme280_spi/test.rp2040.yaml index ba5cb483c6..f6c3f1eeca 100644 --- a/tests/components/bme280_spi/test.rp2040.yaml +++ b/tests/components/bme280_spi/test.rp2040.yaml @@ -1,19 +1,7 @@ -spi: - - id: spi_bme280 - clk_pin: 2 - mosi_pin: 3 - miso_pin: 4 +substitutions: + clk_pin: GPIO2 + mosi_pin: GPIO3 + miso_pin: GPIO4 + cs_pin: GPIO5 -sensor: - - platform: bme280_spi - cs_pin: 6 - temperature: - id: bme280_temperature - name: BME280 Temperature - humidity: - id: bme280_humidity - name: BME280 Humidity - pressure: - id: bme280_pressure - name: BME280 Pressure - update_interval: 15s +<<: !include common.yaml diff --git a/tests/test1.yaml b/tests/test1.yaml index 09994afa42..79b836da4a 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -705,35 +705,6 @@ sensor: update_interval: 30s mode: low_power i2c_id: i2c_bus - - platform: bme280_i2c - temperature: - name: Outside Temperature - oversampling: 16x - pressure: - name: Outside Pressure - oversampling: none - humidity: - name: Outside Humidity - oversampling: 8x - address: 0x77 - iir_filter: 16x - update_interval: 15s - i2c_id: i2c_bus - - platform: bme280_spi - temperature: - name: Outside Temperature - oversampling: 16x - pressure: - name: Outside Pressure - oversampling: none - humidity: - name: Outside Humidity - oversampling: 8x - cs_pin: - allow_other_uses: true - number: GPIO23 - iir_filter: 16x - update_interval: 15s - platform: bme680 temperature: name: Outside Temperature From f2caaf85c89f35fb65d136f38f558da62eb442fa Mon Sep 17 00:00:00 2001 From: Tomek Wasilczyk Date: Sun, 5 May 2024 20:19:13 -0700 Subject: [PATCH 3/5] External components: optional configurable path for git source (#6677) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/external_components/__init__.py | 11 ++++++++++- esphome/config_validation.py | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/esphome/components/external_components/__init__.py b/esphome/components/external_components/__init__.py index bbb703dc5c..f4432a0362 100644 --- a/esphome/components/external_components/__init__.py +++ b/esphome/components/external_components/__init__.py @@ -49,7 +49,16 @@ def _process_git_config(config: dict, refresh) -> str: password=config.get(CONF_PASSWORD), ) - if (repo_dir / "esphome" / "components").is_dir(): + if path := config.get(CONF_PATH): + if (repo_dir / path).is_dir(): + components_dir = repo_dir / path + else: + raise cv.Invalid( + "Could not find components folder for source. Please check the source contains a '" + + path + + "' folder" + ) + elif (repo_dir / "esphome" / "components").is_dir(): components_dir = repo_dir / "esphome" / "components" elif (repo_dir / "components").is_dir(): components_dir = repo_dir / "components" diff --git a/esphome/config_validation.py b/esphome/config_validation.py index 198b44f38d..3554f03836 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -2124,6 +2124,7 @@ GIT_SCHEMA = Schema( Optional(CONF_REF): git_ref, Optional(CONF_USERNAME): string, Optional(CONF_PASSWORD): string, + Optional(CONF_PATH): string, } ) LOCAL_SCHEMA = Schema( From d1758a46bd24c9631e55d500d61da7ff522627e7 Mon Sep 17 00:00:00 2001 From: Markus <974709+Links2004@users.noreply.github.com> Date: Mon, 6 May 2024 21:17:03 +0200 Subject: [PATCH 4/5] Use clang-apply-replacements when clang-apply-replacements-14 does not exist (#6684) --- script/clang-tidy | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/clang-tidy b/script/clang-tidy index 97e4ba0d48..84b02306d5 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -266,7 +266,12 @@ def main(): if args.fix and failed_files: print("Applying fixes ...") try: - subprocess.call(["clang-apply-replacements-14", tmpdir]) + try: + subprocess.call(["clang-apply-replacements-14", tmpdir]) + except FileNotFoundError: + subprocess.call(["clang-apply-replacements", tmpdir]) + except FileNotFoundError: + print("Error please install clang-apply-replacements-14 or clang-apply-replacements.\n", file=sys.stderr) except: print("Error applying fixes.\n", file=sys.stderr) raise From 8463f897e1a7992c87c608270394563dee6e9a66 Mon Sep 17 00:00:00 2001 From: tomaszduda23 Date: Mon, 6 May 2024 21:20:01 +0200 Subject: [PATCH 5/5] fix conflict with EMPTY macro in zephyr (#6679) --- esphome/core/automation.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 8c3da5e7e8..9b62640a0c 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -24,7 +24,7 @@ template struct gens<0, S...> { using type = seq; }; // NOLINT template class TemplatableValue { public: - TemplatableValue() : type_(EMPTY) {} + TemplatableValue() : type_(NONE) {} template::value, int> = 0> TemplatableValue(F value) : type_(VALUE), value_(value) {} @@ -32,13 +32,13 @@ template class TemplatableValue { template::value, int> = 0> TemplatableValue(F f) : type_(LAMBDA), f_(f) {} - bool has_value() { return this->type_ != EMPTY; } + bool has_value() { return this->type_ != NONE; } T value(X... x) { if (this->type_ == LAMBDA) { return this->f_(x...); } - // return value also when empty + // return value also when none return this->value_; } @@ -58,7 +58,7 @@ template class TemplatableValue { protected: enum { - EMPTY, + NONE, VALUE, LAMBDA, } type_;