From 71193e2b2cbfffc46f925263eb8b80c61ef875a8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 7 May 2026 13:21:35 -0500 Subject: [PATCH 01/52] [helpers] Document write_file's external consumer contract (esphome-device-builder) (#16290) --- esphome/helpers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/esphome/helpers.py b/esphome/helpers.py index bb1984e17cb..9d341af1461 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -465,6 +465,12 @@ def _write_file( def write_file(path: Path, text: str | bytes, private: bool = False) -> None: + """Atomically write text or bytes to path. Wraps OSError as EsphomeError. + + Used by esphome-device-builder for in-place YAML rewrites; the + atomicity (sibling tempfile + shutil.move) and EsphomeError + wrapping are part of the public contract. + """ try: _write_file(path, text, private=private) except OSError as err: From 06bd92c3880c575a366f7b8e6fb77f74fd200937 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 14:21:39 -0400 Subject: [PATCH 02/52] [clang-tidy] Concatenate nested namespaces (1/7: components a-c) (#16294) --- esphome/components/a01nyub/a01nyub.cpp | 6 ++---- esphome/components/a01nyub/a01nyub.h | 6 ++---- esphome/components/a02yyuw/a02yyuw.cpp | 6 ++---- esphome/components/a02yyuw/a02yyuw.h | 6 ++---- esphome/components/a4988/a4988.cpp | 6 ++---- esphome/components/a4988/a4988.h | 6 ++---- esphome/components/adalight/adalight_light_effect.cpp | 6 ++---- esphome/components/adalight/adalight_light_effect.h | 6 ++---- esphome/components/adc/adc_sensor.h | 6 ++---- esphome/components/adc/adc_sensor_common.cpp | 6 ++---- esphome/components/adc/adc_sensor_esp32.cpp | 6 ++---- esphome/components/adc128s102/adc128s102.cpp | 6 ++---- esphome/components/adc128s102/adc128s102.h | 6 ++---- .../components/adc128s102/sensor/adc128s102_sensor.cpp | 6 ++---- esphome/components/adc128s102/sensor/adc128s102_sensor.h | 6 ++---- .../addressable_light/addressable_light_display.cpp | 6 ++---- .../addressable_light/addressable_light_display.h | 6 ++---- esphome/components/ade7880/ade7880.cpp | 6 ++---- esphome/components/ade7880/ade7880.h | 6 ++---- esphome/components/ade7880/ade7880_i2c.cpp | 6 ++---- esphome/components/ade7880/ade7880_registers.h | 6 ++---- esphome/components/ade7953_base/ade7953_base.cpp | 6 ++---- esphome/components/ade7953_base/ade7953_base.h | 6 ++---- esphome/components/ade7953_i2c/ade7953_i2c.cpp | 6 ++---- esphome/components/ade7953_i2c/ade7953_i2c.h | 6 ++---- esphome/components/ade7953_spi/ade7953_spi.cpp | 6 ++---- esphome/components/ade7953_spi/ade7953_spi.h | 6 ++---- esphome/components/ads1115/ads1115.cpp | 6 ++---- esphome/components/ads1115/ads1115.h | 6 ++---- esphome/components/ads1115/sensor/ads1115_sensor.cpp | 6 ++---- esphome/components/ads1115/sensor/ads1115_sensor.h | 6 ++---- esphome/components/ads1118/ads1118.cpp | 6 ++---- esphome/components/ads1118/ads1118.h | 6 ++---- esphome/components/ads1118/sensor/ads1118_sensor.cpp | 6 ++---- esphome/components/ads1118/sensor/ads1118_sensor.h | 6 ++---- esphome/components/ags10/ags10.cpp | 6 ++---- esphome/components/ags10/ags10.h | 6 ++---- esphome/components/aht10/aht10.cpp | 6 ++---- esphome/components/aht10/aht10.h | 6 ++---- esphome/components/aic3204/aic3204.cpp | 6 ++---- esphome/components/aic3204/aic3204.h | 6 ++---- esphome/components/aic3204/automation.h | 6 ++---- esphome/components/airthings_ble/airthings_listener.cpp | 6 ++---- esphome/components/airthings_ble/airthings_listener.h | 6 ++---- .../airthings_wave_base/airthings_wave_base.cpp | 6 ++---- .../components/airthings_wave_base/airthings_wave_base.h | 6 ++---- .../airthings_wave_mini/airthings_wave_mini.cpp | 6 ++---- .../components/airthings_wave_mini/airthings_wave_mini.h | 6 ++---- .../airthings_wave_plus/airthings_wave_plus.cpp | 6 ++---- .../components/airthings_wave_plus/airthings_wave_plus.h | 6 ++---- esphome/components/alpha3/alpha3.cpp | 6 ++---- esphome/components/alpha3/alpha3.h | 6 ++---- esphome/components/am2315c/am2315c.cpp | 6 ++---- esphome/components/am2315c/am2315c.h | 6 ++---- esphome/components/am2320/am2320.cpp | 6 ++---- esphome/components/am2320/am2320.h | 6 ++---- esphome/components/am43/am43_base.cpp | 6 ++---- esphome/components/am43/am43_base.h | 6 ++---- esphome/components/am43/cover/am43_cover.cpp | 6 ++---- esphome/components/am43/cover/am43_cover.h | 6 ++---- esphome/components/am43/sensor/am43_sensor.cpp | 6 ++---- esphome/components/am43/sensor/am43_sensor.h | 6 ++---- .../analog_threshold/analog_threshold_binary_sensor.cpp | 6 ++---- .../analog_threshold/analog_threshold_binary_sensor.h | 6 ++---- esphome/components/animation/animation.cpp | 6 ++---- esphome/components/animation/animation.h | 6 ++---- esphome/components/anova/anova.cpp | 6 ++---- esphome/components/anova/anova.h | 6 ++---- esphome/components/anova/anova_base.cpp | 6 ++---- esphome/components/anova/anova_base.h | 6 ++---- esphome/components/apds9306/apds9306.cpp | 6 ++---- esphome/components/apds9306/apds9306.h | 6 ++---- esphome/components/apds9960/apds9960.cpp | 6 ++---- esphome/components/apds9960/apds9960.h | 6 ++---- esphome/components/as3935/as3935.cpp | 6 ++---- esphome/components/as3935/as3935.h | 6 ++---- esphome/components/as3935_i2c/as3935_i2c.cpp | 6 ++---- esphome/components/as3935_i2c/as3935_i2c.h | 6 ++---- esphome/components/as3935_spi/as3935_spi.cpp | 6 ++---- esphome/components/as3935_spi/as3935_spi.h | 6 ++---- esphome/components/as5600/as5600.cpp | 6 ++---- esphome/components/as5600/as5600.h | 6 ++---- esphome/components/as5600/sensor/as5600_sensor.cpp | 6 ++---- esphome/components/as5600/sensor/as5600_sensor.h | 6 ++---- esphome/components/as7341/as7341.cpp | 6 ++---- esphome/components/as7341/as7341.h | 6 ++---- esphome/components/at581x/at581x.cpp | 6 ++---- esphome/components/at581x/at581x.h | 6 ++---- esphome/components/at581x/automation.h | 6 ++---- esphome/components/at581x/switch/rf_switch.cpp | 6 ++---- esphome/components/at581x/switch/rf_switch.h | 6 ++---- .../components/atc_mithermometer/atc_mithermometer.cpp | 6 ++---- esphome/components/atc_mithermometer/atc_mithermometer.h | 6 ++---- esphome/components/atm90e26/atm90e26.cpp | 6 ++---- esphome/components/atm90e26/atm90e26.h | 6 ++---- esphome/components/atm90e26/atm90e26_reg.h | 6 ++---- esphome/components/atm90e32/atm90e32.cpp | 6 ++---- esphome/components/atm90e32/atm90e32.h | 6 ++---- esphome/components/atm90e32/atm90e32_reg.h | 6 ++---- esphome/components/atm90e32/button/atm90e32_button.cpp | 6 ++---- esphome/components/atm90e32/button/atm90e32_button.h | 6 ++---- esphome/components/atm90e32/number/atm90e32_number.h | 6 ++---- esphome/components/audio/audio.cpp | 6 ++---- esphome/components/audio/audio.h | 6 ++---- esphome/components/audio/audio_decoder.cpp | 6 ++---- esphome/components/audio/audio_decoder.h | 6 ++---- esphome/components/audio/audio_reader.cpp | 6 ++---- esphome/components/audio/audio_reader.h | 6 ++---- esphome/components/audio/audio_resampler.cpp | 6 ++---- esphome/components/audio/audio_resampler.h | 6 ++---- esphome/components/audio/audio_transfer_buffer.cpp | 6 ++---- esphome/components/audio/audio_transfer_buffer.h | 6 ++---- esphome/components/audio_adc/audio_adc.h | 6 ++---- esphome/components/audio_adc/automation.h | 6 ++---- esphome/components/audio_dac/audio_dac.h | 6 ++---- esphome/components/audio_dac/automation.h | 6 ++---- .../axs15231/touchscreen/axs15231_touchscreen.cpp | 6 ++---- .../axs15231/touchscreen/axs15231_touchscreen.h | 6 ++---- esphome/components/b_parasite/b_parasite.cpp | 6 ++---- esphome/components/b_parasite/b_parasite.h | 6 ++---- esphome/components/ballu/ballu.cpp | 6 ++---- esphome/components/ballu/ballu.h | 6 ++---- esphome/components/bang_bang/bang_bang_climate.cpp | 6 ++---- esphome/components/bang_bang/bang_bang_climate.h | 6 ++---- esphome/components/bedjet/bedjet_child.h | 6 ++---- esphome/components/bedjet/bedjet_codec.cpp | 6 ++---- esphome/components/bedjet/bedjet_codec.h | 6 ++---- esphome/components/bedjet/bedjet_const.h | 6 ++---- esphome/components/bedjet/bedjet_hub.cpp | 6 ++---- esphome/components/bedjet/bedjet_hub.h | 6 ++---- esphome/components/bedjet/climate/bedjet_climate.cpp | 6 ++---- esphome/components/bedjet/climate/bedjet_climate.h | 6 ++---- esphome/components/bedjet/fan/bedjet_fan.cpp | 6 ++---- esphome/components/bedjet/fan/bedjet_fan.h | 6 ++---- esphome/components/bedjet/sensor/bedjet_sensor.cpp | 6 ++---- esphome/components/bedjet/sensor/bedjet_sensor.h | 6 ++---- esphome/components/bh1900nux/bh1900nux.cpp | 6 ++---- esphome/components/bh1900nux/bh1900nux.h | 6 ++---- esphome/components/binary/fan/binary_fan.cpp | 6 ++---- esphome/components/binary/fan/binary_fan.h | 6 ++---- esphome/components/binary/light/binary_light_output.h | 6 ++---- .../components/binary_sensor_map/binary_sensor_map.cpp | 6 ++---- esphome/components/binary_sensor_map/binary_sensor_map.h | 6 ++---- esphome/components/bl0906/bl0906.cpp | 6 ++---- esphome/components/bl0906/bl0906.h | 6 ++---- esphome/components/bl0906/constants.h | 6 ++---- esphome/components/bl0939/bl0939.cpp | 6 ++---- esphome/components/bl0939/bl0939.h | 6 ++---- esphome/components/bl0940/bl0940.cpp | 6 ++---- esphome/components/bl0940/bl0940.h | 6 ++---- .../components/bl0940/button/calibration_reset_button.cpp | 6 ++---- .../components/bl0940/button/calibration_reset_button.h | 6 ++---- esphome/components/bl0940/number/calibration_number.cpp | 6 ++---- esphome/components/bl0940/number/calibration_number.h | 6 ++---- esphome/components/bl0942/bl0942.cpp | 6 ++---- esphome/components/bl0942/bl0942.h | 6 ++---- esphome/components/ble_presence/ble_presence_device.cpp | 6 ++---- esphome/components/ble_presence/ble_presence_device.h | 6 ++---- esphome/components/ble_rssi/ble_rssi_sensor.cpp | 6 ++---- esphome/components/ble_rssi/ble_rssi_sensor.h | 6 ++---- esphome/components/ble_scanner/ble_scanner.cpp | 6 ++---- esphome/components/ble_scanner/ble_scanner.h | 6 ++---- esphome/components/bme280_base/bme280_base.cpp | 6 ++---- esphome/components/bme280_base/bme280_base.h | 6 ++---- esphome/components/bme280_i2c/bme280_i2c.cpp | 6 ++---- esphome/components/bme280_i2c/bme280_i2c.h | 6 ++---- esphome/components/bme280_spi/bme280_spi.cpp | 6 ++---- esphome/components/bme280_spi/bme280_spi.h | 6 ++---- esphome/components/bme680/bme680.cpp | 6 ++---- esphome/components/bme680/bme680.h | 6 ++---- esphome/components/bme680_bsec/bme680_bsec.cpp | 6 ++---- esphome/components/bme680_bsec/bme680_bsec.h | 6 ++---- esphome/components/bmi160/bmi160.cpp | 6 ++---- esphome/components/bmi160/bmi160.h | 6 ++---- esphome/components/bmp085/bmp085.cpp | 6 ++---- esphome/components/bmp085/bmp085.h | 6 ++---- esphome/components/bmp280_base/bmp280_base.cpp | 6 ++---- esphome/components/bmp280_base/bmp280_base.h | 6 ++---- esphome/components/bmp280_i2c/bmp280_i2c.cpp | 6 ++---- esphome/components/bmp280_i2c/bmp280_i2c.h | 6 ++---- esphome/components/bmp280_spi/bmp280_spi.cpp | 6 ++---- esphome/components/bmp280_spi/bmp280_spi.h | 6 ++---- esphome/components/bmp3xx_base/bmp3xx_base.cpp | 6 ++---- esphome/components/bmp3xx_base/bmp3xx_base.h | 6 ++---- esphome/components/bmp3xx_i2c/bmp3xx_i2c.cpp | 6 ++---- esphome/components/bmp3xx_i2c/bmp3xx_i2c.h | 6 ++---- esphome/components/bmp3xx_spi/bmp3xx_spi.cpp | 6 ++---- esphome/components/bmp3xx_spi/bmp3xx_spi.h | 6 ++---- esphome/components/bp1658cj/bp1658cj.cpp | 6 ++---- esphome/components/bp1658cj/bp1658cj.h | 6 ++---- esphome/components/bp5758d/bp5758d.cpp | 6 ++---- esphome/components/bp5758d/bp5758d.h | 6 ++---- esphome/components/bthome_mithermometer/bthome_ble.cpp | 6 ++---- esphome/components/bthome_mithermometer/bthome_ble.h | 6 ++---- esphome/components/bytebuffer/bytebuffer.h | 6 ++---- esphome/components/camera/camera.cpp | 6 ++---- esphome/components/camera/camera.h | 6 ++---- esphome/components/canbus/canbus.cpp | 6 ++---- esphome/components/canbus/canbus.h | 6 ++---- esphome/components/cap1188/cap1188.cpp | 6 ++---- esphome/components/cap1188/cap1188.h | 6 ++---- esphome/components/captive_portal/captive_portal.cpp | 7 +++---- esphome/components/captive_portal/captive_portal.h | 8 +++----- esphome/components/ccs811/ccs811.cpp | 6 ++---- esphome/components/ccs811/ccs811.h | 6 ++---- esphome/components/cd74hc4067/cd74hc4067.cpp | 6 ++---- esphome/components/cd74hc4067/cd74hc4067.h | 6 ++---- esphome/components/ch422g/ch422g.cpp | 6 ++---- esphome/components/ch422g/ch422g.h | 6 ++---- esphome/components/chsc6x/chsc6x_touchscreen.cpp | 6 ++---- esphome/components/chsc6x/chsc6x_touchscreen.h | 6 ++---- esphome/components/climate_ir/climate_ir.cpp | 6 ++---- esphome/components/climate_ir/climate_ir.h | 6 ++---- esphome/components/climate_ir_lg/climate_ir_lg.cpp | 6 ++---- esphome/components/climate_ir_lg/climate_ir_lg.h | 6 ++---- esphome/components/cm1106/cm1106.cpp | 6 ++---- esphome/components/cm1106/cm1106.h | 6 ++---- esphome/components/color_temperature/ct_light_output.h | 6 ++---- esphome/components/combination/combination.cpp | 6 ++---- esphome/components/combination/combination.h | 6 ++---- esphome/components/coolix/coolix.cpp | 6 ++---- esphome/components/coolix/coolix.h | 6 ++---- .../components/copy/binary_sensor/copy_binary_sensor.cpp | 6 ++---- .../components/copy/binary_sensor/copy_binary_sensor.h | 6 ++---- esphome/components/copy/button/copy_button.cpp | 6 ++---- esphome/components/copy/button/copy_button.h | 6 ++---- esphome/components/copy/cover/copy_cover.cpp | 6 ++---- esphome/components/copy/cover/copy_cover.h | 6 ++---- esphome/components/copy/fan/copy_fan.cpp | 6 ++---- esphome/components/copy/fan/copy_fan.h | 6 ++---- esphome/components/copy/lock/copy_lock.cpp | 6 ++---- esphome/components/copy/lock/copy_lock.h | 6 ++---- esphome/components/copy/number/copy_number.cpp | 6 ++---- esphome/components/copy/number/copy_number.h | 6 ++---- esphome/components/copy/select/copy_select.cpp | 6 ++---- esphome/components/copy/select/copy_select.h | 6 ++---- esphome/components/copy/sensor/copy_sensor.cpp | 6 ++---- esphome/components/copy/sensor/copy_sensor.h | 6 ++---- esphome/components/copy/switch/copy_switch.cpp | 6 ++---- esphome/components/copy/switch/copy_switch.h | 6 ++---- esphome/components/copy/text/copy_text.cpp | 6 ++---- esphome/components/copy/text/copy_text.h | 6 ++---- esphome/components/copy/text_sensor/copy_text_sensor.cpp | 6 ++---- esphome/components/copy/text_sensor/copy_text_sensor.h | 6 ++---- esphome/components/cs5460a/cs5460a.cpp | 6 ++---- esphome/components/cs5460a/cs5460a.h | 6 ++---- esphome/components/cse7761/cse7761.cpp | 6 ++---- esphome/components/cse7761/cse7761.h | 6 ++---- esphome/components/cst226/binary_sensor/cs226_button.h | 6 ++---- esphome/components/cst226/binary_sensor/cstt6_button.cpp | 6 ++---- .../components/cst226/touchscreen/cst226_touchscreen.cpp | 6 ++---- .../components/cst226/touchscreen/cst226_touchscreen.h | 6 ++---- .../components/cst816/touchscreen/cst816_touchscreen.cpp | 6 ++---- .../components/cst816/touchscreen/cst816_touchscreen.h | 6 ++---- esphome/components/ct_clamp/ct_clamp_sensor.cpp | 6 ++---- esphome/components/ct_clamp/ct_clamp_sensor.h | 6 ++---- esphome/components/current_based/current_based_cover.cpp | 6 ++---- esphome/components/current_based/current_based_cover.h | 6 ++---- esphome/components/cwww/cwww_light_output.h | 6 ++---- 259 files changed, 520 insertions(+), 1037 deletions(-) diff --git a/esphome/components/a01nyub/a01nyub.cpp b/esphome/components/a01nyub/a01nyub.cpp index 210c3557b3e..344456854bf 100644 --- a/esphome/components/a01nyub/a01nyub.cpp +++ b/esphome/components/a01nyub/a01nyub.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace a01nyub { +namespace esphome::a01nyub { static const char *const TAG = "a01nyub.sensor"; @@ -42,5 +41,4 @@ void A01nyubComponent::check_buffer_() { void A01nyubComponent::dump_config() { LOG_SENSOR("", "A01nyub Sensor", this); } -} // namespace a01nyub -} // namespace esphome +} // namespace esphome::a01nyub diff --git a/esphome/components/a01nyub/a01nyub.h b/esphome/components/a01nyub/a01nyub.h index 6b22e9bcadb..5c0d20bd378 100644 --- a/esphome/components/a01nyub/a01nyub.h +++ b/esphome/components/a01nyub/a01nyub.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace a01nyub { +namespace esphome::a01nyub { class A01nyubComponent : public sensor::Sensor, public Component, public uart::UARTDevice { public: @@ -23,5 +22,4 @@ class A01nyubComponent : public sensor::Sensor, public Component, public uart::U std::vector buffer_; }; -} // namespace a01nyub -} // namespace esphome +} // namespace esphome::a01nyub diff --git a/esphome/components/a02yyuw/a02yyuw.cpp b/esphome/components/a02yyuw/a02yyuw.cpp index a2aad0cef13..2832334ef19 100644 --- a/esphome/components/a02yyuw/a02yyuw.cpp +++ b/esphome/components/a02yyuw/a02yyuw.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace a02yyuw { +namespace esphome::a02yyuw { static const char *const TAG = "a02yyuw.sensor"; @@ -41,5 +40,4 @@ void A02yyuwComponent::check_buffer_() { void A02yyuwComponent::dump_config() { LOG_SENSOR("", "A02yyuw Sensor", this); } -} // namespace a02yyuw -} // namespace esphome +} // namespace esphome::a02yyuw diff --git a/esphome/components/a02yyuw/a02yyuw.h b/esphome/components/a02yyuw/a02yyuw.h index 6ff370fdc34..693bcfd03c6 100644 --- a/esphome/components/a02yyuw/a02yyuw.h +++ b/esphome/components/a02yyuw/a02yyuw.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace a02yyuw { +namespace esphome::a02yyuw { class A02yyuwComponent : public sensor::Sensor, public Component, public uart::UARTDevice { public: @@ -23,5 +22,4 @@ class A02yyuwComponent : public sensor::Sensor, public Component, public uart::U std::vector buffer_; }; -} // namespace a02yyuw -} // namespace esphome +} // namespace esphome::a02yyuw diff --git a/esphome/components/a4988/a4988.cpp b/esphome/components/a4988/a4988.cpp index b9efb4ea448..d8fc6752f37 100644 --- a/esphome/components/a4988/a4988.cpp +++ b/esphome/components/a4988/a4988.cpp @@ -1,8 +1,7 @@ #include "a4988.h" #include "esphome/core/log.h" -namespace esphome { -namespace a4988 { +namespace esphome::a4988 { static const char *const TAG = "a4988.stepper"; @@ -51,5 +50,4 @@ void A4988::loop() { this->step_pin_->digital_write(false); } -} // namespace a4988 -} // namespace esphome +} // namespace esphome::a4988 diff --git a/esphome/components/a4988/a4988.h b/esphome/components/a4988/a4988.h index 0fe7891110c..04040241c0f 100644 --- a/esphome/components/a4988/a4988.h +++ b/esphome/components/a4988/a4988.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/stepper/stepper.h" -namespace esphome { -namespace a4988 { +namespace esphome::a4988 { class A4988 : public stepper::Stepper, public Component { public: @@ -25,5 +24,4 @@ class A4988 : public stepper::Stepper, public Component { HighFrequencyLoopRequester high_freq_; }; -} // namespace a4988 -} // namespace esphome +} // namespace esphome::a4988 diff --git a/esphome/components/adalight/adalight_light_effect.cpp b/esphome/components/adalight/adalight_light_effect.cpp index 06d7e0e8970..bf6849acaf7 100644 --- a/esphome/components/adalight/adalight_light_effect.cpp +++ b/esphome/components/adalight/adalight_light_effect.cpp @@ -1,8 +1,7 @@ #include "adalight_light_effect.h" #include "esphome/core/log.h" -namespace esphome { -namespace adalight { +namespace esphome::adalight { static const char *const TAG = "adalight_light_effect"; @@ -138,5 +137,4 @@ AdalightLightEffect::Frame AdalightLightEffect::parse_frame_(light::AddressableL return CONSUMED; } -} // namespace adalight -} // namespace esphome +} // namespace esphome::adalight diff --git a/esphome/components/adalight/adalight_light_effect.h b/esphome/components/adalight/adalight_light_effect.h index bb7319c99c4..c30e8467786 100644 --- a/esphome/components/adalight/adalight_light_effect.h +++ b/esphome/components/adalight/adalight_light_effect.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace adalight { +namespace esphome::adalight { class AdalightLightEffect : public light::AddressableLightEffect, public uart::UARTDevice { public: @@ -35,5 +34,4 @@ class AdalightLightEffect : public light::AddressableLightEffect, public uart::U std::vector frame_; }; -} // namespace adalight -} // namespace esphome +} // namespace esphome::adalight diff --git a/esphome/components/adc/adc_sensor.h b/esphome/components/adc/adc_sensor.h index cf48ccd9c3d..676940eca12 100644 --- a/esphome/components/adc/adc_sensor.h +++ b/esphome/components/adc/adc_sensor.h @@ -17,8 +17,7 @@ #include #endif -namespace esphome { -namespace adc { +namespace esphome::adc { #ifdef USE_ESP32 // clang-format off @@ -162,5 +161,4 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage #endif }; -} // namespace adc -} // namespace esphome +} // namespace esphome::adc diff --git a/esphome/components/adc/adc_sensor_common.cpp b/esphome/components/adc/adc_sensor_common.cpp index c779fd5893b..16c86aee18a 100644 --- a/esphome/components/adc/adc_sensor_common.cpp +++ b/esphome/components/adc/adc_sensor_common.cpp @@ -1,8 +1,7 @@ #include "adc_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.common"; @@ -79,5 +78,4 @@ void ADCSensor::set_sample_count(uint8_t sample_count) { void ADCSensor::set_sampling_mode(SamplingMode sampling_mode) { this->sampling_mode_ = sampling_mode; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc diff --git a/esphome/components/adc/adc_sensor_esp32.cpp b/esphome/components/adc/adc_sensor_esp32.cpp index fc707013a89..a761b377490 100644 --- a/esphome/components/adc/adc_sensor_esp32.cpp +++ b/esphome/components/adc/adc_sensor_esp32.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.esp32"; @@ -364,7 +363,6 @@ float ADCSensor::sample_autorange_() { return final_result; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc #endif // USE_ESP32 diff --git a/esphome/components/adc128s102/adc128s102.cpp b/esphome/components/adc128s102/adc128s102.cpp index 935dbde8eac..ef0db4730a1 100644 --- a/esphome/components/adc128s102/adc128s102.cpp +++ b/esphome/components/adc128s102/adc128s102.cpp @@ -1,8 +1,7 @@ #include "adc128s102.h" #include "esphome/core/log.h" -namespace esphome { -namespace adc128s102 { +namespace esphome::adc128s102 { static const char *const TAG = "adc128s102"; @@ -28,5 +27,4 @@ uint16_t ADC128S102::read_data(uint8_t channel) { return digital_value; } -} // namespace adc128s102 -} // namespace esphome +} // namespace esphome::adc128s102 diff --git a/esphome/components/adc128s102/adc128s102.h b/esphome/components/adc128s102/adc128s102.h index bd6b7f7af17..f04ed87b2af 100644 --- a/esphome/components/adc128s102/adc128s102.h +++ b/esphome/components/adc128s102/adc128s102.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace adc128s102 { +namespace esphome::adc128s102 { class ADC128S102 : public Component, public spi::SPIDeviceparent_->read_data(this->channel_); } void ADC128S102Sensor::update() { this->publish_state(this->sample()); } -} // namespace adc128s102 -} // namespace esphome +} // namespace esphome::adc128s102 diff --git a/esphome/components/adc128s102/sensor/adc128s102_sensor.h b/esphome/components/adc128s102/sensor/adc128s102_sensor.h index 5e6fc74e9c5..c840102380f 100644 --- a/esphome/components/adc128s102/sensor/adc128s102_sensor.h +++ b/esphome/components/adc128s102/sensor/adc128s102_sensor.h @@ -7,8 +7,7 @@ #include "../adc128s102.h" -namespace esphome { -namespace adc128s102 { +namespace esphome::adc128s102 { class ADC128S102Sensor : public PollingComponent, public Parented, @@ -24,5 +23,4 @@ class ADC128S102Sensor : public PollingComponent, protected: uint8_t channel_; }; -} // namespace adc128s102 -} // namespace esphome +} // namespace esphome::adc128s102 diff --git a/esphome/components/addressable_light/addressable_light_display.cpp b/esphome/components/addressable_light/addressable_light_display.cpp index 329620bcf04..4cbcb3324be 100644 --- a/esphome/components/addressable_light/addressable_light_display.cpp +++ b/esphome/components/addressable_light/addressable_light_display.cpp @@ -1,8 +1,7 @@ #include "addressable_light_display.h" #include "esphome/core/log.h" -namespace esphome { -namespace addressable_light { +namespace esphome::addressable_light { static const char *const TAG = "addressable_light.display"; @@ -66,5 +65,4 @@ void HOT AddressableLightDisplay::draw_absolute_pixel_internal(int x, int y, Col this->addressable_light_buffer_[y * this->get_width_internal() + x] = color; } } -} // namespace addressable_light -} // namespace esphome +} // namespace esphome::addressable_light diff --git a/esphome/components/addressable_light/addressable_light_display.h b/esphome/components/addressable_light/addressable_light_display.h index d9b8680547f..917d334f05f 100644 --- a/esphome/components/addressable_light/addressable_light_display.h +++ b/esphome/components/addressable_light/addressable_light_display.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace addressable_light { +namespace esphome::addressable_light { class AddressableLightDisplay : public display::DisplayBuffer { public: @@ -61,5 +60,4 @@ class AddressableLightDisplay : public display::DisplayBuffer { optional last_effect_index_; optional> pixel_mapper_f_; }; -} // namespace addressable_light -} // namespace esphome +} // namespace esphome::addressable_light diff --git a/esphome/components/ade7880/ade7880.cpp b/esphome/components/ade7880/ade7880.cpp index 8fb3e55b91a..9d19770c57c 100644 --- a/esphome/components/ade7880/ade7880.cpp +++ b/esphome/components/ade7880/ade7880.cpp @@ -13,8 +13,7 @@ #include -namespace esphome { -namespace ade7880 { +namespace esphome::ade7880 { static const char *const TAG = "ade7880"; @@ -313,5 +312,4 @@ void ADE7880::reset_device_() { this->store_.reset_pending = true; } -} // namespace ade7880 -} // namespace esphome +} // namespace esphome::ade7880 diff --git a/esphome/components/ade7880/ade7880.h b/esphome/components/ade7880/ade7880.h index 40bc22e54a1..69c8e5abba2 100644 --- a/esphome/components/ade7880/ade7880.h +++ b/esphome/components/ade7880/ade7880.h @@ -16,8 +16,7 @@ #include "ade7880_registers.h" -namespace esphome { -namespace ade7880 { +namespace esphome::ade7880 { struct NeutralChannel { void set_current(sensor::Sensor *sens) { this->current = sens; } @@ -125,5 +124,4 @@ class ADE7880 : public i2c::I2CDevice, public PollingComponent { void write_u32_register16_(uint16_t a_register, uint32_t value); }; -} // namespace ade7880 -} // namespace esphome +} // namespace esphome::ade7880 diff --git a/esphome/components/ade7880/ade7880_i2c.cpp b/esphome/components/ade7880/ade7880_i2c.cpp index fae20f175d6..294fd430d3e 100644 --- a/esphome/components/ade7880/ade7880_i2c.cpp +++ b/esphome/components/ade7880/ade7880_i2c.cpp @@ -9,8 +9,7 @@ #include "ade7880.h" -namespace esphome { -namespace ade7880 { +namespace esphome::ade7880 { // adapted from https://stackoverflow.com/a/55912127/1886371 template inline T sign_extend(const T &v) noexcept { @@ -97,5 +96,4 @@ void ADE7880::write_u32_register16_(uint16_t a_register, uint32_t value) { this->write_register16(a_register, reinterpret_cast(&out), sizeof(out)); } -} // namespace ade7880 -} // namespace esphome +} // namespace esphome::ade7880 diff --git a/esphome/components/ade7880/ade7880_registers.h b/esphome/components/ade7880/ade7880_registers.h index 9fd8ca3bf5e..aee4e424455 100644 --- a/esphome/components/ade7880/ade7880_registers.h +++ b/esphome/components/ade7880/ade7880_registers.h @@ -4,8 +4,7 @@ // Source: https://www.analog.com/media/en/technical-documentation/application-notes/AN-1127.pdf -namespace esphome { -namespace ade7880 { +namespace esphome::ade7880 { // DSP Data Memory RAM registers constexpr uint16_t AIGAIN = 0x4380; @@ -242,5 +241,4 @@ constexpr uint8_t DSPWP_SET_RO = (1 << 7); // DSPWP_SEL Register Bits constexpr uint8_t DSPWP_SEL_SET = 0xAD; -} // namespace ade7880 -} // namespace esphome +} // namespace esphome::ade7880 diff --git a/esphome/components/ade7953_base/ade7953_base.cpp b/esphome/components/ade7953_base/ade7953_base.cpp index 2dfab8ff853..1adf44f8f72 100644 --- a/esphome/components/ade7953_base/ade7953_base.cpp +++ b/esphome/components/ade7953_base/ade7953_base.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace ade7953_base { +namespace esphome::ade7953_base { static const char *const TAG = "ade7953"; @@ -160,5 +159,4 @@ void ADE7953::update() { ADE_PUBLISH(frequency, 223750.0f, 1 + val_16); } -} // namespace ade7953_base -} // namespace esphome +} // namespace esphome::ade7953_base diff --git a/esphome/components/ade7953_base/ade7953_base.h b/esphome/components/ade7953_base/ade7953_base.h index b58f95b2304..a1dfea23b04 100644 --- a/esphome/components/ade7953_base/ade7953_base.h +++ b/esphome/components/ade7953_base/ade7953_base.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace ade7953_base { +namespace esphome::ade7953_base { static constexpr uint8_t PGA_V_8 = 0x007; // PGA_V, (R/W) Default: 0x00, Unsigned, Voltage channel gain configuration (Bits[2:0]) @@ -131,5 +130,4 @@ class ADE7953 : public PollingComponent, public sensor::Sensor { virtual bool ade_read_32(uint16_t reg, uint32_t *value) = 0; }; -} // namespace ade7953_base -} // namespace esphome +} // namespace esphome::ade7953_base diff --git a/esphome/components/ade7953_i2c/ade7953_i2c.cpp b/esphome/components/ade7953_i2c/ade7953_i2c.cpp index 59c2254d444..252e55ee5c1 100644 --- a/esphome/components/ade7953_i2c/ade7953_i2c.cpp +++ b/esphome/components/ade7953_i2c/ade7953_i2c.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ade7953_i2c { +namespace esphome::ade7953_i2c { static const char *const TAG = "ade7953"; @@ -76,5 +75,4 @@ bool AdE7953I2c::ade_read_32(uint16_t reg, uint32_t *value) { return false; } -} // namespace ade7953_i2c -} // namespace esphome +} // namespace esphome::ade7953_i2c diff --git a/esphome/components/ade7953_i2c/ade7953_i2c.h b/esphome/components/ade7953_i2c/ade7953_i2c.h index 65dc30dddb7..74d7e3e7cce 100644 --- a/esphome/components/ade7953_i2c/ade7953_i2c.h +++ b/esphome/components/ade7953_i2c/ade7953_i2c.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace ade7953_i2c { +namespace esphome::ade7953_i2c { class AdE7953I2c : public ade7953_base::ADE7953, public i2c::I2CDevice { public: @@ -24,5 +23,4 @@ class AdE7953I2c : public ade7953_base::ADE7953, public i2c::I2CDevice { bool ade_read_32(uint16_t reg, uint32_t *value) override; }; -} // namespace ade7953_i2c -} // namespace esphome +} // namespace esphome::ade7953_i2c diff --git a/esphome/components/ade7953_spi/ade7953_spi.cpp b/esphome/components/ade7953_spi/ade7953_spi.cpp index a69b7d19fb5..c2d85231d6b 100644 --- a/esphome/components/ade7953_spi/ade7953_spi.cpp +++ b/esphome/components/ade7953_spi/ade7953_spi.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ade7953_spi { +namespace esphome::ade7953_spi { static const char *const TAG = "ade7953"; @@ -83,5 +82,4 @@ bool AdE7953Spi::ade_read_32(uint16_t reg, uint32_t *value) { return false; } -} // namespace ade7953_spi -} // namespace esphome +} // namespace esphome::ade7953_spi diff --git a/esphome/components/ade7953_spi/ade7953_spi.h b/esphome/components/ade7953_spi/ade7953_spi.h index 27f6025d983..657397db4e6 100644 --- a/esphome/components/ade7953_spi/ade7953_spi.h +++ b/esphome/components/ade7953_spi/ade7953_spi.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace ade7953_spi { +namespace esphome::ade7953_spi { class AdE7953Spi : public ade7953_base::ADE7953, public spi::SPIDevice -namespace esphome { -namespace ads1115 { +namespace esphome::ads1115 { enum ADS1115Multiplexer { ADS1115_MULTIPLEXER_P0_N1 = 0b000, @@ -60,5 +59,4 @@ class ADS1115Component : public Component, public i2c::I2CDevice { bool continuous_mode_; }; -} // namespace ads1115 -} // namespace esphome +} // namespace esphome::ads1115 diff --git a/esphome/components/ads1115/sensor/ads1115_sensor.cpp b/esphome/components/ads1115/sensor/ads1115_sensor.cpp index fac6b60d0ae..8086d972310 100644 --- a/esphome/components/ads1115/sensor/ads1115_sensor.cpp +++ b/esphome/components/ads1115/sensor/ads1115_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace ads1115 { +namespace esphome::ads1115 { static const char *const TAG = "ads1115.sensor"; @@ -29,5 +28,4 @@ void ADS1115Sensor::dump_config() { this->multiplexer_, this->gain_, this->resolution_, this->samplerate_); } -} // namespace ads1115 -} // namespace esphome +} // namespace esphome::ads1115 diff --git a/esphome/components/ads1115/sensor/ads1115_sensor.h b/esphome/components/ads1115/sensor/ads1115_sensor.h index 5ca25c13add..3b82c153dd5 100644 --- a/esphome/components/ads1115/sensor/ads1115_sensor.h +++ b/esphome/components/ads1115/sensor/ads1115_sensor.h @@ -8,8 +8,7 @@ #include "../ads1115.h" -namespace esphome { -namespace ads1115 { +namespace esphome::ads1115 { /// Internal holder class that is in instance of Sensor so that the hub can create individual sensors. class ADS1115Sensor : public sensor::Sensor, @@ -33,5 +32,4 @@ class ADS1115Sensor : public sensor::Sensor, ADS1115Samplerate samplerate_; }; -} // namespace ads1115 -} // namespace esphome +} // namespace esphome::ads1115 diff --git a/esphome/components/ads1118/ads1118.cpp b/esphome/components/ads1118/ads1118.cpp index f7db9f93dde..0a07193bfe0 100644 --- a/esphome/components/ads1118/ads1118.cpp +++ b/esphome/components/ads1118/ads1118.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ads1118 { +namespace esphome::ads1118 { static const char *const TAG = "ads1118"; static const uint8_t ADS1118_DATA_RATE_860_SPS = 0b111; @@ -122,5 +121,4 @@ float ADS1118::request_measurement(ADS1118Multiplexer multiplexer, ADS1118Gain g } } -} // namespace ads1118 -} // namespace esphome +} // namespace esphome::ads1118 diff --git a/esphome/components/ads1118/ads1118.h b/esphome/components/ads1118/ads1118.h index e96baab3869..ef125a0b44b 100644 --- a/esphome/components/ads1118/ads1118.h +++ b/esphome/components/ads1118/ads1118.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ads1118 { +namespace esphome::ads1118 { enum ADS1118Multiplexer { ADS1118_MULTIPLEXER_P0_N1 = 0b000, @@ -41,5 +40,4 @@ class ADS1118 : public Component, uint16_t config_{0}; }; -} // namespace ads1118 -} // namespace esphome +} // namespace esphome::ads1118 diff --git a/esphome/components/ads1118/sensor/ads1118_sensor.cpp b/esphome/components/ads1118/sensor/ads1118_sensor.cpp index 7193c3c8801..383a3d25fcb 100644 --- a/esphome/components/ads1118/sensor/ads1118_sensor.cpp +++ b/esphome/components/ads1118/sensor/ads1118_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace ads1118 { +namespace esphome::ads1118 { static const char *const TAG = "ads1118.sensor"; @@ -27,5 +26,4 @@ void ADS1118Sensor::update() { } } -} // namespace ads1118 -} // namespace esphome +} // namespace esphome::ads1118 diff --git a/esphome/components/ads1118/sensor/ads1118_sensor.h b/esphome/components/ads1118/sensor/ads1118_sensor.h index d2d7a03f59d..b929e75c62d 100644 --- a/esphome/components/ads1118/sensor/ads1118_sensor.h +++ b/esphome/components/ads1118/sensor/ads1118_sensor.h @@ -8,8 +8,7 @@ #include "../ads1118.h" -namespace esphome { -namespace ads1118 { +namespace esphome::ads1118 { class ADS1118Sensor : public PollingComponent, public sensor::Sensor, @@ -32,5 +31,4 @@ class ADS1118Sensor : public PollingComponent, bool temperature_mode_; }; -} // namespace ads1118 -} // namespace esphome +} // namespace esphome::ads1118 diff --git a/esphome/components/ags10/ags10.cpp b/esphome/components/ags10/ags10.cpp index fa7170114cf..230548ae947 100644 --- a/esphome/components/ags10/ags10.cpp +++ b/esphome/components/ags10/ags10.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace ags10 { +namespace esphome::ags10 { static const char *const TAG = "ags10"; // Data acquisition. @@ -192,5 +191,4 @@ template optional> AGS10Component::read_and_che return data; } -} // namespace ags10 -} // namespace esphome +} // namespace esphome::ags10 diff --git a/esphome/components/ags10/ags10.h b/esphome/components/ags10/ags10.h index 9e034b20cb2..703acd5228c 100644 --- a/esphome/components/ags10/ags10.h +++ b/esphome/components/ags10/ags10.h @@ -5,8 +5,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -namespace esphome { -namespace ags10 { +namespace esphome::ags10 { class AGS10Component : public PollingComponent, public i2c::I2CDevice { public: @@ -136,5 +135,4 @@ template class AGS10SetZeroPointAction : public Action, p } } }; -} // namespace ags10 -} // namespace esphome +} // namespace esphome::ags10 diff --git a/esphome/components/aht10/aht10.cpp b/esphome/components/aht10/aht10.cpp index 1b1f8335cc5..cc90abfc3a6 100644 --- a/esphome/components/aht10/aht10.cpp +++ b/esphome/components/aht10/aht10.cpp @@ -17,8 +17,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace aht10 { +namespace esphome::aht10 { static const char *const TAG = "aht10"; static const uint8_t AHT10_INITIALIZE_CMD[] = {0xE1, 0x08, 0x00}; @@ -160,5 +159,4 @@ void AHT10Component::dump_config() { LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); } -} // namespace aht10 -} // namespace esphome +} // namespace esphome::aht10 diff --git a/esphome/components/aht10/aht10.h b/esphome/components/aht10/aht10.h index ce9cd963ad3..7b9b1761c4d 100644 --- a/esphome/components/aht10/aht10.h +++ b/esphome/components/aht10/aht10.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace aht10 { +namespace esphome::aht10 { enum AHT10Variant { AHT10, AHT20 }; @@ -31,5 +30,4 @@ class AHT10Component : public PollingComponent, public i2c::I2CDevice { uint32_t start_time_{}; }; -} // namespace aht10 -} // namespace esphome +} // namespace esphome::aht10 diff --git a/esphome/components/aic3204/aic3204.cpp b/esphome/components/aic3204/aic3204.cpp index e1acf32f83c..0ba960fd702 100644 --- a/esphome/components/aic3204/aic3204.cpp +++ b/esphome/components/aic3204/aic3204.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace aic3204 { +namespace esphome::aic3204 { static const char *const TAG = "aic3204"; @@ -167,5 +166,4 @@ bool AIC3204::write_volume_() { return true; } -} // namespace aic3204 -} // namespace esphome +} // namespace esphome::aic3204 diff --git a/esphome/components/aic3204/aic3204.h b/esphome/components/aic3204/aic3204.h index 28006e33fcc..9b8c7928246 100644 --- a/esphome/components/aic3204/aic3204.h +++ b/esphome/components/aic3204/aic3204.h @@ -6,8 +6,7 @@ #include "esphome/core/defines.h" #include "esphome/core/hal.h" -namespace esphome { -namespace aic3204 { +namespace esphome::aic3204 { // TLV320AIC3204 Register Addresses // Page 0 @@ -83,5 +82,4 @@ class AIC3204 : public audio_dac::AudioDac, public Component, public i2c::I2CDev float volume_{0}; }; -} // namespace aic3204 -} // namespace esphome +} // namespace esphome::aic3204 diff --git a/esphome/components/aic3204/automation.h b/esphome/components/aic3204/automation.h index 851ff930f8a..50ae03edbd9 100644 --- a/esphome/components/aic3204/automation.h +++ b/esphome/components/aic3204/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "aic3204.h" -namespace esphome { -namespace aic3204 { +namespace esphome::aic3204 { template class SetAutoMuteAction : public Action { public: @@ -19,5 +18,4 @@ template class SetAutoMuteAction : public Action { AIC3204 *aic3204_; }; -} // namespace aic3204 -} // namespace esphome +} // namespace esphome::aic3204 diff --git a/esphome/components/airthings_ble/airthings_listener.cpp b/esphome/components/airthings_ble/airthings_listener.cpp index 58faf923f54..881b3e297b5 100644 --- a/esphome/components/airthings_ble/airthings_listener.cpp +++ b/esphome/components/airthings_ble/airthings_listener.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace airthings_ble { +namespace esphome::airthings_ble { static const char *const TAG = "airthings_ble"; @@ -29,7 +28,6 @@ bool AirthingsListener::parse_device(const esp32_ble_tracker::ESPBTDevice &devic return false; } -} // namespace airthings_ble -} // namespace esphome +} // namespace esphome::airthings_ble #endif diff --git a/esphome/components/airthings_ble/airthings_listener.h b/esphome/components/airthings_ble/airthings_listener.h index 52f69ea9700..707e9c3f210 100644 --- a/esphome/components/airthings_ble/airthings_listener.h +++ b/esphome/components/airthings_ble/airthings_listener.h @@ -5,15 +5,13 @@ #include "esphome/core/component.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" -namespace esphome { -namespace airthings_ble { +namespace esphome::airthings_ble { class AirthingsListener : public esp32_ble_tracker::ESPBTDeviceListener { public: bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; }; -} // namespace airthings_ble -} // namespace esphome +} // namespace esphome::airthings_ble #endif diff --git a/esphome/components/airthings_wave_base/airthings_wave_base.cpp b/esphome/components/airthings_wave_base/airthings_wave_base.cpp index e4c7d2a81d8..5fa59f22fd5 100644 --- a/esphome/components/airthings_wave_base/airthings_wave_base.cpp +++ b/esphome/components/airthings_wave_base/airthings_wave_base.cpp @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace airthings_wave_base { +namespace esphome::airthings_wave_base { static const char *const TAG = "airthings_wave_base"; @@ -211,7 +210,6 @@ void AirthingsWaveBase::set_response_timeout_() { }); } -} // namespace airthings_wave_base -} // namespace esphome +} // namespace esphome::airthings_wave_base #endif // USE_ESP32 diff --git a/esphome/components/airthings_wave_base/airthings_wave_base.h b/esphome/components/airthings_wave_base/airthings_wave_base.h index 1dc2e1f71f2..2f1e15491f9 100644 --- a/esphome/components/airthings_wave_base/airthings_wave_base.h +++ b/esphome/components/airthings_wave_base/airthings_wave_base.h @@ -14,8 +14,7 @@ #include "esphome/core/component.h" #include "esphome/core/log.h" -namespace esphome { -namespace airthings_wave_base { +namespace esphome::airthings_wave_base { namespace espbt = esphome::esp32_ble_tracker; @@ -84,7 +83,6 @@ class AirthingsWaveBase : public PollingComponent, public ble_client::BLEClientN }; }; -} // namespace airthings_wave_base -} // namespace esphome +} // namespace esphome::airthings_wave_base #endif // USE_ESP32 diff --git a/esphome/components/airthings_wave_mini/airthings_wave_mini.cpp b/esphome/components/airthings_wave_mini/airthings_wave_mini.cpp index 873826d06c2..f487e9dbc08 100644 --- a/esphome/components/airthings_wave_mini/airthings_wave_mini.cpp +++ b/esphome/components/airthings_wave_mini/airthings_wave_mini.cpp @@ -2,8 +2,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace airthings_wave_mini { +namespace esphome::airthings_wave_mini { static const char *const TAG = "airthings_wave_mini"; @@ -49,7 +48,6 @@ AirthingsWaveMini::AirthingsWaveMini() { espbt::ESPBTUUID::from_raw(ACCESS_CONTROL_POINT_CHARACTERISTIC_UUID); } -} // namespace airthings_wave_mini -} // namespace esphome +} // namespace esphome::airthings_wave_mini #endif // USE_ESP32 diff --git a/esphome/components/airthings_wave_mini/airthings_wave_mini.h b/esphome/components/airthings_wave_mini/airthings_wave_mini.h index 825ddbdc69b..910ac902390 100644 --- a/esphome/components/airthings_wave_mini/airthings_wave_mini.h +++ b/esphome/components/airthings_wave_mini/airthings_wave_mini.h @@ -4,8 +4,7 @@ #include "esphome/components/airthings_wave_base/airthings_wave_base.h" -namespace esphome { -namespace airthings_wave_mini { +namespace esphome::airthings_wave_mini { namespace espbt = esphome::esp32_ble_tracker; @@ -34,7 +33,6 @@ class AirthingsWaveMini : public airthings_wave_base::AirthingsWaveBase { }; }; -} // namespace airthings_wave_mini -} // namespace esphome +} // namespace esphome::airthings_wave_mini #endif // USE_ESP32 diff --git a/esphome/components/airthings_wave_plus/airthings_wave_plus.cpp b/esphome/components/airthings_wave_plus/airthings_wave_plus.cpp index 5ed62fff623..80fe081b572 100644 --- a/esphome/components/airthings_wave_plus/airthings_wave_plus.cpp +++ b/esphome/components/airthings_wave_plus/airthings_wave_plus.cpp @@ -2,8 +2,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace airthings_wave_plus { +namespace esphome::airthings_wave_plus { static const char *const TAG = "airthings_wave_plus"; @@ -98,7 +97,6 @@ void AirthingsWavePlus::setup() { espbt::ESPBTUUID::from_raw(access_control_point_characteristic_uuid); } -} // namespace airthings_wave_plus -} // namespace esphome +} // namespace esphome::airthings_wave_plus #endif // USE_ESP32 diff --git a/esphome/components/airthings_wave_plus/airthings_wave_plus.h b/esphome/components/airthings_wave_plus/airthings_wave_plus.h index c978a9af927..6f51f3c65ac 100644 --- a/esphome/components/airthings_wave_plus/airthings_wave_plus.h +++ b/esphome/components/airthings_wave_plus/airthings_wave_plus.h @@ -4,8 +4,7 @@ #include "esphome/components/airthings_wave_base/airthings_wave_base.h" -namespace esphome { -namespace airthings_wave_plus { +namespace esphome::airthings_wave_plus { namespace espbt = esphome::esp32_ble_tracker; @@ -58,7 +57,6 @@ class AirthingsWavePlus : public airthings_wave_base::AirthingsWaveBase { }; }; -} // namespace airthings_wave_plus -} // namespace esphome +} // namespace esphome::airthings_wave_plus #endif // USE_ESP32 diff --git a/esphome/components/alpha3/alpha3.cpp b/esphome/components/alpha3/alpha3.cpp index 6e82ec047db..048c365616c 100644 --- a/esphome/components/alpha3/alpha3.cpp +++ b/esphome/components/alpha3/alpha3.cpp @@ -5,8 +5,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace alpha3 { +namespace esphome::alpha3 { static const char *const TAG = "alpha3"; @@ -185,7 +184,6 @@ void Alpha3::update() { delay(25); // need to wait between requests } } -} // namespace alpha3 -} // namespace esphome +} // namespace esphome::alpha3 #endif diff --git a/esphome/components/alpha3/alpha3.h b/esphome/components/alpha3/alpha3.h index 19d8e99331a..c63129031ad 100644 --- a/esphome/components/alpha3/alpha3.h +++ b/esphome/components/alpha3/alpha3.h @@ -9,8 +9,7 @@ #include -namespace esphome { -namespace alpha3 { +namespace esphome::alpha3 { namespace espbt = esphome::esp32_ble_tracker; @@ -64,7 +63,6 @@ class Alpha3 : public esphome::ble_client::BLEClientNode, public PollingComponen void send_request_(uint8_t *request, size_t len); bool is_current_response_type_(const uint8_t *response_type); }; -} // namespace alpha3 -} // namespace esphome +} // namespace esphome::alpha3 #endif diff --git a/esphome/components/am2315c/am2315c.cpp b/esphome/components/am2315c/am2315c.cpp index 1390b749754..8980a8dfc3a 100644 --- a/esphome/components/am2315c/am2315c.cpp +++ b/esphome/components/am2315c/am2315c.cpp @@ -24,8 +24,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace am2315c { +namespace esphome::am2315c { static const char *const TAG = "am2315c"; @@ -176,5 +175,4 @@ void AM2315C::dump_config() { LOG_SENSOR(" ", "Humidity", this->humidity_sensor_); } -} // namespace am2315c -} // namespace esphome +} // namespace esphome::am2315c diff --git a/esphome/components/am2315c/am2315c.h b/esphome/components/am2315c/am2315c.h index d7baf01cae1..5a959af4c37 100644 --- a/esphome/components/am2315c/am2315c.h +++ b/esphome/components/am2315c/am2315c.h @@ -25,8 +25,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace am2315c { +namespace esphome::am2315c { class AM2315C : public PollingComponent, public i2c::I2CDevice { public: @@ -45,5 +44,4 @@ class AM2315C : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace am2315c -} // namespace esphome +} // namespace esphome::am2315c diff --git a/esphome/components/am2320/am2320.cpp b/esphome/components/am2320/am2320.cpp index 7fef3bb3a62..5445ab38981 100644 --- a/esphome/components/am2320/am2320.cpp +++ b/esphome/components/am2320/am2320.cpp @@ -8,8 +8,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace am2320 { +namespace esphome::am2320 { static const char *const TAG = "am2320"; @@ -86,5 +85,4 @@ bool AM2320Component::read_data_(uint8_t *data) { return true; } -} // namespace am2320 -} // namespace esphome +} // namespace esphome::am2320 diff --git a/esphome/components/am2320/am2320.h b/esphome/components/am2320/am2320.h index 708dbb632e8..ddb5c6f1653 100644 --- a/esphome/components/am2320/am2320.h +++ b/esphome/components/am2320/am2320.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace am2320 { +namespace esphome::am2320 { class AM2320Component : public PollingComponent, public i2c::I2CDevice { public: @@ -24,5 +23,4 @@ class AM2320Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace am2320 -} // namespace esphome +} // namespace esphome::am2320 diff --git a/esphome/components/am43/am43_base.cpp b/esphome/components/am43/am43_base.cpp index d70e6383829..977185e5e31 100644 --- a/esphome/components/am43/am43_base.cpp +++ b/esphome/components/am43/am43_base.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include -namespace esphome { -namespace am43 { +namespace esphome::am43 { const uint8_t START_PACKET[5] = {0x00, 0xff, 0x00, 0x00, 0x9a}; @@ -134,5 +133,4 @@ void Am43Decoder::decode(const uint8_t *data, uint16_t length) { } }; -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 diff --git a/esphome/components/am43/am43_base.h b/esphome/components/am43/am43_base.h index 35354af9edd..5df83747c05 100644 --- a/esphome/components/am43/am43_base.h +++ b/esphome/components/am43/am43_base.h @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace am43 { +namespace esphome::am43 { static const uint16_t AM43_SERVICE_UUID = 0xFE50; static const uint16_t AM43_CHARACTERISTIC_UUID = 0xFE51; @@ -74,5 +73,4 @@ class Am43Decoder { bool has_pin_response_; }; -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 diff --git a/esphome/components/am43/cover/am43_cover.cpp b/esphome/components/am43/cover/am43_cover.cpp index 2fa26d266a2..35366dbaa69 100644 --- a/esphome/components/am43/cover/am43_cover.cpp +++ b/esphome/components/am43/cover/am43_cover.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace am43 { +namespace esphome::am43 { static const char *const TAG = "am43_cover"; @@ -154,7 +153,6 @@ void Am43Component::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_ } } -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 #endif diff --git a/esphome/components/am43/cover/am43_cover.h b/esphome/components/am43/cover/am43_cover.h index d6d020e98c9..aa48aced158 100644 --- a/esphome/components/am43/cover/am43_cover.h +++ b/esphome/components/am43/cover/am43_cover.h @@ -10,8 +10,7 @@ #include -namespace esphome { -namespace am43 { +namespace esphome::am43 { namespace espbt = esphome::esp32_ble_tracker; @@ -38,7 +37,6 @@ class Am43Component : public cover::Cover, public esphome::ble_client::BLEClient float position_; }; -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 #endif diff --git a/esphome/components/am43/sensor/am43_sensor.cpp b/esphome/components/am43/sensor/am43_sensor.cpp index b2bc3254e28..ddc3eadae9a 100644 --- a/esphome/components/am43/sensor/am43_sensor.cpp +++ b/esphome/components/am43/sensor/am43_sensor.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace am43 { +namespace esphome::am43 { static const char *const TAG = "am43"; @@ -111,7 +110,6 @@ void Am43::update() { } } -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 #endif diff --git a/esphome/components/am43/sensor/am43_sensor.h b/esphome/components/am43/sensor/am43_sensor.h index 195b96a19eb..9198a5cbcbd 100644 --- a/esphome/components/am43/sensor/am43_sensor.h +++ b/esphome/components/am43/sensor/am43_sensor.h @@ -10,8 +10,7 @@ #include -namespace esphome { -namespace am43 { +namespace esphome::am43 { namespace espbt = esphome::esp32_ble_tracker; @@ -38,7 +37,6 @@ class Am43 : public esphome::ble_client::BLEClientNode, public PollingComponent uint32_t last_battery_update_; }; -} // namespace am43 -} // namespace esphome +} // namespace esphome::am43 #endif diff --git a/esphome/components/analog_threshold/analog_threshold_binary_sensor.cpp b/esphome/components/analog_threshold/analog_threshold_binary_sensor.cpp index 0b3bd0e472f..d25c10021c0 100644 --- a/esphome/components/analog_threshold/analog_threshold_binary_sensor.cpp +++ b/esphome/components/analog_threshold/analog_threshold_binary_sensor.cpp @@ -1,8 +1,7 @@ #include "analog_threshold_binary_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace analog_threshold { +namespace esphome::analog_threshold { static const char *const TAG = "analog_threshold.binary_sensor"; @@ -43,5 +42,4 @@ void AnalogThresholdBinarySensor::dump_config() { this->upper_threshold_.value(), this->lower_threshold_.value()); } -} // namespace analog_threshold -} // namespace esphome +} // namespace esphome::analog_threshold diff --git a/esphome/components/analog_threshold/analog_threshold_binary_sensor.h b/esphome/components/analog_threshold/analog_threshold_binary_sensor.h index 55a822b9b09..c768f1f82d6 100644 --- a/esphome/components/analog_threshold/analog_threshold_binary_sensor.h +++ b/esphome/components/analog_threshold/analog_threshold_binary_sensor.h @@ -5,8 +5,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace analog_threshold { +namespace esphome::analog_threshold { class AnalogThresholdBinarySensor : public Component, public binary_sensor::BinarySensor { public: @@ -24,5 +23,4 @@ class AnalogThresholdBinarySensor : public Component, public binary_sensor::Bina bool raw_state_{false}; // Pre-filter state for hysteresis logic }; -} // namespace analog_threshold -} // namespace esphome +} // namespace esphome::analog_threshold diff --git a/esphome/components/animation/animation.cpp b/esphome/components/animation/animation.cpp index 2f59a7fa5a7..2a293adf1d8 100644 --- a/esphome/components/animation/animation.cpp +++ b/esphome/components/animation/animation.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" -namespace esphome { -namespace animation { +namespace esphome::animation { Animation::Animation(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, image::ImageType type, image::Transparency transparent) @@ -71,5 +70,4 @@ void Animation::update_data_start_() { this->data_start_ = this->animation_data_start_ + image_size * this->current_frame_; } -} // namespace animation -} // namespace esphome +} // namespace esphome::animation diff --git a/esphome/components/animation/animation.h b/esphome/components/animation/animation.h index b33254df30f..ca800ad9311 100644 --- a/esphome/components/animation/animation.h +++ b/esphome/components/animation/animation.h @@ -3,8 +3,7 @@ #include "esphome/core/automation.h" -namespace esphome { -namespace animation { +namespace esphome::animation { class Animation : public image::Image { public: @@ -64,5 +63,4 @@ template class AnimationSetFrameAction : public Action { Animation *parent_; }; -} // namespace animation -} // namespace esphome +} // namespace esphome::animation diff --git a/esphome/components/anova/anova.cpp b/esphome/components/anova/anova.cpp index f21230b075e..6e382872e2b 100644 --- a/esphome/components/anova/anova.cpp +++ b/esphome/components/anova/anova.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace anova { +namespace esphome::anova { static const char *const TAG = "anova"; @@ -160,7 +159,6 @@ void Anova::update() { } } -} // namespace anova -} // namespace esphome +} // namespace esphome::anova #endif diff --git a/esphome/components/anova/anova.h b/esphome/components/anova/anova.h index 2e43ebfb983..a3e175be280 100644 --- a/esphome/components/anova/anova.h +++ b/esphome/components/anova/anova.h @@ -10,8 +10,7 @@ #include -namespace esphome { -namespace anova { +namespace esphome::anova { namespace espbt = esphome::esp32_ble_tracker; @@ -45,7 +44,6 @@ class Anova : public climate::Climate, public esphome::ble_client::BLEClientNode bool fahrenheit_; }; -} // namespace anova -} // namespace esphome +} // namespace esphome::anova #endif diff --git a/esphome/components/anova/anova_base.cpp b/esphome/components/anova/anova_base.cpp index a14dd728a80..84dd4393eb2 100644 --- a/esphome/components/anova/anova_base.cpp +++ b/esphome/components/anova/anova_base.cpp @@ -4,8 +4,7 @@ #include "esphome/core/alloc_helpers.h" -namespace esphome { -namespace anova { +namespace esphome::anova { float ftoc(float f) { return (f - 32.0) * (5.0f / 9.0f); } @@ -132,5 +131,4 @@ void AnovaCodec::decode(const uint8_t *data, uint16_t length) { } } -} // namespace anova -} // namespace esphome +} // namespace esphome::anova diff --git a/esphome/components/anova/anova_base.h b/esphome/components/anova/anova_base.h index b8311578497..b3ed0f01a00 100644 --- a/esphome/components/anova/anova_base.h +++ b/esphome/components/anova/anova_base.h @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace anova { +namespace esphome::anova { enum CurrentQuery { NONE, @@ -75,5 +74,4 @@ class AnovaCodec { CurrentQuery current_query_; }; -} // namespace anova -} // namespace esphome +} // namespace esphome::anova diff --git a/esphome/components/apds9306/apds9306.cpp b/esphome/components/apds9306/apds9306.cpp index fb3adde8688..57a502ca420 100644 --- a/esphome/components/apds9306/apds9306.cpp +++ b/esphome/components/apds9306/apds9306.cpp @@ -5,8 +5,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace apds9306 { +namespace esphome::apds9306 { static const char *const TAG = "apds9306"; @@ -147,5 +146,4 @@ void APDS9306::update() { this->publish_state(lux); } -} // namespace apds9306 -} // namespace esphome +} // namespace esphome::apds9306 diff --git a/esphome/components/apds9306/apds9306.h b/esphome/components/apds9306/apds9306.h index 44362908c81..093ec55bc63 100644 --- a/esphome/components/apds9306/apds9306.h +++ b/esphome/components/apds9306/apds9306.h @@ -7,8 +7,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace apds9306 { +namespace esphome::apds9306 { enum MeasurementBitWidth : uint8_t { MEASUREMENT_BIT_WIDTH_20 = 0, @@ -62,5 +61,4 @@ class APDS9306 : public sensor::Sensor, public PollingComponent, public i2c::I2C AmbientLightGain gain_; }; -} // namespace apds9306 -} // namespace esphome +} // namespace esphome::apds9306 diff --git a/esphome/components/apds9960/apds9960.cpp b/esphome/components/apds9960/apds9960.cpp index a07175f2c9c..da8029b4ee0 100644 --- a/esphome/components/apds9960/apds9960.cpp +++ b/esphome/components/apds9960/apds9960.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace apds9960 { +namespace esphome::apds9960 { static const char *const TAG = "apds9960"; @@ -402,5 +401,4 @@ bool APDS9960::is_gesture_enabled_() const { #endif } -} // namespace apds9960 -} // namespace esphome +} // namespace esphome::apds9960 diff --git a/esphome/components/apds9960/apds9960.h b/esphome/components/apds9960/apds9960.h index 4574b70a42e..2823294207b 100644 --- a/esphome/components/apds9960/apds9960.h +++ b/esphome/components/apds9960/apds9960.h @@ -10,8 +10,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #endif -namespace esphome { -namespace apds9960 { +namespace esphome::apds9960 { class APDS9960 : public PollingComponent, public i2c::I2CDevice { #ifdef USE_SENSOR @@ -71,5 +70,4 @@ class APDS9960 : public PollingComponent, public i2c::I2CDevice { uint32_t gesture_start_{0}; }; -} // namespace apds9960 -} // namespace esphome +} // namespace esphome::apds9960 diff --git a/esphome/components/as3935/as3935.cpp b/esphome/components/as3935/as3935.cpp index c4dc0466a04..a1d74c78deb 100644 --- a/esphome/components/as3935/as3935.cpp +++ b/esphome/components/as3935/as3935.cpp @@ -1,8 +1,7 @@ #include "as3935.h" #include "esphome/core/log.h" -namespace esphome { -namespace as3935 { +namespace esphome::as3935 { static const char *const TAG = "as3935"; @@ -320,5 +319,4 @@ uint8_t AS3935Component::read_register_(uint8_t reg, uint8_t mask) { return value; } -} // namespace as3935 -} // namespace esphome +} // namespace esphome::as3935 diff --git a/esphome/components/as3935/as3935.h b/esphome/components/as3935/as3935.h index 5f46dadfa8c..274ce7a138d 100644 --- a/esphome/components/as3935/as3935.h +++ b/esphome/components/as3935/as3935.h @@ -10,8 +10,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #endif -namespace esphome { -namespace as3935 { +namespace esphome::as3935 { static const uint8_t DIRECT_COMMAND = 0x96; static const uint8_t ANTFREQ = 3; @@ -127,5 +126,4 @@ class AS3935Component : public Component { bool calibration_; }; -} // namespace as3935 -} // namespace esphome +} // namespace esphome::as3935 diff --git a/esphome/components/as3935_i2c/as3935_i2c.cpp b/esphome/components/as3935_i2c/as3935_i2c.cpp index 3a7fa7bf846..4c1020daa77 100644 --- a/esphome/components/as3935_i2c/as3935_i2c.cpp +++ b/esphome/components/as3935_i2c/as3935_i2c.cpp @@ -1,8 +1,7 @@ #include "as3935_i2c.h" #include "esphome/core/log.h" -namespace esphome { -namespace as3935_i2c { +namespace esphome::as3935_i2c { static const char *const TAG = "as3935_i2c"; @@ -40,5 +39,4 @@ void I2CAS3935Component::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace as3935_i2c -} // namespace esphome +} // namespace esphome::as3935_i2c diff --git a/esphome/components/as3935_i2c/as3935_i2c.h b/esphome/components/as3935_i2c/as3935_i2c.h index a2a3d213efa..c43ec4afd5b 100644 --- a/esphome/components/as3935_i2c/as3935_i2c.h +++ b/esphome/components/as3935_i2c/as3935_i2c.h @@ -3,8 +3,7 @@ #include "esphome/components/as3935/as3935.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace as3935_i2c { +namespace esphome::as3935_i2c { class I2CAS3935Component : public as3935::AS3935Component, public i2c::I2CDevice { public: @@ -15,5 +14,4 @@ class I2CAS3935Component : public as3935::AS3935Component, public i2c::I2CDevice uint8_t read_register(uint8_t reg) override; }; -} // namespace as3935_i2c -} // namespace esphome +} // namespace esphome::as3935_i2c diff --git a/esphome/components/as3935_spi/as3935_spi.cpp b/esphome/components/as3935_spi/as3935_spi.cpp index 1b2e9ccd3fa..026fde2f213 100644 --- a/esphome/components/as3935_spi/as3935_spi.cpp +++ b/esphome/components/as3935_spi/as3935_spi.cpp @@ -1,8 +1,7 @@ #include "as3935_spi.h" #include "esphome/core/log.h" -namespace esphome { -namespace as3935_spi { +namespace esphome::as3935_spi { static const char *const TAG = "as3935_spi"; @@ -42,5 +41,4 @@ uint8_t SPIAS3935Component::read_register(uint8_t reg) { return value; } -} // namespace as3935_spi -} // namespace esphome +} // namespace esphome::as3935_spi diff --git a/esphome/components/as3935_spi/as3935_spi.h b/esphome/components/as3935_spi/as3935_spi.h index e5422f9b377..935707a18c0 100644 --- a/esphome/components/as3935_spi/as3935_spi.h +++ b/esphome/components/as3935_spi/as3935_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/as3935/as3935.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace as3935_spi { +namespace esphome::as3935_spi { enum AS3935RegisterMasks { SPI_READ_M = 0x40 }; @@ -21,5 +20,4 @@ class SPIAS3935Component : public as3935::AS3935Component, uint8_t read_register(uint8_t reg) override; }; -} // namespace as3935_spi -} // namespace esphome +} // namespace esphome::as3935_spi diff --git a/esphome/components/as5600/as5600.cpp b/esphome/components/as5600/as5600.cpp index ee3083d5611..da1add5458b 100644 --- a/esphome/components/as5600/as5600.cpp +++ b/esphome/components/as5600/as5600.cpp @@ -1,8 +1,7 @@ #include "as5600.h" #include "esphome/core/log.h" -namespace esphome { -namespace as5600 { +namespace esphome::as5600 { static const char *const TAG = "as5600"; @@ -134,5 +133,4 @@ optional AS5600Component::read_raw_position() { return pos; } -} // namespace as5600 -} // namespace esphome +} // namespace esphome::as5600 diff --git a/esphome/components/as5600/as5600.h b/esphome/components/as5600/as5600.h index 914a4431bd0..414633f978b 100644 --- a/esphome/components/as5600/as5600.h +++ b/esphome/components/as5600/as5600.h @@ -6,8 +6,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace as5600 { +namespace esphome::as5600 { static const uint16_t POSITION_COUNT = 4096; static const float RAW_TO_DEGREES = 360.0 / POSITION_COUNT; @@ -100,5 +99,4 @@ class AS5600Component : public Component, public i2c::I2CDevice { float range_scale_{1.0}; }; -} // namespace as5600 -} // namespace esphome +} // namespace esphome::as5600 diff --git a/esphome/components/as5600/sensor/as5600_sensor.cpp b/esphome/components/as5600/sensor/as5600_sensor.cpp index 4e549d24d52..ba295659a13 100644 --- a/esphome/components/as5600/sensor/as5600_sensor.cpp +++ b/esphome/components/as5600/sensor/as5600_sensor.cpp @@ -1,8 +1,7 @@ #include "as5600_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace as5600 { +namespace esphome::as5600 { static const char *const TAG = "as5600.sensor"; @@ -75,5 +74,4 @@ void AS5600Sensor::update() { this->status_clear_warning(); } -} // namespace as5600 -} // namespace esphome +} // namespace esphome::as5600 diff --git a/esphome/components/as5600/sensor/as5600_sensor.h b/esphome/components/as5600/sensor/as5600_sensor.h index 77593f4b12c..0086fe54ccd 100644 --- a/esphome/components/as5600/sensor/as5600_sensor.h +++ b/esphome/components/as5600/sensor/as5600_sensor.h @@ -7,8 +7,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/as5600/as5600.h" -namespace esphome { -namespace as5600 { +namespace esphome::as5600 { class AS5600Sensor : public PollingComponent, public Parented, public sensor::Sensor { public: @@ -32,5 +31,4 @@ class AS5600Sensor : public PollingComponent, public Parented, OutRangeMode out_of_range_mode_{OUT_RANGE_MODE_MIN_MAX}; }; -} // namespace as5600 -} // namespace esphome +} // namespace esphome::as5600 diff --git a/esphome/components/as7341/as7341.cpp b/esphome/components/as7341/as7341.cpp index 1e78d814c8c..32094ddf101 100644 --- a/esphome/components/as7341/as7341.cpp +++ b/esphome/components/as7341/as7341.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace as7341 { +namespace esphome::as7341 { static const char *const TAG = "as7341"; @@ -266,5 +265,4 @@ bool AS7341Component::clear_register_bit(uint8_t address, uint8_t bit_position) uint16_t AS7341Component::swap_bytes(uint16_t data) { return (data >> 8) | (data << 8); } -} // namespace as7341 -} // namespace esphome +} // namespace esphome::as7341 diff --git a/esphome/components/as7341/as7341.h b/esphome/components/as7341/as7341.h index 3ede9d4aa4b..8bc157fe79a 100644 --- a/esphome/components/as7341/as7341.h +++ b/esphome/components/as7341/as7341.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace as7341 { +namespace esphome::as7341 { static const uint8_t AS7341_CHIP_ID = 0x09; @@ -139,5 +138,4 @@ class AS7341Component : public PollingComponent, public i2c::I2CDevice { uint16_t channel_readings_[12]; }; -} // namespace as7341 -} // namespace esphome +} // namespace esphome::as7341 diff --git a/esphome/components/at581x/at581x.cpp b/esphome/components/at581x/at581x.cpp index 6fc85b07902..575a9afd40b 100644 --- a/esphome/components/at581x/at581x.cpp +++ b/esphome/components/at581x/at581x.cpp @@ -49,8 +49,7 @@ const uint8_t TRIGGER_KEEP_TIME_ADDR = 0x42; // 4 bytes, so up to 0x45 const uint8_t TIME41_VALUE = 1; const uint8_t SELF_CHECK_TIME_ADDR = 0x38; // 2 bytes, up to 0x39 -namespace esphome { -namespace at581x { +namespace esphome::at581x { static const char *const TAG = "at581x"; @@ -199,5 +198,4 @@ void AT581XComponent::set_rf_mode(bool enable) { } } -} // namespace at581x -} // namespace esphome +} // namespace esphome::at581x diff --git a/esphome/components/at581x/at581x.h b/esphome/components/at581x/at581x.h index 558a5c8b19d..e7f8ee36923 100644 --- a/esphome/components/at581x/at581x.h +++ b/esphome/components/at581x/at581x.h @@ -10,8 +10,7 @@ #endif #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace at581x { +namespace esphome::at581x { class AT581XComponent : public Component, public i2c::I2CDevice { public: @@ -58,5 +57,4 @@ class AT581XComponent : public Component, public i2c::I2CDevice { int power_; /*!< In µA */ }; -} // namespace at581x -} // namespace esphome +} // namespace esphome::at581x diff --git a/esphome/components/at581x/automation.h b/esphome/components/at581x/automation.h index b1611a6758f..eb8b1b25628 100644 --- a/esphome/components/at581x/automation.h +++ b/esphome/components/at581x/automation.h @@ -5,8 +5,7 @@ #include "at581x.h" -namespace esphome { -namespace at581x { +namespace esphome::at581x { template class AT581XResetAction : public Action, public Parented { public: @@ -67,5 +66,4 @@ template class AT581XSettingsAction : public Action, publ } } }; -} // namespace at581x -} // namespace esphome +} // namespace esphome::at581x diff --git a/esphome/components/at581x/switch/rf_switch.cpp b/esphome/components/at581x/switch/rf_switch.cpp index f1d03dc8a54..7432233863e 100644 --- a/esphome/components/at581x/switch/rf_switch.cpp +++ b/esphome/components/at581x/switch/rf_switch.cpp @@ -1,12 +1,10 @@ #include "rf_switch.h" -namespace esphome { -namespace at581x { +namespace esphome::at581x { void RFSwitch::write_state(bool state) { this->publish_state(state); this->parent_->set_rf_mode(state); } -} // namespace at581x -} // namespace esphome +} // namespace esphome::at581x diff --git a/esphome/components/at581x/switch/rf_switch.h b/esphome/components/at581x/switch/rf_switch.h index 920ddbb66a1..47367fad45f 100644 --- a/esphome/components/at581x/switch/rf_switch.h +++ b/esphome/components/at581x/switch/rf_switch.h @@ -3,13 +3,11 @@ #include "esphome/components/switch/switch.h" #include "../at581x.h" -namespace esphome { -namespace at581x { +namespace esphome::at581x { class RFSwitch : public switch_::Switch, public Parented { protected: void write_state(bool state) override; }; -} // namespace at581x -} // namespace esphome +} // namespace esphome::at581x diff --git a/esphome/components/atc_mithermometer/atc_mithermometer.cpp b/esphome/components/atc_mithermometer/atc_mithermometer.cpp index 9afd6334f5b..f8bbd9d55ee 100644 --- a/esphome/components/atc_mithermometer/atc_mithermometer.cpp +++ b/esphome/components/atc_mithermometer/atc_mithermometer.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace atc_mithermometer { +namespace esphome::atc_mithermometer { static const char *const TAG = "atc_mithermometer"; @@ -133,7 +132,6 @@ bool ATCMiThermometer::report_results_(const optional &result, cons return true; } -} // namespace atc_mithermometer -} // namespace esphome +} // namespace esphome::atc_mithermometer #endif diff --git a/esphome/components/atc_mithermometer/atc_mithermometer.h b/esphome/components/atc_mithermometer/atc_mithermometer.h index e37b5f43507..8f62f05bc13 100644 --- a/esphome/components/atc_mithermometer/atc_mithermometer.h +++ b/esphome/components/atc_mithermometer/atc_mithermometer.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace atc_mithermometer { +namespace esphome::atc_mithermometer { struct ParseResult { optional temperature; @@ -44,7 +43,6 @@ class ATCMiThermometer : public Component, public esp32_ble_tracker::ESPBTDevice bool report_results_(const optional &result, const char *address); }; -} // namespace atc_mithermometer -} // namespace esphome +} // namespace esphome::atc_mithermometer #endif diff --git a/esphome/components/atm90e26/atm90e26.cpp b/esphome/components/atm90e26/atm90e26.cpp index e6602411bb8..46948be47d8 100644 --- a/esphome/components/atm90e26/atm90e26.cpp +++ b/esphome/components/atm90e26/atm90e26.cpp @@ -2,8 +2,7 @@ #include "atm90e26_reg.h" #include "esphome/core/log.h" -namespace esphome { -namespace atm90e26 { +namespace esphome::atm90e26 { static const char *const TAG = "atm90e26"; @@ -229,5 +228,4 @@ float ATM90E26Component::get_frequency_() { return freq / 100.0f; } -} // namespace atm90e26 -} // namespace esphome +} // namespace esphome::atm90e26 diff --git a/esphome/components/atm90e26/atm90e26.h b/esphome/components/atm90e26/atm90e26.h index d15a53ea433..657f8f3c433 100644 --- a/esphome/components/atm90e26/atm90e26.h +++ b/esphome/components/atm90e26/atm90e26.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace atm90e26 { +namespace esphome::atm90e26 { class ATM90E26Component : public PollingComponent, public spi::SPIDevice #include "esphome/core/log.h" -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { static const char *const TAG = "atm90e32"; @@ -1313,5 +1312,4 @@ bool ATM90E32Component::validate_spi_read_(uint16_t expected, const char *contex return true; } -} // namespace atm90e32 -} // namespace esphome +} // namespace esphome::atm90e32 diff --git a/esphome/components/atm90e32/atm90e32.h b/esphome/components/atm90e32/atm90e32.h index 62c7bada86c..5fa224b3535 100644 --- a/esphome/components/atm90e32/atm90e32.h +++ b/esphome/components/atm90e32/atm90e32.h @@ -11,8 +11,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { class ATM90E32Component : public PollingComponent, public spi::SPIDevice -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { /* STATUS REGISTERS */ static const uint16_t ATM90E32_REGISTER_METEREN = 0x00; // Metering Enable @@ -268,5 +267,4 @@ static const uint16_t ATM90E32_REGISTER_UANGLEA = 0xFD; // A Voltage Phase Angl static const uint16_t ATM90E32_REGISTER_UANGLEB = 0xFE; // B Voltage Phase Angle static const uint16_t ATM90E32_REGISTER_UANGLEC = 0xFF; // C Voltage Phase Angle -} // namespace atm90e32 -} // namespace esphome +} // namespace esphome::atm90e32 diff --git a/esphome/components/atm90e32/button/atm90e32_button.cpp b/esphome/components/atm90e32/button/atm90e32_button.cpp index a89f071997d..e120e453644 100644 --- a/esphome/components/atm90e32/button/atm90e32_button.cpp +++ b/esphome/components/atm90e32/button/atm90e32_button.cpp @@ -2,8 +2,7 @@ #include "esphome/core/component.h" #include "esphome/core/log.h" -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { static const char *const TAG = "atm90e32.button"; @@ -75,5 +74,4 @@ void ATM90E32ClearPowerOffsetCalibrationButton::press_action() { this->parent_->clear_power_offset_calibrations(); } -} // namespace atm90e32 -} // namespace esphome +} // namespace esphome::atm90e32 diff --git a/esphome/components/atm90e32/button/atm90e32_button.h b/esphome/components/atm90e32/button/atm90e32_button.h index 24495815315..0cfce622934 100644 --- a/esphome/components/atm90e32/button/atm90e32_button.h +++ b/esphome/components/atm90e32/button/atm90e32_button.h @@ -4,8 +4,7 @@ #include "esphome/components/atm90e32/atm90e32.h" #include "esphome/components/button/button.h" -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { class ATM90E32GainCalibrationButton : public button::Button, public Parented { public: @@ -55,5 +54,4 @@ class ATM90E32ClearPowerOffsetCalibrationButton : public button::Button, public void press_action() override; }; -} // namespace atm90e32 -} // namespace esphome +} // namespace esphome::atm90e32 diff --git a/esphome/components/atm90e32/number/atm90e32_number.h b/esphome/components/atm90e32/number/atm90e32_number.h index 9b6129b26d6..a575a94ea49 100644 --- a/esphome/components/atm90e32/number/atm90e32_number.h +++ b/esphome/components/atm90e32/number/atm90e32_number.h @@ -4,13 +4,11 @@ #include "esphome/components/atm90e32/atm90e32.h" #include "esphome/components/number/number.h" -namespace esphome { -namespace atm90e32 { +namespace esphome::atm90e32 { class ATM90E32Number : public number::Number, public Parented { public: void control(float value) override { this->publish_state(value); } }; -} // namespace atm90e32 -} // namespace esphome +} // namespace esphome::atm90e32 diff --git a/esphome/components/audio/audio.cpp b/esphome/components/audio/audio.cpp index b977c4e9181..b0aa3c1abbe 100644 --- a/esphome/components/audio/audio.cpp +++ b/esphome/components/audio/audio.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace audio { +namespace esphome::audio { // Euclidean's algorithm for finding the greatest common divisor static uint32_t gcd(uint32_t a, uint32_t b) { @@ -129,5 +128,4 @@ void scale_audio_samples(const int16_t *audio_samples, int16_t *output_buffer, i } } -} // namespace audio -} // namespace esphome +} // namespace esphome::audio diff --git a/esphome/components/audio/audio.h b/esphome/components/audio/audio.h index 9259f0a3c65..62c57b18cf7 100644 --- a/esphome/components/audio/audio.h +++ b/esphome/components/audio/audio.h @@ -5,8 +5,7 @@ #include #include -namespace esphome { -namespace audio { +namespace esphome::audio { class AudioStreamInfo { /* Class to respresent important parameters of the audio stream that also provides helper function to convert between @@ -195,5 +194,4 @@ inline void pack_q31_as_audio_sample(int32_t sample, uint8_t *data, size_t bytes } } -} // namespace audio -} // namespace esphome +} // namespace esphome::audio diff --git a/esphome/components/audio/audio_decoder.cpp b/esphome/components/audio/audio_decoder.cpp index 7abd03a36e5..3e6fad1101e 100644 --- a/esphome/components/audio/audio_decoder.cpp +++ b/esphome/components/audio/audio_decoder.cpp @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace audio { +namespace esphome::audio { static const char *const TAG = "audio.decoder"; @@ -428,7 +427,6 @@ FileDecoderState AudioDecoder::decode_wav_() { } #endif -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_decoder.h b/esphome/components/audio/audio_decoder.h index 58e982317c3..7ea7a824f96 100644 --- a/esphome/components/audio/audio_decoder.h +++ b/esphome/components/audio/audio_decoder.h @@ -35,8 +35,7 @@ #include #endif -namespace esphome { -namespace audio { +namespace esphome::audio { enum class AudioDecoderState : uint8_t { DECODING = 0, // More data is available to decode @@ -155,7 +154,6 @@ class AudioDecoder { bool pause_output_{false}; }; -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_reader.cpp b/esphome/components/audio/audio_reader.cpp index 79ebf58889f..500f20533cd 100644 --- a/esphome/components/audio/audio_reader.cpp +++ b/esphome/components/audio/audio_reader.cpp @@ -11,8 +11,7 @@ #include "esp_crt_bundle.h" #endif -namespace esphome { -namespace audio { +namespace esphome::audio { static const uint32_t READ_WRITE_TIMEOUT_MS = 20; @@ -289,7 +288,6 @@ void AudioReader::cleanup_connection_() { } } -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_reader.h b/esphome/components/audio/audio_reader.h index 753b310213e..61f187d151d 100644 --- a/esphome/components/audio/audio_reader.h +++ b/esphome/components/audio/audio_reader.h @@ -11,8 +11,7 @@ #include -namespace esphome { -namespace audio { +namespace esphome::audio { enum class AudioReaderState : uint8_t { READING = 0, // More data is available to read @@ -74,7 +73,6 @@ class AudioReader { AudioFileType audio_file_type_{AudioFileType::NONE}; const uint8_t *file_current_{nullptr}; }; -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_resampler.cpp b/esphome/components/audio/audio_resampler.cpp index 20d246f1e04..ac1039971e6 100644 --- a/esphome/components/audio/audio_resampler.cpp +++ b/esphome/components/audio/audio_resampler.cpp @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace audio { +namespace esphome::audio { static const uint32_t READ_WRITE_TIMEOUT_MS = 20; @@ -157,7 +156,6 @@ AudioResamplerState AudioResampler::resample(bool stop_gracefully, int32_t *ms_d return AudioResamplerState::RESAMPLING; } -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_resampler.h b/esphome/components/audio/audio_resampler.h index 082ade33712..e7503d1de07 100644 --- a/esphome/components/audio/audio_resampler.h +++ b/esphome/components/audio/audio_resampler.h @@ -17,8 +17,7 @@ #include // esp-audio-libs -namespace esphome { -namespace audio { +namespace esphome::audio { enum class AudioResamplerState : uint8_t { RESAMPLING, // More data is available to resample @@ -96,7 +95,6 @@ class AudioResampler { std::unique_ptr resampler_; }; -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_transfer_buffer.cpp b/esphome/components/audio/audio_transfer_buffer.cpp index 5cd7cf9e631..6ee9e4d28c0 100644 --- a/esphome/components/audio/audio_transfer_buffer.cpp +++ b/esphome/components/audio/audio_transfer_buffer.cpp @@ -6,8 +6,7 @@ #include "esphome/core/helpers.h" -namespace esphome { -namespace audio { +namespace esphome::audio { AudioTransferBuffer::~AudioTransferBuffer() { this->deallocate_buffer_(); }; @@ -208,7 +207,6 @@ void ConstAudioSourceBuffer::consume(size_t bytes) { this->data_start_ += bytes; } -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio/audio_transfer_buffer.h b/esphome/components/audio/audio_transfer_buffer.h index c32d4d0e41d..7aa830fafa1 100644 --- a/esphome/components/audio/audio_transfer_buffer.h +++ b/esphome/components/audio/audio_transfer_buffer.h @@ -12,8 +12,7 @@ #include -namespace esphome { -namespace audio { +namespace esphome::audio { /// @brief Abstract interface for writing decoded audio data to a sink. class AudioSinkCallback { @@ -213,7 +212,6 @@ class ConstAudioSourceBuffer : public AudioReadableBuffer { size_t length_{0}; }; -} // namespace audio -} // namespace esphome +} // namespace esphome::audio #endif diff --git a/esphome/components/audio_adc/audio_adc.h b/esphome/components/audio_adc/audio_adc.h index 94bfb57db55..a1da2360acd 100644 --- a/esphome/components/audio_adc/audio_adc.h +++ b/esphome/components/audio_adc/audio_adc.h @@ -3,8 +3,7 @@ #include "esphome/core/defines.h" #include "esphome/core/hal.h" -namespace esphome { -namespace audio_adc { +namespace esphome::audio_adc { class AudioAdc { public: @@ -13,5 +12,4 @@ class AudioAdc { virtual float mic_gain() = 0; }; -} // namespace audio_adc -} // namespace esphome +} // namespace esphome::audio_adc diff --git a/esphome/components/audio_adc/automation.h b/esphome/components/audio_adc/automation.h index 0c424684793..e74e0232036 100644 --- a/esphome/components/audio_adc/automation.h +++ b/esphome/components/audio_adc/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "audio_adc.h" -namespace esphome { -namespace audio_adc { +namespace esphome::audio_adc { template class SetMicGainAction : public Action { public: @@ -19,5 +18,4 @@ template class SetMicGainAction : public Action { AudioAdc *audio_adc_; }; -} // namespace audio_adc -} // namespace esphome +} // namespace esphome::audio_adc diff --git a/esphome/components/audio_dac/audio_dac.h b/esphome/components/audio_dac/audio_dac.h index a62d17b8497..16a422f4ac7 100644 --- a/esphome/components/audio_dac/audio_dac.h +++ b/esphome/components/audio_dac/audio_dac.h @@ -3,8 +3,7 @@ #include "esphome/core/defines.h" #include "esphome/core/hal.h" -namespace esphome { -namespace audio_dac { +namespace esphome::audio_dac { class AudioDac { public: @@ -19,5 +18,4 @@ class AudioDac { bool is_muted_{false}; }; -} // namespace audio_dac -} // namespace esphome +} // namespace esphome::audio_dac diff --git a/esphome/components/audio_dac/automation.h b/esphome/components/audio_dac/automation.h index 3eb3441f3d3..67bbc78ac21 100644 --- a/esphome/components/audio_dac/automation.h +++ b/esphome/components/audio_dac/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "audio_dac.h" -namespace esphome { -namespace audio_dac { +namespace esphome::audio_dac { template class MuteOffAction : public Action { public: @@ -39,5 +38,4 @@ template class SetVolumeAction : public Action { AudioDac *audio_dac_; }; -} // namespace audio_dac -} // namespace esphome +} // namespace esphome::audio_dac diff --git a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp index ab3f1dad4f9..3869224b911 100644 --- a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp +++ b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace axs15231 { +namespace esphome::axs15231 { static const char *const TAG = "ax15231.touchscreen"; @@ -64,5 +63,4 @@ void AXS15231Touchscreen::dump_config() { this->x_raw_max_, this->y_raw_max_); } -} // namespace axs15231 -} // namespace esphome +} // namespace esphome::axs15231 diff --git a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.h b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.h index a55c5c0d324..94d232777c6 100644 --- a/esphome/components/axs15231/touchscreen/axs15231_touchscreen.h +++ b/esphome/components/axs15231/touchscreen/axs15231_touchscreen.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace axs15231 { +namespace esphome::axs15231 { class AXS15231Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice { public: @@ -23,5 +22,4 @@ class AXS15231Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevi GPIOPin *reset_pin_{}; }; -} // namespace axs15231 -} // namespace esphome +} // namespace esphome::axs15231 diff --git a/esphome/components/b_parasite/b_parasite.cpp b/esphome/components/b_parasite/b_parasite.cpp index 7be26efa7f2..160d22a5b66 100644 --- a/esphome/components/b_parasite/b_parasite.cpp +++ b/esphome/components/b_parasite/b_parasite.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace b_parasite { +namespace esphome::b_parasite { static const char *const TAG = "b_parasite"; @@ -113,7 +112,6 @@ bool BParasite::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { return true; } -} // namespace b_parasite -} // namespace esphome +} // namespace esphome::b_parasite #endif // USE_ESP32 diff --git a/esphome/components/b_parasite/b_parasite.h b/esphome/components/b_parasite/b_parasite.h index 7dd08968ec0..c719599b998 100644 --- a/esphome/components/b_parasite/b_parasite.h +++ b/esphome/components/b_parasite/b_parasite.h @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace b_parasite { +namespace esphome::b_parasite { class BParasite : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -35,7 +34,6 @@ class BParasite : public Component, public esp32_ble_tracker::ESPBTDeviceListene sensor::Sensor *illuminance_{nullptr}; }; -} // namespace b_parasite -} // namespace esphome +} // namespace esphome::b_parasite #endif // USE_ESP32 diff --git a/esphome/components/ballu/ballu.cpp b/esphome/components/ballu/ballu.cpp index deb742f8c67..eebc970795a 100644 --- a/esphome/components/ballu/ballu.cpp +++ b/esphome/components/ballu/ballu.cpp @@ -1,8 +1,7 @@ #include "ballu.h" #include "esphome/core/log.h" -namespace esphome { -namespace ballu { +namespace esphome::ballu { static const char *const TAG = "ballu.climate"; @@ -235,5 +234,4 @@ bool BalluClimate::on_receive(remote_base::RemoteReceiveData data) { return true; } -} // namespace ballu -} // namespace esphome +} // namespace esphome::ballu diff --git a/esphome/components/ballu/ballu.h b/esphome/components/ballu/ballu.h index 80a4699cfb0..8a45d39c703 100644 --- a/esphome/components/ballu/ballu.h +++ b/esphome/components/ballu/ballu.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace ballu { +namespace esphome::ballu { // Support for Ballu air conditioners with YKR-K/002E remote @@ -27,5 +26,4 @@ class BalluClimate : public climate_ir::ClimateIR { bool on_receive(remote_base::RemoteReceiveData data) override; }; -} // namespace ballu -} // namespace esphome +} // namespace esphome::ballu diff --git a/esphome/components/bang_bang/bang_bang_climate.cpp b/esphome/components/bang_bang/bang_bang_climate.cpp index 1058bce6a45..5dfb1213429 100644 --- a/esphome/components/bang_bang/bang_bang_climate.cpp +++ b/esphome/components/bang_bang/bang_bang_climate.cpp @@ -1,8 +1,7 @@ #include "bang_bang_climate.h" #include "esphome/core/log.h" -namespace esphome { -namespace bang_bang { +namespace esphome::bang_bang { static const char *const TAG = "bang_bang.climate"; @@ -231,5 +230,4 @@ BangBangClimateTargetTempConfig::BangBangClimateTargetTempConfig(float default_t float default_temperature_high) : default_temperature_low(default_temperature_low), default_temperature_high(default_temperature_high) {} -} // namespace bang_bang -} // namespace esphome +} // namespace esphome::bang_bang diff --git a/esphome/components/bang_bang/bang_bang_climate.h b/esphome/components/bang_bang/bang_bang_climate.h index d0ddef2848e..1e5ff84883f 100644 --- a/esphome/components/bang_bang/bang_bang_climate.h +++ b/esphome/components/bang_bang/bang_bang_climate.h @@ -5,8 +5,7 @@ #include "esphome/components/climate/climate.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bang_bang { +namespace esphome::bang_bang { struct BangBangClimateTargetTempConfig { public: @@ -84,5 +83,4 @@ class BangBangClimate : public climate::Climate, public Component { BangBangClimateTargetTempConfig away_config_{}; }; -} // namespace bang_bang -} // namespace esphome +} // namespace esphome::bang_bang diff --git a/esphome/components/bedjet/bedjet_child.h b/esphome/components/bedjet/bedjet_child.h index 4e07745c631..5b6c5f7f25a 100644 --- a/esphome/components/bedjet/bedjet_child.h +++ b/esphome/components/bedjet/bedjet_child.h @@ -3,8 +3,7 @@ #include "bedjet_codec.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { // Forward declare BedJetHub class BedJetHub; @@ -19,5 +18,4 @@ class BedJetClient : public Parented { virtual std::string describe() = 0; }; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bedjet/bedjet_codec.cpp b/esphome/components/bedjet/bedjet_codec.cpp index 7a959390f31..6f6242a4cd7 100644 --- a/esphome/components/bedjet/bedjet_codec.cpp +++ b/esphome/components/bedjet/bedjet_codec.cpp @@ -3,8 +3,7 @@ #include #include -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { /// Converts a BedJet temp step into degrees Fahrenheit. float bedjet_temp_to_f(const uint8_t temp) { @@ -177,5 +176,4 @@ float bedjet_temp_to_c(uint8_t temp) { return temp / 2.0f; } -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bedjet/bedjet_codec.h b/esphome/components/bedjet/bedjet_codec.h index 3936ba23151..7cf463b5665 100644 --- a/esphome/components/bedjet/bedjet_codec.h +++ b/esphome/components/bedjet/bedjet_codec.h @@ -5,8 +5,7 @@ #include "bedjet_const.h" -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { struct BedjetPacket { uint8_t data_length; @@ -190,5 +189,4 @@ class BedjetCodec { /// Converts a BedJet temp step into degrees Celsius. float bedjet_temp_to_c(uint8_t temp); -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bedjet/bedjet_const.h b/esphome/components/bedjet/bedjet_const.h index 10f403dd1ac..eb777a6a834 100644 --- a/esphome/components/bedjet/bedjet_const.h +++ b/esphome/components/bedjet/bedjet_const.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { static const char *const TAG = "bedjet"; @@ -101,5 +100,4 @@ static const uint8_t BEDJET_FAN_SPEED_COUNT = 20; static constexpr const char *const BEDJET_FAN_STEP_NAMES[BEDJET_FAN_SPEED_COUNT] = BEDJET_FAN_STEP_NAMES_; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bedjet/bedjet_hub.cpp b/esphome/components/bedjet/bedjet_hub.cpp index fec34c5b2ab..b04603b8c6d 100644 --- a/esphome/components/bedjet/bedjet_hub.cpp +++ b/esphome/components/bedjet/bedjet_hub.cpp @@ -6,8 +6,7 @@ #include "esphome/core/application.h" #include -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { static const LogString *bedjet_button_to_string(BedjetButton button) { switch (button) { @@ -551,7 +550,6 @@ void BedJetHub::register_child(BedJetClient *obj) { obj->set_parent(this); } -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/bedjet_hub.h b/esphome/components/bedjet/bedjet_hub.h index 59b0af93ade..9f25f7a4660 100644 --- a/esphome/components/bedjet/bedjet_hub.h +++ b/esphome/components/bedjet/bedjet_hub.h @@ -18,8 +18,7 @@ #include -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { namespace espbt = esphome::esp32_ble_tracker; @@ -172,7 +171,6 @@ class BedJetHub : public esphome::ble_client::BLEClientNode, public PollingCompo uint8_t write_notify_config_descriptor_(bool enable); }; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/climate/bedjet_climate.cpp b/esphome/components/bedjet/climate/bedjet_climate.cpp index 88ed902a112..196d4785e98 100644 --- a/esphome/components/bedjet/climate/bedjet_climate.cpp +++ b/esphome/components/bedjet/climate/bedjet_climate.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { using namespace esphome::climate; @@ -359,7 +358,6 @@ void BedJetClimate::update() { ESP_LOGD(TAG, "[%s] update_status result=%s", this->get_name().c_str(), result ? "true" : "false"); } -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/climate/bedjet_climate.h b/esphome/components/bedjet/climate/bedjet_climate.h index d12c2a8255c..f59e67eeb7b 100644 --- a/esphome/components/bedjet/climate/bedjet_climate.h +++ b/esphome/components/bedjet/climate/bedjet_climate.h @@ -10,8 +10,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { class BedJetClimate : public climate::Climate, public BedJetClient, public PollingComponent { public: @@ -72,7 +71,6 @@ class BedJetClimate : public climate::Climate, public BedJetClient, public Polli } }; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/fan/bedjet_fan.cpp b/esphome/components/bedjet/fan/bedjet_fan.cpp index 9539e169a45..4b1bd14ae34 100644 --- a/esphome/components/bedjet/fan/bedjet_fan.cpp +++ b/esphome/components/bedjet/fan/bedjet_fan.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { using namespace esphome::fan; @@ -109,7 +108,6 @@ void BedJetFan::reset_state_() { this->state = false; this->publish_state(); } -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/fan/bedjet_fan.h b/esphome/components/bedjet/fan/bedjet_fan.h index 19db06e9d3c..03f42f1438a 100644 --- a/esphome/components/bedjet/fan/bedjet_fan.h +++ b/esphome/components/bedjet/fan/bedjet_fan.h @@ -10,8 +10,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { class BedJetFan : public fan::Fan, public BedJetClient, public PollingComponent { public: @@ -34,7 +33,6 @@ class BedJetFan : public fan::Fan, public BedJetClient, public PollingComponent bool update_status_(); }; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet #endif diff --git a/esphome/components/bedjet/sensor/bedjet_sensor.cpp b/esphome/components/bedjet/sensor/bedjet_sensor.cpp index 2fda8c927f1..05417bd5193 100644 --- a/esphome/components/bedjet/sensor/bedjet_sensor.cpp +++ b/esphome/components/bedjet/sensor/bedjet_sensor.cpp @@ -1,8 +1,7 @@ #include "bedjet_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { std::string BedjetSensor::describe() { return "BedJet Sensor"; } @@ -30,5 +29,4 @@ void BedjetSensor::on_status(const BedjetStatusPacket *data) { } } -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bedjet/sensor/bedjet_sensor.h b/esphome/components/bedjet/sensor/bedjet_sensor.h index 8cbaa863eec..0c3f713579d 100644 --- a/esphome/components/bedjet/sensor/bedjet_sensor.h +++ b/esphome/components/bedjet/sensor/bedjet_sensor.h @@ -5,8 +5,7 @@ #include "esphome/components/bedjet/bedjet_child.h" #include "esphome/components/bedjet/bedjet_codec.h" -namespace esphome { -namespace bedjet { +namespace esphome::bedjet { class BedjetSensor : public BedJetClient, public Component { public: @@ -28,5 +27,4 @@ class BedjetSensor : public BedJetClient, public Component { sensor::Sensor *ambient_temperature_sensor_{nullptr}; }; -} // namespace bedjet -} // namespace esphome +} // namespace esphome::bedjet diff --git a/esphome/components/bh1900nux/bh1900nux.cpp b/esphome/components/bh1900nux/bh1900nux.cpp index 0e71bd6532b..4f746a17d4b 100644 --- a/esphome/components/bh1900nux/bh1900nux.cpp +++ b/esphome/components/bh1900nux/bh1900nux.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "bh1900nux.h" -namespace esphome { -namespace bh1900nux { +namespace esphome::bh1900nux { static const char *const TAG = "bh1900nux.sensor"; @@ -50,5 +49,4 @@ void BH1900NUXSensor::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace bh1900nux -} // namespace esphome +} // namespace esphome::bh1900nux diff --git a/esphome/components/bh1900nux/bh1900nux.h b/esphome/components/bh1900nux/bh1900nux.h index fd7f8848d63..61d1bac268e 100644 --- a/esphome/components/bh1900nux/bh1900nux.h +++ b/esphome/components/bh1900nux/bh1900nux.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bh1900nux { +namespace esphome::bh1900nux { class BH1900NUXSensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { public: @@ -14,5 +13,4 @@ class BH1900NUXSensor : public sensor::Sensor, public PollingComponent, public i void dump_config() override; }; -} // namespace bh1900nux -} // namespace esphome +} // namespace esphome::bh1900nux diff --git a/esphome/components/binary/fan/binary_fan.cpp b/esphome/components/binary/fan/binary_fan.cpp index 17d4df095a0..118d87c09d0 100644 --- a/esphome/components/binary/fan/binary_fan.cpp +++ b/esphome/components/binary/fan/binary_fan.cpp @@ -1,8 +1,7 @@ #include "binary_fan.h" #include "esphome/core/log.h" -namespace esphome { -namespace binary { +namespace esphome::binary { static const char *const TAG = "binary.fan"; @@ -39,5 +38,4 @@ void BinaryFan::write_state_() { this->direction_->set_state(this->direction == fan::FanDirection::REVERSE); } -} // namespace binary -} // namespace esphome +} // namespace esphome::binary diff --git a/esphome/components/binary/fan/binary_fan.h b/esphome/components/binary/fan/binary_fan.h index 16bce2e6af2..17157dd29ca 100644 --- a/esphome/components/binary/fan/binary_fan.h +++ b/esphome/components/binary/fan/binary_fan.h @@ -4,8 +4,7 @@ #include "esphome/components/output/binary_output.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace binary { +namespace esphome::binary { class BinaryFan : public Component, public fan::Fan { public: @@ -27,5 +26,4 @@ class BinaryFan : public Component, public fan::Fan { output::BinaryOutput *direction_{nullptr}; }; -} // namespace binary -} // namespace esphome +} // namespace esphome::binary diff --git a/esphome/components/binary/light/binary_light_output.h b/esphome/components/binary/light/binary_light_output.h index 8346a82cf0e..f6be7e162e9 100644 --- a/esphome/components/binary/light/binary_light_output.h +++ b/esphome/components/binary/light/binary_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/binary_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace binary { +namespace esphome::binary { class BinaryLightOutput : public light::LightOutput { public: @@ -29,5 +28,4 @@ class BinaryLightOutput : public light::LightOutput { output::BinaryOutput *output_; }; -} // namespace binary -} // namespace esphome +} // namespace esphome::binary diff --git a/esphome/components/binary_sensor_map/binary_sensor_map.cpp b/esphome/components/binary_sensor_map/binary_sensor_map.cpp index 0bf62028939..316d44ba59e 100644 --- a/esphome/components/binary_sensor_map/binary_sensor_map.cpp +++ b/esphome/components/binary_sensor_map/binary_sensor_map.cpp @@ -1,8 +1,7 @@ #include "binary_sensor_map.h" #include "esphome/core/log.h" -namespace esphome { -namespace binary_sensor_map { +namespace esphome::binary_sensor_map { static const char *const TAG = "binary_sensor_map"; @@ -138,5 +137,4 @@ void BinarySensorMap::add_channel(binary_sensor::BinarySensor *sensor, float pro }; this->channels_.push_back(sensor_channel); } -} // namespace binary_sensor_map -} // namespace esphome +} // namespace esphome::binary_sensor_map diff --git a/esphome/components/binary_sensor_map/binary_sensor_map.h b/esphome/components/binary_sensor_map/binary_sensor_map.h index a07154c0e86..60224242db6 100644 --- a/esphome/components/binary_sensor_map/binary_sensor_map.h +++ b/esphome/components/binary_sensor_map/binary_sensor_map.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace binary_sensor_map { +namespace esphome::binary_sensor_map { enum BinarySensorMapType { BINARY_SENSOR_MAP_TYPE_GROUP, @@ -96,5 +95,4 @@ class BinarySensorMap : public sensor::Sensor, public Component { float bayesian_predicate_(bool sensor_state, float prior, float prob_given_true, float prob_given_false); }; -} // namespace binary_sensor_map -} // namespace esphome +} // namespace esphome::binary_sensor_map diff --git a/esphome/components/bl0906/bl0906.cpp b/esphome/components/bl0906/bl0906.cpp index d554057f7b0..d3877570512 100644 --- a/esphome/components/bl0906/bl0906.cpp +++ b/esphome/components/bl0906/bl0906.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace bl0906 { +namespace esphome::bl0906 { static const char *const TAG = "bl0906"; @@ -262,5 +261,4 @@ void BL0906::dump_config() { LOG_SENSOR(" ", "Temperature", this->temperature_sensor_); } -} // namespace bl0906 -} // namespace esphome +} // namespace esphome::bl0906 diff --git a/esphome/components/bl0906/bl0906.h b/esphome/components/bl0906/bl0906.h index f7ba5423d27..821aac476c4 100644 --- a/esphome/components/bl0906/bl0906.h +++ b/esphome/components/bl0906/bl0906.h @@ -9,8 +9,7 @@ // https://www.belling.com.cn/media/file_object/bel_product/BL0906/datasheet/BL0906_V1.02_cn.pdf // https://www.belling.com.cn/media/file_object/bel_product/BL0906/guide/BL0906%20APP%20Note_V1.02.pdf -namespace esphome { -namespace bl0906 { +namespace esphome::bl0906 { // Stage values for the read state machine. After STAGE_CHANNEL_6 the state machine // jumps to the two sentinel stages below, then to STAGE_IDLE which marks the cycle @@ -109,5 +108,4 @@ template class ResetEnergyAction : public Action, public void play(const Ts &...x) override { this->parent_->enqueue_action_(&BL0906::reset_energy_); } }; -} // namespace bl0906 -} // namespace esphome +} // namespace esphome::bl0906 diff --git a/esphome/components/bl0906/constants.h b/esphome/components/bl0906/constants.h index a174e54bb26..423d460210c 100644 --- a/esphome/components/bl0906/constants.h +++ b/esphome/components/bl0906/constants.h @@ -1,8 +1,7 @@ #pragma once #include -namespace esphome { -namespace bl0906 { +namespace esphome::bl0906 { // Total power conversion static const float BL0906_WATT = 16 * 1.097 * 1.097 * (20000 + 20000 + 20000 + 20000 + 20000) / @@ -118,5 +117,4 @@ const uint8_t BL0906_INIT[2][6] = { // Enable User Operation Write {BL0906_WRITE_COMMAND, BL0906_USR_WRPROT, 0x55, 0x55, 0x00, 0xB7}}; -} // namespace bl0906 -} // namespace esphome +} // namespace esphome::bl0906 diff --git a/esphome/components/bl0939/bl0939.cpp b/esphome/components/bl0939/bl0939.cpp index 7428e487402..9ae3360e3ac 100644 --- a/esphome/components/bl0939/bl0939.cpp +++ b/esphome/components/bl0939/bl0939.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace bl0939 { +namespace esphome::bl0939 { static const char *const TAG = "bl0939"; @@ -142,5 +141,4 @@ uint32_t BL0939::to_uint32_t(ube24_t input) { return input.h << 16 | input.m << int32_t BL0939::to_int32_t(sbe24_t input) { return input.h << 16 | input.m << 8 | input.l; } -} // namespace bl0939 -} // namespace esphome +} // namespace esphome::bl0939 diff --git a/esphome/components/bl0939/bl0939.h b/esphome/components/bl0939/bl0939.h index 673d4ff351f..b4f6d42e71f 100644 --- a/esphome/components/bl0939/bl0939.h +++ b/esphome/components/bl0939/bl0939.h @@ -4,8 +4,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bl0939 { +namespace esphome::bl0939 { // https://datasheet.lcsc.com/lcsc/2108071830_BL-Shanghai-Belling-BL0939_C2841044.pdf // (unfortunately chinese, but the formulas can be easily understood) @@ -103,5 +102,4 @@ class BL0939 : public PollingComponent, public uart::UARTDevice { void received_package_(const DataPacket *data) const; }; -} // namespace bl0939 -} // namespace esphome +} // namespace esphome::bl0939 diff --git a/esphome/components/bl0940/bl0940.cpp b/esphome/components/bl0940/bl0940.cpp index 31625ebf6d6..b7df603f2f4 100644 --- a/esphome/components/bl0940/bl0940.cpp +++ b/esphome/components/bl0940/bl0940.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { static const char *const TAG = "bl0940"; @@ -274,5 +273,4 @@ void BL0940::dump_config() { // NOLINT(readability-function-cognitive-complexit LOG_SENSOR("", "External temperature", this->external_temperature_sensor_); } -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0940/bl0940.h b/esphome/components/bl0940/bl0940.h index e0ca748a222..14cb69d0b09 100644 --- a/esphome/components/bl0940/bl0940.h +++ b/esphome/components/bl0940/bl0940.h @@ -12,8 +12,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { // Caveat: All these values are big endian (low - middle - high) struct DataPacket { @@ -148,5 +147,4 @@ class BL0940 : public PollingComponent, public uart::UARTDevice { void recalibrate_(); }; -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0940/button/calibration_reset_button.cpp b/esphome/components/bl0940/button/calibration_reset_button.cpp index 79a6b872d82..a0b41b9a5bb 100644 --- a/esphome/components/bl0940/button/calibration_reset_button.cpp +++ b/esphome/components/bl0940/button/calibration_reset_button.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { static const char *const TAG = "bl0940.button.calibration_reset"; @@ -16,5 +15,4 @@ void CalibrationResetButton::press_action() { this->parent_->reset_calibration(); } -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0940/button/calibration_reset_button.h b/esphome/components/bl0940/button/calibration_reset_button.h index 6ea3b35cb49..d528992d586 100644 --- a/esphome/components/bl0940/button/calibration_reset_button.h +++ b/esphome/components/bl0940/button/calibration_reset_button.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/button/button.h" -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { class BL0940; // Forward declaration of BL0940 class @@ -15,5 +14,4 @@ class CalibrationResetButton : public button::Button, public Component, public P void press_action() override; }; -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0940/number/calibration_number.cpp b/esphome/components/bl0940/number/calibration_number.cpp index 5e775004bd9..6f054443a28 100644 --- a/esphome/components/bl0940/number/calibration_number.cpp +++ b/esphome/components/bl0940/number/calibration_number.cpp @@ -1,8 +1,7 @@ #include "calibration_number.h" #include "esphome/core/log.h" -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { static const char *const TAG = "bl0940.number"; @@ -25,5 +24,4 @@ void CalibrationNumber::control(float value) { void CalibrationNumber::dump_config() { LOG_NUMBER("", "Calibration Number", this); } -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0940/number/calibration_number.h b/esphome/components/bl0940/number/calibration_number.h index 3a19e36dc95..062890d918e 100644 --- a/esphome/components/bl0940/number/calibration_number.h +++ b/esphome/components/bl0940/number/calibration_number.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace bl0940 { +namespace esphome::bl0940 { class CalibrationNumber : public number::Number, public Component { public: @@ -22,5 +21,4 @@ class CalibrationNumber : public number::Number, public Component { ESPPreferenceObject pref_; }; -} // namespace bl0940 -} // namespace esphome +} // namespace esphome::bl0940 diff --git a/esphome/components/bl0942/bl0942.cpp b/esphome/components/bl0942/bl0942.cpp index 074aff96431..1c57616c826 100644 --- a/esphome/components/bl0942/bl0942.cpp +++ b/esphome/components/bl0942/bl0942.cpp @@ -4,8 +4,7 @@ // Datasheet: https://www.belling.com.cn/media/file_object/bel_product/BL0942/datasheet/BL0942_V1.06_en.pdf -namespace esphome { -namespace bl0942 { +namespace esphome::bl0942 { static const char *const TAG = "bl0942"; @@ -210,5 +209,4 @@ void BL0942::dump_config() { // NOLINT(readability-function-cognitive-complexit LOG_SENSOR("", "Frequency", this->frequency_sensor_); } -} // namespace bl0942 -} // namespace esphome +} // namespace esphome::bl0942 diff --git a/esphome/components/bl0942/bl0942.h b/esphome/components/bl0942/bl0942.h index 7604399c25d..c3668786377 100644 --- a/esphome/components/bl0942/bl0942.h +++ b/esphome/components/bl0942/bl0942.h @@ -5,8 +5,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bl0942 { +namespace esphome::bl0942 { // The BL0942 IC is "calibration-free", which means that it doesn't care // at all about calibration, and that's left to software. It measures a @@ -147,5 +146,4 @@ class BL0942 : public PollingComponent, public uart::UARTDevice { void write_reg_(uint8_t reg, uint32_t val); void received_package_(DataPacket *data); }; -} // namespace bl0942 -} // namespace esphome +} // namespace esphome::bl0942 diff --git a/esphome/components/ble_presence/ble_presence_device.cpp b/esphome/components/ble_presence/ble_presence_device.cpp index e482bb9a78d..4a70648ac52 100644 --- a/esphome/components/ble_presence/ble_presence_device.cpp +++ b/esphome/components/ble_presence/ble_presence_device.cpp @@ -3,14 +3,12 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_presence { +namespace esphome::ble_presence { static const char *const TAG = "ble_presence"; void BLEPresenceDevice::dump_config() { LOG_BINARY_SENSOR("", "BLE Presence", this); } -} // namespace ble_presence -} // namespace esphome +} // namespace esphome::ble_presence #endif diff --git a/esphome/components/ble_presence/ble_presence_device.h b/esphome/components/ble_presence/ble_presence_device.h index 8ae5edab3ad..76e80799485 100644 --- a/esphome/components/ble_presence/ble_presence_device.h +++ b/esphome/components/ble_presence/ble_presence_device.h @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_presence { +namespace esphome::ble_presence { class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff, public esp32_ble_tracker::ESPBTDeviceListener, @@ -137,7 +136,6 @@ class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff, uint32_t timeout_{}; }; -} // namespace ble_presence -} // namespace esphome +} // namespace esphome::ble_presence #endif diff --git a/esphome/components/ble_rssi/ble_rssi_sensor.cpp b/esphome/components/ble_rssi/ble_rssi_sensor.cpp index 4b37fcc6ef5..f678865f47c 100644 --- a/esphome/components/ble_rssi/ble_rssi_sensor.cpp +++ b/esphome/components/ble_rssi/ble_rssi_sensor.cpp @@ -3,14 +3,12 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_rssi { +namespace esphome::ble_rssi { static const char *const TAG = "ble_rssi"; void BLERSSISensor::dump_config() { LOG_SENSOR("", "BLE RSSI Sensor", this); } -} // namespace ble_rssi -} // namespace esphome +} // namespace esphome::ble_rssi #endif diff --git a/esphome/components/ble_rssi/ble_rssi_sensor.h b/esphome/components/ble_rssi/ble_rssi_sensor.h index 81f21c94ddb..a876fa51d27 100644 --- a/esphome/components/ble_rssi/ble_rssi_sensor.h +++ b/esphome/components/ble_rssi/ble_rssi_sensor.h @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_rssi { +namespace esphome::ble_rssi { class BLERSSISensor : public sensor::Sensor, public esp32_ble_tracker::ESPBTDeviceListener, public Component { public: @@ -120,7 +119,6 @@ class BLERSSISensor : public sensor::Sensor, public esp32_ble_tracker::ESPBTDevi bool check_ibeacon_minor_; }; -} // namespace ble_rssi -} // namespace esphome +} // namespace esphome::ble_rssi #endif diff --git a/esphome/components/ble_scanner/ble_scanner.cpp b/esphome/components/ble_scanner/ble_scanner.cpp index f2cda227bb3..d85894edc8a 100644 --- a/esphome/components/ble_scanner/ble_scanner.cpp +++ b/esphome/components/ble_scanner/ble_scanner.cpp @@ -3,14 +3,12 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_scanner { +namespace esphome::ble_scanner { static const char *const TAG = "ble_scanner"; void BLEScanner::dump_config() { LOG_TEXT_SENSOR("", "BLE Scanner", this); } -} // namespace ble_scanner -} // namespace esphome +} // namespace esphome::ble_scanner #endif diff --git a/esphome/components/ble_scanner/ble_scanner.h b/esphome/components/ble_scanner/ble_scanner.h index c6d7f24ccec..c2d48741b1e 100644 --- a/esphome/components/ble_scanner/ble_scanner.h +++ b/esphome/components/ble_scanner/ble_scanner.h @@ -10,8 +10,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ble_scanner { +namespace esphome::ble_scanner { class BLEScanner : public text_sensor::TextSensor, public esp32_ble_tracker::ESPBTDeviceListener, public Component { public: @@ -43,7 +42,6 @@ class BLEScanner : public text_sensor::TextSensor, public esp32_ble_tracker::ESP void dump_config() override; }; -} // namespace ble_scanner -} // namespace esphome +} // namespace esphome::ble_scanner #endif diff --git a/esphome/components/bme280_base/bme280_base.cpp b/esphome/components/bme280_base/bme280_base.cpp index f31940df106..0f7e42cce3e 100644 --- a/esphome/components/bme280_base/bme280_base.cpp +++ b/esphome/components/bme280_base/bme280_base.cpp @@ -9,8 +9,7 @@ #define BME280_ERROR_WRONG_CHIP_ID "Wrong chip ID or no response" -namespace esphome { -namespace bme280_base { +namespace esphome::bme280_base { static const char *const TAG = "bme280.sensor"; @@ -355,5 +354,4 @@ uint16_t BME280Component::read_u16_le_(uint8_t a_register) { } int16_t BME280Component::read_s16_le_(uint8_t a_register) { return this->read_u16_le_(a_register); } -} // namespace bme280_base -} // namespace esphome +} // namespace esphome::bme280_base diff --git a/esphome/components/bme280_base/bme280_base.h b/esphome/components/bme280_base/bme280_base.h index 00781d05b20..7fe5f7401da 100644 --- a/esphome/components/bme280_base/bme280_base.h +++ b/esphome/components/bme280_base/bme280_base.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bme280_base { +namespace esphome::bme280_base { /// Internal struct storing the calibration values of an BME280. struct BME280CalibrationData { @@ -109,5 +108,4 @@ class BME280Component : public PollingComponent { } error_code_{NONE}; }; -} // namespace bme280_base -} // namespace esphome +} // namespace esphome::bme280_base diff --git a/esphome/components/bme280_i2c/bme280_i2c.cpp b/esphome/components/bme280_i2c/bme280_i2c.cpp index e29675b5b75..f4380b0d343 100644 --- a/esphome/components/bme280_i2c/bme280_i2c.cpp +++ b/esphome/components/bme280_i2c/bme280_i2c.cpp @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "../bme280_base/bme280_base.h" -namespace esphome { -namespace bme280_i2c { +namespace esphome::bme280_i2c { bool BME280I2CComponent::read_byte(uint8_t a_register, uint8_t *data) { return I2CDevice::read_byte(a_register, data); @@ -26,5 +25,4 @@ void BME280I2CComponent::dump_config() { BME280Component::dump_config(); } -} // namespace bme280_i2c -} // namespace esphome +} // namespace esphome::bme280_i2c diff --git a/esphome/components/bme280_i2c/bme280_i2c.h b/esphome/components/bme280_i2c/bme280_i2c.h index c5e2f7e342a..ad4a283fc78 100644 --- a/esphome/components/bme280_i2c/bme280_i2c.h +++ b/esphome/components/bme280_i2c/bme280_i2c.h @@ -3,8 +3,7 @@ #include "esphome/components/bme280_base/bme280_base.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bme280_i2c { +namespace esphome::bme280_i2c { static const char *const TAG = "bme280_i2c.sensor"; @@ -16,5 +15,4 @@ class BME280I2CComponent : public esphome::bme280_base::BME280Component, public void dump_config() override; }; -} // namespace bme280_i2c -} // namespace esphome +} // namespace esphome::bme280_i2c diff --git a/esphome/components/bme280_spi/bme280_spi.cpp b/esphome/components/bme280_spi/bme280_spi.cpp index c6ebfdfd0b6..a4e7b7d95c3 100644 --- a/esphome/components/bme280_spi/bme280_spi.cpp +++ b/esphome/components/bme280_spi/bme280_spi.cpp @@ -4,8 +4,7 @@ #include "bme280_spi.h" #include -namespace esphome { -namespace bme280_spi { +namespace esphome::bme280_spi { uint8_t set_bit(uint8_t num, int position) { int mask = 1 << position; @@ -61,5 +60,4 @@ bool BME280SPIComponent::read_byte_16(uint8_t a_register, uint16_t *data) { return true; } -} // namespace bme280_spi -} // namespace esphome +} // namespace esphome::bme280_spi diff --git a/esphome/components/bme280_spi/bme280_spi.h b/esphome/components/bme280_spi/bme280_spi.h index b6b8997fa76..4e842e9596c 100644 --- a/esphome/components/bme280_spi/bme280_spi.h +++ b/esphome/components/bme280_spi/bme280_spi.h @@ -3,8 +3,7 @@ #include "esphome/components/bme280_base/bme280_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace bme280_spi { +namespace esphome::bme280_spi { class BME280SPIComponent : public esphome::bme280_base::BME280Component, public spi::SPIDeviceheater_duration_ = heater_duration; } -} // namespace bme680 -} // namespace esphome +} // namespace esphome::bme680 diff --git a/esphome/components/bme680/bme680.h b/esphome/components/bme680/bme680.h index 239823fa8c9..e40daf87201 100644 --- a/esphome/components/bme680/bme680.h +++ b/esphome/components/bme680/bme680.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bme680 { +namespace esphome::bme680 { /// Enum listing all IIR Filter options for the BME680. enum BME680IIRFilter { @@ -134,5 +133,4 @@ class BME680Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *gas_resistance_sensor_{nullptr}; }; -} // namespace bme680 -} // namespace esphome +} // namespace esphome::bme680 diff --git a/esphome/components/bme680_bsec/bme680_bsec.cpp b/esphome/components/bme680_bsec/bme680_bsec.cpp index bb0417b823d..b7f8c0da77b 100644 --- a/esphome/components/bme680_bsec/bme680_bsec.cpp +++ b/esphome/components/bme680_bsec/bme680_bsec.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace bme680_bsec { +namespace esphome::bme680_bsec { #ifdef USE_BSEC static const char *const TAG = "bme680_bsec.sensor"; @@ -565,5 +564,4 @@ void BME680BSECComponent::save_state_(uint8_t accuracy) { ESP_LOGI(TAG, "Saved state"); } #endif -} // namespace bme680_bsec -} // namespace esphome +} // namespace esphome::bme680_bsec diff --git a/esphome/components/bme680_bsec/bme680_bsec.h b/esphome/components/bme680_bsec/bme680_bsec.h index 22aa2789e6b..742b07b59bf 100644 --- a/esphome/components/bme680_bsec/bme680_bsec.h +++ b/esphome/components/bme680_bsec/bme680_bsec.h @@ -13,8 +13,7 @@ #include #endif -namespace esphome { -namespace bme680_bsec { +namespace esphome::bme680_bsec { #ifdef USE_BSEC enum IAQMode { @@ -133,5 +132,4 @@ class BME680BSECComponent : public Component, public i2c::I2CDevice { sensor::Sensor *breath_voc_equivalent_sensor_{nullptr}; }; #endif -} // namespace bme680_bsec -} // namespace esphome +} // namespace esphome::bme680_bsec diff --git a/esphome/components/bmi160/bmi160.cpp b/esphome/components/bmi160/bmi160.cpp index ed92979d24e..442ee183bf9 100644 --- a/esphome/components/bmi160/bmi160.cpp +++ b/esphome/components/bmi160/bmi160.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace bmi160 { +namespace esphome::bmi160 { static const char *const TAG = "bmi160"; static constexpr uint32_t GYRO_WAKEUP_TIMEOUT_MS = 100; @@ -265,5 +264,4 @@ void BMI160Component::update() { this->status_clear_warning(); } -} // namespace bmi160 -} // namespace esphome +} // namespace esphome::bmi160 diff --git a/esphome/components/bmi160/bmi160.h b/esphome/components/bmi160/bmi160.h index 16cab697330..e86c353eaa9 100644 --- a/esphome/components/bmi160/bmi160.h +++ b/esphome/components/bmi160/bmi160.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bmi160 { +namespace esphome::bmi160 { class BMI160Component : public PollingComponent, public i2c::I2CDevice { public: @@ -38,5 +37,4 @@ class BMI160Component : public PollingComponent, public i2c::I2CDevice { i2c::ErrorCode read_le_int16_(uint8_t reg, int16_t *value, uint8_t len); }; -} // namespace bmi160 -} // namespace esphome +} // namespace esphome::bmi160 diff --git a/esphome/components/bmp085/bmp085.cpp b/esphome/components/bmp085/bmp085.cpp index 9a383b26546..f42875b2089 100644 --- a/esphome/components/bmp085/bmp085.cpp +++ b/esphome/components/bmp085/bmp085.cpp @@ -1,8 +1,7 @@ #include "bmp085.h" #include "esphome/core/log.h" -namespace esphome { -namespace bmp085 { +namespace esphome::bmp085 { static const char *const TAG = "bmp085.sensor"; @@ -132,5 +131,4 @@ bool BMP085Component::set_mode_(uint8_t mode) { return this->write_byte(BMP085_REGISTER_CONTROL, mode); } -} // namespace bmp085 -} // namespace esphome +} // namespace esphome::bmp085 diff --git a/esphome/components/bmp085/bmp085.h b/esphome/components/bmp085/bmp085.h index c7315827e0e..a64f3936f0a 100644 --- a/esphome/components/bmp085/bmp085.h +++ b/esphome/components/bmp085/bmp085.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bmp085 { +namespace esphome::bmp085 { class BMP085Component : public PollingComponent, public i2c::I2CDevice { public: @@ -39,5 +38,4 @@ class BMP085Component : public PollingComponent, public i2c::I2CDevice { CalibrationData calibration_; }; -} // namespace bmp085 -} // namespace esphome +} // namespace esphome::bmp085 diff --git a/esphome/components/bmp280_base/bmp280_base.cpp b/esphome/components/bmp280_base/bmp280_base.cpp index 603966a2b52..1dae5a689e6 100644 --- a/esphome/components/bmp280_base/bmp280_base.cpp +++ b/esphome/components/bmp280_base/bmp280_base.cpp @@ -4,8 +4,7 @@ #define BMP280_ERROR_WRONG_CHIP_ID "Wrong chip ID or no response" -namespace esphome { -namespace bmp280_base { +namespace esphome::bmp280_base { static const char *const TAG = "bmp280.sensor"; @@ -268,5 +267,4 @@ uint16_t BMP280Component::read_u16_le_(uint8_t a_register) { } int16_t BMP280Component::read_s16_le_(uint8_t a_register) { return this->read_u16_le_(a_register); } -} // namespace bmp280_base -} // namespace esphome +} // namespace esphome::bmp280_base diff --git a/esphome/components/bmp280_base/bmp280_base.h b/esphome/components/bmp280_base/bmp280_base.h index 836eafaf8b6..3bf1edab043 100644 --- a/esphome/components/bmp280_base/bmp280_base.h +++ b/esphome/components/bmp280_base/bmp280_base.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bmp280_base { +namespace esphome::bmp280_base { /// Internal struct storing the calibration values of an BMP280. struct BMP280CalibrationData { @@ -93,5 +92,4 @@ class BMP280Component : public PollingComponent { } error_code_{NONE}; }; -} // namespace bmp280_base -} // namespace esphome +} // namespace esphome::bmp280_base diff --git a/esphome/components/bmp280_i2c/bmp280_i2c.cpp b/esphome/components/bmp280_i2c/bmp280_i2c.cpp index 75d899008d3..098d1aff8b8 100644 --- a/esphome/components/bmp280_i2c/bmp280_i2c.cpp +++ b/esphome/components/bmp280_i2c/bmp280_i2c.cpp @@ -2,13 +2,11 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace bmp280_i2c { +namespace esphome::bmp280_i2c { void BMP280I2CComponent::dump_config() { LOG_I2C_DEVICE(this); BMP280Component::dump_config(); } -} // namespace bmp280_i2c -} // namespace esphome +} // namespace esphome::bmp280_i2c diff --git a/esphome/components/bmp280_i2c/bmp280_i2c.h b/esphome/components/bmp280_i2c/bmp280_i2c.h index 0ac956202b9..bf1c2fd6247 100644 --- a/esphome/components/bmp280_i2c/bmp280_i2c.h +++ b/esphome/components/bmp280_i2c/bmp280_i2c.h @@ -3,8 +3,7 @@ #include "esphome/components/bmp280_base/bmp280_base.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bmp280_i2c { +namespace esphome::bmp280_i2c { static const char *const TAG = "bmp280_i2c.sensor"; @@ -20,5 +19,4 @@ class BMP280I2CComponent : public esphome::bmp280_base::BMP280Component, public void dump_config() override; }; -} // namespace bmp280_i2c -} // namespace esphome +} // namespace esphome::bmp280_i2c diff --git a/esphome/components/bmp280_spi/bmp280_spi.cpp b/esphome/components/bmp280_spi/bmp280_spi.cpp index 88983e77c37..04f92f9b899 100644 --- a/esphome/components/bmp280_spi/bmp280_spi.cpp +++ b/esphome/components/bmp280_spi/bmp280_spi.cpp @@ -4,8 +4,7 @@ #include "bmp280_spi.h" #include -namespace esphome { -namespace bmp280_spi { +namespace esphome::bmp280_spi { uint8_t set_bit(uint8_t num, uint8_t position) { uint8_t mask = 1 << position; @@ -61,5 +60,4 @@ bool BMP280SPIComponent::bmp_read_byte_16(uint8_t a_register, uint16_t *data) { return true; } -} // namespace bmp280_spi -} // namespace esphome +} // namespace esphome::bmp280_spi diff --git a/esphome/components/bmp280_spi/bmp280_spi.h b/esphome/components/bmp280_spi/bmp280_spi.h index 1bb7678e55b..17d39998849 100644 --- a/esphome/components/bmp280_spi/bmp280_spi.h +++ b/esphome/components/bmp280_spi/bmp280_spi.h @@ -3,8 +3,7 @@ #include "esphome/components/bmp280_base/bmp280_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace bmp280_spi { +namespace esphome::bmp280_spi { class BMP280SPIComponent : public esphome::bmp280_base::BMP280Component, public spi::SPIDevice -namespace esphome { -namespace bmp3xx_base { +namespace esphome::bmp3xx_base { static const char *const TAG = "bmp3xx.sensor"; @@ -356,5 +355,4 @@ float BMP3XXComponent::bmp388_compensate_pressure_(float uncomp_press, float t_l return partial_out1 + partial_out2 + partial_data4; } -} // namespace bmp3xx_base -} // namespace esphome +} // namespace esphome::bmp3xx_base diff --git a/esphome/components/bmp3xx_base/bmp3xx_base.h b/esphome/components/bmp3xx_base/bmp3xx_base.h index 8d2312231b9..cd70b2fb163 100644 --- a/esphome/components/bmp3xx_base/bmp3xx_base.h +++ b/esphome/components/bmp3xx_base/bmp3xx_base.h @@ -10,8 +10,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace bmp3xx_base { +namespace esphome::bmp3xx_base { static const uint8_t BMP388_ID = 0x50; // The BMP388 device ID static const uint8_t BMP390_ID = 0x60; // The BMP390 device ID @@ -237,5 +236,4 @@ class BMP3XXComponent : public PollingComponent { virtual bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0; }; -} // namespace bmp3xx_base -} // namespace esphome +} // namespace esphome::bmp3xx_base diff --git a/esphome/components/bmp3xx_i2c/bmp3xx_i2c.cpp b/esphome/components/bmp3xx_i2c/bmp3xx_i2c.cpp index 75310901850..704d415993d 100644 --- a/esphome/components/bmp3xx_i2c/bmp3xx_i2c.cpp +++ b/esphome/components/bmp3xx_i2c/bmp3xx_i2c.cpp @@ -2,8 +2,7 @@ #include "bmp3xx_i2c.h" #include -namespace esphome { -namespace bmp3xx_i2c { +namespace esphome::bmp3xx_i2c { static const char *const TAG = "bmp3xx_i2c.sensor"; @@ -25,5 +24,4 @@ void BMP3XXI2CComponent::dump_config() { BMP3XXComponent::dump_config(); } -} // namespace bmp3xx_i2c -} // namespace esphome +} // namespace esphome::bmp3xx_i2c diff --git a/esphome/components/bmp3xx_i2c/bmp3xx_i2c.h b/esphome/components/bmp3xx_i2c/bmp3xx_i2c.h index d8b95cf8432..bec99cf9f8b 100644 --- a/esphome/components/bmp3xx_i2c/bmp3xx_i2c.h +++ b/esphome/components/bmp3xx_i2c/bmp3xx_i2c.h @@ -2,8 +2,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/bmp3xx_base/bmp3xx_base.h" -namespace esphome { -namespace bmp3xx_i2c { +namespace esphome::bmp3xx_i2c { class BMP3XXI2CComponent : public bmp3xx_base::BMP3XXComponent, public i2c::I2CDevice { bool read_byte(uint8_t a_register, uint8_t *data) override; @@ -13,5 +12,4 @@ class BMP3XXI2CComponent : public bmp3xx_base::BMP3XXComponent, public i2c::I2CD void dump_config() override; }; -} // namespace bmp3xx_i2c -} // namespace esphome +} // namespace esphome::bmp3xx_i2c diff --git a/esphome/components/bmp3xx_spi/bmp3xx_spi.cpp b/esphome/components/bmp3xx_spi/bmp3xx_spi.cpp index 20845301259..5657626c2d7 100644 --- a/esphome/components/bmp3xx_spi/bmp3xx_spi.cpp +++ b/esphome/components/bmp3xx_spi/bmp3xx_spi.cpp @@ -1,8 +1,7 @@ #include "bmp3xx_spi.h" #include -namespace esphome { -namespace bmp3xx_spi { +namespace esphome::bmp3xx_spi { static const char *const TAG = "bmp3xx_spi.sensor"; @@ -53,5 +52,4 @@ bool BMP3XXSPIComponent::write_bytes(uint8_t a_register, uint8_t *data, size_t l return true; } -} // namespace bmp3xx_spi -} // namespace esphome +} // namespace esphome::bmp3xx_spi diff --git a/esphome/components/bmp3xx_spi/bmp3xx_spi.h b/esphome/components/bmp3xx_spi/bmp3xx_spi.h index 2183994abe5..fa0c0e1b477 100644 --- a/esphome/components/bmp3xx_spi/bmp3xx_spi.h +++ b/esphome/components/bmp3xx_spi/bmp3xx_spi.h @@ -2,8 +2,7 @@ #include "esphome/components/bmp3xx_base/bmp3xx_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace bmp3xx_spi { +namespace esphome::bmp3xx_spi { class BMP3XXSPIComponent : public bmp3xx_base::BMP3XXComponent, public spi::SPIDevice -namespace esphome { -namespace bp1658cj { +namespace esphome::bp1658cj { class BP1658CJ : public Component { public: @@ -60,5 +59,4 @@ class BP1658CJ : public Component { bool update_{true}; }; -} // namespace bp1658cj -} // namespace esphome +} // namespace esphome::bp1658cj diff --git a/esphome/components/bp5758d/bp5758d.cpp b/esphome/components/bp5758d/bp5758d.cpp index 4f330b9c773..3cd841b2cd6 100644 --- a/esphome/components/bp5758d/bp5758d.cpp +++ b/esphome/components/bp5758d/bp5758d.cpp @@ -1,8 +1,7 @@ #include "bp5758d.h" #include "esphome/core/log.h" -namespace esphome { -namespace bp5758d { +namespace esphome::bp5758d { static const char *const TAG = "bp5758d"; @@ -164,5 +163,4 @@ void BP5758D::write_buffer_(uint8_t *buffer, uint8_t size) { delayMicroseconds(BP5758D_DELAY); } -} // namespace bp5758d -} // namespace esphome +} // namespace esphome::bp5758d diff --git a/esphome/components/bp5758d/bp5758d.h b/esphome/components/bp5758d/bp5758d.h index cc7cc3d5f8a..f07d51fe518 100644 --- a/esphome/components/bp5758d/bp5758d.h +++ b/esphome/components/bp5758d/bp5758d.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include -namespace esphome { -namespace bp5758d { +namespace esphome::bp5758d { class BP5758D : public Component { public: @@ -60,5 +59,4 @@ class BP5758D : public Component { bool update_{true}; }; -} // namespace bp5758d -} // namespace esphome +} // namespace esphome::bp5758d diff --git a/esphome/components/bthome_mithermometer/bthome_ble.cpp b/esphome/components/bthome_mithermometer/bthome_ble.cpp index 32278dbfbd4..ff12e6157dd 100644 --- a/esphome/components/bthome_mithermometer/bthome_ble.cpp +++ b/esphome/components/bthome_mithermometer/bthome_ble.cpp @@ -17,8 +17,7 @@ #include "mbedtls/ccm.h" #endif -namespace esphome { -namespace bthome_mithermometer { +namespace esphome::bthome_mithermometer { static const char *const TAG = "bthome_mithermometer"; static constexpr size_t BTHOME_BINDKEY_SIZE = 16; @@ -434,7 +433,6 @@ bool BTHomeMiThermometer::handle_service_data_(const esp32_ble_tracker::ServiceD return reported; } -} // namespace bthome_mithermometer -} // namespace esphome +} // namespace esphome::bthome_mithermometer #endif diff --git a/esphome/components/bthome_mithermometer/bthome_ble.h b/esphome/components/bthome_mithermometer/bthome_ble.h index ef3038ec93e..9bec8ba7a10 100644 --- a/esphome/components/bthome_mithermometer/bthome_ble.h +++ b/esphome/components/bthome_mithermometer/bthome_ble.h @@ -10,8 +10,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace bthome_mithermometer { +namespace esphome::bthome_mithermometer { class BTHomeMiThermometer : public esp32_ble_tracker::ESPBTDeviceListener, public Component { public: @@ -45,7 +44,6 @@ class BTHomeMiThermometer : public esp32_ble_tracker::ESPBTDeviceListener, publi sensor::Sensor *signal_strength_{nullptr}; }; -} // namespace bthome_mithermometer -} // namespace esphome +} // namespace esphome::bthome_mithermometer #endif diff --git a/esphome/components/bytebuffer/bytebuffer.h b/esphome/components/bytebuffer/bytebuffer.h index 3c68094dbcc..f17b9873941 100644 --- a/esphome/components/bytebuffer/bytebuffer.h +++ b/esphome/components/bytebuffer/bytebuffer.h @@ -6,8 +6,7 @@ #include #include "esphome/core/helpers.h" -namespace esphome { -namespace bytebuffer { +namespace esphome::bytebuffer { enum Endian { LITTLE, BIG }; @@ -417,5 +416,4 @@ class ByteBuffer { size_t limit_{0}; }; -} // namespace bytebuffer -} // namespace esphome +} // namespace esphome::bytebuffer diff --git a/esphome/components/camera/camera.cpp b/esphome/components/camera/camera.cpp index 66b8138f38b..d35f7a47931 100644 --- a/esphome/components/camera/camera.cpp +++ b/esphome/components/camera/camera.cpp @@ -1,7 +1,6 @@ #include "camera.h" -namespace esphome { -namespace camera { +namespace esphome::camera { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) Camera *Camera::global_camera = nullptr; @@ -18,5 +17,4 @@ Camera::Camera() { Camera *Camera::instance() { return global_camera; } -} // namespace camera -} // namespace esphome +} // namespace esphome::camera diff --git a/esphome/components/camera/camera.h b/esphome/components/camera/camera.h index 6e1fc8cc06b..bf80b42e54d 100644 --- a/esphome/components/camera/camera.h +++ b/esphome/components/camera/camera.h @@ -5,8 +5,7 @@ #include "esphome/core/entity_base.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace camera { +namespace esphome::camera { /** Different sources for filtering. * IDLE: Camera requests to send an image to the API. @@ -134,5 +133,4 @@ class Camera : public EntityBase, public Component { static Camera *global_camera; }; -} // namespace camera -} // namespace esphome +} // namespace esphome::camera diff --git a/esphome/components/canbus/canbus.cpp b/esphome/components/canbus/canbus.cpp index ce48bfbba51..c5ba59a645a 100644 --- a/esphome/components/canbus/canbus.cpp +++ b/esphome/components/canbus/canbus.cpp @@ -2,8 +2,7 @@ #include #include "esphome/core/log.h" -namespace esphome { -namespace canbus { +namespace esphome::canbus { static const char *const TAG = "canbus"; @@ -103,5 +102,4 @@ void Canbus::loop() { } } -} // namespace canbus -} // namespace esphome +} // namespace esphome::canbus diff --git a/esphome/components/canbus/canbus.h b/esphome/components/canbus/canbus.h index 420125e1d34..691d7384f1d 100644 --- a/esphome/components/canbus/canbus.h +++ b/esphome/components/canbus/canbus.h @@ -7,8 +7,7 @@ #include #include -namespace esphome { -namespace canbus { +namespace esphome::canbus { enum Error : uint8_t { ERROR_OK = 0, @@ -177,5 +176,4 @@ class CanbusTrigger : public Trigger, uint32_t, bool>, publ optional remote_transmission_request_{}; }; -} // namespace canbus -} // namespace esphome +} // namespace esphome::canbus diff --git a/esphome/components/cap1188/cap1188.cpp b/esphome/components/cap1188/cap1188.cpp index 64bdc620cd8..125a4aba51e 100644 --- a/esphome/components/cap1188/cap1188.cpp +++ b/esphome/components/cap1188/cap1188.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace cap1188 { +namespace esphome::cap1188 { static const char *const TAG = "cap1188"; @@ -100,5 +99,4 @@ void CAP1188Component::loop() { } } -} // namespace cap1188 -} // namespace esphome +} // namespace esphome::cap1188 diff --git a/esphome/components/cap1188/cap1188.h b/esphome/components/cap1188/cap1188.h index 297c601b050..848e6fe4305 100644 --- a/esphome/components/cap1188/cap1188.h +++ b/esphome/components/cap1188/cap1188.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace cap1188 { +namespace esphome::cap1188 { enum { CAP1188_I2CADDR = 0x29, @@ -67,5 +66,4 @@ class CAP1188Component : public Component, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace cap1188 -} // namespace esphome +} // namespace esphome::cap1188 diff --git a/esphome/components/captive_portal/captive_portal.cpp b/esphome/components/captive_portal/captive_portal.cpp index 183f16c5f84..365e5f64db5 100644 --- a/esphome/components/captive_portal/captive_portal.cpp +++ b/esphome/components/captive_portal/captive_portal.cpp @@ -5,8 +5,7 @@ #include "esphome/components/wifi/wifi_component.h" #include "captive_index.h" -namespace esphome { -namespace captive_portal { +namespace esphome::captive_portal { static const char *const TAG = "captive_portal"; @@ -135,6 +134,6 @@ void CaptivePortal::dump_config() { ESP_LOGCONFIG(TAG, "Captive Portal:"); } CaptivePortal *global_captive_portal = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace captive_portal -} // namespace esphome +} // namespace esphome::captive_portal + #endif diff --git a/esphome/components/captive_portal/captive_portal.h b/esphome/components/captive_portal/captive_portal.h index 0c63a3670ab..8c8b43e608c 100644 --- a/esphome/components/captive_portal/captive_portal.h +++ b/esphome/components/captive_portal/captive_portal.h @@ -12,9 +12,7 @@ #include "esphome/core/preferences.h" #include "esphome/components/web_server_base/web_server_base.h" -namespace esphome { - -namespace captive_portal { +namespace esphome::captive_portal { class CaptivePortal : public AsyncWebHandler, public Component { public: @@ -69,6 +67,6 @@ class CaptivePortal : public AsyncWebHandler, public Component { extern CaptivePortal *global_captive_portal; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace captive_portal -} // namespace esphome +} // namespace esphome::captive_portal + #endif diff --git a/esphome/components/ccs811/ccs811.cpp b/esphome/components/ccs811/ccs811.cpp index 9ff01b32b21..afaeac55aaa 100644 --- a/esphome/components/ccs811/ccs811.cpp +++ b/esphome/components/ccs811/ccs811.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ccs811 { +namespace esphome::ccs811 { static const char *const TAG = "ccs811"; @@ -186,5 +185,4 @@ void CCS811Component::dump_config() { } } -} // namespace ccs811 -} // namespace esphome +} // namespace esphome::ccs811 diff --git a/esphome/components/ccs811/ccs811.h b/esphome/components/ccs811/ccs811.h index 675ba7da97c..fde24947532 100644 --- a/esphome/components/ccs811/ccs811.h +++ b/esphome/components/ccs811/ccs811.h @@ -6,8 +6,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ccs811 { +namespace esphome::ccs811 { class CCS811Component : public PollingComponent, public i2c::I2CDevice { public: @@ -51,5 +50,4 @@ class CCS811Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *temperature_{nullptr}; }; -} // namespace ccs811 -} // namespace esphome +} // namespace esphome::ccs811 diff --git a/esphome/components/cd74hc4067/cd74hc4067.cpp b/esphome/components/cd74hc4067/cd74hc4067.cpp index 302c83d7d3a..c275aca75f7 100644 --- a/esphome/components/cd74hc4067/cd74hc4067.cpp +++ b/esphome/components/cd74hc4067/cd74hc4067.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace cd74hc4067 { +namespace esphome::cd74hc4067 { static const char *const TAG = "cd74hc4067"; @@ -81,5 +80,4 @@ void CD74HC4067Sensor::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace cd74hc4067 -} // namespace esphome +} // namespace esphome::cd74hc4067 diff --git a/esphome/components/cd74hc4067/cd74hc4067.h b/esphome/components/cd74hc4067/cd74hc4067.h index 76ebc1ebbe1..f41b5e294ab 100644 --- a/esphome/components/cd74hc4067/cd74hc4067.h +++ b/esphome/components/cd74hc4067/cd74hc4067.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/voltage_sampler/voltage_sampler.h" -namespace esphome { -namespace cd74hc4067 { +namespace esphome::cd74hc4067 { class CD74HC4067Component : public Component { public: @@ -60,5 +59,4 @@ class CD74HC4067Sensor : public sensor::Sensor, public PollingComponent, public uint8_t pin_; }; -} // namespace cd74hc4067 -} // namespace esphome +} // namespace esphome::cd74hc4067 diff --git a/esphome/components/ch422g/ch422g.cpp b/esphome/components/ch422g/ch422g.cpp index fc856cd5636..85603f46f4f 100644 --- a/esphome/components/ch422g/ch422g.cpp +++ b/esphome/components/ch422g/ch422g.cpp @@ -1,8 +1,7 @@ #include "ch422g.h" #include "esphome/core/log.h" -namespace esphome { -namespace ch422g { +namespace esphome::ch422g { static const uint8_t CH422G_REG_MODE = 0x24; static const uint8_t CH422G_MODE_OUTPUT = 0x01; // enables output mode on 0-7 @@ -136,5 +135,4 @@ void CH422GGPIOPin::set_flags(gpio::Flags flags) { this->parent_->pin_mode(this->pin_, flags); } -} // namespace ch422g -} // namespace esphome +} // namespace esphome::ch422g diff --git a/esphome/components/ch422g/ch422g.h b/esphome/components/ch422g/ch422g.h index 6e6bdad64a0..f74e0c46a47 100644 --- a/esphome/components/ch422g/ch422g.h +++ b/esphome/components/ch422g/ch422g.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ch422g { +namespace esphome::ch422g { class CH422GComponent : public Component, public i2c::I2CDevice { public: @@ -65,5 +64,4 @@ class CH422GGPIOPin : public GPIOPin { gpio::Flags flags_{}; }; -} // namespace ch422g -} // namespace esphome +} // namespace esphome::ch422g diff --git a/esphome/components/chsc6x/chsc6x_touchscreen.cpp b/esphome/components/chsc6x/chsc6x_touchscreen.cpp index 941144e451d..297e7b65a2d 100644 --- a/esphome/components/chsc6x/chsc6x_touchscreen.cpp +++ b/esphome/components/chsc6x/chsc6x_touchscreen.cpp @@ -1,7 +1,6 @@ #include "chsc6x_touchscreen.h" -namespace esphome { -namespace chsc6x { +namespace esphome::chsc6x { void CHSC6XTouchscreen::setup() { if (this->interrupt_pin_ != nullptr) { @@ -42,5 +41,4 @@ void CHSC6XTouchscreen::dump_config() { LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_); } -} // namespace chsc6x -} // namespace esphome +} // namespace esphome::chsc6x diff --git a/esphome/components/chsc6x/chsc6x_touchscreen.h b/esphome/components/chsc6x/chsc6x_touchscreen.h index 25b79ad34af..32077b3d33c 100644 --- a/esphome/components/chsc6x/chsc6x_touchscreen.h +++ b/esphome/components/chsc6x/chsc6x_touchscreen.h @@ -6,8 +6,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace chsc6x { +namespace esphome::chsc6x { static const char *const TAG = "chsc6x.touchscreen"; @@ -30,5 +29,4 @@ class CHSC6XTouchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice InternalGPIOPin *interrupt_pin_{}; }; -} // namespace chsc6x -} // namespace esphome +} // namespace esphome::chsc6x diff --git a/esphome/components/climate_ir/climate_ir.cpp b/esphome/components/climate_ir/climate_ir.cpp index cc291ff17cf..a8edaae6ea8 100644 --- a/esphome/components/climate_ir/climate_ir.cpp +++ b/esphome/components/climate_ir/climate_ir.cpp @@ -1,8 +1,7 @@ #include "climate_ir.h" #include "esphome/core/log.h" -namespace esphome { -namespace climate_ir { +namespace esphome::climate_ir { static const char *const TAG = "climate_ir"; @@ -100,5 +99,4 @@ void ClimateIR::dump_config() { YESNO(this->supports_cool_)); } -} // namespace climate_ir -} // namespace esphome +} // namespace esphome::climate_ir diff --git a/esphome/components/climate_ir/climate_ir.h b/esphome/components/climate_ir/climate_ir.h index ac76d338538..6c49b310303 100644 --- a/esphome/components/climate_ir/climate_ir.h +++ b/esphome/components/climate_ir/climate_ir.h @@ -7,8 +7,7 @@ #include "esphome/components/remote_transmitter/remote_transmitter.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace climate_ir { +namespace esphome::climate_ir { /* A base for climate which works by sending (and receiving) IR codes @@ -71,5 +70,4 @@ class ClimateIR : public Component, sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace climate_ir -} // namespace esphome +} // namespace esphome::climate_ir diff --git a/esphome/components/climate_ir_lg/climate_ir_lg.cpp b/esphome/components/climate_ir_lg/climate_ir_lg.cpp index 90e3d006a85..588566dd9d4 100644 --- a/esphome/components/climate_ir_lg/climate_ir_lg.cpp +++ b/esphome/components/climate_ir_lg/climate_ir_lg.cpp @@ -1,8 +1,7 @@ #include "climate_ir_lg.h" #include "esphome/core/log.h" -namespace esphome { -namespace climate_ir_lg { +namespace esphome::climate_ir_lg { static const char *const TAG = "climate.climate_ir_lg"; @@ -218,5 +217,4 @@ void LgIrClimate::calc_checksum_(uint32_t &value) { value |= (sum & mask); } -} // namespace climate_ir_lg -} // namespace esphome +} // namespace esphome::climate_ir_lg diff --git a/esphome/components/climate_ir_lg/climate_ir_lg.h b/esphome/components/climate_ir_lg/climate_ir_lg.h index 958245279f2..a09da65ac6c 100644 --- a/esphome/components/climate_ir_lg/climate_ir_lg.h +++ b/esphome/components/climate_ir_lg/climate_ir_lg.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace climate_ir_lg { +namespace esphome::climate_ir_lg { // Temperature const uint8_t TEMP_MIN = 18; // Celsius @@ -54,5 +53,4 @@ class LgIrClimate : public climate_ir::ClimateIR { climate::ClimateMode mode_before_{climate::CLIMATE_MODE_OFF}; }; -} // namespace climate_ir_lg -} // namespace esphome +} // namespace esphome::climate_ir_lg diff --git a/esphome/components/cm1106/cm1106.cpp b/esphome/components/cm1106/cm1106.cpp index d88ea2e1da4..7e5d25b7aef 100644 --- a/esphome/components/cm1106/cm1106.cpp +++ b/esphome/components/cm1106/cm1106.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace cm1106 { +namespace esphome::cm1106 { static const char *const TAG = "cm1106"; static const uint8_t C_M1106_CMD_GET_CO2[4] = {0x11, 0x01, 0x01, 0xED}; @@ -107,5 +106,4 @@ void CM1106Component::dump_config() { } } -} // namespace cm1106 -} // namespace esphome +} // namespace esphome::cm1106 diff --git a/esphome/components/cm1106/cm1106.h b/esphome/components/cm1106/cm1106.h index 8c33e564578..047e91d6326 100644 --- a/esphome/components/cm1106/cm1106.h +++ b/esphome/components/cm1106/cm1106.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace cm1106 { +namespace esphome::cm1106 { class CM1106Component : public PollingComponent, public uart::UARTDevice { public: @@ -34,5 +33,4 @@ template class CM1106CalibrateZeroAction : public Action CM1106Component *cm1106_; }; -} // namespace cm1106 -} // namespace esphome +} // namespace esphome::cm1106 diff --git a/esphome/components/color_temperature/ct_light_output.h b/esphome/components/color_temperature/ct_light_output.h index 4ff86c8b802..a4da1011b09 100644 --- a/esphome/components/color_temperature/ct_light_output.h +++ b/esphome/components/color_temperature/ct_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/core/component.h" -namespace esphome { -namespace color_temperature { +namespace esphome::color_temperature { class CTLightOutput : public light::LightOutput { public: @@ -34,5 +33,4 @@ class CTLightOutput : public light::LightOutput { float warm_white_temperature_; }; -} // namespace color_temperature -} // namespace esphome +} // namespace esphome::color_temperature diff --git a/esphome/components/combination/combination.cpp b/esphome/components/combination/combination.cpp index b858eee4ee4..ddf1a105e0e 100644 --- a/esphome/components/combination/combination.cpp +++ b/esphome/components/combination/combination.cpp @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace combination { +namespace esphome::combination { static const char *const TAG = "combination"; @@ -267,5 +266,4 @@ void SumCombinationComponent::handle_new_value(float value) { this->publish_state(sum); } -} // namespace combination -} // namespace esphome +} // namespace esphome::combination diff --git a/esphome/components/combination/combination.h b/esphome/components/combination/combination.h index 463eedc5644..34e9e4e2c65 100644 --- a/esphome/components/combination/combination.h +++ b/esphome/components/combination/combination.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace combination { +namespace esphome::combination { class CombinationComponent : public Component, public sensor::Sensor { public: @@ -143,5 +142,4 @@ class SumCombinationComponent : public CombinationNoParameterComponent { void handle_new_value(float value) override; }; -} // namespace combination -} // namespace esphome +} // namespace esphome::combination diff --git a/esphome/components/coolix/coolix.cpp b/esphome/components/coolix/coolix.cpp index d8ea6764781..56eb43cd82b 100644 --- a/esphome/components/coolix/coolix.cpp +++ b/esphome/components/coolix/coolix.cpp @@ -2,8 +2,7 @@ #include "esphome/components/remote_base/coolix_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace coolix { +namespace esphome::coolix { static const char *const TAG = "coolix.climate"; @@ -159,5 +158,4 @@ bool CoolixClimate::on_coolix(climate::Climate *parent, remote_base::RemoteRecei return true; } -} // namespace coolix -} // namespace esphome +} // namespace esphome::coolix diff --git a/esphome/components/coolix/coolix.h b/esphome/components/coolix/coolix.h index 51ddcdf8f2f..2d8862e2b63 100644 --- a/esphome/components/coolix/coolix.h +++ b/esphome/components/coolix/coolix.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace coolix { +namespace esphome::coolix { // Temperature const uint8_t COOLIX_TEMP_MIN = 17; // Celsius @@ -42,5 +41,4 @@ class CoolixClimate : public climate_ir::ClimateIR { bool send_swing_cmd_{false}; }; -} // namespace coolix -} // namespace esphome +} // namespace esphome::coolix diff --git a/esphome/components/copy/binary_sensor/copy_binary_sensor.cpp b/esphome/components/copy/binary_sensor/copy_binary_sensor.cpp index 0d96f58750e..b084b0080a9 100644 --- a/esphome/components/copy/binary_sensor/copy_binary_sensor.cpp +++ b/esphome/components/copy/binary_sensor/copy_binary_sensor.cpp @@ -1,8 +1,7 @@ #include "copy_binary_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.binary_sensor"; @@ -14,5 +13,4 @@ void CopyBinarySensor::setup() { void CopyBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Copy Binary Sensor", this); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/binary_sensor/copy_binary_sensor.h b/esphome/components/copy/binary_sensor/copy_binary_sensor.h index fc1e368b387..a6ce705a2a4 100644 --- a/esphome/components/copy/binary_sensor/copy_binary_sensor.h +++ b/esphome/components/copy/binary_sensor/copy_binary_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyBinarySensor : public binary_sensor::BinarySensor, public Component { public: @@ -16,5 +15,4 @@ class CopyBinarySensor : public binary_sensor::BinarySensor, public Component { binary_sensor::BinarySensor *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/button/copy_button.cpp b/esphome/components/copy/button/copy_button.cpp index 595388775cc..297e1b0c948 100644 --- a/esphome/components/copy/button/copy_button.cpp +++ b/esphome/components/copy/button/copy_button.cpp @@ -1,8 +1,7 @@ #include "copy_button.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.button"; @@ -10,5 +9,4 @@ void CopyButton::dump_config() { LOG_BUTTON("", "Copy Button", this); } void CopyButton::press_action() { source_->press(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/button/copy_button.h b/esphome/components/copy/button/copy_button.h index 79d5dbcf040..afd783375d9 100644 --- a/esphome/components/copy/button/copy_button.h +++ b/esphome/components/copy/button/copy_button.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/button/button.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyButton : public button::Button, public Component { public: @@ -17,5 +16,4 @@ class CopyButton : public button::Button, public Component { button::Button *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/cover/copy_cover.cpp b/esphome/components/copy/cover/copy_cover.cpp index c139869d8f5..3412784cc77 100644 --- a/esphome/components/copy/cover/copy_cover.cpp +++ b/esphome/components/copy/cover/copy_cover.cpp @@ -1,8 +1,7 @@ #include "copy_cover.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.cover"; @@ -50,5 +49,4 @@ void CopyCover::control(const cover::CoverCall &call) { call2.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/cover/copy_cover.h b/esphome/components/copy/cover/copy_cover.h index ec27b6782aa..0b493e4c3bb 100644 --- a/esphome/components/copy/cover/copy_cover.h +++ b/esphome/components/copy/cover/copy_cover.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyCover : public cover::Cover, public Component { public: @@ -20,5 +19,4 @@ class CopyCover : public cover::Cover, public Component { cover::Cover *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/fan/copy_fan.cpp b/esphome/components/copy/fan/copy_fan.cpp index bdaa35c467b..6eed787b058 100644 --- a/esphome/components/copy/fan/copy_fan.cpp +++ b/esphome/components/copy/fan/copy_fan.cpp @@ -1,8 +1,7 @@ #include "copy_fan.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.fan"; @@ -69,5 +68,4 @@ void CopyFan::control(const fan::FanCall &call) { call2.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/fan/copy_fan.h b/esphome/components/copy/fan/copy_fan.h index 988129f07b9..9090c910957 100644 --- a/esphome/components/copy/fan/copy_fan.h +++ b/esphome/components/copy/fan/copy_fan.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyFan : public fan::Fan, public Component { public: @@ -21,5 +20,4 @@ class CopyFan : public fan::Fan, public Component { fan::Fan *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/lock/copy_lock.cpp b/esphome/components/copy/lock/copy_lock.cpp index c846954510f..5fdb9a757b8 100644 --- a/esphome/components/copy/lock/copy_lock.cpp +++ b/esphome/components/copy/lock/copy_lock.cpp @@ -1,8 +1,7 @@ #include "copy_lock.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.lock"; @@ -25,5 +24,4 @@ void CopyLock::control(const lock::LockCall &call) { call2.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/lock/copy_lock.h b/esphome/components/copy/lock/copy_lock.h index 8799eebb4a2..c6c46467a9e 100644 --- a/esphome/components/copy/lock/copy_lock.h +++ b/esphome/components/copy/lock/copy_lock.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/lock/lock.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyLock : public lock::Lock, public Component { public: @@ -18,5 +17,4 @@ class CopyLock : public lock::Lock, public Component { lock::Lock *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/number/copy_number.cpp b/esphome/components/copy/number/copy_number.cpp index 46dc200b735..a10bd209f4e 100644 --- a/esphome/components/copy/number/copy_number.cpp +++ b/esphome/components/copy/number/copy_number.cpp @@ -1,8 +1,7 @@ #include "copy_number.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.number"; @@ -25,5 +24,4 @@ void CopyNumber::control(float value) { call2.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/number/copy_number.h b/esphome/components/copy/number/copy_number.h index 09b65e2cbf2..b4d8bb83e68 100644 --- a/esphome/components/copy/number/copy_number.h +++ b/esphome/components/copy/number/copy_number.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/number/number.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyNumber : public number::Number, public Component { public: @@ -18,5 +17,4 @@ class CopyNumber : public number::Number, public Component { number::Number *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/select/copy_select.cpp b/esphome/components/copy/select/copy_select.cpp index 227fe33182b..e4f97f3c162 100644 --- a/esphome/components/copy/select/copy_select.cpp +++ b/esphome/components/copy/select/copy_select.cpp @@ -1,8 +1,7 @@ #include "copy_select.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.select"; @@ -24,5 +23,4 @@ void CopySelect::control(size_t index) { call.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/select/copy_select.h b/esphome/components/copy/select/copy_select.h index bd74a93e820..1a17c7a55aa 100644 --- a/esphome/components/copy/select/copy_select.h +++ b/esphome/components/copy/select/copy_select.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/select/select.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopySelect : public select::Select, public Component { public: @@ -18,5 +17,4 @@ class CopySelect : public select::Select, public Component { select::Select *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/sensor/copy_sensor.cpp b/esphome/components/copy/sensor/copy_sensor.cpp index a47a0cf22b4..9df23ab92d0 100644 --- a/esphome/components/copy/sensor/copy_sensor.cpp +++ b/esphome/components/copy/sensor/copy_sensor.cpp @@ -1,8 +1,7 @@ #include "copy_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.sensor"; @@ -14,5 +13,4 @@ void CopySensor::setup() { void CopySensor::dump_config() { LOG_SENSOR("", "Copy Sensor", this); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/sensor/copy_sensor.h b/esphome/components/copy/sensor/copy_sensor.h index 500e6872fe2..d6e5026ce13 100644 --- a/esphome/components/copy/sensor/copy_sensor.h +++ b/esphome/components/copy/sensor/copy_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopySensor : public sensor::Sensor, public Component { public: @@ -16,5 +15,4 @@ class CopySensor : public sensor::Sensor, public Component { sensor::Sensor *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/switch/copy_switch.cpp b/esphome/components/copy/switch/copy_switch.cpp index 8a9fbb03dd0..91b76f11c0a 100644 --- a/esphome/components/copy/switch/copy_switch.cpp +++ b/esphome/components/copy/switch/copy_switch.cpp @@ -1,8 +1,7 @@ #include "copy_switch.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.switch"; @@ -22,5 +21,4 @@ void CopySwitch::write_state(bool state) { } } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/switch/copy_switch.h b/esphome/components/copy/switch/copy_switch.h index 80310af03f0..9ce6b48ed14 100644 --- a/esphome/components/copy/switch/copy_switch.h +++ b/esphome/components/copy/switch/copy_switch.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopySwitch : public switch_::Switch, public Component { public: @@ -18,5 +17,4 @@ class CopySwitch : public switch_::Switch, public Component { switch_::Switch *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/text/copy_text.cpp b/esphome/components/copy/text/copy_text.cpp index cb742013839..5ec3ba05b7c 100644 --- a/esphome/components/copy/text/copy_text.cpp +++ b/esphome/components/copy/text/copy_text.cpp @@ -1,8 +1,7 @@ #include "copy_text.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.text"; @@ -21,5 +20,4 @@ void CopyText::control(const std::string &value) { call2.perform(); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/text/copy_text.h b/esphome/components/copy/text/copy_text.h index 9eaebae4bea..ad289365227 100644 --- a/esphome/components/copy/text/copy_text.h +++ b/esphome/components/copy/text/copy_text.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/text/text.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyText : public text::Text, public Component { public: @@ -18,5 +17,4 @@ class CopyText : public text::Text, public Component { text::Text *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/text_sensor/copy_text_sensor.cpp b/esphome/components/copy/text_sensor/copy_text_sensor.cpp index 95fa6d7a1bd..97182e8a618 100644 --- a/esphome/components/copy/text_sensor/copy_text_sensor.cpp +++ b/esphome/components/copy/text_sensor/copy_text_sensor.cpp @@ -1,8 +1,7 @@ #include "copy_text_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace copy { +namespace esphome::copy { static const char *const TAG = "copy.text_sensor"; @@ -14,5 +13,4 @@ void CopyTextSensor::setup() { void CopyTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Copy Sensor", this); } -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/copy/text_sensor/copy_text_sensor.h b/esphome/components/copy/text_sensor/copy_text_sensor.h index 489986c59d6..dc4ef7a29da 100644 --- a/esphome/components/copy/text_sensor/copy_text_sensor.h +++ b/esphome/components/copy/text_sensor/copy_text_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace copy { +namespace esphome::copy { class CopyTextSensor : public text_sensor::TextSensor, public Component { public: @@ -16,5 +15,4 @@ class CopyTextSensor : public text_sensor::TextSensor, public Component { text_sensor::TextSensor *source_; }; -} // namespace copy -} // namespace esphome +} // namespace esphome::copy diff --git a/esphome/components/cs5460a/cs5460a.cpp b/esphome/components/cs5460a/cs5460a.cpp index e026eccf80e..c9e8f3cf472 100644 --- a/esphome/components/cs5460a/cs5460a.cpp +++ b/esphome/components/cs5460a/cs5460a.cpp @@ -1,8 +1,7 @@ #include "cs5460a.h" #include "esphome/core/log.h" -namespace esphome { -namespace cs5460a { +namespace esphome::cs5460a { static const char *const TAG = "cs5460a"; @@ -339,5 +338,4 @@ void CS5460AComponent::dump_config() { LOG_SENSOR(" ", "Power", power_sensor_); } -} // namespace cs5460a -} // namespace esphome +} // namespace esphome::cs5460a diff --git a/esphome/components/cs5460a/cs5460a.h b/esphome/components/cs5460a/cs5460a.h index 99c30175101..c6b02f53ee7 100644 --- a/esphome/components/cs5460a/cs5460a.h +++ b/esphome/components/cs5460a/cs5460a.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace cs5460a { +namespace esphome::cs5460a { enum CS5460ACommand { CMD_SYNC0 = 0xfe, @@ -119,5 +118,4 @@ template class CS5460ARestartAction : public Action { CS5460AComponent *cs5460a_; }; -} // namespace cs5460a -} // namespace esphome +} // namespace esphome::cs5460a diff --git a/esphome/components/cse7761/cse7761.cpp b/esphome/components/cse7761/cse7761.cpp index 0ecaaced7f6..42517515314 100644 --- a/esphome/components/cse7761/cse7761.cpp +++ b/esphome/components/cse7761/cse7761.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace cse7761 { +namespace esphome::cse7761 { static const char *const TAG = "cse7761"; @@ -244,5 +243,4 @@ void CSE7761Component::get_data_() { } } -} // namespace cse7761 -} // namespace esphome +} // namespace esphome::cse7761 diff --git a/esphome/components/cse7761/cse7761.h b/esphome/components/cse7761/cse7761.h index 0e03171956f..5f683f424bd 100644 --- a/esphome/components/cse7761/cse7761.h +++ b/esphome/components/cse7761/cse7761.h @@ -4,8 +4,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/core/component.h" -namespace esphome { -namespace cse7761 { +namespace esphome::cse7761 { struct CSE7761DataStruct { uint32_t frequency = 0; @@ -45,5 +44,4 @@ class CSE7761Component : public PollingComponent, public uart::UARTDevice { void get_data_(); }; -} // namespace cse7761 -} // namespace esphome +} // namespace esphome::cse7761 diff --git a/esphome/components/cst226/binary_sensor/cs226_button.h b/esphome/components/cst226/binary_sensor/cs226_button.h index 6d409df04ff..e7e334b9bbf 100644 --- a/esphome/components/cst226/binary_sensor/cs226_button.h +++ b/esphome/components/cst226/binary_sensor/cs226_button.h @@ -4,8 +4,7 @@ #include "../touchscreen/cst226_touchscreen.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace cst226 { +namespace esphome::cst226 { class CST226Button : public binary_sensor::BinarySensor, public Component, @@ -18,5 +17,4 @@ class CST226Button : public binary_sensor::BinarySensor, void update_button(bool state) override; }; -} // namespace cst226 -} // namespace esphome +} // namespace esphome::cst226 diff --git a/esphome/components/cst226/binary_sensor/cstt6_button.cpp b/esphome/components/cst226/binary_sensor/cstt6_button.cpp index c481ce5d570..c14da2b176a 100644 --- a/esphome/components/cst226/binary_sensor/cstt6_button.cpp +++ b/esphome/components/cst226/binary_sensor/cstt6_button.cpp @@ -1,8 +1,7 @@ #include "cs226_button.h" #include "esphome/core/log.h" -namespace esphome { -namespace cst226 { +namespace esphome::cst226 { static const char *const TAG = "CST226.binary_sensor"; @@ -15,5 +14,4 @@ void CST226Button::dump_config() { LOG_BINARY_SENSOR("", "CST226 Button", this); void CST226Button::update_button(bool state) { this->publish_state(state); } -} // namespace cst226 -} // namespace esphome +} // namespace esphome::cst226 diff --git a/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp b/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp index e65997b7fce..49d61cbfbca 100644 --- a/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp +++ b/esphome/components/cst226/touchscreen/cst226_touchscreen.cpp @@ -1,7 +1,6 @@ #include "cst226_touchscreen.h" -namespace esphome { -namespace cst226 { +namespace esphome::cst226 { static const char *const TAG = "cst226.touchscreen"; @@ -110,5 +109,4 @@ void CST226Touchscreen::dump_config() { LOG_PIN(" Reset Pin: ", this->reset_pin_); } -} // namespace cst226 -} // namespace esphome +} // namespace esphome::cst226 diff --git a/esphome/components/cst226/touchscreen/cst226_touchscreen.h b/esphome/components/cst226/touchscreen/cst226_touchscreen.h index c744e51fecb..362eee5fc2d 100644 --- a/esphome/components/cst226/touchscreen/cst226_touchscreen.h +++ b/esphome/components/cst226/touchscreen/cst226_touchscreen.h @@ -6,8 +6,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace cst226 { +namespace esphome::cst226 { static const uint8_t CST226_REG_STATUS = 0x00; @@ -40,5 +39,4 @@ class CST226Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice bool button_touched_{}; }; -} // namespace cst226 -} // namespace esphome +} // namespace esphome::cst226 diff --git a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp index d18d4e7c94c..50ebebbbb5b 100644 --- a/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp +++ b/esphome/components/cst816/touchscreen/cst816_touchscreen.cpp @@ -1,8 +1,7 @@ #include "cst816_touchscreen.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace cst816 { +namespace esphome::cst816 { void CST816Touchscreen::continue_setup_() { if (this->interrupt_pin_ != nullptr) { @@ -121,5 +120,4 @@ void CST816Touchscreen::dump_config() { ESP_LOGCONFIG(TAG, " Chip type: %s", name); } -} // namespace cst816 -} // namespace esphome +} // namespace esphome::cst816 diff --git a/esphome/components/cst816/touchscreen/cst816_touchscreen.h b/esphome/components/cst816/touchscreen/cst816_touchscreen.h index 99b93d8342f..19c169c3ecb 100644 --- a/esphome/components/cst816/touchscreen/cst816_touchscreen.h +++ b/esphome/components/cst816/touchscreen/cst816_touchscreen.h @@ -6,8 +6,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace cst816 { +namespace esphome::cst816 { static const char *const TAG = "cst816.touchscreen"; @@ -57,5 +56,4 @@ class CST816Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice bool skip_probe_{}; // if set, do not expect to be able to probe the controller on the i2c bus. }; -} // namespace cst816 -} // namespace esphome +} // namespace esphome::cst816 diff --git a/esphome/components/ct_clamp/ct_clamp_sensor.cpp b/esphome/components/ct_clamp/ct_clamp_sensor.cpp index 0aa0258a9b6..613c3428be3 100644 --- a/esphome/components/ct_clamp/ct_clamp_sensor.cpp +++ b/esphome/components/ct_clamp/ct_clamp_sensor.cpp @@ -4,8 +4,7 @@ #include #include -namespace esphome { -namespace ct_clamp { +namespace esphome::ct_clamp { static const char *const TAG = "ct_clamp"; @@ -70,5 +69,4 @@ void CTClampSensor::loop() { this->sample_squared_sum_ += value * value; } -} // namespace ct_clamp -} // namespace esphome +} // namespace esphome::ct_clamp diff --git a/esphome/components/ct_clamp/ct_clamp_sensor.h b/esphome/components/ct_clamp/ct_clamp_sensor.h index db4dc1ea57e..2055edbd3eb 100644 --- a/esphome/components/ct_clamp/ct_clamp_sensor.h +++ b/esphome/components/ct_clamp/ct_clamp_sensor.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/voltage_sampler/voltage_sampler.h" -namespace esphome { -namespace ct_clamp { +namespace esphome::ct_clamp { class CTClampSensor : public sensor::Sensor, public PollingComponent { public: @@ -50,5 +49,4 @@ class CTClampSensor : public sensor::Sensor, public PollingComponent { bool is_sampling_ = false; }; -} // namespace ct_clamp -} // namespace esphome +} // namespace esphome::ct_clamp diff --git a/esphome/components/current_based/current_based_cover.cpp b/esphome/components/current_based/current_based_cover.cpp index 13bf11b9912..5a499d54a41 100644 --- a/esphome/components/current_based/current_based_cover.cpp +++ b/esphome/components/current_based/current_based_cover.cpp @@ -4,8 +4,7 @@ #include "esphome/core/application.h" #include -namespace esphome { -namespace current_based { +namespace esphome::current_based { static const char *const TAG = "current_based.cover"; @@ -271,5 +270,4 @@ void CurrentBasedCover::recompute_position_() { this->last_recompute_time_ = now; } -} // namespace current_based -} // namespace esphome +} // namespace esphome::current_based diff --git a/esphome/components/current_based/current_based_cover.h b/esphome/components/current_based/current_based_cover.h index 40b39517e4e..531f8d5a4f5 100644 --- a/esphome/components/current_based/current_based_cover.h +++ b/esphome/components/current_based/current_based_cover.h @@ -6,8 +6,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace current_based { +namespace esphome::current_based { class CurrentBasedCover : public cover::Cover, public Component { public: @@ -92,5 +91,4 @@ class CurrentBasedCover : public cover::Cover, public Component { cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING}; }; -} // namespace current_based -} // namespace esphome +} // namespace esphome::current_based diff --git a/esphome/components/cwww/cwww_light_output.h b/esphome/components/cwww/cwww_light_output.h index 2b7698ce5aa..6eed8de7ccc 100644 --- a/esphome/components/cwww/cwww_light_output.h +++ b/esphome/components/cwww/cwww_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace cwww { +namespace esphome::cwww { class CWWWLightOutput : public light::LightOutput { public: @@ -36,5 +35,4 @@ class CWWWLightOutput : public light::LightOutput { bool constant_brightness_; }; -} // namespace cwww -} // namespace esphome +} // namespace esphome::cwww From 4e4e4b4411e09a0c5cfa68bc4309067ba81987ba Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 16:49:55 -0400 Subject: [PATCH 03/52] [clang-tidy] Concatenate nested namespaces (2/7: components d-h) (#16295) --- esphome/components/dac7678/dac7678_output.cpp | 6 ++---- esphome/components/dac7678/dac7678_output.h | 6 ++---- esphome/components/daikin/daikin.cpp | 6 ++---- esphome/components/daikin/daikin.h | 6 ++---- esphome/components/daikin_arc/daikin_arc.cpp | 6 ++---- esphome/components/daikin_arc/daikin_arc.h | 6 ++---- esphome/components/daikin_brc/daikin_brc.cpp | 6 ++---- esphome/components/daikin_brc/daikin_brc.h | 6 ++---- esphome/components/dallas_temp/dallas_temp.cpp | 6 ++---- esphome/components/dallas_temp/dallas_temp.h | 6 ++---- esphome/components/daly_bms/daly_bms.cpp | 6 ++---- esphome/components/daly_bms/daly_bms.h | 6 ++---- esphome/components/dashboard_import/dashboard_import.cpp | 6 ++---- esphome/components/dashboard_import/dashboard_import.h | 6 ++---- esphome/components/debug/debug_component.cpp | 6 ++---- esphome/components/debug/debug_component.h | 6 ++---- esphome/components/debug/debug_esp32.cpp | 7 +++---- esphome/components/deep_sleep/deep_sleep_component.cpp | 6 ++---- esphome/components/deep_sleep/deep_sleep_component.h | 6 ++---- esphome/components/deep_sleep/deep_sleep_esp32.cpp | 7 +++---- esphome/components/delonghi/delonghi.cpp | 6 ++---- esphome/components/delonghi/delonghi.h | 6 ++---- esphome/components/demo/demo_alarm_control_panel.h | 6 ++---- esphome/components/demo/demo_binary_sensor.h | 6 ++---- esphome/components/demo/demo_button.h | 6 ++---- esphome/components/demo/demo_climate.h | 6 ++---- esphome/components/demo/demo_cover.h | 6 ++---- esphome/components/demo/demo_date.h | 6 ++---- esphome/components/demo/demo_datetime.h | 6 ++---- esphome/components/demo/demo_fan.h | 6 ++---- esphome/components/demo/demo_light.h | 6 ++---- esphome/components/demo/demo_lock.h | 6 ++---- esphome/components/demo/demo_number.h | 6 ++---- esphome/components/demo/demo_select.h | 6 ++---- esphome/components/demo/demo_sensor.h | 6 ++---- esphome/components/demo/demo_switch.h | 6 ++---- esphome/components/demo/demo_text.h | 6 ++---- esphome/components/demo/demo_text_sensor.h | 6 ++---- esphome/components/demo/demo_time.h | 6 ++---- esphome/components/demo/demo_valve.h | 6 ++---- esphome/components/dfplayer/dfplayer.cpp | 6 ++---- esphome/components/dfplayer/dfplayer.h | 6 ++---- esphome/components/dfrobot_sen0395/automation.h | 6 ++---- esphome/components/dfrobot_sen0395/commands.cpp | 6 ++---- esphome/components/dfrobot_sen0395/commands.h | 6 ++---- esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp | 6 ++---- esphome/components/dfrobot_sen0395/dfrobot_sen0395.h | 6 ++---- .../dfrobot_sen0395/switch/dfrobot_sen0395_switch.cpp | 6 ++---- .../dfrobot_sen0395/switch/dfrobot_sen0395_switch.h | 6 ++---- esphome/components/dht12/dht12.cpp | 6 ++---- esphome/components/dht12/dht12.h | 6 ++---- esphome/components/display/display.cpp | 6 ++---- esphome/components/display/display.h | 6 ++---- esphome/components/display/display_buffer.cpp | 6 ++---- esphome/components/display/display_buffer.h | 6 ++---- esphome/components/display/display_color_utils.h | 6 ++---- esphome/components/display/rect.cpp | 6 ++---- esphome/components/display/rect.h | 6 ++---- esphome/components/display_menu_base/automation.h | 6 ++---- .../components/display_menu_base/display_menu_base.cpp | 6 ++---- esphome/components/display_menu_base/display_menu_base.h | 6 ++---- esphome/components/display_menu_base/menu_item.cpp | 6 ++---- esphome/components/display_menu_base/menu_item.h | 6 ++---- esphome/components/dps310/dps310.cpp | 6 ++---- esphome/components/dps310/dps310.h | 6 ++---- esphome/components/ds1307/ds1307.cpp | 6 ++---- esphome/components/ds1307/ds1307.h | 6 ++---- esphome/components/ds2484/ds2484.cpp | 6 ++---- esphome/components/ds2484/ds2484.h | 6 ++---- esphome/components/duty_cycle/duty_cycle_sensor.cpp | 6 ++---- esphome/components/duty_cycle/duty_cycle_sensor.h | 6 ++---- esphome/components/duty_time/duty_time_sensor.cpp | 6 ++---- esphome/components/duty_time/duty_time_sensor.h | 6 ++---- esphome/components/e131/e131.cpp | 7 +++---- esphome/components/e131/e131.h | 7 +++---- esphome/components/e131/e131_addressable_light_effect.cpp | 7 +++---- esphome/components/e131/e131_addressable_light_effect.h | 8 ++++---- esphome/components/e131/e131_packet.cpp | 7 +++---- esphome/components/ee895/ee895.cpp | 6 ++---- esphome/components/ee895/ee895.h | 6 ++---- esphome/components/ektf2232/touchscreen/ektf2232.cpp | 6 ++---- esphome/components/ektf2232/touchscreen/ektf2232.h | 6 ++---- esphome/components/emc2101/emc2101.cpp | 6 ++---- esphome/components/emc2101/emc2101.h | 6 ++---- esphome/components/emc2101/output/emc2101_output.cpp | 6 ++---- esphome/components/emc2101/output/emc2101_output.h | 6 ++---- esphome/components/emc2101/sensor/emc2101_sensor.cpp | 6 ++---- esphome/components/emc2101/sensor/emc2101_sensor.h | 6 ++---- esphome/components/emmeti/emmeti.cpp | 6 ++---- esphome/components/emmeti/emmeti.h | 6 ++---- esphome/components/endstop/endstop_cover.cpp | 6 ++---- esphome/components/endstop/endstop_cover.h | 6 ++---- esphome/components/ens160_base/ens160_base.cpp | 6 ++---- esphome/components/ens160_base/ens160_base.h | 6 ++---- esphome/components/ens160_i2c/ens160_i2c.cpp | 6 ++---- esphome/components/ens160_i2c/ens160_i2c.h | 6 ++---- esphome/components/ens160_spi/ens160_spi.cpp | 6 ++---- esphome/components/ens160_spi/ens160_spi.h | 6 ++---- esphome/components/ens210/ens210.cpp | 6 ++---- esphome/components/ens210/ens210.h | 6 ++---- esphome/components/es7210/es7210.cpp | 6 ++---- esphome/components/es7210/es7210.h | 6 ++---- esphome/components/es7210/es7210_const.h | 6 ++---- esphome/components/es7243e/es7243e.cpp | 6 ++---- esphome/components/es7243e/es7243e.h | 6 ++---- esphome/components/es7243e/es7243e_const.h | 6 ++---- esphome/components/es8156/es8156.cpp | 6 ++---- esphome/components/es8156/es8156.h | 6 ++---- esphome/components/es8156/es8156_const.h | 6 ++---- esphome/components/es8311/es8311.cpp | 6 ++---- esphome/components/es8311/es8311.h | 6 ++---- esphome/components/es8311/es8311_const.h | 6 ++---- esphome/components/es8388/es8388.cpp | 6 ++---- esphome/components/es8388/es8388.h | 6 ++---- esphome/components/es8388/es8388_const.h | 6 ++---- esphome/components/es8388/select/adc_input_mic_select.cpp | 6 ++---- esphome/components/es8388/select/adc_input_mic_select.h | 6 ++---- esphome/components/es8388/select/dac_output_select.cpp | 6 ++---- esphome/components/es8388/select/dac_output_select.h | 6 ++---- esphome/components/esp32/gpio.h | 6 ++---- esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp | 6 ++---- esphome/components/esp32_ble_beacon/esp32_ble_beacon.h | 6 ++---- esphome/components/esp32_ble_server/ble_2902.cpp | 6 ++---- esphome/components/esp32_ble_server/ble_2902.h | 6 ++---- .../components/esp32_ble_server/ble_characteristic.cpp | 6 ++---- esphome/components/esp32_ble_server/ble_characteristic.h | 6 ++---- esphome/components/esp32_ble_server/ble_descriptor.cpp | 6 ++---- esphome/components/esp32_ble_server/ble_descriptor.h | 6 ++---- esphome/components/esp32_ble_server/ble_server.cpp | 6 ++---- esphome/components/esp32_ble_server/ble_server.h | 6 ++---- .../esp32_ble_server/ble_server_automations.cpp | 8 ++------ .../components/esp32_ble_server/ble_server_automations.h | 8 ++------ esphome/components/esp32_ble_server/ble_service.cpp | 6 ++---- esphome/components/esp32_ble_server/ble_service.h | 6 ++---- esphome/components/esp32_camera/esp32_camera.cpp | 6 ++---- esphome/components/esp32_camera/esp32_camera.h | 6 ++---- .../esp32_camera_web_server/camera_web_server.cpp | 6 ++---- .../esp32_camera_web_server/camera_web_server.h | 6 ++---- esphome/components/esp32_can/esp32_can.cpp | 6 ++---- esphome/components/esp32_can/esp32_can.h | 6 ++---- esphome/components/esp32_dac/esp32_dac.cpp | 6 ++---- esphome/components/esp32_dac/esp32_dac.h | 6 ++---- esphome/components/esp32_improv/automation.h | 7 +++---- .../components/esp32_improv/esp32_improv_component.cpp | 6 ++---- esphome/components/esp32_improv/esp32_improv_component.h | 6 ++---- esphome/components/esp32_rmt_led_strip/led_strip.cpp | 6 ++---- esphome/components/esp32_rmt_led_strip/led_strip.h | 6 ++---- .../espnow/packet_transport/espnow_transport.cpp | 6 ++---- .../components/espnow/packet_transport/espnow_transport.h | 6 ++---- esphome/components/event/automation.h | 6 ++---- esphome/components/event/event.cpp | 6 ++---- esphome/components/event/event.h | 6 ++---- .../exposure_notifications/exposure_notifications.cpp | 6 ++---- .../exposure_notifications/exposure_notifications.h | 6 ++---- esphome/components/ezo/ezo.cpp | 6 ++---- esphome/components/ezo/ezo.h | 6 ++---- esphome/components/ezo_pmp/ezo_pmp.cpp | 6 ++---- esphome/components/ezo_pmp/ezo_pmp.h | 6 ++---- .../factory_reset/button/factory_reset_button.cpp | 6 ++---- .../factory_reset/button/factory_reset_button.h | 6 ++---- .../factory_reset/switch/factory_reset_switch.cpp | 6 ++---- .../factory_reset/switch/factory_reset_switch.h | 6 ++---- esphome/components/fan/automation.h | 6 ++---- esphome/components/fan/fan.cpp | 6 ++---- esphome/components/fan/fan.h | 6 ++---- esphome/components/fan/fan_traits.h | 7 ++----- esphome/components/fastled_base/fastled_light.cpp | 6 ++---- esphome/components/fastled_base/fastled_light.h | 6 ++---- esphome/components/fingerprint_grow/fingerprint_grow.cpp | 6 ++---- esphome/components/fingerprint_grow/fingerprint_grow.h | 6 ++---- esphome/components/font/font.cpp | 6 ++---- esphome/components/font/font.h | 6 ++---- esphome/components/fs3000/fs3000.cpp | 6 ++---- esphome/components/fs3000/fs3000.h | 6 ++---- .../components/ft5x06/touchscreen/ft5x06_touchscreen.cpp | 6 ++---- .../components/ft5x06/touchscreen/ft5x06_touchscreen.h | 6 ++---- esphome/components/ft63x6/ft63x6.cpp | 7 +++---- esphome/components/ft63x6/ft63x6.h | 6 ++---- esphome/components/fujitsu_general/fujitsu_general.cpp | 6 ++---- esphome/components/fujitsu_general/fujitsu_general.h | 6 ++---- esphome/components/gcja5/gcja5.cpp | 6 ++---- esphome/components/gcja5/gcja5.h | 6 ++---- esphome/components/gdk101/gdk101.cpp | 6 ++---- esphome/components/gdk101/gdk101.h | 6 ++---- esphome/components/gl_r01_i2c/gl_r01_i2c.cpp | 6 ++---- esphome/components/gl_r01_i2c/gl_r01_i2c.h | 6 ++---- esphome/components/gp2y1010au0f/gp2y1010au0f.cpp | 6 ++---- esphome/components/gp2y1010au0f/gp2y1010au0f.h | 6 ++---- esphome/components/gp8403/gp8403.cpp | 6 ++---- esphome/components/gp8403/gp8403.h | 6 ++---- esphome/components/gp8403/output/gp8403_output.cpp | 6 ++---- esphome/components/gp8403/output/gp8403_output.h | 6 ++---- .../components/gpio/binary_sensor/gpio_binary_sensor.cpp | 6 ++---- .../components/gpio/binary_sensor/gpio_binary_sensor.h | 6 ++---- esphome/components/gpio/one_wire/gpio_one_wire.cpp | 6 ++---- esphome/components/gpio/one_wire/gpio_one_wire.h | 6 ++---- esphome/components/gpio/output/gpio_binary_output.cpp | 6 ++---- esphome/components/gpio/output/gpio_binary_output.h | 6 ++---- esphome/components/gpio/switch/gpio_switch.cpp | 6 ++---- esphome/components/gpio/switch/gpio_switch.h | 6 ++---- esphome/components/gps/gps.cpp | 6 ++---- esphome/components/gps/gps.h | 6 ++---- esphome/components/gps/time/gps_time.cpp | 6 ++---- esphome/components/gps/time/gps_time.h | 6 ++---- esphome/components/graph/graph.cpp | 7 +++---- .../graphical_display_menu/graphical_display_menu.cpp | 6 ++---- esphome/components/gree/gree.cpp | 6 ++---- esphome/components/gree/switch/gree_switch.cpp | 6 ++---- esphome/components/gree/switch/gree_switch.h | 6 ++---- esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp | 6 ++---- esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h | 6 ++---- esphome/components/grove_tb6612fng/grove_tb6612fng.cpp | 6 ++---- esphome/components/grove_tb6612fng/grove_tb6612fng.h | 8 +++----- esphome/components/growatt_solar/growatt_solar.cpp | 6 ++---- esphome/components/growatt_solar/growatt_solar.h | 6 ++---- esphome/components/gt911/binary_sensor/gt911_button.cpp | 6 ++---- esphome/components/gt911/binary_sensor/gt911_button.h | 6 ++---- .../components/gt911/touchscreen/gt911_touchscreen.cpp | 6 ++---- esphome/components/gt911/touchscreen/gt911_touchscreen.h | 6 ++---- esphome/components/haier/automation.h | 6 ++---- esphome/components/haier/button/self_cleaning.cpp | 6 ++---- esphome/components/haier/button/self_cleaning.h | 6 ++---- esphome/components/haier/button/steri_cleaning.cpp | 6 ++---- esphome/components/haier/button/steri_cleaning.h | 6 ++---- esphome/components/haier/haier_base.cpp | 6 ++---- esphome/components/haier/haier_base.h | 6 ++---- esphome/components/haier/hon_climate.cpp | 6 ++---- esphome/components/haier/hon_climate.h | 6 ++---- esphome/components/haier/hon_packet.h | 8 ++------ esphome/components/haier/logger_handler.cpp | 6 ++---- esphome/components/haier/logger_handler.h | 6 ++---- esphome/components/haier/smartair2_climate.cpp | 6 ++---- esphome/components/haier/smartair2_climate.h | 6 ++---- esphome/components/haier/smartair2_packet.h | 8 ++------ esphome/components/haier/switch/beeper.cpp | 6 ++---- esphome/components/haier/switch/beeper.h | 6 ++---- esphome/components/haier/switch/display.cpp | 6 ++---- esphome/components/haier/switch/display.h | 6 ++---- esphome/components/haier/switch/health_mode.cpp | 6 ++---- esphome/components/haier/switch/health_mode.h | 6 ++---- esphome/components/haier/switch/quiet_mode.cpp | 6 ++---- esphome/components/haier/switch/quiet_mode.h | 6 ++---- esphome/components/havells_solar/havells_solar.cpp | 6 ++---- esphome/components/havells_solar/havells_solar.h | 6 ++---- .../components/havells_solar/havells_solar_registers.h | 7 +++---- esphome/components/hbridge/fan/hbridge_fan.cpp | 6 ++---- esphome/components/hbridge/fan/hbridge_fan.h | 6 ++---- esphome/components/hbridge/light/hbridge_light_output.h | 6 ++---- esphome/components/hbridge/switch/hbridge_switch.cpp | 6 ++---- esphome/components/hbridge/switch/hbridge_switch.h | 6 ++---- esphome/components/hdc1080/hdc1080.cpp | 6 ++---- esphome/components/hdc1080/hdc1080.h | 6 ++---- esphome/components/hdc2010/hdc2010.cpp | 7 +++---- esphome/components/hdc2010/hdc2010.h | 6 ++---- esphome/components/he60r/he60r.cpp | 6 ++---- esphome/components/he60r/he60r.h | 6 ++---- esphome/components/heatpumpir/heatpumpir.cpp | 6 ++---- esphome/components/heatpumpir/heatpumpir.h | 6 ++---- esphome/components/hitachi_ac344/hitachi_ac344.cpp | 6 ++---- esphome/components/hitachi_ac344/hitachi_ac344.h | 6 ++---- esphome/components/hitachi_ac424/hitachi_ac424.cpp | 6 ++---- esphome/components/hitachi_ac424/hitachi_ac424.h | 6 ++---- esphome/components/hlw8012/hlw8012.cpp | 6 ++---- esphome/components/hlw8012/hlw8012.h | 6 ++---- esphome/components/hm3301/hm3301.cpp | 6 ++---- esphome/components/hm3301/hm3301.h | 6 ++---- esphome/components/hmac_md5/hmac_md5.cpp | 7 +++---- esphome/components/hmac_md5/hmac_md5.h | 7 +++---- esphome/components/hmc5883l/hmc5883l.cpp | 6 ++---- esphome/components/hmc5883l/hmc5883l.h | 6 ++---- .../binary_sensor/homeassistant_binary_sensor.cpp | 6 ++---- .../binary_sensor/homeassistant_binary_sensor.h | 6 ++---- .../homeassistant/number/homeassistant_number.cpp | 6 ++---- .../homeassistant/number/homeassistant_number.h | 6 ++---- .../homeassistant/sensor/homeassistant_sensor.cpp | 6 ++---- .../homeassistant/sensor/homeassistant_sensor.h | 6 ++---- .../homeassistant/switch/homeassistant_switch.cpp | 6 ++---- .../homeassistant/switch/homeassistant_switch.h | 6 ++---- .../text_sensor/homeassistant_text_sensor.cpp | 6 ++---- .../homeassistant/text_sensor/homeassistant_text_sensor.h | 6 ++---- .../components/homeassistant/time/homeassistant_time.cpp | 6 ++---- .../components/homeassistant/time/homeassistant_time.h | 6 ++---- esphome/components/honeywell_hih_i2c/honeywell_hih.cpp | 6 ++---- esphome/components/honeywell_hih_i2c/honeywell_hih.h | 6 ++---- esphome/components/honeywellabp/honeywellabp.cpp | 6 ++---- esphome/components/honeywellabp/honeywellabp.h | 6 ++---- esphome/components/honeywellabp2_i2c/honeywellabp2.cpp | 6 ++---- esphome/components/honeywellabp2_i2c/honeywellabp2.h | 6 ++---- esphome/components/host/time/host_time.h | 6 ++---- esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.cpp | 6 ++---- esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.h | 6 ++---- esphome/components/hte501/hte501.cpp | 6 ++---- esphome/components/hte501/hte501.h | 6 ++---- esphome/components/http_request/ota/automation.h | 6 ++---- esphome/components/http_request/ota/ota_http_request.cpp | 6 ++---- esphome/components/http_request/ota/ota_http_request.h | 6 ++---- .../http_request/update/http_request_update.cpp | 6 ++---- .../components/http_request/update/http_request_update.h | 6 ++---- esphome/components/htu21d/htu21d.cpp | 6 ++---- esphome/components/htu21d/htu21d.h | 6 ++---- esphome/components/htu31d/htu31d.cpp | 6 ++---- esphome/components/htu31d/htu31d.h | 6 ++---- esphome/components/hx711/hx711.cpp | 6 ++---- esphome/components/hx711/hx711.h | 6 ++---- esphome/components/hydreon_rgxx/hydreon_rgxx.cpp | 6 ++---- esphome/components/hydreon_rgxx/hydreon_rgxx.h | 6 ++---- esphome/components/hyt271/hyt271.cpp | 6 ++---- esphome/components/hyt271/hyt271.h | 6 ++---- 308 files changed, 632 insertions(+), 1242 deletions(-) diff --git a/esphome/components/dac7678/dac7678_output.cpp b/esphome/components/dac7678/dac7678_output.cpp index 27ab54f0be9..15575583d97 100644 --- a/esphome/components/dac7678/dac7678_output.cpp +++ b/esphome/components/dac7678/dac7678_output.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace dac7678 { +namespace esphome::dac7678 { static const char *const TAG = "dac7678"; @@ -82,5 +81,4 @@ void DAC7678Channel::write_state(float state) { this->parent_->set_channel_value_(this->channel_, input); } -} // namespace dac7678 -} // namespace esphome +} // namespace esphome::dac7678 diff --git a/esphome/components/dac7678/dac7678_output.h b/esphome/components/dac7678/dac7678_output.h index abd9875e4ce..a0173259398 100644 --- a/esphome/components/dac7678/dac7678_output.h +++ b/esphome/components/dac7678/dac7678_output.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace dac7678 { +namespace esphome::dac7678 { class DAC7678Output; @@ -51,5 +50,4 @@ class DAC7678Output : public Component, public i2c::I2CDevice { }; }; -} // namespace dac7678 -} // namespace esphome +} // namespace esphome::dac7678 diff --git a/esphome/components/daikin/daikin.cpp b/esphome/components/daikin/daikin.cpp index a285f3613db..d45586ba2dc 100644 --- a/esphome/components/daikin/daikin.cpp +++ b/esphome/components/daikin/daikin.cpp @@ -1,8 +1,7 @@ #include "daikin.h" #include "esphome/components/remote_base/remote_base.h" -namespace esphome { -namespace daikin { +namespace esphome::daikin { static const char *const TAG = "daikin.climate"; @@ -251,5 +250,4 @@ bool DaikinClimate::on_receive(remote_base::RemoteReceiveData data) { return this->parse_state_frame_(state_frame); } -} // namespace daikin -} // namespace esphome +} // namespace esphome::daikin diff --git a/esphome/components/daikin/daikin.h b/esphome/components/daikin/daikin.h index 159292cb554..9c05993f378 100644 --- a/esphome/components/daikin/daikin.h +++ b/esphome/components/daikin/daikin.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace daikin { +namespace esphome::daikin { // Values for Daikin ARC43XXX IR Controllers // Temperature @@ -60,5 +59,4 @@ class DaikinClimate : public climate_ir::ClimateIR { bool parse_state_frame_(const uint8_t frame[]); }; -} // namespace daikin -} // namespace esphome +} // namespace esphome::daikin diff --git a/esphome/components/daikin_arc/daikin_arc.cpp b/esphome/components/daikin_arc/daikin_arc.cpp index 18f12dbfc6c..a455e2fd7f8 100644 --- a/esphome/components/daikin_arc/daikin_arc.cpp +++ b/esphome/components/daikin_arc/daikin_arc.cpp @@ -5,8 +5,7 @@ #include "esphome/components/remote_base/remote_base.h" #include "esphome/core/log.h" -namespace esphome { -namespace daikin_arc { +namespace esphome::daikin_arc { static const char *const TAG = "daikin.climate"; @@ -492,5 +491,4 @@ void DaikinArcClimate::control(const climate::ClimateCall &call) { climate_ir::ClimateIR::control(call); } -} // namespace daikin_arc -} // namespace esphome +} // namespace esphome::daikin_arc diff --git a/esphome/components/daikin_arc/daikin_arc.h b/esphome/components/daikin_arc/daikin_arc.h index 2b4d4375aae..2337351e280 100644 --- a/esphome/components/daikin_arc/daikin_arc.h +++ b/esphome/components/daikin_arc/daikin_arc.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace daikin_arc { +namespace esphome::daikin_arc { // Values for Daikin ARC43XXX IR Controllers // Temperature @@ -73,5 +72,4 @@ class DaikinArcClimate : public climate_ir::ClimateIR { uint8_t last_humidity_{0x66}; }; -} // namespace daikin_arc -} // namespace esphome +} // namespace esphome::daikin_arc diff --git a/esphome/components/daikin_brc/daikin_brc.cpp b/esphome/components/daikin_brc/daikin_brc.cpp index 1179cb07d70..5fe3d30a850 100644 --- a/esphome/components/daikin_brc/daikin_brc.cpp +++ b/esphome/components/daikin_brc/daikin_brc.cpp @@ -1,8 +1,7 @@ #include "daikin_brc.h" #include "esphome/components/remote_base/remote_base.h" -namespace esphome { -namespace daikin_brc { +namespace esphome::daikin_brc { static const char *const TAG = "daikin_brc.climate"; @@ -269,5 +268,4 @@ bool DaikinBrcClimate::on_receive(remote_base::RemoteReceiveData data) { return this->parse_state_frame_(state_frame); } -} // namespace daikin_brc -} // namespace esphome +} // namespace esphome::daikin_brc diff --git a/esphome/components/daikin_brc/daikin_brc.h b/esphome/components/daikin_brc/daikin_brc.h index bdc63848092..4b5c679f7fc 100644 --- a/esphome/components/daikin_brc/daikin_brc.h +++ b/esphome/components/daikin_brc/daikin_brc.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace daikin_brc { +namespace esphome::daikin_brc { // Values for Daikin BRC4CXXX IR Controllers // Temperature @@ -78,5 +77,4 @@ class DaikinBrcClimate : public climate_ir::ClimateIR { bool fahrenheit_{false}; }; -} // namespace daikin_brc -} // namespace esphome +} // namespace esphome::daikin_brc diff --git a/esphome/components/dallas_temp/dallas_temp.cpp b/esphome/components/dallas_temp/dallas_temp.cpp index f119e28e78e..35488eab03f 100644 --- a/esphome/components/dallas_temp/dallas_temp.cpp +++ b/esphome/components/dallas_temp/dallas_temp.cpp @@ -1,8 +1,7 @@ #include "dallas_temp.h" #include "esphome/core/log.h" -namespace esphome { -namespace dallas_temp { +namespace esphome::dallas_temp { static const char *const TAG = "dallas.temp.sensor"; @@ -159,5 +158,4 @@ float DallasTemperatureSensor::get_temp_c_() { return temp / 16.0f; } -} // namespace dallas_temp -} // namespace esphome +} // namespace esphome::dallas_temp diff --git a/esphome/components/dallas_temp/dallas_temp.h b/esphome/components/dallas_temp/dallas_temp.h index 1bd28650952..3f7b447fc7c 100644 --- a/esphome/components/dallas_temp/dallas_temp.h +++ b/esphome/components/dallas_temp/dallas_temp.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/one_wire/one_wire.h" -namespace esphome { -namespace dallas_temp { +namespace esphome::dallas_temp { class DallasTemperatureSensor : public PollingComponent, public sensor::Sensor, public one_wire::OneWireDevice { public: @@ -27,5 +26,4 @@ class DallasTemperatureSensor : public PollingComponent, public sensor::Sensor, float get_temp_c_(); }; -} // namespace dallas_temp -} // namespace esphome +} // namespace esphome::dallas_temp diff --git a/esphome/components/daly_bms/daly_bms.cpp b/esphome/components/daly_bms/daly_bms.cpp index 90ccee78f8a..530d8ad5415 100644 --- a/esphome/components/daly_bms/daly_bms.cpp +++ b/esphome/components/daly_bms/daly_bms.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace daly_bms { +namespace esphome::daly_bms { static const char *const TAG = "daly_bms"; @@ -321,5 +320,4 @@ void DalyBmsComponent::decode_data_(std::vector data) { } } -} // namespace daly_bms -} // namespace esphome +} // namespace esphome::daly_bms diff --git a/esphome/components/daly_bms/daly_bms.h b/esphome/components/daly_bms/daly_bms.h index 1983ba0ef19..6dcc66b5eeb 100644 --- a/esphome/components/daly_bms/daly_bms.h +++ b/esphome/components/daly_bms/daly_bms.h @@ -15,8 +15,7 @@ #include -namespace esphome { -namespace daly_bms { +namespace esphome::daly_bms { class DalyBmsComponent : public PollingComponent, public uart::UARTDevice { public: @@ -88,5 +87,4 @@ class DalyBmsComponent : public PollingComponent, public uart::UARTDevice { uint8_t next_request_; }; -} // namespace daly_bms -} // namespace esphome +} // namespace esphome::daly_bms diff --git a/esphome/components/dashboard_import/dashboard_import.cpp b/esphome/components/dashboard_import/dashboard_import.cpp index d4a95b81f6c..f553adf273a 100644 --- a/esphome/components/dashboard_import/dashboard_import.cpp +++ b/esphome/components/dashboard_import/dashboard_import.cpp @@ -1,12 +1,10 @@ #include "dashboard_import.h" -namespace esphome { -namespace dashboard_import { +namespace esphome::dashboard_import { static const char *g_package_import_url = ""; // NOLINT const char *get_package_import_url() { return g_package_import_url; } void set_package_import_url(const char *url) { g_package_import_url = url; } -} // namespace dashboard_import -} // namespace esphome +} // namespace esphome::dashboard_import diff --git a/esphome/components/dashboard_import/dashboard_import.h b/esphome/components/dashboard_import/dashboard_import.h index 488bf80a2ed..19f69b85461 100644 --- a/esphome/components/dashboard_import/dashboard_import.h +++ b/esphome/components/dashboard_import/dashboard_import.h @@ -1,10 +1,8 @@ #pragma once -namespace esphome { -namespace dashboard_import { +namespace esphome::dashboard_import { const char *get_package_import_url(); void set_package_import_url(const char *url); -} // namespace dashboard_import -} // namespace esphome +} // namespace esphome::dashboard_import diff --git a/esphome/components/debug/debug_component.cpp b/esphome/components/debug/debug_component.cpp index d97a4aa135a..9020c261c26 100644 --- a/esphome/components/debug/debug_component.cpp +++ b/esphome/components/debug/debug_component.cpp @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace debug { +namespace esphome::debug { static const char *const TAG = "debug"; @@ -93,5 +92,4 @@ void DebugComponent::update() { float DebugComponent::get_setup_priority() const { return setup_priority::LATE; } -} // namespace debug -} // namespace esphome +} // namespace esphome::debug diff --git a/esphome/components/debug/debug_component.h b/esphome/components/debug/debug_component.h index 3da6b800c6f..871b7cfd258 100644 --- a/esphome/components/debug/debug_component.h +++ b/esphome/components/debug/debug_component.h @@ -13,8 +13,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #endif -namespace esphome { -namespace debug { +namespace esphome::debug { static constexpr size_t DEVICE_INFO_BUFFER_SIZE = 256; static constexpr size_t RESET_REASON_BUFFER_SIZE = 128; @@ -101,5 +100,4 @@ class DebugComponent : public PollingComponent { void update_platform_(); }; -} // namespace debug -} // namespace esphome +} // namespace esphome::debug diff --git a/esphome/components/debug/debug_esp32.cpp b/esphome/components/debug/debug_esp32.cpp index ea0c635207f..7c01f9b54fe 100644 --- a/esphome/components/debug/debug_esp32.cpp +++ b/esphome/components/debug/debug_esp32.cpp @@ -16,8 +16,7 @@ #include #endif -namespace esphome { -namespace debug { +namespace esphome::debug { static const char *const TAG = "debug"; @@ -311,6 +310,6 @@ void DebugComponent::update_platform_() { #endif } -} // namespace debug -} // namespace esphome +} // namespace esphome::debug + #endif // USE_ESP32 diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index d5e34b1f1c8..e7ce70b60c3 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -2,8 +2,7 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" -namespace esphome { -namespace deep_sleep { +namespace esphome::deep_sleep { static const char *const TAG = "deep_sleep"; // 5 seconds for deep sleep to ensure clean disconnect from Home Assistant @@ -81,5 +80,4 @@ void DeepSleepComponent::prevent_deep_sleep() { this->prevent_ = true; } void DeepSleepComponent::allow_deep_sleep() { this->prevent_ = false; } -} // namespace deep_sleep -} // namespace esphome +} // namespace esphome::deep_sleep diff --git a/esphome/components/deep_sleep/deep_sleep_component.h b/esphome/components/deep_sleep/deep_sleep_component.h index 59381eeabeb..2df53f15407 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.h +++ b/esphome/components/deep_sleep/deep_sleep_component.h @@ -15,8 +15,7 @@ #include -namespace esphome { -namespace deep_sleep { +namespace esphome::deep_sleep { #if defined(USE_ESP32) || defined(USE_BK72XX) @@ -244,5 +243,4 @@ template class AllowDeepSleepAction : public Action, publ void play(const Ts &...x) override { this->parent_->allow_deep_sleep(); } }; -} // namespace deep_sleep -} // namespace esphome +} // namespace esphome::deep_sleep diff --git a/esphome/components/deep_sleep/deep_sleep_esp32.cpp b/esphome/components/deep_sleep/deep_sleep_esp32.cpp index 80a218e9133..c905b8fcbca 100644 --- a/esphome/components/deep_sleep/deep_sleep_esp32.cpp +++ b/esphome/components/deep_sleep/deep_sleep_esp32.cpp @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace deep_sleep { +namespace esphome::deep_sleep { // Deep Sleep feature support matrix for ESP32 variants: // @@ -167,6 +166,6 @@ void DeepSleepComponent::deep_sleep_() { bool DeepSleepComponent::should_teardown_() { return true; } -} // namespace deep_sleep -} // namespace esphome +} // namespace esphome::deep_sleep + #endif // USE_ESP32 diff --git a/esphome/components/delonghi/delonghi.cpp b/esphome/components/delonghi/delonghi.cpp index 19af703ab26..fab2d68347b 100644 --- a/esphome/components/delonghi/delonghi.cpp +++ b/esphome/components/delonghi/delonghi.cpp @@ -1,8 +1,7 @@ #include "delonghi.h" #include "esphome/components/remote_base/remote_base.h" -namespace esphome { -namespace delonghi { +namespace esphome::delonghi { static const char *const TAG = "delonghi.climate"; @@ -182,5 +181,4 @@ bool DelonghiClimate::on_receive(remote_base::RemoteReceiveData data) { return this->parse_state_frame_(state_frame); } -} // namespace delonghi -} // namespace esphome +} // namespace esphome::delonghi diff --git a/esphome/components/delonghi/delonghi.h b/esphome/components/delonghi/delonghi.h index d310a58aee3..c2fbc36b4f7 100644 --- a/esphome/components/delonghi/delonghi.h +++ b/esphome/components/delonghi/delonghi.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace delonghi { +namespace esphome::delonghi { // Values for DELONGHI ARC43XXX IR Controllers const uint8_t DELONGHI_ADDRESS = 83; @@ -60,5 +59,4 @@ class DelonghiClimate : public climate_ir::ClimateIR { bool parse_state_frame_(const uint8_t frame[]); }; -} // namespace delonghi -} // namespace esphome +} // namespace esphome::delonghi diff --git a/esphome/components/demo/demo_alarm_control_panel.h b/esphome/components/demo/demo_alarm_control_panel.h index 5f0725dd4bb..7aaf3219cf1 100644 --- a/esphome/components/demo/demo_alarm_control_panel.h +++ b/esphome/components/demo/demo_alarm_control_panel.h @@ -3,8 +3,7 @@ #include "esphome/components/alarm_control_panel/alarm_control_panel.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { using namespace alarm_control_panel; @@ -62,5 +61,4 @@ class DemoAlarmControlPanel : public AlarmControlPanel, public Component { DemoAlarmControlPanelType type_{}; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_binary_sensor.h b/esphome/components/demo/demo_binary_sensor.h index 4dfd038761c..4bc3737d5a2 100644 --- a/esphome/components/demo/demo_binary_sensor.h +++ b/esphome/components/demo/demo_binary_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoBinarySensor : public binary_sensor::BinarySensor, public PollingComponent { public: @@ -18,5 +17,4 @@ class DemoBinarySensor : public binary_sensor::BinarySensor, public PollingCompo bool last_state_ = false; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_button.h b/esphome/components/demo/demo_button.h index be80d26a8af..a0ed92d3d8e 100644 --- a/esphome/components/demo/demo_button.h +++ b/esphome/components/demo/demo_button.h @@ -3,13 +3,11 @@ #include "esphome/components/button/button.h" #include "esphome/core/log.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoButton : public button::Button { protected: void press_action() override {} }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_climate.h b/esphome/components/demo/demo_climate.h index c6d328b1bc5..d0cd2d553d3 100644 --- a/esphome/components/demo/demo_climate.h +++ b/esphome/components/demo/demo_climate.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/climate/climate.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoClimateType { TYPE_1, @@ -158,5 +157,4 @@ class DemoClimate : public climate::Climate, public Component { DemoClimateType type_; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_cover.h b/esphome/components/demo/demo_cover.h index 69dd5a4d2d1..c1597a75653 100644 --- a/esphome/components/demo/demo_cover.h +++ b/esphome/components/demo/demo_cover.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoCoverType { TYPE_1, @@ -85,5 +84,4 @@ class DemoCover : public cover::Cover, public Component { DemoCoverType type_; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_date.h b/esphome/components/demo/demo_date.h index e09ab5f8873..5a868342cd4 100644 --- a/esphome/components/demo/demo_date.h +++ b/esphome/components/demo/demo_date.h @@ -7,8 +7,7 @@ #include "esphome/components/datetime/date_entity.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoDate : public datetime::DateEntity, public Component { public: @@ -28,7 +27,6 @@ class DemoDate : public datetime::DateEntity, public Component { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo #endif diff --git a/esphome/components/demo/demo_datetime.h b/esphome/components/demo/demo_datetime.h index 5ebcc3e64ed..84869d1a9f8 100644 --- a/esphome/components/demo/demo_datetime.h +++ b/esphome/components/demo/demo_datetime.h @@ -7,8 +7,7 @@ #include "esphome/components/datetime/datetime_entity.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoDateTime : public datetime::DateTimeEntity, public Component { public: @@ -34,7 +33,6 @@ class DemoDateTime : public datetime::DateTimeEntity, public Component { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo #endif diff --git a/esphome/components/demo/demo_fan.h b/esphome/components/demo/demo_fan.h index a8b397f19ac..2e2fbce7d66 100644 --- a/esphome/components/demo/demo_fan.h +++ b/esphome/components/demo/demo_fan.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoFanType { TYPE_1, @@ -66,5 +65,4 @@ class DemoFan : public fan::Fan, public Component { DemoFanType type_; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_light.h b/esphome/components/demo/demo_light.h index 2007e9ff506..071adb0831c 100644 --- a/esphome/components/demo/demo_light.h +++ b/esphome/components/demo/demo_light.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoLightType { // binary @@ -64,5 +63,4 @@ class DemoLight : public light::LightOutput, public Component { DemoLightType type_; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_lock.h b/esphome/components/demo/demo_lock.h index 1e3fd51db4c..85c1c238ef7 100644 --- a/esphome/components/demo/demo_lock.h +++ b/esphome/components/demo/demo_lock.h @@ -2,8 +2,7 @@ #include "esphome/components/lock/lock.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoLock : public lock::Lock { protected: @@ -14,5 +13,4 @@ class DemoLock : public lock::Lock { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_number.h b/esphome/components/demo/demo_number.h index 2ce3a269bc7..0059cdc2eec 100644 --- a/esphome/components/demo/demo_number.h +++ b/esphome/components/demo/demo_number.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/number/number.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoNumberType { TYPE_1, @@ -35,5 +34,4 @@ class DemoNumber : public number::Number, public Component { DemoNumberType type_; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_select.h b/esphome/components/demo/demo_select.h index 1a5df13eda7..2ecb37db99f 100644 --- a/esphome/components/demo/demo_select.h +++ b/esphome/components/demo/demo_select.h @@ -3,13 +3,11 @@ #include "esphome/components/select/select.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoSelect : public select::Select, public Component { protected: void control(size_t index) override { this->publish_state(index); } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_sensor.h b/esphome/components/demo/demo_sensor.h index d965d987dea..867115f21bc 100644 --- a/esphome/components/demo/demo_sensor.h +++ b/esphome/components/demo/demo_sensor.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoSensor : public sensor::Sensor, public PollingComponent { public: @@ -25,5 +24,4 @@ class DemoSensor : public sensor::Sensor, public PollingComponent { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_switch.h b/esphome/components/demo/demo_switch.h index 9c291318cac..b2d6e52c673 100644 --- a/esphome/components/demo/demo_switch.h +++ b/esphome/components/demo/demo_switch.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoSwitch : public switch_::Switch, public Component { public: @@ -18,5 +17,4 @@ class DemoSwitch : public switch_::Switch, public Component { void write_state(bool state) override { this->publish_state(state); } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_text.h b/esphome/components/demo/demo_text.h index a753175062d..56376c8c42a 100644 --- a/esphome/components/demo/demo_text.h +++ b/esphome/components/demo/demo_text.h @@ -3,8 +3,7 @@ #include "esphome/components/text/text.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoText : public text::Text, public Component { public: @@ -14,5 +13,4 @@ class DemoText : public text::Text, public Component { void control(const std::string &value) override { this->publish_state(value); } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_text_sensor.h b/esphome/components/demo/demo_text_sensor.h index b4152fc2483..03852a1e7f8 100644 --- a/esphome/components/demo/demo_text_sensor.h +++ b/esphome/components/demo/demo_text_sensor.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoTextSensor : public text_sensor::TextSensor, public PollingComponent { public: @@ -21,5 +20,4 @@ class DemoTextSensor : public text_sensor::TextSensor, public PollingComponent { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/demo/demo_time.h b/esphome/components/demo/demo_time.h index 42788504bbc..f94678fae40 100644 --- a/esphome/components/demo/demo_time.h +++ b/esphome/components/demo/demo_time.h @@ -7,8 +7,7 @@ #include "esphome/components/datetime/time_entity.h" #include "esphome/core/component.h" -namespace esphome { -namespace demo { +namespace esphome::demo { class DemoTime : public datetime::TimeEntity, public Component { public: @@ -28,7 +27,6 @@ class DemoTime : public datetime::TimeEntity, public Component { } }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo #endif diff --git a/esphome/components/demo/demo_valve.h b/esphome/components/demo/demo_valve.h index 9a3122aca5c..3f1342959ad 100644 --- a/esphome/components/demo/demo_valve.h +++ b/esphome/components/demo/demo_valve.h @@ -2,8 +2,7 @@ #include "esphome/components/valve/valve.h" -namespace esphome { -namespace demo { +namespace esphome::demo { enum class DemoValveType { TYPE_1, @@ -53,5 +52,4 @@ class DemoValve : public valve::Valve { DemoValveType type_{}; }; -} // namespace demo -} // namespace esphome +} // namespace esphome::demo diff --git a/esphome/components/dfplayer/dfplayer.cpp b/esphome/components/dfplayer/dfplayer.cpp index 1e1c33adaf3..5c9d497c877 100644 --- a/esphome/components/dfplayer/dfplayer.cpp +++ b/esphome/components/dfplayer/dfplayer.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace dfplayer { +namespace esphome::dfplayer { static const char *const TAG = "dfplayer"; @@ -283,5 +282,4 @@ void DFPlayer::dump_config() { this->check_uart_settings(9600); } -} // namespace dfplayer -} // namespace esphome +} // namespace esphome::dfplayer diff --git a/esphome/components/dfplayer/dfplayer.h b/esphome/components/dfplayer/dfplayer.h index 0d240566c3d..5936a06b60c 100644 --- a/esphome/components/dfplayer/dfplayer.h +++ b/esphome/components/dfplayer/dfplayer.h @@ -6,8 +6,7 @@ const size_t DFPLAYER_READ_BUFFER_LENGTH = 25; // two messages + some extra -namespace esphome { -namespace dfplayer { +namespace esphome::dfplayer { enum EqPreset { NORMAL = 0, @@ -171,5 +170,4 @@ template class DFPlayerIsPlayingCondition : public Conditionparent_->is_playing(); } }; -} // namespace dfplayer -} // namespace esphome +} // namespace esphome::dfplayer diff --git a/esphome/components/dfrobot_sen0395/automation.h b/esphome/components/dfrobot_sen0395/automation.h index 422555d6eba..bd91381d474 100644 --- a/esphome/components/dfrobot_sen0395/automation.h +++ b/esphome/components/dfrobot_sen0395/automation.h @@ -5,8 +5,7 @@ #include "dfrobot_sen0395.h" -namespace esphome { -namespace dfrobot_sen0395 { +namespace esphome::dfrobot_sen0395 { template class DfrobotSen0395ResetAction : public Action, public Parented { @@ -85,5 +84,4 @@ class DfrobotSen0395SettingsAction : public Action, public Parentedparent_->enqueue(make_unique(state)); } @@ -44,5 +43,4 @@ void Sen0395StartAfterBootSwitch::write_state(bool state) { } } -} // namespace dfrobot_sen0395 -} // namespace esphome +} // namespace esphome::dfrobot_sen0395 diff --git a/esphome/components/dfrobot_sen0395/switch/dfrobot_sen0395_switch.h b/esphome/components/dfrobot_sen0395/switch/dfrobot_sen0395_switch.h index ab32d81dd8f..d83734b0344 100644 --- a/esphome/components/dfrobot_sen0395/switch/dfrobot_sen0395_switch.h +++ b/esphome/components/dfrobot_sen0395/switch/dfrobot_sen0395_switch.h @@ -5,8 +5,7 @@ #include "../dfrobot_sen0395.h" -namespace esphome { -namespace dfrobot_sen0395 { +namespace esphome::dfrobot_sen0395 { class DfrobotSen0395Switch : public switch_::Switch, public Component, public Parented {}; @@ -30,5 +29,4 @@ class Sen0395StartAfterBootSwitch : public DfrobotSen0395Switch { void write_state(bool state) override; }; -} // namespace dfrobot_sen0395 -} // namespace esphome +} // namespace esphome::dfrobot_sen0395 diff --git a/esphome/components/dht12/dht12.cpp b/esphome/components/dht12/dht12.cpp index 1d884daad68..78f9140929b 100644 --- a/esphome/components/dht12/dht12.cpp +++ b/esphome/components/dht12/dht12.cpp @@ -5,8 +5,7 @@ #include "dht12.h" #include "esphome/core/log.h" -namespace esphome { -namespace dht12 { +namespace esphome::dht12 { static const char *const TAG = "dht12"; @@ -65,5 +64,4 @@ bool DHT12Component::read_data_(uint8_t *data) { return true; } -} // namespace dht12 -} // namespace esphome +} // namespace esphome::dht12 diff --git a/esphome/components/dht12/dht12.h b/esphome/components/dht12/dht12.h index ab19d7c7230..5f4f822e70f 100644 --- a/esphome/components/dht12/dht12.h +++ b/esphome/components/dht12/dht12.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace dht12 { +namespace esphome::dht12 { class DHT12Component : public PollingComponent, public i2c::I2CDevice { public: @@ -23,5 +22,4 @@ class DHT12Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace dht12 -} // namespace esphome +} // namespace esphome::dht12 diff --git a/esphome/components/display/display.cpp b/esphome/components/display/display.cpp index f8569b6e7c9..cd2d2143f58 100644 --- a/esphome/components/display/display.cpp +++ b/esphome/components/display/display.cpp @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace display { +namespace esphome::display { static const char *const TAG = "display"; // COLOR_OFF and COLOR_ON are now inline constexpr in display.h @@ -927,5 +926,4 @@ const LogString *text_align_to_string(TextAlign textalign) { return LOG_STR("UNKNOWN"); } } -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/display.h b/esphome/components/display/display.h index 6e38300d0e5..6d0b7acfe88 100644 --- a/esphome/components/display/display.h +++ b/esphome/components/display/display.h @@ -23,8 +23,7 @@ #include "esphome/components/graphical_display_menu/graphical_display_menu.h" #endif -namespace esphome { -namespace display { +namespace esphome::display { /** TextAlign is used to tell the display class how to position a piece of text. By default * the coordinates you enter for the print*() functions take the upper left corner of the text @@ -871,5 +870,4 @@ class DisplayOnPageChangeTrigger : public Trigger const LogString *text_align_to_string(TextAlign textalign); -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/display_buffer.cpp b/esphome/components/display/display_buffer.cpp index 0ecdccc38a3..4c919140494 100644 --- a/esphome/components/display/display_buffer.cpp +++ b/esphome/components/display/display_buffer.cpp @@ -5,8 +5,7 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" -namespace esphome { -namespace display { +namespace esphome::display { static const char *const TAG = "display"; @@ -68,5 +67,4 @@ void HOT DisplayBuffer::draw_pixel_at(int x, int y, Color color) { App.feed_wdt(); } -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/display_buffer.h b/esphome/components/display/display_buffer.h index b7c4db56bea..d3032a33f7e 100644 --- a/esphome/components/display/display_buffer.h +++ b/esphome/components/display/display_buffer.h @@ -9,8 +9,7 @@ #include "esphome/core/component.h" #include "esphome/core/defines.h" -namespace esphome { -namespace display { +namespace esphome::display { class DisplayBuffer : public Display { public: @@ -30,5 +29,4 @@ class DisplayBuffer : public Display { uint8_t *buffer_{nullptr}; }; -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/display_color_utils.h b/esphome/components/display/display_color_utils.h index 3114dee3592..608642caa44 100644 --- a/esphome/components/display/display_color_utils.h +++ b/esphome/components/display/display_color_utils.h @@ -1,8 +1,7 @@ #pragma once #include "esphome/core/color.h" -namespace esphome { -namespace display { +namespace esphome::display { enum ColorOrder : uint8_t { COLOR_ORDER_RGB = 0, COLOR_ORDER_BGR = 1, COLOR_ORDER_GRB = 2 }; enum ColorBitness : uint8_t { COLOR_BITNESS_888 = 0, COLOR_BITNESS_565 = 1, COLOR_BITNESS_332 = 2 }; inline static uint8_t esp_scale(uint8_t i, uint8_t scale, uint8_t max_value = 255) { return (max_value * i / scale); } @@ -155,5 +154,4 @@ class ColorUtil { return color; } }; -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/rect.cpp b/esphome/components/display/rect.cpp index 2c41127860c..a47f7269175 100644 --- a/esphome/components/display/rect.cpp +++ b/esphome/components/display/rect.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace display { +namespace esphome::display { static const char *const TAG = "display"; @@ -90,5 +89,4 @@ void Rect::info(const std::string &prefix) { } } -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display/rect.h b/esphome/components/display/rect.h index 5f11d94681c..f4958fab88c 100644 --- a/esphome/components/display/rect.h +++ b/esphome/components/display/rect.h @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" -namespace esphome { -namespace display { +namespace esphome::display { static const int16_t VALUE_NO_SET = 32766; @@ -32,5 +31,4 @@ class Rect { void info(const std::string &prefix = "rect info:"); }; -} // namespace display -} // namespace esphome +} // namespace esphome::display diff --git a/esphome/components/display_menu_base/automation.h b/esphome/components/display_menu_base/automation.h index 50c26c344cd..d4f83055d19 100644 --- a/esphome/components/display_menu_base/automation.h +++ b/esphome/components/display_menu_base/automation.h @@ -3,8 +3,7 @@ #include "esphome/core/automation.h" #include "display_menu_base.h" -namespace esphome { -namespace display_menu_base { +namespace esphome::display_menu_base { template class UpAction : public Action { public: @@ -144,5 +143,4 @@ class DisplayMenuOnPrevTrigger : public Trigger { MenuItemCustom *parent_; }; -} // namespace display_menu_base -} // namespace esphome +} // namespace esphome::display_menu_base diff --git a/esphome/components/display_menu_base/display_menu_base.cpp b/esphome/components/display_menu_base/display_menu_base.cpp index 2d8e6ae5fc2..634a82a8927 100644 --- a/esphome/components/display_menu_base/display_menu_base.cpp +++ b/esphome/components/display_menu_base/display_menu_base.cpp @@ -1,8 +1,7 @@ #include "display_menu_base.h" #include -namespace esphome { -namespace display_menu_base { +namespace esphome::display_menu_base { void DisplayMenuComponent::up() { if (this->check_healthy_and_active_()) { @@ -325,5 +324,4 @@ void DisplayMenuComponent::draw_menu() { } } -} // namespace display_menu_base -} // namespace esphome +} // namespace esphome::display_menu_base diff --git a/esphome/components/display_menu_base/display_menu_base.h b/esphome/components/display_menu_base/display_menu_base.h index 6208fcd3b46..07cdb7a10f5 100644 --- a/esphome/components/display_menu_base/display_menu_base.h +++ b/esphome/components/display_menu_base/display_menu_base.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace display_menu_base { +namespace esphome::display_menu_base { enum MenuMode { MENU_MODE_ROTARY, @@ -78,5 +77,4 @@ class DisplayMenuComponent : public Component { bool root_on_enter_called_{false}; }; -} // namespace display_menu_base -} // namespace esphome +} // namespace esphome::display_menu_base diff --git a/esphome/components/display_menu_base/menu_item.cpp b/esphome/components/display_menu_base/menu_item.cpp index ad8b03de606..8d1d315e322 100644 --- a/esphome/components/display_menu_base/menu_item.cpp +++ b/esphome/components/display_menu_base/menu_item.cpp @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace display_menu_base { +namespace esphome::display_menu_base { const LogString *menu_item_type_to_string(MenuItemType type) { switch (type) { @@ -201,5 +200,4 @@ void MenuItemCustom::on_next_() { this->on_next_callbacks_.call(); } void MenuItemCustom::on_prev_() { this->on_prev_callbacks_.call(); } -} // namespace display_menu_base -} // namespace esphome +} // namespace esphome::display_menu_base diff --git a/esphome/components/display_menu_base/menu_item.h b/esphome/components/display_menu_base/menu_item.h index 57d7350b9e7..f3c41583f73 100644 --- a/esphome/components/display_menu_base/menu_item.h +++ b/esphome/components/display_menu_base/menu_item.h @@ -16,8 +16,7 @@ #include #include "esphome/core/log.h" -namespace esphome { -namespace display_menu_base { +namespace esphome::display_menu_base { enum MenuItemType { MENU_ITEM_LABEL, @@ -187,5 +186,4 @@ class MenuItemCustom : public MenuItemEditable { CallbackManager on_prev_callbacks_{}; }; -} // namespace display_menu_base -} // namespace esphome +} // namespace esphome::display_menu_base diff --git a/esphome/components/dps310/dps310.cpp b/esphome/components/dps310/dps310.cpp index b1366cd0697..3b4693139d3 100644 --- a/esphome/components/dps310/dps310.cpp +++ b/esphome/components/dps310/dps310.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace dps310 { +namespace esphome::dps310 { static const char *const TAG = "dps310"; @@ -182,5 +181,4 @@ int32_t DPS310Component::twos_complement(int32_t val, uint8_t bits) { return val; } -} // namespace dps310 -} // namespace esphome +} // namespace esphome::dps310 diff --git a/esphome/components/dps310/dps310.h b/esphome/components/dps310/dps310.h index dce220d44b5..09143bf6b88 100644 --- a/esphome/components/dps310/dps310.h +++ b/esphome/components/dps310/dps310.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace dps310 { +namespace esphome::dps310 { static const uint8_t DPS310_REG_PRS_B2 = 0x00; // Highest byte of pressure data static const uint8_t DPS310_REG_TMP_B2 = 0x03; // Highest byte of temperature data @@ -60,5 +59,4 @@ class DPS310Component : public PollingComponent, public i2c::I2CDevice { bool got_pres_, got_temp_, update_in_progress_; }; -} // namespace dps310 -} // namespace esphome +} // namespace esphome::dps310 diff --git a/esphome/components/ds1307/ds1307.cpp b/esphome/components/ds1307/ds1307.cpp index ba2ad6032f4..1d04b52168e 100644 --- a/esphome/components/ds1307/ds1307.cpp +++ b/esphome/components/ds1307/ds1307.cpp @@ -4,8 +4,7 @@ // Datasheet: // - https://datasheets.maximintegrated.com/en/ds/DS1307.pdf -namespace esphome { -namespace ds1307 { +namespace esphome::ds1307 { static const char *const TAG = "ds1307"; @@ -99,5 +98,4 @@ bool DS1307Component::write_rtc_() { ds1307_.reg.day, ONOFF(ds1307_.reg.ch), ds1307_.reg.rs, ONOFF(ds1307_.reg.sqwe), ONOFF(ds1307_.reg.out)); return true; } -} // namespace ds1307 -} // namespace esphome +} // namespace esphome::ds1307 diff --git a/esphome/components/ds1307/ds1307.h b/esphome/components/ds1307/ds1307.h index 1712056006d..2004978cc66 100644 --- a/esphome/components/ds1307/ds1307.h +++ b/esphome/components/ds1307/ds1307.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/time/real_time_clock.h" -namespace esphome { -namespace ds1307 { +namespace esphome::ds1307 { class DS1307Component : public time::RealTimeClock, public i2c::I2CDevice { public: @@ -65,5 +64,4 @@ template class ReadAction : public Action, public Parente public: void play(const Ts &...x) override { this->parent_->read_time(); } }; -} // namespace ds1307 -} // namespace esphome +} // namespace esphome::ds1307 diff --git a/esphome/components/ds2484/ds2484.cpp b/esphome/components/ds2484/ds2484.cpp index 0b36f868749..69103ccbd22 100644 --- a/esphome/components/ds2484/ds2484.cpp +++ b/esphome/components/ds2484/ds2484.cpp @@ -1,7 +1,6 @@ #include "ds2484.h" -namespace esphome { -namespace ds2484 { +namespace esphome::ds2484 { static const char *const TAG = "ds2484.onewire"; void DS2484OneWireBus::setup() { @@ -204,5 +203,4 @@ uint64_t IRAM_ATTR DS2484OneWireBus::search_int() { return address; } -} // namespace ds2484 -} // namespace esphome +} // namespace esphome::ds2484 diff --git a/esphome/components/ds2484/ds2484.h b/esphome/components/ds2484/ds2484.h index 223227c0a26..9e6bb088584 100644 --- a/esphome/components/ds2484/ds2484.h +++ b/esphome/components/ds2484/ds2484.h @@ -6,8 +6,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/one_wire/one_wire.h" -namespace esphome { -namespace ds2484 { +namespace esphome::ds2484 { class DS2484OneWireBus : public one_wire::OneWireBus, public i2c::I2CDevice, public Component { public: @@ -39,5 +38,4 @@ class DS2484OneWireBus : public one_wire::OneWireBus, public i2c::I2CDevice, pub bool active_pullup_{false}; bool strong_pullup_{false}; }; -} // namespace ds2484 -} // namespace esphome +} // namespace esphome::ds2484 diff --git a/esphome/components/duty_cycle/duty_cycle_sensor.cpp b/esphome/components/duty_cycle/duty_cycle_sensor.cpp index f801769d272..fd0a48b9351 100644 --- a/esphome/components/duty_cycle/duty_cycle_sensor.cpp +++ b/esphome/components/duty_cycle/duty_cycle_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace duty_cycle { +namespace esphome::duty_cycle { static const char *const TAG = "duty_cycle"; @@ -56,5 +55,4 @@ void IRAM_ATTR DutyCycleSensorStore::gpio_intr(DutyCycleSensorStore *arg) { arg->last_interrupt = now; } -} // namespace duty_cycle -} // namespace esphome +} // namespace esphome::duty_cycle diff --git a/esphome/components/duty_cycle/duty_cycle_sensor.h b/esphome/components/duty_cycle/duty_cycle_sensor.h index ffb8e3b6221..58beee946a2 100644 --- a/esphome/components/duty_cycle/duty_cycle_sensor.h +++ b/esphome/components/duty_cycle/duty_cycle_sensor.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace duty_cycle { +namespace esphome::duty_cycle { /// Store data in a class that doesn't use multiple-inheritance (vtables in flash) struct DutyCycleSensorStore { @@ -32,5 +31,4 @@ class DutyCycleSensor : public sensor::Sensor, public PollingComponent { uint32_t last_update_{0}; }; -} // namespace duty_cycle -} // namespace esphome +} // namespace esphome::duty_cycle diff --git a/esphome/components/duty_time/duty_time_sensor.cpp b/esphome/components/duty_time/duty_time_sensor.cpp index 561040623d3..697a4e96f3c 100644 --- a/esphome/components/duty_time/duty_time_sensor.cpp +++ b/esphome/components/duty_time/duty_time_sensor.cpp @@ -1,8 +1,7 @@ #include "duty_time_sensor.h" #include "esphome/core/hal.h" -namespace esphome { -namespace duty_time_sensor { +namespace esphome::duty_time_sensor { static const char *const TAG = "duty_time_sensor"; @@ -103,5 +102,4 @@ void DutyTimeSensor::dump_config() { LOG_SENSOR(" ", "Last Duty Time Sensor:", this->last_duty_time_sensor_); } -} // namespace duty_time_sensor -} // namespace esphome +} // namespace esphome::duty_time_sensor diff --git a/esphome/components/duty_time/duty_time_sensor.h b/esphome/components/duty_time/duty_time_sensor.h index d21802ebb6c..9b1e10ea8c4 100644 --- a/esphome/components/duty_time/duty_time_sensor.h +++ b/esphome/components/duty_time/duty_time_sensor.h @@ -10,8 +10,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #endif -namespace esphome { -namespace duty_time_sensor { +namespace esphome::duty_time_sensor { class DutyTimeSensor : public sensor::Sensor, public PollingComponent { public: @@ -71,5 +70,4 @@ template class RunningCondition : public Condition, publi bool state_; }; -} // namespace duty_time_sensor -} // namespace esphome +} // namespace esphome::duty_time_sensor diff --git a/esphome/components/e131/e131.cpp b/esphome/components/e131/e131.cpp index a7a695c1679..061af4c4c0e 100644 --- a/esphome/components/e131/e131.cpp +++ b/esphome/components/e131/e131.cpp @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace e131 { +namespace esphome::e131 { static const char *const TAG = "e131"; static const int PORT = 5568; @@ -134,6 +133,6 @@ bool E131Component::process_(int universe, const E131Packet &packet) { return handled; } -} // namespace e131 -} // namespace esphome +} // namespace esphome::e131 + #endif diff --git a/esphome/components/e131/e131.h b/esphome/components/e131/e131.h index 8f0b808946c..bfcb0ca7f8e 100644 --- a/esphome/components/e131/e131.h +++ b/esphome/components/e131/e131.h @@ -12,8 +12,7 @@ #include #include -namespace esphome { -namespace e131 { +namespace esphome::e131 { class E131AddressableLightEffect; @@ -72,6 +71,6 @@ class E131Component : public esphome::Component { std::vector universe_consumers_; }; -} // namespace e131 -} // namespace esphome +} // namespace esphome::e131 + #endif diff --git a/esphome/components/e131/e131_addressable_light_effect.cpp b/esphome/components/e131/e131_addressable_light_effect.cpp index f6300874ac0..6157eba4e93 100644 --- a/esphome/components/e131/e131_addressable_light_effect.cpp +++ b/esphome/components/e131/e131_addressable_light_effect.cpp @@ -3,8 +3,7 @@ #ifdef USE_NETWORK #include "esphome/core/log.h" -namespace esphome { -namespace e131 { +namespace esphome::e131 { static const char *const TAG = "e131_addressable_light_effect"; static const int MAX_DATA_SIZE = (sizeof(E131Packet::values) - 1); @@ -91,6 +90,6 @@ bool E131AddressableLightEffect::process_(int universe, const E131Packet &packet return true; } -} // namespace e131 -} // namespace esphome +} // namespace esphome::e131 + #endif diff --git a/esphome/components/e131/e131_addressable_light_effect.h b/esphome/components/e131/e131_addressable_light_effect.h index 381e08163b1..b28dc22dbe2 100644 --- a/esphome/components/e131/e131_addressable_light_effect.h +++ b/esphome/components/e131/e131_addressable_light_effect.h @@ -3,8 +3,8 @@ #include "esphome/core/component.h" #include "esphome/components/light/addressable_light_effect.h" #ifdef USE_NETWORK -namespace esphome { -namespace e131 { + +namespace esphome::e131 { class E131Component; struct E131Packet; @@ -40,6 +40,6 @@ class E131AddressableLightEffect : public light::AddressableLightEffect { friend class E131Component; }; -} // namespace e131 -} // namespace esphome +} // namespace esphome::e131 + #endif diff --git a/esphome/components/e131/e131_packet.cpp b/esphome/components/e131/e131_packet.cpp index 600793f5d35..afed2abe311 100644 --- a/esphome/components/e131/e131_packet.cpp +++ b/esphome/components/e131/e131_packet.cpp @@ -12,8 +12,7 @@ #include #include -namespace esphome { -namespace e131 { +namespace esphome::e131 { static const char *const TAG = "e131"; @@ -158,6 +157,6 @@ bool E131Component::packet_(const uint8_t *data, size_t len, int &universe, E131 return true; } -} // namespace e131 -} // namespace esphome +} // namespace esphome::e131 + #endif diff --git a/esphome/components/ee895/ee895.cpp b/esphome/components/ee895/ee895.cpp index 93e5d4203b6..2dd7405ff5f 100644 --- a/esphome/components/ee895/ee895.cpp +++ b/esphome/components/ee895/ee895.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ee895 { +namespace esphome::ee895 { static const char *const TAG = "ee895"; @@ -111,5 +110,4 @@ uint16_t EE895Component::calc_crc16_(const uint8_t buf[], uint8_t len) { uint16_t crc = crc16(&addr, 1); return crc16(buf, len, crc); } -} // namespace ee895 -} // namespace esphome +} // namespace esphome::ee895 diff --git a/esphome/components/ee895/ee895.h b/esphome/components/ee895/ee895.h index ff1085e05d8..ba8e594feac 100644 --- a/esphome/components/ee895/ee895.h +++ b/esphome/components/ee895/ee895.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ee895 { +namespace esphome::ee895 { /// This class implements support for the ee895 of temperature i2c sensors. class EE895Component : public PollingComponent, public i2c::I2CDevice { @@ -29,5 +28,4 @@ class EE895Component : public PollingComponent, public i2c::I2CDevice { enum ErrorCode { NONE = 0, COMMUNICATION_FAILED, CRC_CHECK_FAILED } error_code_{NONE}; }; -} // namespace ee895 -} // namespace esphome +} // namespace esphome::ee895 diff --git a/esphome/components/ektf2232/touchscreen/ektf2232.cpp b/esphome/components/ektf2232/touchscreen/ektf2232.cpp index 63ebb2166b2..51532548c1f 100644 --- a/esphome/components/ektf2232/touchscreen/ektf2232.cpp +++ b/esphome/components/ektf2232/touchscreen/ektf2232.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace ektf2232 { +namespace esphome::ektf2232 { static const char *const TAG = "ektf2232"; @@ -130,5 +129,4 @@ void EKTF2232Touchscreen::dump_config() { LOG_PIN(" Reset Pin: ", this->reset_pin_); } -} // namespace ektf2232 -} // namespace esphome +} // namespace esphome::ektf2232 diff --git a/esphome/components/ektf2232/touchscreen/ektf2232.h b/esphome/components/ektf2232/touchscreen/ektf2232.h index 2ddc60851f2..45da74a2a5d 100644 --- a/esphome/components/ektf2232/touchscreen/ektf2232.h +++ b/esphome/components/ektf2232/touchscreen/ektf2232.h @@ -6,8 +6,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ektf2232 { +namespace esphome::ektf2232 { using namespace touchscreen; @@ -31,5 +30,4 @@ class EKTF2232Touchscreen : public Touchscreen, public i2c::I2CDevice { GPIOPin *reset_pin_; }; -} // namespace ektf2232 -} // namespace esphome +} // namespace esphome::ektf2232 diff --git a/esphome/components/emc2101/emc2101.cpp b/esphome/components/emc2101/emc2101.cpp index 068e25568f1..464f49fe519 100644 --- a/esphome/components/emc2101/emc2101.cpp +++ b/esphome/components/emc2101/emc2101.cpp @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include "emc2101.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { static const char *const TAG = "EMC2101"; @@ -165,5 +164,4 @@ float Emc2101Component::get_speed() { return tach == 0xFFFF ? 0.0f : 5400000.0f / tach; } -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emc2101/emc2101.h b/esphome/components/emc2101/emc2101.h index 0f4bc560ddd..1fe03a26307 100644 --- a/esphome/components/emc2101/emc2101.h +++ b/esphome/components/emc2101/emc2101.h @@ -3,8 +3,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { /** Enum listing all DAC conversion rates for the EMC2101. * @@ -111,5 +110,4 @@ class Emc2101Component : public Component, public i2c::I2CDevice { Emc2101DACConversionRate dac_conversion_rate_; }; -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emc2101/output/emc2101_output.cpp b/esphome/components/emc2101/output/emc2101_output.cpp index 2ed506cd99c..6b046296f3a 100644 --- a/esphome/components/emc2101/output/emc2101_output.cpp +++ b/esphome/components/emc2101/output/emc2101_output.cpp @@ -1,9 +1,7 @@ #include "emc2101_output.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { void EMC2101Output::write_state(float state) { this->parent_->set_duty_cycle(state); } -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emc2101/output/emc2101_output.h b/esphome/components/emc2101/output/emc2101_output.h index 232df6ff5f2..95077f55242 100644 --- a/esphome/components/emc2101/output/emc2101_output.h +++ b/esphome/components/emc2101/output/emc2101_output.h @@ -3,8 +3,7 @@ #include "../emc2101.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { /// This class allows to control the EMC2101 output. class EMC2101Output : public output::FloatOutput { @@ -18,5 +17,4 @@ class EMC2101Output : public output::FloatOutput { Emc2101Component *parent_; }; -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emc2101/sensor/emc2101_sensor.cpp b/esphome/components/emc2101/sensor/emc2101_sensor.cpp index 3014c7da07c..bb5eea21f3b 100644 --- a/esphome/components/emc2101/sensor/emc2101_sensor.cpp +++ b/esphome/components/emc2101/sensor/emc2101_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { static const char *const TAG = "EMC2101.sensor"; @@ -37,5 +36,4 @@ void EMC2101Sensor::update() { } } -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emc2101/sensor/emc2101_sensor.h b/esphome/components/emc2101/sensor/emc2101_sensor.h index 3e033f58a73..2336ac2f15c 100644 --- a/esphome/components/emc2101/sensor/emc2101_sensor.h +++ b/esphome/components/emc2101/sensor/emc2101_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace emc2101 { +namespace esphome::emc2101 { /// This class exposes the EMC2101 sensors. class EMC2101Sensor : public PollingComponent { @@ -33,5 +32,4 @@ class EMC2101Sensor : public PollingComponent { sensor::Sensor *duty_cycle_sensor_{nullptr}; }; -} // namespace emc2101 -} // namespace esphome +} // namespace esphome::emc2101 diff --git a/esphome/components/emmeti/emmeti.cpp b/esphome/components/emmeti/emmeti.cpp index 04976d95d70..82991aeac75 100644 --- a/esphome/components/emmeti/emmeti.cpp +++ b/esphome/components/emmeti/emmeti.cpp @@ -1,8 +1,7 @@ #include "emmeti.h" #include "esphome/components/remote_base/remote_base.h" -namespace esphome { -namespace emmeti { +namespace esphome::emmeti { static const char *const TAG = "emmeti.climate"; @@ -308,5 +307,4 @@ bool EmmetiClimate::on_receive(remote_base::RemoteReceiveData data) { return this->parse_state_frame_(curr_state); } -} // namespace emmeti -} // namespace esphome +} // namespace esphome::emmeti diff --git a/esphome/components/emmeti/emmeti.h b/esphome/components/emmeti/emmeti.h index 9bfb7a7a984..9dc78ce07c2 100644 --- a/esphome/components/emmeti/emmeti.h +++ b/esphome/components/emmeti/emmeti.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace emmeti { +namespace esphome::emmeti { const uint8_t EMMETI_TEMP_MIN = 16; // Celsius const uint8_t EMMETI_TEMP_MAX = 30; // Celsius @@ -105,5 +104,4 @@ class EmmetiClimate : public climate_ir::ClimateIR { uint8_t blades_ = EMMETI_BLADES_STOP; }; -} // namespace emmeti -} // namespace esphome +} // namespace esphome::emmeti diff --git a/esphome/components/endstop/endstop_cover.cpp b/esphome/components/endstop/endstop_cover.cpp index 5e0b9c72d3c..b3c210a8d8a 100644 --- a/esphome/components/endstop/endstop_cover.cpp +++ b/esphome/components/endstop/endstop_cover.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/application.h" -namespace esphome { -namespace endstop { +namespace esphome::endstop { static const char *const TAG = "endstop.cover"; @@ -192,5 +191,4 @@ void EndstopCover::recompute_position_() { this->last_recompute_time_ = now; } -} // namespace endstop -} // namespace esphome +} // namespace esphome::endstop diff --git a/esphome/components/endstop/endstop_cover.h b/esphome/components/endstop/endstop_cover.h index 32ede123356..b910139bcd6 100644 --- a/esphome/components/endstop/endstop_cover.h +++ b/esphome/components/endstop/endstop_cover.h @@ -5,8 +5,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace endstop { +namespace esphome::endstop { class EndstopCover : public cover::Cover, public Component { public: @@ -53,5 +52,4 @@ class EndstopCover : public cover::Cover, public Component { cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING}; }; -} // namespace endstop -} // namespace esphome +} // namespace esphome::endstop diff --git a/esphome/components/ens160_base/ens160_base.cpp b/esphome/components/ens160_base/ens160_base.cpp index 42baa68b35d..20c67c34505 100644 --- a/esphome/components/ens160_base/ens160_base.cpp +++ b/esphome/components/ens160_base/ens160_base.cpp @@ -18,8 +18,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ens160_base { +namespace esphome::ens160_base { static const char *const TAG = "ens160"; @@ -332,5 +331,4 @@ void ENS160Component::dump_config() { } } -} // namespace ens160_base -} // namespace esphome +} // namespace esphome::ens160_base diff --git a/esphome/components/ens160_base/ens160_base.h b/esphome/components/ens160_base/ens160_base.h index ae850c81807..f42272684ed 100644 --- a/esphome/components/ens160_base/ens160_base.h +++ b/esphome/components/ens160_base/ens160_base.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace ens160_base { +namespace esphome::ens160_base { class ENS160Component : public PollingComponent, public sensor::Sensor { public: @@ -59,5 +58,4 @@ class ENS160Component : public PollingComponent, public sensor::Sensor { sensor::Sensor *temperature_{nullptr}; }; -} // namespace ens160_base -} // namespace esphome +} // namespace esphome::ens160_base diff --git a/esphome/components/ens160_i2c/ens160_i2c.cpp b/esphome/components/ens160_i2c/ens160_i2c.cpp index 7163a5ad6e1..1f02ddb7182 100644 --- a/esphome/components/ens160_i2c/ens160_i2c.cpp +++ b/esphome/components/ens160_i2c/ens160_i2c.cpp @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "../ens160_base/ens160_base.h" -namespace esphome { -namespace ens160_i2c { +namespace esphome::ens160_i2c { static const char *const TAG = "ens160_i2c.sensor"; @@ -28,5 +27,4 @@ void ENS160I2CComponent::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace ens160_i2c -} // namespace esphome +} // namespace esphome::ens160_i2c diff --git a/esphome/components/ens160_i2c/ens160_i2c.h b/esphome/components/ens160_i2c/ens160_i2c.h index 2df32f27bf1..98318a7eca7 100644 --- a/esphome/components/ens160_i2c/ens160_i2c.h +++ b/esphome/components/ens160_i2c/ens160_i2c.h @@ -3,8 +3,7 @@ #include "esphome/components/ens160_base/ens160_base.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ens160_i2c { +namespace esphome::ens160_i2c { class ENS160I2CComponent : public esphome::ens160_base::ENS160Component, public i2c::I2CDevice { void dump_config() override; @@ -15,5 +14,4 @@ class ENS160I2CComponent : public esphome::ens160_base::ENS160Component, public bool write_bytes(uint8_t a_register, uint8_t *data, size_t len) override; }; -} // namespace ens160_i2c -} // namespace esphome +} // namespace esphome::ens160_i2c diff --git a/esphome/components/ens160_spi/ens160_spi.cpp b/esphome/components/ens160_spi/ens160_spi.cpp index fba2fdf0e43..41ab8298dbb 100644 --- a/esphome/components/ens160_spi/ens160_spi.cpp +++ b/esphome/components/ens160_spi/ens160_spi.cpp @@ -4,8 +4,7 @@ #include "ens160_spi.h" #include -namespace esphome { -namespace ens160_spi { +namespace esphome::ens160_spi { static const char *const TAG = "ens160_spi.sensor"; @@ -55,5 +54,4 @@ bool ENS160SPIComponent::write_bytes(uint8_t a_register, uint8_t *data, size_t l return true; } -} // namespace ens160_spi -} // namespace esphome +} // namespace esphome::ens160_spi diff --git a/esphome/components/ens160_spi/ens160_spi.h b/esphome/components/ens160_spi/ens160_spi.h index 3371f37ffd8..d4d3cf3ae99 100644 --- a/esphome/components/ens160_spi/ens160_spi.h +++ b/esphome/components/ens160_spi/ens160_spi.h @@ -3,8 +3,7 @@ #include "esphome/components/ens160_base/ens160_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ens160_spi { +namespace esphome::ens160_spi { class ENS160SPIComponent : public esphome::ens160_base::ENS160Component, public spi::SPIDevice -namespace esphome { -namespace es7210 { +namespace esphome::es7210 { static const char *const TAG = "es7210"; @@ -224,5 +223,4 @@ bool ES7210::es7210_update_reg_bit_(uint8_t reg_addr, uint8_t update_bits, uint8 return this->write_byte(reg_addr, regv); } -} // namespace es7210 -} // namespace esphome +} // namespace esphome::es7210 diff --git a/esphome/components/es7210/es7210.h b/esphome/components/es7210/es7210.h index 7071a547ec8..914fbd633b8 100644 --- a/esphome/components/es7210/es7210.h +++ b/esphome/components/es7210/es7210.h @@ -6,8 +6,7 @@ #include "es7210_const.h" -namespace esphome { -namespace es7210 { +namespace esphome::es7210 { enum ES7210BitsPerSample : uint8_t { ES7210_BITS_PER_SAMPLE_16 = 16, @@ -57,5 +56,4 @@ class ES7210 : public audio_adc::AudioAdc, public Component, public i2c::I2CDevi uint32_t sample_rate_{0}; }; -} // namespace es7210 -} // namespace esphome +} // namespace esphome::es7210 diff --git a/esphome/components/es7210/es7210_const.h b/esphome/components/es7210/es7210_const.h index e5ffea57431..70705b24748 100644 --- a/esphome/components/es7210/es7210_const.h +++ b/esphome/components/es7210/es7210_const.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace es7210 { +namespace esphome::es7210 { // ES7210 register addresses static const uint8_t ES7210_RESET_REG00 = 0x00; /* Reset control */ @@ -125,5 +124,4 @@ static const ES7210Coefficient ES7210_COEFFICIENTS[] = { static const float ES7210_MIC_GAIN_MIN = 0.0; static const float ES7210_MIC_GAIN_MAX = 37.5; -} // namespace es7210 -} // namespace esphome +} // namespace esphome::es7210 diff --git a/esphome/components/es7243e/es7243e.cpp b/esphome/components/es7243e/es7243e.cpp index d45c1d5a8c7..b4d9fba4c52 100644 --- a/esphome/components/es7243e/es7243e.cpp +++ b/esphome/components/es7243e/es7243e.cpp @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace es7243e { +namespace esphome::es7243e { static const char *const TAG = "es7243e"; @@ -119,5 +118,4 @@ uint8_t ES7243E::es7243e_gain_reg_value_(float mic_gain) { return 14; } -} // namespace es7243e -} // namespace esphome +} // namespace esphome::es7243e diff --git a/esphome/components/es7243e/es7243e.h b/esphome/components/es7243e/es7243e.h index f7c9d67371b..6386ea529a7 100644 --- a/esphome/components/es7243e/es7243e.h +++ b/esphome/components/es7243e/es7243e.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace es7243e { +namespace esphome::es7243e { class ES7243E : public audio_adc::AudioAdc, public Component, public i2c::I2CDevice { /* Class for configuring an ES7243E ADC for microphone input. @@ -32,5 +31,4 @@ class ES7243E : public audio_adc::AudioAdc, public Component, public i2c::I2CDev float mic_gain_{0}; }; -} // namespace es7243e -} // namespace esphome +} // namespace esphome::es7243e diff --git a/esphome/components/es7243e/es7243e_const.h b/esphome/components/es7243e/es7243e_const.h index daae53a1083..9f926db3b17 100644 --- a/esphome/components/es7243e/es7243e_const.h +++ b/esphome/components/es7243e/es7243e_const.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace es7243e { +namespace esphome::es7243e { // ES7243E register addresses static const uint8_t ES7243E_RESET_REG00 = 0x00; // Reset control @@ -50,5 +49,4 @@ static const uint8_t ES7243E_CHIP_ID1_REGFD = 0xFD; // chip ID 1, reads 0x7 static const uint8_t ES7243E_CHIP_ID2_REGFE = 0xFE; // chip ID 2, reads 0x43 (RO) static const uint8_t ES7243E_CHIP_VERSION_REGFF = 0xFF; // chip version, reads 0x00 (RO) -} // namespace es7243e -} // namespace esphome +} // namespace esphome::es7243e diff --git a/esphome/components/es8156/es8156.cpp b/esphome/components/es8156/es8156.cpp index 961dc24b295..03d9713df95 100644 --- a/esphome/components/es8156/es8156.cpp +++ b/esphome/components/es8156/es8156.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace es8156 { +namespace esphome::es8156 { static const char *const TAG = "es8156"; @@ -118,5 +117,4 @@ bool ES8156::set_mute_state_(bool mute_state) { return this->write_byte(ES8156_REG13_DAC_MUTE, reg13); } -} // namespace es8156 -} // namespace esphome +} // namespace esphome::es8156 diff --git a/esphome/components/es8156/es8156.h b/esphome/components/es8156/es8156.h index 082514485c2..c3cec3dc14d 100644 --- a/esphome/components/es8156/es8156.h +++ b/esphome/components/es8156/es8156.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace es8156 { +namespace esphome::es8156 { class ES8156 : public audio_dac::AudioDac, public Component, public i2c::I2CDevice { public: @@ -46,5 +45,4 @@ class ES8156 : public audio_dac::AudioDac, public Component, public i2c::I2CDevi bool set_mute_state_(bool mute_state); }; -} // namespace es8156 -} // namespace esphome +} // namespace esphome::es8156 diff --git a/esphome/components/es8156/es8156_const.h b/esphome/components/es8156/es8156_const.h index 0bc8f89dd44..0836e4766dd 100644 --- a/esphome/components/es8156/es8156_const.h +++ b/esphome/components/es8156/es8156_const.h @@ -2,8 +2,7 @@ #include "es8156.h" -namespace esphome { -namespace es8156 { +namespace esphome::es8156 { /* ES8156 register addresses */ /* @@ -64,5 +63,4 @@ static const uint8_t ES8156_REGFD_CHIPID1 = 0xFD; static const uint8_t ES8156_REGFE_CHIPID0 = 0xFE; static const uint8_t ES8156_REGFF_CHIP_VERSION = 0xFF; -} // namespace es8156 -} // namespace esphome +} // namespace esphome::es8156 diff --git a/esphome/components/es8311/es8311.cpp b/esphome/components/es8311/es8311.cpp index cf864187f99..0386d84200f 100644 --- a/esphome/components/es8311/es8311.cpp +++ b/esphome/components/es8311/es8311.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace es8311 { +namespace esphome::es8311 { static const char *const TAG = "es8311"; @@ -223,5 +222,4 @@ bool ES8311::set_mute_state_(bool mute_state) { return this->write_byte(ES8311_REG31_DAC, reg31); } -} // namespace es8311 -} // namespace esphome +} // namespace esphome::es8311 diff --git a/esphome/components/es8311/es8311.h b/esphome/components/es8311/es8311.h index 5eccc480047..1190bcb0aa0 100644 --- a/esphome/components/es8311/es8311.h +++ b/esphome/components/es8311/es8311.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace es8311 { +namespace esphome::es8311 { enum ES8311MicGain { ES8311_MIC_GAIN_MIN = -1, @@ -130,5 +129,4 @@ class ES8311 : public audio_dac::AudioDac, public Component, public i2c::I2CDevi ES8311Resolution resolution_out_; }; -} // namespace es8311 -} // namespace esphome +} // namespace esphome::es8311 diff --git a/esphome/components/es8311/es8311_const.h b/esphome/components/es8311/es8311_const.h index 7463a92ef1c..27b9e02c138 100644 --- a/esphome/components/es8311/es8311_const.h +++ b/esphome/components/es8311/es8311_const.h @@ -2,8 +2,7 @@ #include "es8311.h" -namespace esphome { -namespace es8311 { +namespace esphome::es8311 { // ES8311 register addresses static const uint8_t ES8311_REG00_RESET = 0x00; // Reset @@ -191,5 +190,4 @@ static const ES8311Coefficient ES8311_COEFFICIENTS[] = { // clang-format on }; -} // namespace es8311 -} // namespace esphome +} // namespace esphome::es8311 diff --git a/esphome/components/es8388/es8388.cpp b/esphome/components/es8388/es8388.cpp index c252cdb707d..c015393e146 100644 --- a/esphome/components/es8388/es8388.cpp +++ b/esphome/components/es8388/es8388.cpp @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { static const char *const TAG = "es8388"; @@ -284,5 +283,4 @@ optional ES8388::get_mic_input() { }; } -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/es8388.h b/esphome/components/es8388/es8388.h index 373f71b437f..1f744e25b37 100644 --- a/esphome/components/es8388/es8388.h +++ b/esphome/components/es8388/es8388.h @@ -11,8 +11,7 @@ #include "es8388_const.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { enum DacOutputLine : uint8_t { DAC_OUTPUT_LINE1, @@ -76,5 +75,4 @@ class ES8388 : public audio_dac::AudioDac, public Component, public i2c::I2CDevi bool set_mute_state_(bool mute_state); }; -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/es8388_const.h b/esphome/components/es8388/es8388_const.h index 2a51f078bc4..451c9cc0266 100644 --- a/esphome/components/es8388/es8388_const.h +++ b/esphome/components/es8388/es8388_const.h @@ -1,8 +1,7 @@ #pragma once #include -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { /* ES8388 register */ static const uint8_t ES8388_CONTROL1 = 0x00; @@ -79,5 +78,4 @@ static const uint8_t ES8388_ADC_INPUT_MIC2 = 0x06; static const uint8_t ES8388_ADC_INPUT_LINPUT2_RINPUT2 = 0x50; static const uint8_t ES8388_ADC_INPUT_DIFFERENCE = 0xf0; -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/adc_input_mic_select.cpp b/esphome/components/es8388/select/adc_input_mic_select.cpp index 2e475342961..a91ccf4d5b4 100644 --- a/esphome/components/es8388/select/adc_input_mic_select.cpp +++ b/esphome/components/es8388/select/adc_input_mic_select.cpp @@ -1,12 +1,10 @@ #include "adc_input_mic_select.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { void ADCInputMicSelect::control(size_t index) { this->publish_state(index); this->parent_->set_adc_input_mic(static_cast(index)); } -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/adc_input_mic_select.h b/esphome/components/es8388/select/adc_input_mic_select.h index f0fa840d006..29978f1623b 100644 --- a/esphome/components/es8388/select/adc_input_mic_select.h +++ b/esphome/components/es8388/select/adc_input_mic_select.h @@ -3,13 +3,11 @@ #include "esphome/components/es8388/es8388.h" #include "esphome/components/select/select.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { class ADCInputMicSelect : public select::Select, public Parented { protected: void control(size_t index) override; }; -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/dac_output_select.cpp b/esphome/components/es8388/select/dac_output_select.cpp index 9af288a721d..cfe0fe1472f 100644 --- a/esphome/components/es8388/select/dac_output_select.cpp +++ b/esphome/components/es8388/select/dac_output_select.cpp @@ -1,12 +1,10 @@ #include "dac_output_select.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { void DacOutputSelect::control(size_t index) { this->publish_state(index); this->parent_->set_dac_output(static_cast(index)); } -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/es8388/select/dac_output_select.h b/esphome/components/es8388/select/dac_output_select.h index 40d8a665535..030f12406e1 100644 --- a/esphome/components/es8388/select/dac_output_select.h +++ b/esphome/components/es8388/select/dac_output_select.h @@ -3,13 +3,11 @@ #include "esphome/components/es8388/es8388.h" #include "esphome/components/select/select.h" -namespace esphome { -namespace es8388 { +namespace esphome::es8388 { class DacOutputSelect : public select::Select, public Parented { protected: void control(size_t index) override; }; -} // namespace es8388 -} // namespace esphome +} // namespace esphome::es8388 diff --git a/esphome/components/esp32/gpio.h b/esphome/components/esp32/gpio.h index 3c13bd9b4ff..a140eeef775 100644 --- a/esphome/components/esp32/gpio.h +++ b/esphome/components/esp32/gpio.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace esp32 { +namespace esphome::esp32 { // Static assertions to ensure our bit-packed fields can hold the enum values static_assert(GPIO_NUM_MAX <= 256, "gpio_num_t has too many values for uint8_t"); @@ -51,7 +50,6 @@ class ESP32InternalGPIOPin : public InternalGPIOPin { static bool isr_service_installed; }; -} // namespace esp32 -} // namespace esphome +} // namespace esphome::esp32 #endif // USE_ESP32 diff --git a/esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp b/esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp index 093273b399b..9f1723430b4 100644 --- a/esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp +++ b/esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp @@ -16,8 +16,7 @@ #include "esphome/core/hal.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace esp32_ble_beacon { +namespace esphome::esp32_ble_beacon { static const char *const TAG = "esp32_ble_beacon"; @@ -129,7 +128,6 @@ void ESP32BLEBeacon::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap } } -} // namespace esp32_ble_beacon -} // namespace esphome +} // namespace esphome::esp32_ble_beacon #endif diff --git a/esphome/components/esp32_ble_beacon/esp32_ble_beacon.h b/esphome/components/esp32_ble_beacon/esp32_ble_beacon.h index 44a71334543..8b3899a681d 100644 --- a/esphome/components/esp32_ble_beacon/esp32_ble_beacon.h +++ b/esphome/components/esp32_ble_beacon/esp32_ble_beacon.h @@ -10,8 +10,7 @@ #endif #include -namespace esphome { -namespace esp32_ble_beacon { +namespace esphome::esp32_ble_beacon { using esp_ble_ibeacon_head_t = struct { uint8_t flags[3]; @@ -69,7 +68,6 @@ class ESP32BLEBeacon : public Component { bool advertising_{false}; }; -} // namespace esp32_ble_beacon -} // namespace esphome +} // namespace esphome::esp32_ble_beacon #endif diff --git a/esphome/components/esp32_ble_server/ble_2902.cpp b/esphome/components/esp32_ble_server/ble_2902.cpp index 2f34573c372..90d0871a967 100644 --- a/esphome/components/esp32_ble_server/ble_2902.cpp +++ b/esphome/components/esp32_ble_server/ble_2902.cpp @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { BLE2902::BLE2902() : BLEDescriptor(esp32_ble::ESPBTUUID::from_uint16(0x2902)) { this->value_.attr_len = 2; @@ -14,7 +13,6 @@ BLE2902::BLE2902() : BLEDescriptor(esp32_ble::ESPBTUUID::from_uint16(0x2902)) { memcpy(this->value_.attr_value, data, 2); } -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_2902.h b/esphome/components/esp32_ble_server/ble_2902.h index 64605924ade..46a5f73e9ed 100644 --- a/esphome/components/esp32_ble_server/ble_2902.h +++ b/esphome/components/esp32_ble_server/ble_2902.h @@ -4,15 +4,13 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { class BLE2902 : public BLEDescriptor { public: BLE2902(); }; -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_characteristic.cpp b/esphome/components/esp32_ble_server/ble_characteristic.cpp index aa82b773ba6..cc519846be4 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.cpp +++ b/esphome/components/esp32_ble_server/ble_characteristic.cpp @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { static const char *const TAG = "esp32_ble_server.characteristic"; @@ -340,7 +339,6 @@ BLECharacteristic::ClientNotificationEntry *BLECharacteristic::find_client_in_no return nullptr; } -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_characteristic.h b/esphome/components/esp32_ble_server/ble_characteristic.h index 062052cdf8c..94c7495cbd3 100644 --- a/esphome/components/esp32_ble_server/ble_characteristic.h +++ b/esphome/components/esp32_ble_server/ble_characteristic.h @@ -17,8 +17,7 @@ #include #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { using namespace esp32_ble; using namespace bytebuffer; @@ -109,7 +108,6 @@ class BLECharacteristic { } state_{INIT}; }; -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_descriptor.cpp b/esphome/components/esp32_ble_server/ble_descriptor.cpp index 4ffca7312b6..5ca80d6a7a3 100644 --- a/esphome/components/esp32_ble_server/ble_descriptor.cpp +++ b/esphome/components/esp32_ble_server/ble_descriptor.cpp @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { static const char *const TAG = "esp32_ble_server.descriptor"; @@ -91,7 +90,6 @@ void BLEDescriptor::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ } } -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_descriptor.h b/esphome/components/esp32_ble_server/ble_descriptor.h index 5f4f146d6f4..5096d39f284 100644 --- a/esphome/components/esp32_ble_server/ble_descriptor.h +++ b/esphome/components/esp32_ble_server/ble_descriptor.h @@ -11,8 +11,7 @@ #include #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { using namespace esp32_ble; using namespace bytebuffer; @@ -63,7 +62,6 @@ class BLEDescriptor { } state_{INIT}; }; -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_server.cpp b/esphome/components/esp32_ble_server/ble_server.cpp index be0691dc065..2dea1666bbe 100644 --- a/esphome/components/esp32_ble_server/ble_server.cpp +++ b/esphome/components/esp32_ble_server/ble_server.cpp @@ -16,8 +16,7 @@ #include #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { static const char *const TAG = "esp32_ble_server"; @@ -248,7 +247,6 @@ void BLEServer::dump_config() { BLEServer *global_ble_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_server.h b/esphome/components/esp32_ble_server/ble_server.h index 9708ed40c8b..9ba108499e0 100644 --- a/esphome/components/esp32_ble_server/ble_server.h +++ b/esphome/components/esp32_ble_server/ble_server.h @@ -18,8 +18,7 @@ #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { using namespace esp32_ble; using namespace bytebuffer; @@ -113,7 +112,6 @@ class BLEServer : public Component, public Parented { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern BLEServer *global_ble_server; -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_ble_server/ble_server_automations.cpp b/esphome/components/esp32_ble_server/ble_server_automations.cpp index 0761de994a2..1b15c90fe8c 100644 --- a/esphome/components/esp32_ble_server/ble_server_automations.cpp +++ b/esphome/components/esp32_ble_server/ble_server_automations.cpp @@ -2,10 +2,8 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_ble_server { // Interface to interact with ESPHome automations and triggers -namespace esp32_ble_server_automations { +namespace esphome::esp32_ble_server::esp32_ble_server_automations { using namespace esp32_ble; @@ -86,8 +84,6 @@ void BLECharacteristicSetValueActionManager::remove_listener_(BLECharacteristic } #endif -} // namespace esp32_ble_server_automations -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server::esp32_ble_server_automations #endif diff --git a/esphome/components/esp32_ble_server/ble_server_automations.h b/esphome/components/esp32_ble_server/ble_server_automations.h index 0bbfdffd5bd..b4e9ed004ec 100644 --- a/esphome/components/esp32_ble_server/ble_server_automations.h +++ b/esphome/components/esp32_ble_server/ble_server_automations.h @@ -11,10 +11,8 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_ble_server { // Interface to interact with ESPHome actions and triggers -namespace esp32_ble_server_automations { +namespace esphome::esp32_ble_server::esp32_ble_server_automations { using namespace esp32_ble; @@ -125,8 +123,6 @@ template class BLEDescriptorSetValueAction : public Action #include -namespace esphome { -namespace esp32_ble_server { +namespace esphome::esp32_ble_server { class BLEServer; @@ -80,7 +79,6 @@ class BLEService { } state_{INIT}; }; -} // namespace esp32_ble_server -} // namespace esphome +} // namespace esphome::esp32_ble_server #endif diff --git a/esphome/components/esp32_camera/esp32_camera.cpp b/esphome/components/esp32_camera/esp32_camera.cpp index a7546476d89..598fe61d464 100644 --- a/esphome/components/esp32_camera/esp32_camera.cpp +++ b/esphome/components/esp32_camera/esp32_camera.cpp @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace esp32_camera { +namespace esphome::esp32_camera { static const char *const TAG = "esp32_camera"; static constexpr size_t FRAMEBUFFER_TASK_STACK_SIZE = 1792; @@ -556,7 +555,6 @@ bool ESP32CameraImage::was_requested_by(camera::CameraRequester requester) const return (this->requesters_ & (1 << requester)) != 0; } -} // namespace esp32_camera -} // namespace esphome +} // namespace esphome::esp32_camera #endif diff --git a/esphome/components/esp32_camera/esp32_camera.h b/esphome/components/esp32_camera/esp32_camera.h index 9fbd3848f28..7d020b5caf7 100644 --- a/esphome/components/esp32_camera/esp32_camera.h +++ b/esphome/components/esp32_camera/esp32_camera.h @@ -15,8 +15,7 @@ #include "esphome/components/i2c/i2c_bus.h" #endif // USE_I2C -namespace esphome { -namespace esp32_camera { +namespace esphome::esp32_camera { class ESP32Camera; @@ -259,7 +258,6 @@ class ESP32CameraStreamStopTrigger : public Trigger<>, public camera::CameraList void on_stream_stop() override { this->trigger(); } }; -} // namespace esp32_camera -} // namespace esphome +} // namespace esphome::esp32_camera #endif diff --git a/esphome/components/esp32_camera_web_server/camera_web_server.cpp b/esphome/components/esp32_camera_web_server/camera_web_server.cpp index f49578c425d..7527bbf7e4e 100644 --- a/esphome/components/esp32_camera_web_server/camera_web_server.cpp +++ b/esphome/components/esp32_camera_web_server/camera_web_server.cpp @@ -11,8 +11,7 @@ #include #include -namespace esphome { -namespace esp32_camera_web_server { +namespace esphome::esp32_camera_web_server { static const int IMAGE_REQUEST_TIMEOUT = 5000; static const char *const TAG = "esp32_camera_web_server"; @@ -242,7 +241,6 @@ esp_err_t CameraWebServer::snapshot_handler_(struct httpd_req *req) { return res; } -} // namespace esp32_camera_web_server -} // namespace esphome +} // namespace esphome::esp32_camera_web_server #endif // USE_ESP32 diff --git a/esphome/components/esp32_camera_web_server/camera_web_server.h b/esphome/components/esp32_camera_web_server/camera_web_server.h index ad7b29fb11c..568dc68c460 100644 --- a/esphome/components/esp32_camera_web_server/camera_web_server.h +++ b/esphome/components/esp32_camera_web_server/camera_web_server.h @@ -13,8 +13,7 @@ struct httpd_req; // NOLINT(readability-identifier-naming) -namespace esphome { -namespace esp32_camera_web_server { +namespace esphome::esp32_camera_web_server { enum Mode { STREAM, SNAPSHOT }; @@ -48,7 +47,6 @@ class CameraWebServer : public Component, public camera::CameraListener { Mode mode_{STREAM}; }; -} // namespace esp32_camera_web_server -} // namespace esphome +} // namespace esphome::esp32_camera_web_server #endif // USE_ESP32 diff --git a/esphome/components/esp32_can/esp32_can.cpp b/esphome/components/esp32_can/esp32_can.cpp index f521b63430f..e04405c63c0 100644 --- a/esphome/components/esp32_can/esp32_can.cpp +++ b/esphome/components/esp32_can/esp32_can.cpp @@ -9,8 +9,7 @@ #undef CAN_IO_UNUSED #define CAN_IO_UNUSED ((gpio_num_t) -1) -namespace esphome { -namespace esp32_can { +namespace esphome::esp32_can { static const char *const TAG = "esp32_can"; @@ -184,7 +183,6 @@ canbus::Error ESP32Can::read_message(struct canbus::CanFrame *frame) { return canbus::ERROR_OK; } -} // namespace esp32_can -} // namespace esphome +} // namespace esphome::esp32_can #endif diff --git a/esphome/components/esp32_can/esp32_can.h b/esphome/components/esp32_can/esp32_can.h index c3f200271bb..2e10d254e6e 100644 --- a/esphome/components/esp32_can/esp32_can.h +++ b/esphome/components/esp32_can/esp32_can.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace esp32_can { +namespace esphome::esp32_can { enum CanMode : uint8_t { CAN_MODE_NORMAL = 0, @@ -41,7 +40,6 @@ class ESP32Can : public canbus::Canbus { twai_handle_t twai_handle_{nullptr}; }; -} // namespace esp32_can -} // namespace esphome +} // namespace esphome::esp32_can #endif diff --git a/esphome/components/esp32_dac/esp32_dac.cpp b/esphome/components/esp32_dac/esp32_dac.cpp index 8f226a5cc22..54b89c46ad0 100644 --- a/esphome/components/esp32_dac/esp32_dac.cpp +++ b/esphome/components/esp32_dac/esp32_dac.cpp @@ -4,8 +4,7 @@ #if defined(USE_ESP32_VARIANT_ESP32) || defined(USE_ESP32_VARIANT_ESP32S2) -namespace esphome { -namespace esp32_dac { +namespace esphome::esp32_dac { #ifdef USE_ESP32_VARIANT_ESP32S2 static constexpr uint8_t DAC0_PIN = 17; @@ -41,7 +40,6 @@ void ESP32DAC::write_state(float state) { dac_oneshot_output_voltage(this->dac_handle_, state); } -} // namespace esp32_dac -} // namespace esphome +} // namespace esphome::esp32_dac #endif // USE_ESP32_VARIANT_ESP32 || USE_ESP32_VARIANT_ESP32S2 diff --git a/esphome/components/esp32_dac/esp32_dac.h b/esphome/components/esp32_dac/esp32_dac.h index 95c687d3072..108b96cd399 100644 --- a/esphome/components/esp32_dac/esp32_dac.h +++ b/esphome/components/esp32_dac/esp32_dac.h @@ -9,8 +9,7 @@ #include -namespace esphome { -namespace esp32_dac { +namespace esphome::esp32_dac { class ESP32DAC : public output::FloatOutput, public Component { public: @@ -30,7 +29,6 @@ class ESP32DAC : public output::FloatOutput, public Component { dac_oneshot_handle_t dac_handle_; }; -} // namespace esp32_dac -} // namespace esphome +} // namespace esphome::esp32_dac #endif // USE_ESP32_VARIANT_ESP32 || USE_ESP32_VARIANT_ESP32S2 diff --git a/esphome/components/esp32_improv/automation.h b/esphome/components/esp32_improv/automation.h index cd2bd84c30c..19e1b6e7e39 100644 --- a/esphome/components/esp32_improv/automation.h +++ b/esphome/components/esp32_improv/automation.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace esp32_improv { +namespace esphome::esp32_improv { class ESP32ImprovProvisionedTrigger : public Trigger<> { public: @@ -81,7 +80,7 @@ class ESP32ImprovStoppedTrigger : public Trigger<> { ESP32ImprovComponent *parent_; }; -} // namespace esp32_improv -} // namespace esphome +} // namespace esphome::esp32_improv + #endif #endif diff --git a/esphome/components/esp32_improv/esp32_improv_component.cpp b/esphome/components/esp32_improv/esp32_improv_component.cpp index c24b08b06fa..183820256f4 100644 --- a/esphome/components/esp32_improv/esp32_improv_component.cpp +++ b/esphome/components/esp32_improv/esp32_improv_component.cpp @@ -9,8 +9,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace esp32_improv { +namespace esphome::esp32_improv { using namespace bytebuffer; @@ -490,7 +489,6 @@ improv::State ESP32ImprovComponent::get_initial_state_() const { ESP32ImprovComponent *global_improv_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace esp32_improv -} // namespace esphome +} // namespace esphome::esp32_improv #endif diff --git a/esphome/components/esp32_improv/esp32_improv_component.h b/esphome/components/esp32_improv/esp32_improv_component.h index 41799f23251..400006cfb32 100644 --- a/esphome/components/esp32_improv/esp32_improv_component.h +++ b/esphome/components/esp32_improv/esp32_improv_component.h @@ -28,8 +28,7 @@ #include -namespace esphome { -namespace esp32_improv { +namespace esphome::esp32_improv { using namespace esp32_ble_server; @@ -124,7 +123,6 @@ class ESP32ImprovComponent : public Component, public improv_base::ImprovBase { // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) extern ESP32ImprovComponent *global_improv_component; -} // namespace esp32_improv -} // namespace esphome +} // namespace esphome::esp32_improv #endif diff --git a/esphome/components/esp32_rmt_led_strip/led_strip.cpp b/esphome/components/esp32_rmt_led_strip/led_strip.cpp index ca97a181fd4..ed2a8c5a686 100644 --- a/esphome/components/esp32_rmt_led_strip/led_strip.cpp +++ b/esphome/components/esp32_rmt_led_strip/led_strip.cpp @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace esp32_rmt_led_strip { +namespace esphome::esp32_rmt_led_strip { static const char *const TAG = "esp32_rmt_led_strip"; @@ -305,7 +304,6 @@ void ESP32RMTLEDStripLightOutput::dump_config() { float ESP32RMTLEDStripLightOutput::get_setup_priority() const { return setup_priority::HARDWARE; } -} // namespace esp32_rmt_led_strip -} // namespace esphome +} // namespace esphome::esp32_rmt_led_strip #endif // USE_ESP32 diff --git a/esphome/components/esp32_rmt_led_strip/led_strip.h b/esphome/components/esp32_rmt_led_strip/led_strip.h index 6f3aea98784..8fb6b63afed 100644 --- a/esphome/components/esp32_rmt_led_strip/led_strip.h +++ b/esphome/components/esp32_rmt_led_strip/led_strip.h @@ -13,8 +13,7 @@ #include #include -namespace esphome { -namespace esp32_rmt_led_strip { +namespace esphome::esp32_rmt_led_strip { enum RGBOrder : uint8_t { ORDER_RGB, @@ -102,7 +101,6 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight { optional max_refresh_rate_{}; }; -} // namespace esp32_rmt_led_strip -} // namespace esphome +} // namespace esphome::esp32_rmt_led_strip #endif // USE_ESP32 diff --git a/esphome/components/espnow/packet_transport/espnow_transport.cpp b/esphome/components/espnow/packet_transport/espnow_transport.cpp index 384e3fe2a9a..1e37073321e 100644 --- a/esphome/components/espnow/packet_transport/espnow_transport.cpp +++ b/esphome/components/espnow/packet_transport/espnow_transport.cpp @@ -5,8 +5,7 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" -namespace esphome { -namespace espnow { +namespace esphome::espnow { static const char *const TAG = "espnow.transport"; @@ -86,7 +85,6 @@ bool ESPNowTransport::on_broadcast(const ESPNowRecvInfo &info, const uint8_t *da return false; // Allow other handlers to run } -} // namespace espnow -} // namespace esphome +} // namespace esphome::espnow #endif // USE_ESP32 diff --git a/esphome/components/espnow/packet_transport/espnow_transport.h b/esphome/components/espnow/packet_transport/espnow_transport.h index 98c33f01fdb..5916a7fa5f0 100644 --- a/esphome/components/espnow/packet_transport/espnow_transport.h +++ b/esphome/components/espnow/packet_transport/espnow_transport.h @@ -9,8 +9,7 @@ #include -namespace esphome { -namespace espnow { +namespace esphome::espnow { class ESPNowTransport : public packet_transport::PacketTransport, public Parented, @@ -37,7 +36,6 @@ class ESPNowTransport : public packet_transport::PacketTransport, std::vector packet_buffer_; }; -} // namespace espnow -} // namespace esphome +} // namespace esphome::espnow #endif // USE_ESP32 diff --git a/esphome/components/event/automation.h b/esphome/components/event/automation.h index 7730506c108..3444a7b1bb7 100644 --- a/esphome/components/event/automation.h +++ b/esphome/components/event/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -namespace esphome { -namespace event { +namespace esphome::event { template class TriggerEventAction : public Action, public Parented { public: @@ -21,5 +20,4 @@ class EventTrigger : public Trigger { } }; -} // namespace event -} // namespace esphome +} // namespace esphome::event diff --git a/esphome/components/event/event.cpp b/esphome/components/event/event.cpp index a5d64a2748d..673ccc98028 100644 --- a/esphome/components/event/event.cpp +++ b/esphome/components/event/event.cpp @@ -3,8 +3,7 @@ #include "esphome/core/controller_registry.h" #include "esphome/core/log.h" -namespace esphome { -namespace event { +namespace esphome::event { static const char *const TAG = "event"; @@ -45,5 +44,4 @@ void Event::set_event_types(const std::vector &event_types) { this->last_event_type_ = nullptr; // Reset when types change } -} // namespace event -} // namespace esphome +} // namespace esphome::event diff --git a/esphome/components/event/event.h b/esphome/components/event/event.h index ebbee0bfe23..e6fc7111c8b 100644 --- a/esphome/components/event/event.h +++ b/esphome/components/event/event.h @@ -10,8 +10,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace event { +namespace esphome::event { #define LOG_EVENT(prefix, type, obj) \ if ((obj) != nullptr) { \ @@ -80,5 +79,4 @@ class Event : public EntityBase { const char *last_event_type_{nullptr}; }; -} // namespace event -} // namespace esphome +} // namespace esphome::event diff --git a/esphome/components/exposure_notifications/exposure_notifications.cpp b/esphome/components/exposure_notifications/exposure_notifications.cpp index 307bee26f86..e7038d2ca9e 100644 --- a/esphome/components/exposure_notifications/exposure_notifications.cpp +++ b/esphome/components/exposure_notifications/exposure_notifications.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace exposure_notifications { +namespace esphome::exposure_notifications { using namespace esp32_ble_tracker; @@ -43,7 +42,6 @@ bool ExposureNotificationTrigger::parse_device(const ESPBTDevice &device) { return true; } -} // namespace exposure_notifications -} // namespace esphome +} // namespace esphome::exposure_notifications #endif diff --git a/esphome/components/exposure_notifications/exposure_notifications.h b/esphome/components/exposure_notifications/exposure_notifications.h index f7383c28d91..80184f9cfd4 100644 --- a/esphome/components/exposure_notifications/exposure_notifications.h +++ b/esphome/components/exposure_notifications/exposure_notifications.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace exposure_notifications { +namespace esphome::exposure_notifications { struct ExposureNotification { std::array address; @@ -23,7 +22,6 @@ class ExposureNotificationTrigger : public Trigger, bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; }; -} // namespace exposure_notifications -} // namespace esphome +} // namespace esphome::exposure_notifications #endif diff --git a/esphome/components/ezo/ezo.cpp b/esphome/components/ezo/ezo.cpp index bb8fb92f21a..d18e6e67cb1 100644 --- a/esphome/components/ezo/ezo.cpp +++ b/esphome/components/ezo/ezo.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ezo { +namespace esphome::ezo { static const char *const EZO_COMMAND_TYPE_STRINGS[] = {"EZO_READ", "EZO_LED", "EZO_DEVICE_INFORMATION", "EZO_SLOPE", "EZO_CALIBRATION", "EZO_SLEEP", @@ -238,5 +237,4 @@ void EZOSensor::send_custom(const std::string &to_send) { this->add_command_(to_send.c_str(), EzoCommandType::EZO_CUSTOM); } -} // namespace ezo -} // namespace esphome +} // namespace esphome::ezo diff --git a/esphome/components/ezo/ezo.h b/esphome/components/ezo/ezo.h index d80869fbd9a..aea276e0011 100644 --- a/esphome/components/ezo/ezo.h +++ b/esphome/components/ezo/ezo.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include -namespace esphome { -namespace ezo { +namespace esphome::ezo { static const char *const TAG = "ezo.sensor"; @@ -102,5 +101,4 @@ class EZOSensor : public sensor::Sensor, public PollingComponent, public i2c::I2 uint32_t start_time_ = 0; }; -} // namespace ezo -} // namespace esphome +} // namespace esphome::ezo diff --git a/esphome/components/ezo_pmp/ezo_pmp.cpp b/esphome/components/ezo_pmp/ezo_pmp.cpp index 4ce4da57ffc..21307fcd7af 100644 --- a/esphome/components/ezo_pmp/ezo_pmp.cpp +++ b/esphome/components/ezo_pmp/ezo_pmp.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ezo_pmp { +namespace esphome::ezo_pmp { static const char *const TAG = "ezo-pmp"; @@ -547,5 +546,4 @@ void EzoPMP::exec_arbitrary_command(const std::basic_string &command) { this->queue_command_(EZO_PMP_COMMAND_EXEC_ARBITRARY_COMMAND_ADDRESS, 0, 0, true); } -} // namespace ezo_pmp -} // namespace esphome +} // namespace esphome::ezo_pmp diff --git a/esphome/components/ezo_pmp/ezo_pmp.h b/esphome/components/ezo_pmp/ezo_pmp.h index bbfd8991707..8a6da5fe744 100644 --- a/esphome/components/ezo_pmp/ezo_pmp.h +++ b/esphome/components/ezo_pmp/ezo_pmp.h @@ -17,8 +17,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #endif -namespace esphome { -namespace ezo_pmp { +namespace esphome::ezo_pmp { class EzoPMP : public PollingComponent, public i2c::I2CDevice { public: @@ -247,5 +246,4 @@ template class EzoPMPArbitraryCommandAction : public Action { StringRef last_preset_mode_{}; }; -} // namespace fan -} // namespace esphome +} // namespace esphome::fan diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index 9301e0cea41..853bf94ffe4 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/progmem.h" -namespace esphome { -namespace fan { +namespace esphome::fan { static const char *const TAG = "fan"; @@ -345,5 +344,4 @@ void Fan::dump_traits_(const char *tag, const char *prefix) { } } -} // namespace fan -} // namespace esphome +} // namespace esphome::fan diff --git a/esphome/components/fan/fan.h b/esphome/components/fan/fan.h index d5763edf2f7..3d731e6eb08 100644 --- a/esphome/components/fan/fan.h +++ b/esphome/components/fan/fan.h @@ -8,8 +8,7 @@ #include "esphome/core/string_ref.h" #include "fan_traits.h" -namespace esphome { -namespace fan { +namespace esphome::fan { #define LOG_FAN(prefix, type, obj) \ if ((obj) != nullptr) { \ @@ -199,5 +198,4 @@ class Fan : public EntityBase { const char *preset_mode_{nullptr}; }; -} // namespace fan -} // namespace esphome +} // namespace esphome::fan diff --git a/esphome/components/fan/fan_traits.h b/esphome/components/fan/fan_traits.h index a2b2633af17..1d42cce371a 100644 --- a/esphome/components/fan/fan_traits.h +++ b/esphome/components/fan/fan_traits.h @@ -5,9 +5,7 @@ #include #include "esphome/core/helpers.h" -namespace esphome { - -namespace fan { +namespace esphome::fan { class Fan; // Forward declaration @@ -95,5 +93,4 @@ class FanTraits { std::vector compat_preset_modes_; }; -} // namespace fan -} // namespace esphome +} // namespace esphome::fan diff --git a/esphome/components/fastled_base/fastled_light.cpp b/esphome/components/fastled_base/fastled_light.cpp index 504b8d473e4..8d1dd49dad3 100644 --- a/esphome/components/fastled_base/fastled_light.cpp +++ b/esphome/components/fastled_base/fastled_light.cpp @@ -3,8 +3,7 @@ #include "fastled_light.h" #include "esphome/core/log.h" -namespace esphome { -namespace fastled_base { +namespace esphome::fastled_base { static const char *const TAG = "fastled"; @@ -39,7 +38,6 @@ void FastLEDLightOutput::write_state(light::LightState *state) { this->controller_->showLeds(this->state_parent_->current_values.get_brightness() * 255); } -} // namespace fastled_base -} // namespace esphome +} // namespace esphome::fastled_base #endif // USE_ARDUINO diff --git a/esphome/components/fastled_base/fastled_light.h b/esphome/components/fastled_base/fastled_light.h index 26f0f33d2a8..8e87f67e6d2 100644 --- a/esphome/components/fastled_base/fastled_light.h +++ b/esphome/components/fastled_base/fastled_light.h @@ -15,8 +15,7 @@ #include "FastLED.h" -namespace esphome { -namespace fastled_base { +namespace esphome::fastled_base { class FastLEDLightOutput : public light::AddressableLight { public: @@ -237,7 +236,6 @@ class FastLEDLightOutput : public light::AddressableLight { optional max_refresh_rate_{}; }; -} // namespace fastled_base -} // namespace esphome +} // namespace esphome::fastled_base #endif // USE_ARDUINO diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.cpp b/esphome/components/fingerprint_grow/fingerprint_grow.cpp index a633fbca282..3f57789034e 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.cpp +++ b/esphome/components/fingerprint_grow/fingerprint_grow.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace fingerprint_grow { +namespace esphome::fingerprint_grow { static const char *const TAG = "fingerprint_grow"; @@ -581,5 +580,4 @@ void FingerprintGrowComponent::dump_config() { } } -} // namespace fingerprint_grow -} // namespace esphome +} // namespace esphome::fingerprint_grow diff --git a/esphome/components/fingerprint_grow/fingerprint_grow.h b/esphome/components/fingerprint_grow/fingerprint_grow.h index 947c701c98a..7cecb7dc82f 100644 --- a/esphome/components/fingerprint_grow/fingerprint_grow.h +++ b/esphome/components/fingerprint_grow/fingerprint_grow.h @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace fingerprint_grow { +namespace esphome::fingerprint_grow { static const uint16_t START_CODE = 0xEF01; @@ -274,5 +273,4 @@ template class AuraLEDControlAction : public Action, publ } }; -} // namespace fingerprint_grow -} // namespace esphome +} // namespace esphome::fingerprint_grow diff --git a/esphome/components/font/font.cpp b/esphome/components/font/font.cpp index ecf0ca6bdd2..fda9c269e51 100644 --- a/esphome/components/font/font.cpp +++ b/esphome/components/font/font.cpp @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace font { +namespace esphome::font { static const char *const TAG = "font"; #ifdef USE_LVGL_FONT @@ -359,5 +358,4 @@ void Font::print(int x_start, int y_start, display::Display *display, Color colo } } #endif -} // namespace font -} // namespace esphome +} // namespace esphome::font diff --git a/esphome/components/font/font.h b/esphome/components/font/font.h index 4a09d7314d2..9c9cfa0f6d0 100644 --- a/esphome/components/font/font.h +++ b/esphome/components/font/font.h @@ -10,8 +10,7 @@ #include #endif -namespace esphome { -namespace font { +namespace esphome::font { class Font; @@ -98,5 +97,4 @@ class Font #endif }; -} // namespace font -} // namespace esphome +} // namespace esphome::font diff --git a/esphome/components/fs3000/fs3000.cpp b/esphome/components/fs3000/fs3000.cpp index cea599211de..a89b1661828 100644 --- a/esphome/components/fs3000/fs3000.cpp +++ b/esphome/components/fs3000/fs3000.cpp @@ -1,8 +1,7 @@ #include "fs3000.h" #include "esphome/core/log.h" -namespace esphome { -namespace fs3000 { +namespace esphome::fs3000 { static const char *const TAG = "fs3000"; @@ -101,5 +100,4 @@ float FS3000Component::fit_raw_(uint16_t raw_value) { } } -} // namespace fs3000 -} // namespace esphome +} // namespace esphome::fs3000 diff --git a/esphome/components/fs3000/fs3000.h b/esphome/components/fs3000/fs3000.h index e33c72215fd..c019b1366bc 100644 --- a/esphome/components/fs3000/fs3000.h +++ b/esphome/components/fs3000/fs3000.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace fs3000 { +namespace esphome::fs3000 { // FS3000 has two models, 1005 and 1015 // 1005 has a max speed detection of 7.23 m/s @@ -30,5 +29,4 @@ class FS3000Component : public PollingComponent, public i2c::I2CDevice, public s float fit_raw_(uint16_t raw_value); }; -} // namespace fs3000 -} // namespace esphome +} // namespace esphome::fs3000 diff --git a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp index 505c3cffc0f..835dc4aac03 100644 --- a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp +++ b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ft5x06 { +namespace esphome::ft5x06 { static const char *const TAG = "ft5x06.touchscreen"; @@ -99,5 +98,4 @@ bool FT5x06Touchscreen::set_mode_(FTMode mode) { return this->err_check_(this->write_register(FT5X06_MODE_REG, (uint8_t *) &mode, 1), "Set mode"); } -} // namespace ft5x06 -} // namespace esphome +} // namespace esphome::ft5x06 diff --git a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.h b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.h index 23e5a0c49fd..7cf8769f7ac 100644 --- a/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.h +++ b/esphome/components/ft5x06/touchscreen/ft5x06_touchscreen.h @@ -6,8 +6,7 @@ #include "esphome/core/gpio.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ft5x06 { +namespace esphome::ft5x06 { enum VendorId { FT5X06_ID_UNKNOWN = 0, @@ -52,5 +51,4 @@ class FT5x06Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice InternalGPIOPin *interrupt_pin_{nullptr}; }; -} // namespace ft5x06 -} // namespace esphome +} // namespace esphome::ft5x06 diff --git a/esphome/components/ft63x6/ft63x6.cpp b/esphome/components/ft63x6/ft63x6.cpp index f7c4f255a07..dd8f5ba629a 100644 --- a/esphome/components/ft63x6/ft63x6.cpp +++ b/esphome/components/ft63x6/ft63x6.cpp @@ -10,8 +10,8 @@ // Registers // Reference: https://focuslcds.com/content/FT6236.pdf -namespace esphome { -namespace ft63x6 { + +namespace esphome::ft63x6 { static const uint8_t FT6X36_ADDR_DEVICE_MODE = 0x00; static const uint8_t FT63X6_ADDR_TD_STATUS = 0x02; @@ -133,5 +133,4 @@ uint8_t FT63X6Touchscreen::read_byte_(uint8_t addr) { return byte; } -} // namespace ft63x6 -} // namespace esphome +} // namespace esphome::ft63x6 diff --git a/esphome/components/ft63x6/ft63x6.h b/esphome/components/ft63x6/ft63x6.h index 8000894294e..efa03168d97 100644 --- a/esphome/components/ft63x6/ft63x6.h +++ b/esphome/components/ft63x6/ft63x6.h @@ -11,8 +11,7 @@ #include "esphome/components/touchscreen/touchscreen.h" #include "esphome/core/component.h" -namespace esphome { -namespace ft63x6 { +namespace esphome::ft63x6 { using namespace touchscreen; @@ -47,5 +46,4 @@ class FT63X6Touchscreen : public Touchscreen, public i2c::I2CDevice { uint8_t read_byte_(uint8_t addr); }; -} // namespace ft63x6 -} // namespace esphome +} // namespace esphome::ft63x6 diff --git a/esphome/components/fujitsu_general/fujitsu_general.cpp b/esphome/components/fujitsu_general/fujitsu_general.cpp index 8aa0f517287..f801239153c 100644 --- a/esphome/components/fujitsu_general/fujitsu_general.cpp +++ b/esphome/components/fujitsu_general/fujitsu_general.cpp @@ -1,7 +1,6 @@ #include "fujitsu_general.h" -namespace esphome { -namespace fujitsu_general { +namespace esphome::fujitsu_general { // bytes' bits are reversed for fujitsu, so nibbles are ordered 1, 0, 3, 2, 5, 4, etc... @@ -400,5 +399,4 @@ bool FujitsuGeneralClimate::on_receive(remote_base::RemoteReceiveData data) { return true; } -} // namespace fujitsu_general -} // namespace esphome +} // namespace esphome::fujitsu_general diff --git a/esphome/components/fujitsu_general/fujitsu_general.h b/esphome/components/fujitsu_general/fujitsu_general.h index d7d01bf6f3e..ca93e4b3002 100644 --- a/esphome/components/fujitsu_general/fujitsu_general.h +++ b/esphome/components/fujitsu_general/fujitsu_general.h @@ -5,8 +5,7 @@ #include "esphome/core/automation.h" #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace fujitsu_general { +namespace esphome::fujitsu_general { const uint8_t FUJITSU_GENERAL_TEMP_MIN = 16; // Celsius // TODO 16 for heating, 18 for cooling, unsupported in ESPH const uint8_t FUJITSU_GENERAL_TEMP_MAX = 30; // Celsius @@ -78,5 +77,4 @@ class FujitsuGeneralClimate : public climate_ir::ClimateIR { bool power_{false}; }; -} // namespace fujitsu_general -} // namespace esphome +} // namespace esphome::fujitsu_general diff --git a/esphome/components/gcja5/gcja5.cpp b/esphome/components/gcja5/gcja5.cpp index 43b2fa20d3f..e84c51bde8a 100644 --- a/esphome/components/gcja5/gcja5.cpp +++ b/esphome/components/gcja5/gcja5.cpp @@ -9,8 +9,7 @@ #include "esphome/core/application.h" #include -namespace esphome { -namespace gcja5 { +namespace esphome::gcja5 { static const char *const TAG = "gcja5"; @@ -107,5 +106,4 @@ void GCJA5Component::parse_data_() { void GCJA5Component::dump_config() { ; } -} // namespace gcja5 -} // namespace esphome +} // namespace esphome::gcja5 diff --git a/esphome/components/gcja5/gcja5.h b/esphome/components/gcja5/gcja5.h index 30bc8771695..30c9464b4a2 100644 --- a/esphome/components/gcja5/gcja5.h +++ b/esphome/components/gcja5/gcja5.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace gcja5 { +namespace esphome::gcja5 { class GCJA5Component : public Component, public uart::UARTDevice { public: @@ -52,5 +51,4 @@ class GCJA5Component : public Component, public uart::UARTDevice { sensor::Sensor *pmc_10_0_sensor_{nullptr}; }; -} // namespace gcja5 -} // namespace esphome +} // namespace esphome::gcja5 diff --git a/esphome/components/gdk101/gdk101.cpp b/esphome/components/gdk101/gdk101.cpp index 0ee718cd20e..bc0ef70578f 100644 --- a/esphome/components/gdk101/gdk101.cpp +++ b/esphome/components/gdk101/gdk101.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace gdk101 { +namespace esphome::gdk101 { static const char *const TAG = "gdk101"; static constexpr uint8_t NUMBER_OF_READ_RETRIES = 5; @@ -206,5 +205,4 @@ bool GDK101Component::read_measurement_duration_(uint8_t *data) { return true; } -} // namespace gdk101 -} // namespace esphome +} // namespace esphome::gdk101 diff --git a/esphome/components/gdk101/gdk101.h b/esphome/components/gdk101/gdk101.h index abe3fd60d83..2ef75262947 100644 --- a/esphome/components/gdk101/gdk101.h +++ b/esphome/components/gdk101/gdk101.h @@ -13,8 +13,7 @@ #endif // USE_TEXT_SENSOR #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace gdk101 { +namespace esphome::gdk101 { static const uint8_t GDK101_REG_READ_FIRMWARE = 0xB4; // Firmware version static const uint8_t GDK101_REG_RESET = 0xA0; // Reset register - reading its value triggers reset @@ -55,5 +54,4 @@ class GDK101Component : public PollingComponent, public i2c::I2CDevice { uint8_t reset_retries_remaining_{0}; }; -} // namespace gdk101 -} // namespace esphome +} // namespace esphome::gdk101 diff --git a/esphome/components/gl_r01_i2c/gl_r01_i2c.cpp b/esphome/components/gl_r01_i2c/gl_r01_i2c.cpp index 38328c4b034..75f0c69a7b1 100644 --- a/esphome/components/gl_r01_i2c/gl_r01_i2c.cpp +++ b/esphome/components/gl_r01_i2c/gl_r01_i2c.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "gl_r01_i2c.h" -namespace esphome { -namespace gl_r01_i2c { +namespace esphome::gl_r01_i2c { static const char *const TAG = "gl_r01_i2c"; @@ -65,5 +64,4 @@ void GLR01I2CComponent::read_distance_() { } } -} // namespace gl_r01_i2c -} // namespace esphome +} // namespace esphome::gl_r01_i2c diff --git a/esphome/components/gl_r01_i2c/gl_r01_i2c.h b/esphome/components/gl_r01_i2c/gl_r01_i2c.h index 9a7aa023fd2..1d023c245ae 100644 --- a/esphome/components/gl_r01_i2c/gl_r01_i2c.h +++ b/esphome/components/gl_r01_i2c/gl_r01_i2c.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace gl_r01_i2c { +namespace esphome::gl_r01_i2c { class GLR01I2CComponent : public sensor::Sensor, public i2c::I2CDevice, public PollingComponent { public: @@ -18,5 +17,4 @@ class GLR01I2CComponent : public sensor::Sensor, public i2c::I2CDevice, public P uint16_t version_{0}; }; -} // namespace gl_r01_i2c -} // namespace esphome +} // namespace esphome::gl_r01_i2c diff --git a/esphome/components/gp2y1010au0f/gp2y1010au0f.cpp b/esphome/components/gp2y1010au0f/gp2y1010au0f.cpp index c8b0f13d3a8..0dd4a13a212 100644 --- a/esphome/components/gp2y1010au0f/gp2y1010au0f.cpp +++ b/esphome/components/gp2y1010au0f/gp2y1010au0f.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace gp2y1010au0f { +namespace esphome::gp2y1010au0f { static const char *const TAG = "gp2y1010au0f"; static const float MIN_VOLTAGE = 0.0f; @@ -65,5 +64,4 @@ void GP2Y1010AU0FSensor::loop() { this->sample_sum_ += read_voltage; } -} // namespace gp2y1010au0f -} // namespace esphome +} // namespace esphome::gp2y1010au0f diff --git a/esphome/components/gp2y1010au0f/gp2y1010au0f.h b/esphome/components/gp2y1010au0f/gp2y1010au0f.h index 5ee58e68d29..f3398ac4a3a 100644 --- a/esphome/components/gp2y1010au0f/gp2y1010au0f.h +++ b/esphome/components/gp2y1010au0f/gp2y1010au0f.h @@ -5,8 +5,7 @@ #include "esphome/components/voltage_sampler/voltage_sampler.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace gp2y1010au0f { +namespace esphome::gp2y1010au0f { class GP2Y1010AU0FSensor : public sensor::Sensor, public PollingComponent { public: @@ -48,5 +47,4 @@ class GP2Y1010AU0FSensor : public sensor::Sensor, public PollingComponent { bool is_sampling_ = false; }; -} // namespace gp2y1010au0f -} // namespace esphome +} // namespace esphome::gp2y1010au0f diff --git a/esphome/components/gp8403/gp8403.cpp b/esphome/components/gp8403/gp8403.cpp index 11c2f9a7c06..7e93bb6295d 100644 --- a/esphome/components/gp8403/gp8403.cpp +++ b/esphome/components/gp8403/gp8403.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace gp8403 { +namespace esphome::gp8403 { static const char *const TAG = "gp8403"; @@ -51,5 +50,4 @@ void GP8403Component::write_state(float state, uint8_t channel) { } } -} // namespace gp8403 -} // namespace esphome +} // namespace esphome::gp8403 diff --git a/esphome/components/gp8403/gp8403.h b/esphome/components/gp8403/gp8403.h index a19df15515d..d30d9674795 100644 --- a/esphome/components/gp8403/gp8403.h +++ b/esphome/components/gp8403/gp8403.h @@ -3,8 +3,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace gp8403 { +namespace esphome::gp8403 { enum GP8403Voltage : uint8_t { GP8403_VOLTAGE_5V = 0x00, @@ -30,5 +29,4 @@ class GP8403Component : public Component, public i2c::I2CDevice { GP8403Model model_{GP8403Model::GP8403}; }; -} // namespace gp8403 -} // namespace esphome +} // namespace esphome::gp8403 diff --git a/esphome/components/gp8403/output/gp8403_output.cpp b/esphome/components/gp8403/output/gp8403_output.cpp index dfdc2d6ccb1..7a22a280ac7 100644 --- a/esphome/components/gp8403/output/gp8403_output.cpp +++ b/esphome/components/gp8403/output/gp8403_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace gp8403 { +namespace esphome::gp8403 { static const char *const TAG = "gp8403.output"; @@ -16,5 +15,4 @@ void GP8403Output::dump_config() { void GP8403Output::write_state(float state) { this->parent_->write_state(state, this->channel_); } -} // namespace gp8403 -} // namespace esphome +} // namespace esphome::gp8403 diff --git a/esphome/components/gp8403/output/gp8403_output.h b/esphome/components/gp8403/output/gp8403_output.h index c0d6650500e..8b1f920680d 100644 --- a/esphome/components/gp8403/output/gp8403_output.h +++ b/esphome/components/gp8403/output/gp8403_output.h @@ -5,8 +5,7 @@ #include "esphome/components/gp8403/gp8403.h" -namespace esphome { -namespace gp8403 { +namespace esphome::gp8403 { class GP8403Output : public Component, public output::FloatOutput, public Parented { public: @@ -19,5 +18,4 @@ class GP8403Output : public Component, public output::FloatOutput, public Parent uint8_t channel_; }; -} // namespace gp8403 -} // namespace esphome +} // namespace esphome::gp8403 diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp index 1f0154c70b7..ff07d76901f 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/progmem.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { static const char *const TAG = "gpio.binary_sensor"; @@ -86,5 +85,4 @@ void GPIOBinarySensor::loop() { float GPIOBinarySensor::get_setup_priority() const { return setup_priority::HARDWARE; } -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h index 24efc2a0e60..100edb4cca4 100644 --- a/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h +++ b/esphome/components/gpio/binary_sensor/gpio_binary_sensor.h @@ -5,8 +5,7 @@ #include "esphome/core/helpers.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { // Store class for ISR data and configuration (no vtables, ISR-safe) class GPIOBinarySensorStore { @@ -64,5 +63,4 @@ class GPIOBinarySensor final : public binary_sensor::BinarySensor, public Compon GPIOBinarySensorStore store_; }; -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/one_wire/gpio_one_wire.cpp b/esphome/components/gpio/one_wire/gpio_one_wire.cpp index 4e2a306fc94..1fecfbf0dd1 100644 --- a/esphome/components/gpio/one_wire/gpio_one_wire.cpp +++ b/esphome/components/gpio/one_wire/gpio_one_wire.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { static const char *const TAG = "gpio.one_wire"; @@ -202,5 +201,4 @@ uint64_t IRAM_ATTR GPIOOneWireBus::search_int() { return address; } -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/one_wire/gpio_one_wire.h b/esphome/components/gpio/one_wire/gpio_one_wire.h index 88747039715..02797b57371 100644 --- a/esphome/components/gpio/one_wire/gpio_one_wire.h +++ b/esphome/components/gpio/one_wire/gpio_one_wire.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/one_wire/one_wire.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { class GPIOOneWireBus : public one_wire::OneWireBus, public Component { public: @@ -38,5 +37,4 @@ class GPIOOneWireBus : public one_wire::OneWireBus, public Component { bool read_bit_(uint32_t *t); }; -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/output/gpio_binary_output.cpp b/esphome/components/gpio/output/gpio_binary_output.cpp index 13538b6f2bd..402ad03c49a 100644 --- a/esphome/components/gpio/output/gpio_binary_output.cpp +++ b/esphome/components/gpio/output/gpio_binary_output.cpp @@ -1,8 +1,7 @@ #include "gpio_binary_output.h" #include "esphome/core/log.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { static const char *const TAG = "gpio.output"; @@ -12,5 +11,4 @@ void GPIOBinaryOutput::dump_config() { LOG_BINARY_OUTPUT(this); } -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/output/gpio_binary_output.h b/esphome/components/gpio/output/gpio_binary_output.h index 6b72c61c0f6..4100cb94c2b 100644 --- a/esphome/components/gpio/output/gpio_binary_output.h +++ b/esphome/components/gpio/output/gpio_binary_output.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { class GPIOBinaryOutput : public output::BinaryOutput, public Component { public: @@ -25,5 +24,4 @@ class GPIOBinaryOutput : public output::BinaryOutput, public Component { GPIOPin *pin_; }; -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/switch/gpio_switch.cpp b/esphome/components/gpio/switch/gpio_switch.cpp index 9c6464815a0..d432655a2a4 100644 --- a/esphome/components/gpio/switch/gpio_switch.cpp +++ b/esphome/components/gpio/switch/gpio_switch.cpp @@ -1,8 +1,7 @@ #include "gpio_switch.h" #include "esphome/core/log.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { static const char *const TAG = "switch.gpio"; #ifdef USE_GPIO_SWITCH_INTERLOCK @@ -79,5 +78,4 @@ void GPIOSwitch::write_state(bool state) { void GPIOSwitch::set_interlock(const std::initializer_list &interlock) { this->interlock_ = interlock; } #endif -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gpio/switch/gpio_switch.h b/esphome/components/gpio/switch/gpio_switch.h index f7415d1dba1..7ed0de7c6f0 100644 --- a/esphome/components/gpio/switch/gpio_switch.h +++ b/esphome/components/gpio/switch/gpio_switch.h @@ -5,8 +5,7 @@ #include "esphome/core/helpers.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace gpio { +namespace esphome::gpio { class GPIOSwitch final : public switch_::Switch, public Component { public: @@ -33,5 +32,4 @@ class GPIOSwitch final : public switch_::Switch, public Component { #endif }; -} // namespace gpio -} // namespace esphome +} // namespace esphome::gpio diff --git a/esphome/components/gps/gps.cpp b/esphome/components/gps/gps.cpp index 65cddcd9842..4b8abd219b0 100644 --- a/esphome/components/gps/gps.cpp +++ b/esphome/components/gps/gps.cpp @@ -1,8 +1,7 @@ #include "gps.h" #include "esphome/core/log.h" -namespace esphome { -namespace gps { +namespace esphome::gps { static const char *const TAG = "gps"; @@ -91,5 +90,4 @@ void GPS::loop() { } } -} // namespace gps -} // namespace esphome +} // namespace esphome::gps diff --git a/esphome/components/gps/gps.h b/esphome/components/gps/gps.h index 36923c68be4..9cd79e25b42 100644 --- a/esphome/components/gps/gps.h +++ b/esphome/components/gps/gps.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace gps { +namespace esphome::gps { class GPS; @@ -67,5 +66,4 @@ class GPS : public PollingComponent, public uart::UARTDevice { std::vector listeners_{}; }; -} // namespace gps -} // namespace esphome +} // namespace esphome::gps diff --git a/esphome/components/gps/time/gps_time.cpp b/esphome/components/gps/time/gps_time.cpp index fb662a3d60e..3859983ceb7 100644 --- a/esphome/components/gps/time/gps_time.cpp +++ b/esphome/components/gps/time/gps_time.cpp @@ -1,8 +1,7 @@ #include "gps_time.h" #include "esphome/core/log.h" -namespace esphome { -namespace gps { +namespace esphome::gps { static const char *const TAG = "gps.time"; @@ -24,5 +23,4 @@ void GPSTime::from_tiny_gps_(TinyGPSPlus &tiny_gps) { this->has_time_ = true; } -} // namespace gps -} // namespace esphome +} // namespace esphome::gps diff --git a/esphome/components/gps/time/gps_time.h b/esphome/components/gps/time/gps_time.h index a8414f00154..3d6d870efc2 100644 --- a/esphome/components/gps/time/gps_time.h +++ b/esphome/components/gps/time/gps_time.h @@ -4,8 +4,7 @@ #include "esphome/components/time/real_time_clock.h" #include "esphome/core/component.h" -namespace esphome { -namespace gps { +namespace esphome::gps { class GPSTime : public time::RealTimeClock, public GPSListener { public: @@ -21,5 +20,4 @@ class GPSTime : public time::RealTimeClock, public GPSListener { bool has_time_{false}; }; -} // namespace gps -} // namespace esphome +} // namespace esphome::gps diff --git a/esphome/components/graph/graph.cpp b/esphome/components/graph/graph.cpp index 801c97e3f56..5d59f605095 100644 --- a/esphome/components/graph/graph.cpp +++ b/esphome/components/graph/graph.cpp @@ -4,8 +4,8 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" #include -namespace esphome { -namespace graph { + +namespace esphome::graph { using namespace display; @@ -397,5 +397,4 @@ void Graph::dump_config() { } } -} // namespace graph -} // namespace esphome +} // namespace esphome::graph diff --git a/esphome/components/graphical_display_menu/graphical_display_menu.cpp b/esphome/components/graphical_display_menu/graphical_display_menu.cpp index cf1672f217a..81971e457cd 100644 --- a/esphome/components/graphical_display_menu/graphical_display_menu.cpp +++ b/esphome/components/graphical_display_menu/graphical_display_menu.cpp @@ -5,8 +5,7 @@ #include #include "esphome/components/display/display.h" -namespace esphome { -namespace graphical_display_menu { +namespace esphome::graphical_display_menu { static const char *const TAG = "graphical_display_menu"; @@ -246,5 +245,4 @@ void GraphicalDisplayMenu::draw_item(const display_menu_base::MenuItem *item, co void GraphicalDisplayMenu::update() { this->on_redraw_callbacks_.call(); } -} // namespace graphical_display_menu -} // namespace esphome +} // namespace esphome::graphical_display_menu diff --git a/esphome/components/gree/gree.cpp b/esphome/components/gree/gree.cpp index 732ebd9632e..705c741dd0f 100644 --- a/esphome/components/gree/gree.cpp +++ b/esphome/components/gree/gree.cpp @@ -1,8 +1,7 @@ #include "gree.h" #include "esphome/components/remote_base/remote_base.h" -namespace esphome { -namespace gree { +namespace esphome::gree { static const char *const TAG = "gree.climate"; @@ -241,5 +240,4 @@ uint8_t GreeClimate::preset_() { return GREE_PRESET_NONE; } -} // namespace gree -} // namespace esphome +} // namespace esphome::gree diff --git a/esphome/components/gree/switch/gree_switch.cpp b/esphome/components/gree/switch/gree_switch.cpp index 13f14e54530..2f649733afc 100644 --- a/esphome/components/gree/switch/gree_switch.cpp +++ b/esphome/components/gree/switch/gree_switch.cpp @@ -1,8 +1,7 @@ #include "gree_switch.h" #include "esphome/core/log.h" -namespace esphome { -namespace gree { +namespace esphome::gree { static const char *const TAG = "gree.switch"; @@ -20,5 +19,4 @@ void GreeModeBitSwitch::write_state(bool state) { this->publish_state(state); } -} // namespace gree -} // namespace esphome +} // namespace esphome::gree diff --git a/esphome/components/gree/switch/gree_switch.h b/esphome/components/gree/switch/gree_switch.h index 239ac4bf171..9d9f187f9d5 100644 --- a/esphome/components/gree/switch/gree_switch.h +++ b/esphome/components/gree/switch/gree_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/components/gree/gree.h" -namespace esphome { -namespace gree { +namespace esphome::gree { class GreeModeBitSwitch : public switch_::Switch, public Component, public Parented { public: @@ -20,5 +19,4 @@ class GreeModeBitSwitch : public switch_::Switch, public Component, public Paren uint8_t bit_mask_; }; -} // namespace gree -} // namespace esphome +} // namespace esphome::gree diff --git a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp index b0f3429314c..0de0b02182f 100644 --- a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp +++ b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace grove_gas_mc_v2 { +namespace esphome::grove_gas_mc_v2 { static const char *const TAG = "grove_gas_mc_v2"; @@ -82,5 +81,4 @@ void GroveGasMultichannelV2Component::dump_config() { } } -} // namespace grove_gas_mc_v2 -} // namespace esphome +} // namespace esphome::grove_gas_mc_v2 diff --git a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h index aab881bd059..38165ab68cd 100644 --- a/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h +++ b/esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace grove_gas_mc_v2 { +namespace esphome::grove_gas_mc_v2 { class GroveGasMultichannelV2Component : public PollingComponent, public i2c::I2CDevice { SUB_SENSOR(tvoc) @@ -33,5 +32,4 @@ class GroveGasMultichannelV2Component : public PollingComponent, public i2c::I2C bool read_sensor_(uint8_t address, sensor::Sensor *sensor); }; -} // namespace grove_gas_mc_v2 -} // namespace esphome +} // namespace esphome::grove_gas_mc_v2 diff --git a/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp b/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp index c10fa4cf257..eaa1440c4da 100644 --- a/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp +++ b/esphome/components/grove_tb6612fng/grove_tb6612fng.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace grove_tb6612fng { +namespace esphome::grove_tb6612fng { static const char *const TAG = "GroveMotorDriveTB6612FNG"; @@ -167,5 +166,4 @@ void GroveMotorDriveTB6612FNG::stepper_keep_run(StepperModeTypeT mode, uint16_t return; } } -} // namespace grove_tb6612fng -} // namespace esphome +} // namespace esphome::grove_tb6612fng diff --git a/esphome/components/grove_tb6612fng/grove_tb6612fng.h b/esphome/components/grove_tb6612fng/grove_tb6612fng.h index bf471632267..c0216805198 100644 --- a/esphome/components/grove_tb6612fng/grove_tb6612fng.h +++ b/esphome/components/grove_tb6612fng/grove_tb6612fng.h @@ -4,7 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" #include "esphome/core/hal.h" -//#include "esphome/core/helpers.h" +// #include "esphome/core/helpers.h" /* Grove_Motor_Driver_TB6612FNG.h @@ -33,8 +33,7 @@ THE SOFTWARE. */ -namespace esphome { -namespace grove_tb6612fng { +namespace esphome::grove_tb6612fng { enum MotorChannelTypeT { MOTOR_CHA = 0, @@ -219,5 +218,4 @@ class GROVETB6612FNGMotorChangeAddressAction : public Action, public Pare void play(const Ts &...x) override { this->parent_->set_i2c_addr(this->address_.value(x...)); } }; -} // namespace grove_tb6612fng -} // namespace esphome +} // namespace esphome::grove_tb6612fng diff --git a/esphome/components/growatt_solar/growatt_solar.cpp b/esphome/components/growatt_solar/growatt_solar.cpp index 29974258723..41beb6e4e94 100644 --- a/esphome/components/growatt_solar/growatt_solar.cpp +++ b/esphome/components/growatt_solar/growatt_solar.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace growatt_solar { +namespace esphome::growatt_solar { static const char *const TAG = "growatt_solar"; @@ -141,5 +140,4 @@ void GrowattSolar::dump_config() { this->address_); } -} // namespace growatt_solar -} // namespace esphome +} // namespace esphome::growatt_solar diff --git a/esphome/components/growatt_solar/growatt_solar.h b/esphome/components/growatt_solar/growatt_solar.h index 833d6a36ddb..7eba7956015 100644 --- a/esphome/components/growatt_solar/growatt_solar.h +++ b/esphome/components/growatt_solar/growatt_solar.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace growatt_solar { +namespace esphome::growatt_solar { static const float TWO_DEC_UNIT = 0.01; static const float ONE_DEC_UNIT = 0.1; @@ -83,5 +82,4 @@ class GrowattSolar : public PollingComponent, public modbus::ModbusDevice { GrowattProtocolVersion protocol_version_; }; -} // namespace growatt_solar -} // namespace esphome +} // namespace esphome::growatt_solar diff --git a/esphome/components/gt911/binary_sensor/gt911_button.cpp b/esphome/components/gt911/binary_sensor/gt911_button.cpp index 35ffaecefcc..7b356f3946d 100644 --- a/esphome/components/gt911/binary_sensor/gt911_button.cpp +++ b/esphome/components/gt911/binary_sensor/gt911_button.cpp @@ -1,8 +1,7 @@ #include "gt911_button.h" #include "esphome/core/log.h" -namespace esphome { -namespace gt911 { +namespace esphome::gt911 { static const char *const TAG = "GT911.binary_sensor"; @@ -23,5 +22,4 @@ void GT911Button::update_button(uint8_t index, bool state) { this->publish_state(state); } -} // namespace gt911 -} // namespace esphome +} // namespace esphome::gt911 diff --git a/esphome/components/gt911/binary_sensor/gt911_button.h b/esphome/components/gt911/binary_sensor/gt911_button.h index 556ed65f919..5aab4570950 100644 --- a/esphome/components/gt911/binary_sensor/gt911_button.h +++ b/esphome/components/gt911/binary_sensor/gt911_button.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace gt911 { +namespace esphome::gt911 { class GT911Button : public binary_sensor::BinarySensor, public Component, @@ -24,5 +23,4 @@ class GT911Button : public binary_sensor::BinarySensor, uint8_t index_; }; -} // namespace gt911 -} // namespace esphome +} // namespace esphome::gt911 diff --git a/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp b/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp index 17bfa82cb45..2152ae7b842 100644 --- a/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +++ b/esphome/components/gt911/touchscreen/gt911_touchscreen.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/gpio.h" -namespace esphome { -namespace gt911 { +namespace esphome::gt911 { static const char *const TAG = "gt911.touchscreen"; @@ -157,5 +156,4 @@ void GT911Touchscreen::dump_config() { LOG_PIN(" Reset Pin: ", this->reset_pin_); } -} // namespace gt911 -} // namespace esphome +} // namespace esphome::gt911 diff --git a/esphome/components/gt911/touchscreen/gt911_touchscreen.h b/esphome/components/gt911/touchscreen/gt911_touchscreen.h index a6577b5879d..0f1eeae7207 100644 --- a/esphome/components/gt911/touchscreen/gt911_touchscreen.h +++ b/esphome/components/gt911/touchscreen/gt911_touchscreen.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace gt911 { +namespace esphome::gt911 { class GT911ButtonListener { public: @@ -57,5 +56,4 @@ class GT911Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice uint8_t button_state_{0xFF}; // last button state. Initial FF guarantees first update. }; -} // namespace gt911 -} // namespace esphome +} // namespace esphome::gt911 diff --git a/esphome/components/haier/automation.h b/esphome/components/haier/automation.h index c1ce7c01ea4..e345867d6f8 100644 --- a/esphome/components/haier/automation.h +++ b/esphome/components/haier/automation.h @@ -4,8 +4,7 @@ #include "haier_base.h" #include "hon_climate.h" -namespace esphome { -namespace haier { +namespace esphome::haier { template class DisplayOnAction : public Action { public: @@ -126,5 +125,4 @@ template class PowerToggleAction : public Action { HaierClimateBase *parent_; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/button/self_cleaning.cpp b/esphome/components/haier/button/self_cleaning.cpp index 128726036e3..bf4baa716e6 100644 --- a/esphome/components/haier/button/self_cleaning.cpp +++ b/esphome/components/haier/button/self_cleaning.cpp @@ -1,9 +1,7 @@ #include "self_cleaning.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void SelfCleaningButton::press_action() { this->parent_->start_self_cleaning(); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/button/self_cleaning.h b/esphome/components/haier/button/self_cleaning.h index 308fb70f064..9d330e4dfe4 100644 --- a/esphome/components/haier/button/self_cleaning.h +++ b/esphome/components/haier/button/self_cleaning.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../hon_climate.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class SelfCleaningButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class SelfCleaningButton : public button::Button, public Parented { void press_action() override; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/button/steri_cleaning.cpp b/esphome/components/haier/button/steri_cleaning.cpp index 02b723f1a4c..8c4f5808b21 100644 --- a/esphome/components/haier/button/steri_cleaning.cpp +++ b/esphome/components/haier/button/steri_cleaning.cpp @@ -1,9 +1,7 @@ #include "steri_cleaning.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void SteriCleaningButton::press_action() { this->parent_->start_steri_cleaning(); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/button/steri_cleaning.h b/esphome/components/haier/button/steri_cleaning.h index 6cad313fb38..cac02dd2678 100644 --- a/esphome/components/haier/button/steri_cleaning.h +++ b/esphome/components/haier/button/steri_cleaning.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../hon_climate.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class SteriCleaningButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class SteriCleaningButton : public button::Button, public Parented { void press_action() override; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/haier_base.cpp b/esphome/components/haier/haier_base.cpp index 4a06066d3c9..74a218263d9 100644 --- a/esphome/components/haier/haier_base.cpp +++ b/esphome/components/haier/haier_base.cpp @@ -10,8 +10,7 @@ using namespace esphome::climate; using namespace esphome::uart; -namespace esphome { -namespace haier { +namespace esphome::haier { static const char *const TAG = "haier.climate"; constexpr size_t COMMUNICATION_TIMEOUT_MS = 60000; @@ -418,5 +417,4 @@ void HaierClimateBase::send_message_(const haier_protocol::HaierMessage &command this->last_request_timestamp_ = std::chrono::steady_clock::now(); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/haier_base.h b/esphome/components/haier/haier_base.h index 0c416623c08..13e8d7548d5 100644 --- a/esphome/components/haier/haier_base.h +++ b/esphome/components/haier/haier_base.h @@ -11,8 +11,7 @@ #include "esphome/components/switch/switch.h" #endif -namespace esphome { -namespace haier { +namespace esphome::haier { enum class ActionRequest : uint8_t { SEND_CUSTOM_COMMAND = 0, @@ -177,5 +176,4 @@ class HaierClimateBase : public esphome::Component, ESPPreferenceObject base_rtc_; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/hon_climate.cpp b/esphome/components/haier/hon_climate.cpp index 87b8add2a37..0ad9b00ce4f 100644 --- a/esphome/components/haier/hon_climate.cpp +++ b/esphome/components/haier/hon_climate.cpp @@ -9,8 +9,7 @@ using namespace esphome::climate; using namespace esphome::uart; -namespace esphome { -namespace haier { +namespace esphome::haier { static const char *const TAG = "haier.climate"; constexpr size_t SIGNAL_LEVEL_UPDATE_INTERVAL_MS = 10000; @@ -1370,5 +1369,4 @@ bool HonClimate::should_get_big_data_() { return false; } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/hon_climate.h b/esphome/components/haier/hon_climate.h index a0bcdfb548c..5b477a5cea1 100644 --- a/esphome/components/haier/hon_climate.h +++ b/esphome/components/haier/hon_climate.h @@ -18,8 +18,7 @@ #include "haier_base.h" #include "hon_packet.h" -namespace esphome { -namespace haier { +namespace esphome::haier { enum class CleaningState : uint8_t { NO_CLEANING = 0, @@ -201,5 +200,4 @@ class HonClimate : public HaierClimateBase { SwitchState quiet_mode_state_{SwitchState::OFF}; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/hon_packet.h b/esphome/components/haier/hon_packet.h index 615f93528ec..63799f04ba1 100644 --- a/esphome/components/haier/hon_packet.h +++ b/esphome/components/haier/hon_packet.h @@ -2,9 +2,7 @@ #include -namespace esphome { -namespace haier { -namespace hon_protocol { +namespace esphome::haier::hon_protocol { enum class VerticalSwingMode : uint8_t { HEALTH_UP = 0x01, @@ -255,6 +253,4 @@ const std::string HON_ALARM_MESSAGES[] = { constexpr size_t HON_ALARM_COUNT = sizeof(HON_ALARM_MESSAGES) / sizeof(HON_ALARM_MESSAGES[0]); -} // namespace hon_protocol -} // namespace haier -} // namespace esphome +} // namespace esphome::haier::hon_protocol diff --git a/esphome/components/haier/logger_handler.cpp b/esphome/components/haier/logger_handler.cpp index f886318097a..1c4004cf6ce 100644 --- a/esphome/components/haier/logger_handler.cpp +++ b/esphome/components/haier/logger_handler.cpp @@ -1,8 +1,7 @@ #include "logger_handler.h" #include "esphome/core/log.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void esphome_logger(haier_protocol::HaierLogLevel level, const char *tag, const char *message) { switch (level) { @@ -29,5 +28,4 @@ void esphome_logger(haier_protocol::HaierLogLevel level, const char *tag, const void init_haier_protocol_logging() { haier_protocol::set_log_handler(esphome::haier::esphome_logger); }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/logger_handler.h b/esphome/components/haier/logger_handler.h index 2955468f37e..192259409f2 100644 --- a/esphome/components/haier/logger_handler.h +++ b/esphome/components/haier/logger_handler.h @@ -3,12 +3,10 @@ // HaierProtocol #include -namespace esphome { -namespace haier { +namespace esphome::haier { // This file is called in the code generated by python script // Do not use it directly! void init_haier_protocol_logging(); -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/smartair2_climate.cpp b/esphome/components/haier/smartair2_climate.cpp index 752f4d4f1c0..bd5678a4258 100644 --- a/esphome/components/haier/smartair2_climate.cpp +++ b/esphome/components/haier/smartair2_climate.cpp @@ -7,8 +7,7 @@ using namespace esphome::climate; using namespace esphome::uart; -namespace esphome { -namespace haier { +namespace esphome::haier { static const char *const TAG = "haier.climate"; constexpr size_t SIGNAL_LEVEL_UPDATE_INTERVAL_MS = 10000; @@ -555,5 +554,4 @@ void Smartair2Climate::set_alternative_swing_control(bool swing_control) { this->use_alternative_swing_control_ = swing_control; } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/smartair2_climate.h b/esphome/components/haier/smartair2_climate.h index 6914d8a1fbb..68b0e4a0db2 100644 --- a/esphome/components/haier/smartair2_climate.h +++ b/esphome/components/haier/smartair2_climate.h @@ -3,8 +3,7 @@ #include #include "haier_base.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class Smartair2Climate : public HaierClimateBase { public: @@ -36,5 +35,4 @@ class Smartair2Climate : public HaierClimateBase { bool use_alternative_swing_control_; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/smartair2_packet.h b/esphome/components/haier/smartair2_packet.h index 22570ff048a..144b7db8795 100644 --- a/esphome/components/haier/smartair2_packet.h +++ b/esphome/components/haier/smartair2_packet.h @@ -1,8 +1,6 @@ #pragma once -namespace esphome { -namespace haier { -namespace smartair2_protocol { +namespace esphome::haier::smartair2_protocol { enum class ConditioningMode : uint8_t { AUTO = 0x00, COOL = 0x01, HEAT = 0x02, FAN = 0x03, DRY = 0x04 }; @@ -83,6 +81,4 @@ struct HaierStatus { HaierPacketControl control; }; -} // namespace smartair2_protocol -} // namespace haier -} // namespace esphome +} // namespace esphome::haier::smartair2_protocol diff --git a/esphome/components/haier/switch/beeper.cpp b/esphome/components/haier/switch/beeper.cpp index 1ce64d0848c..40b048be5c7 100644 --- a/esphome/components/haier/switch/beeper.cpp +++ b/esphome/components/haier/switch/beeper.cpp @@ -1,7 +1,6 @@ #include "beeper.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void BeeperSwitch::write_state(bool state) { if (this->parent_->get_beeper_state() != state) { @@ -10,5 +9,4 @@ void BeeperSwitch::write_state(bool state) { this->publish_state(state); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/beeper.h b/esphome/components/haier/switch/beeper.h index 7396a7a0dda..2d20f1cd835 100644 --- a/esphome/components/haier/switch/beeper.h +++ b/esphome/components/haier/switch/beeper.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "../hon_climate.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class BeeperSwitch : public switch_::Switch, public Parented { public: @@ -14,5 +13,4 @@ class BeeperSwitch : public switch_::Switch, public Parented { void write_state(bool state) override; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/display.cpp b/esphome/components/haier/switch/display.cpp index 5e24843dcf1..e34b45985f4 100644 --- a/esphome/components/haier/switch/display.cpp +++ b/esphome/components/haier/switch/display.cpp @@ -1,7 +1,6 @@ #include "display.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void DisplaySwitch::write_state(bool state) { if (this->parent_->get_display_state() != state) { @@ -10,5 +9,4 @@ void DisplaySwitch::write_state(bool state) { this->publish_state(state); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/display.h b/esphome/components/haier/switch/display.h index f93ccfcdb7e..9baf3b9fb8c 100644 --- a/esphome/components/haier/switch/display.h +++ b/esphome/components/haier/switch/display.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "../haier_base.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class DisplaySwitch : public switch_::Switch, public Parented { public: @@ -14,5 +13,4 @@ class DisplaySwitch : public switch_::Switch, public Parented void write_state(bool state) override; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/health_mode.cpp b/esphome/components/haier/switch/health_mode.cpp index 3715759bdd0..c8656fe0d4e 100644 --- a/esphome/components/haier/switch/health_mode.cpp +++ b/esphome/components/haier/switch/health_mode.cpp @@ -1,7 +1,6 @@ #include "health_mode.h" -namespace esphome { -namespace haier { +namespace esphome::haier { void HealthModeSwitch::write_state(bool state) { if (this->parent_->get_health_mode() != state) { @@ -10,5 +9,4 @@ void HealthModeSwitch::write_state(bool state) { this->publish_state(state); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/health_mode.h b/esphome/components/haier/switch/health_mode.h index cfd2aa2f226..ec77b1638aa 100644 --- a/esphome/components/haier/switch/health_mode.h +++ b/esphome/components/haier/switch/health_mode.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "../haier_base.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class HealthModeSwitch : public switch_::Switch, public Parented { public: @@ -14,5 +13,4 @@ class HealthModeSwitch : public switch_::Switch, public Parentedparent_->get_quiet_mode_state() != state) { @@ -10,5 +9,4 @@ void QuietModeSwitch::write_state(bool state) { this->publish_state(state); } -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/haier/switch/quiet_mode.h b/esphome/components/haier/switch/quiet_mode.h index bad52895008..8ef7b5bb894 100644 --- a/esphome/components/haier/switch/quiet_mode.h +++ b/esphome/components/haier/switch/quiet_mode.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "../hon_climate.h" -namespace esphome { -namespace haier { +namespace esphome::haier { class QuietModeSwitch : public switch_::Switch, public Parented { public: @@ -14,5 +13,4 @@ class QuietModeSwitch : public switch_::Switch, public Parented { void write_state(bool state) override; }; -} // namespace haier -} // namespace esphome +} // namespace esphome::haier diff --git a/esphome/components/havells_solar/havells_solar.cpp b/esphome/components/havells_solar/havells_solar.cpp index 20dddf39ed0..9257a37fd92 100644 --- a/esphome/components/havells_solar/havells_solar.cpp +++ b/esphome/components/havells_solar/havells_solar.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace havells_solar { +namespace esphome::havells_solar { static const char *const TAG = "havells_solar"; @@ -164,5 +163,4 @@ void HavellsSolar::dump_config() { LOG_SENSOR(" ", "DCI Of T", this->dci_of_t_sensor_); } -} // namespace havells_solar -} // namespace esphome +} // namespace esphome::havells_solar diff --git a/esphome/components/havells_solar/havells_solar.h b/esphome/components/havells_solar/havells_solar.h index f3ac8fafcfc..c54b0dcf148 100644 --- a/esphome/components/havells_solar/havells_solar.h +++ b/esphome/components/havells_solar/havells_solar.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace havells_solar { +namespace esphome::havells_solar { class HavellsSolar : public PollingComponent, public modbus::ModbusDevice { public: @@ -113,5 +112,4 @@ class HavellsSolar : public PollingComponent, public modbus::ModbusDevice { sensor::Sensor *dci_of_t_sensor_{nullptr}; }; -} // namespace havells_solar -} // namespace esphome +} // namespace esphome::havells_solar diff --git a/esphome/components/havells_solar/havells_solar_registers.h b/esphome/components/havells_solar/havells_solar_registers.h index 8e1cb3ec7af..4ed797b3e7a 100644 --- a/esphome/components/havells_solar/havells_solar_registers.h +++ b/esphome/components/havells_solar/havells_solar_registers.h @@ -1,6 +1,6 @@ #pragma once -namespace esphome { -namespace havells_solar { + +namespace esphome::havells_solar { static const float TWO_DEC_UNIT = 0.01; static const float ONE_DEC_UNIT = 0.1; @@ -45,5 +45,4 @@ static const uint16_t HAVELLS_GFCI_VALUE = 0x002A; static const uint16_t HAVELLS_DCI_OF_R = 0x002B; static const uint16_t HAVELLS_DCI_OF_S = 0x002C; static const uint16_t HAVELLS_DCI_OF_T = 0x002D; -} // namespace havells_solar -} // namespace esphome +} // namespace esphome::havells_solar diff --git a/esphome/components/hbridge/fan/hbridge_fan.cpp b/esphome/components/hbridge/fan/hbridge_fan.cpp index d548128b99b..fc2a738e8d5 100644 --- a/esphome/components/hbridge/fan/hbridge_fan.cpp +++ b/esphome/components/hbridge/fan/hbridge_fan.cpp @@ -1,8 +1,7 @@ #include "hbridge_fan.h" #include "esphome/core/log.h" -namespace esphome { -namespace hbridge { +namespace esphome::hbridge { static const char *const TAG = "fan.hbridge"; @@ -93,5 +92,4 @@ void HBridgeFan::write_state_() { this->oscillating_->set_state(this->oscillating); } -} // namespace hbridge -} // namespace esphome +} // namespace esphome::hbridge diff --git a/esphome/components/hbridge/fan/hbridge_fan.h b/esphome/components/hbridge/fan/hbridge_fan.h index 997f66ae486..62149d99cd0 100644 --- a/esphome/components/hbridge/fan/hbridge_fan.h +++ b/esphome/components/hbridge/fan/hbridge_fan.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace hbridge { +namespace esphome::hbridge { enum DecayMode { DECAY_MODE_SLOW = 0, @@ -56,5 +55,4 @@ template class BrakeAction : public Action { HBridgeFan *parent_; }; -} // namespace hbridge -} // namespace esphome +} // namespace esphome::hbridge diff --git a/esphome/components/hbridge/light/hbridge_light_output.h b/esphome/components/hbridge/light/hbridge_light_output.h index 4e064d53522..16408f24f1b 100644 --- a/esphome/components/hbridge/light/hbridge_light_output.h +++ b/esphome/components/hbridge/light/hbridge_light_output.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace hbridge { +namespace esphome::hbridge { class HBridgeLightOutput : public Component, public light::LightOutput { public: @@ -68,5 +67,4 @@ class HBridgeLightOutput : public Component, public light::LightOutput { HighFrequencyLoopRequester high_freq_; }; -} // namespace hbridge -} // namespace esphome +} // namespace esphome::hbridge diff --git a/esphome/components/hbridge/switch/hbridge_switch.cpp b/esphome/components/hbridge/switch/hbridge_switch.cpp index 55012fed211..1012a264f24 100644 --- a/esphome/components/hbridge/switch/hbridge_switch.cpp +++ b/esphome/components/hbridge/switch/hbridge_switch.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace hbridge { +namespace esphome::hbridge { static const char *const TAG = "switch.hbridge"; @@ -89,5 +88,4 @@ void HBridgeSwitch::timer_fn_() { this->timer_running_ = false; } -} // namespace hbridge -} // namespace esphome +} // namespace esphome::hbridge diff --git a/esphome/components/hbridge/switch/hbridge_switch.h b/esphome/components/hbridge/switch/hbridge_switch.h index ce00c6baa2a..de867271fe2 100644 --- a/esphome/components/hbridge/switch/hbridge_switch.h +++ b/esphome/components/hbridge/switch/hbridge_switch.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace hbridge { +namespace esphome::hbridge { enum RelayState : uint8_t { RELAY_STATE_OFF = 0, @@ -46,5 +45,4 @@ class HBridgeSwitch : public switch_::Switch, public Component { bool optimistic_{false}; }; -} // namespace hbridge -} // namespace esphome +} // namespace esphome::hbridge diff --git a/esphome/components/hdc1080/hdc1080.cpp b/esphome/components/hdc1080/hdc1080.cpp index fa293f6fc5e..6692345e62e 100644 --- a/esphome/components/hdc1080/hdc1080.cpp +++ b/esphome/components/hdc1080/hdc1080.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace hdc1080 { +namespace esphome::hdc1080 { static const char *const TAG = "hdc1080"; @@ -78,5 +77,4 @@ void HDC1080Component::update() { }); } -} // namespace hdc1080 -} // namespace esphome +} // namespace esphome::hdc1080 diff --git a/esphome/components/hdc1080/hdc1080.h b/esphome/components/hdc1080/hdc1080.h index a5bece82c49..1e3bf777888 100644 --- a/esphome/components/hdc1080/hdc1080.h +++ b/esphome/components/hdc1080/hdc1080.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace hdc1080 { +namespace esphome::hdc1080 { class HDC1080Component : public PollingComponent, public i2c::I2CDevice { public: @@ -21,5 +20,4 @@ class HDC1080Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_{nullptr}; }; -} // namespace hdc1080 -} // namespace esphome +} // namespace esphome::hdc1080 diff --git a/esphome/components/hdc2010/hdc2010.cpp b/esphome/components/hdc2010/hdc2010.cpp index 0334b30eeca..946cf4898f1 100644 --- a/esphome/components/hdc2010/hdc2010.cpp +++ b/esphome/components/hdc2010/hdc2010.cpp @@ -2,8 +2,8 @@ #include "hdc2010.h" // https://github.com/vigsterkr/homebridge-hdc2010/blob/main/src/hdc2010.js // https://github.com/lime-labs/HDC2080-Arduino/blob/master/src/HDC2080.cpp -namespace esphome { -namespace hdc2010 { + +namespace esphome::hdc2010 { static const char *const TAG = "hdc2010"; @@ -93,5 +93,4 @@ float HDC2010Component::read_humidity() { return (float) humidity * 0.001525879f; } -} // namespace hdc2010 -} // namespace esphome +} // namespace esphome::hdc2010 diff --git a/esphome/components/hdc2010/hdc2010.h b/esphome/components/hdc2010/hdc2010.h index 52c00686e65..ad6df3ff48d 100644 --- a/esphome/components/hdc2010/hdc2010.h +++ b/esphome/components/hdc2010/hdc2010.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace hdc2010 { +namespace esphome::hdc2010 { class HDC2010Component : public PollingComponent, public i2c::I2CDevice { public: @@ -28,5 +27,4 @@ class HDC2010Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace hdc2010 -} // namespace esphome +} // namespace esphome::hdc2010 diff --git a/esphome/components/he60r/he60r.cpp b/esphome/components/he60r/he60r.cpp index 47440cc1f73..84edbb2866a 100644 --- a/esphome/components/he60r/he60r.cpp +++ b/esphome/components/he60r/he60r.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace he60r { +namespace esphome::he60r { static const char *const TAG = "he60r.cover"; static const uint8_t QUERY_BYTE = 0x38; @@ -264,5 +263,4 @@ void HE60rCover::recompute_position_() { } } -} // namespace he60r -} // namespace esphome +} // namespace esphome::he60r diff --git a/esphome/components/he60r/he60r.h b/esphome/components/he60r/he60r.h index 02a2b44e66f..e7b5c97969d 100644 --- a/esphome/components/he60r/he60r.h +++ b/esphome/components/he60r/he60r.h @@ -5,8 +5,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace he60r { +namespace esphome::he60r { class HE60rCover : public cover::Cover, public Component, public uart::UARTDevice { public: @@ -41,5 +40,4 @@ class HE60rCover : public cover::Cover, public Component, public uart::UARTDevic uint8_t counter_{}; }; -} // namespace he60r -} // namespace esphome +} // namespace esphome::he60r diff --git a/esphome/components/heatpumpir/heatpumpir.cpp b/esphome/components/heatpumpir/heatpumpir.cpp index 11e7672dc13..8e9a2c52985 100644 --- a/esphome/components/heatpumpir/heatpumpir.cpp +++ b/esphome/components/heatpumpir/heatpumpir.cpp @@ -8,8 +8,7 @@ #include "esphome/components/remote_base/remote_base.h" #include "esphome/core/log.h" -namespace esphome { -namespace heatpumpir { +namespace esphome::heatpumpir { // IRSenderESPHome - bridge between ESPHome's remote_transmitter and HeatpumpIR library // Defined here (not in a header) to isolate HeatpumpIR's headers from the rest of ESPHome, @@ -243,7 +242,6 @@ void HeatpumpIRClimate::transmit_state() { swing_h_cmd); } -} // namespace heatpumpir -} // namespace esphome +} // namespace esphome::heatpumpir #endif diff --git a/esphome/components/heatpumpir/heatpumpir.h b/esphome/components/heatpumpir/heatpumpir.h index 6270dd1e5af..a277424df6b 100644 --- a/esphome/components/heatpumpir/heatpumpir.h +++ b/esphome/components/heatpumpir/heatpumpir.h @@ -8,8 +8,7 @@ // that conflict with ESPHome. class HeatpumpIR; -namespace esphome { -namespace heatpumpir { +namespace esphome::heatpumpir { // Simple enum to represent protocols. enum Protocol { @@ -126,7 +125,6 @@ class HeatpumpIRClimate : public climate_ir::ClimateIR { float min_temperature_; }; -} // namespace heatpumpir -} // namespace esphome +} // namespace esphome::heatpumpir #endif diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.cpp b/esphome/components/hitachi_ac344/hitachi_ac344.cpp index 69469cab2ea..ea211a7a59b 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.cpp +++ b/esphome/components/hitachi_ac344/hitachi_ac344.cpp @@ -1,7 +1,6 @@ #include "hitachi_ac344.h" -namespace esphome { -namespace hitachi_ac344 { +namespace esphome::hitachi_ac344 { static const char *const TAG = "climate.hitachi_ac344"; @@ -366,5 +365,4 @@ void HitachiClimate::dump_state_(const char action[], uint8_t state[]) { ESP_LOGV(TAG, "%s: %02X %02X %02X", action, state[40], state[41], state[42]); } -} // namespace hitachi_ac344 -} // namespace esphome +} // namespace esphome::hitachi_ac344 diff --git a/esphome/components/hitachi_ac344/hitachi_ac344.h b/esphome/components/hitachi_ac344/hitachi_ac344.h index 0877b832617..b9d776cc59d 100644 --- a/esphome/components/hitachi_ac344/hitachi_ac344.h +++ b/esphome/components/hitachi_ac344/hitachi_ac344.h @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace hitachi_ac344 { +namespace esphome::hitachi_ac344 { const uint16_t HITACHI_AC344_HDR_MARK = 3300; // ac const uint16_t HITACHI_AC344_HDR_SPACE = 1700; // ac @@ -117,5 +116,4 @@ class HitachiClimate : public climate_ir::ClimateIR { void dump_state_(const char action[], uint8_t remote_state[]); }; -} // namespace hitachi_ac344 -} // namespace esphome +} // namespace esphome::hitachi_ac344 diff --git a/esphome/components/hitachi_ac424/hitachi_ac424.cpp b/esphome/components/hitachi_ac424/hitachi_ac424.cpp index 0b3cc99a82b..cdf8dda22ce 100644 --- a/esphome/components/hitachi_ac424/hitachi_ac424.cpp +++ b/esphome/components/hitachi_ac424/hitachi_ac424.cpp @@ -1,7 +1,6 @@ #include "hitachi_ac424.h" -namespace esphome { -namespace hitachi_ac424 { +namespace esphome::hitachi_ac424 { static const char *const TAG = "climate.hitachi_ac424"; @@ -367,5 +366,4 @@ void HitachiClimate::dump_state_(const char action[], uint8_t state[]) { ESP_LOGV(TAG, "%s: %02X %02X %02X", action, state[40], state[41], state[42]); } -} // namespace hitachi_ac424 -} // namespace esphome +} // namespace esphome::hitachi_ac424 diff --git a/esphome/components/hitachi_ac424/hitachi_ac424.h b/esphome/components/hitachi_ac424/hitachi_ac424.h index 1005aa6df79..ef7f128a5a2 100644 --- a/esphome/components/hitachi_ac424/hitachi_ac424.h +++ b/esphome/components/hitachi_ac424/hitachi_ac424.h @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace hitachi_ac424 { +namespace esphome::hitachi_ac424 { const uint16_t HITACHI_AC424_HDR_MARK = 3416; // ac const uint16_t HITACHI_AC424_HDR_SPACE = 1604; // ac @@ -119,5 +118,4 @@ class HitachiClimate : public climate_ir::ClimateIR { void dump_state_(const char action[], uint8_t remote_state[]); }; -} // namespace hitachi_ac424 -} // namespace esphome +} // namespace esphome::hitachi_ac424 diff --git a/esphome/components/hlw8012/hlw8012.cpp b/esphome/components/hlw8012/hlw8012.cpp index 22f292e47e1..c92c76a20ad 100644 --- a/esphome/components/hlw8012/hlw8012.cpp +++ b/esphome/components/hlw8012/hlw8012.cpp @@ -1,8 +1,7 @@ #include "hlw8012.h" #include "esphome/core/log.h" -namespace esphome { -namespace hlw8012 { +namespace esphome::hlw8012 { static const char *const TAG = "hlw8012"; @@ -104,5 +103,4 @@ void HLW8012Component::update() { } } -} // namespace hlw8012 -} // namespace esphome +} // namespace esphome::hlw8012 diff --git a/esphome/components/hlw8012/hlw8012.h b/esphome/components/hlw8012/hlw8012.h index 8a13ec07d8e..d1d340bf45d 100644 --- a/esphome/components/hlw8012/hlw8012.h +++ b/esphome/components/hlw8012/hlw8012.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace hlw8012 { +namespace esphome::hlw8012 { enum HLW8012InitialMode { HLW8012_INITIAL_MODE_CURRENT = 0, HLW8012_INITIAL_MODE_VOLTAGE }; @@ -72,5 +71,4 @@ class HLW8012Component : public PollingComponent { float power_multiplier_{0.0f}; }; -} // namespace hlw8012 -} // namespace esphome +} // namespace esphome::hlw8012 diff --git a/esphome/components/hm3301/hm3301.cpp b/esphome/components/hm3301/hm3301.cpp index 9343b47823f..f46a6b85806 100644 --- a/esphome/components/hm3301/hm3301.cpp +++ b/esphome/components/hm3301/hm3301.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "hm3301.h" -namespace esphome { -namespace hm3301 { +namespace esphome::hm3301 { static const char *const TAG = "hm3301.sensor"; @@ -94,5 +93,4 @@ uint16_t HM3301Component::get_sensor_value_(const uint8_t *data, uint8_t i) { return (uint16_t) data[i * 2] << 8 | data[i * 2 + 1]; } -} // namespace hm3301 -} // namespace esphome +} // namespace esphome::hm3301 diff --git a/esphome/components/hm3301/hm3301.h b/esphome/components/hm3301/hm3301.h index 6b10a5e2373..55e708e34a1 100644 --- a/esphome/components/hm3301/hm3301.h +++ b/esphome/components/hm3301/hm3301.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/aqi/aqi_calculator_factory.h" -namespace esphome { -namespace hm3301 { +namespace esphome::hm3301 { static const uint8_t SELECT_COMM_CMD = 0x88; @@ -47,5 +46,4 @@ class HM3301Component : public PollingComponent, public i2c::I2CDevice { uint16_t get_sensor_value_(const uint8_t *data, uint8_t i); }; -} // namespace hm3301 -} // namespace esphome +} // namespace esphome::hm3301 diff --git a/esphome/components/hmac_md5/hmac_md5.cpp b/esphome/components/hmac_md5/hmac_md5.cpp index d766a55fabb..49a55592d33 100644 --- a/esphome/components/hmac_md5/hmac_md5.cpp +++ b/esphome/components/hmac_md5/hmac_md5.cpp @@ -4,8 +4,7 @@ #ifdef USE_MD5 #include "esphome/core/helpers.h" -namespace esphome { -namespace hmac_md5 { +namespace esphome::hmac_md5 { void HmacMD5::init(const uint8_t *key, size_t len) { uint8_t ipad[64], opad[64]; @@ -53,6 +52,6 @@ bool HmacMD5::equals_bytes(const uint8_t *expected) { return this->ohash_.equals bool HmacMD5::equals_hex(const char *expected) { return this->ohash_.equals_hex(expected); } -} // namespace hmac_md5 -} // namespace esphome +} // namespace esphome::hmac_md5 + #endif diff --git a/esphome/components/hmac_md5/hmac_md5.h b/esphome/components/hmac_md5/hmac_md5.h index fb9479e3afa..c2fd7f28009 100644 --- a/esphome/components/hmac_md5/hmac_md5.h +++ b/esphome/components/hmac_md5/hmac_md5.h @@ -5,8 +5,7 @@ #include "esphome/components/md5/md5.h" #include -namespace esphome { -namespace hmac_md5 { +namespace esphome::hmac_md5 { class HmacMD5 { public: @@ -44,6 +43,6 @@ class HmacMD5 { md5::MD5Digest ohash_; }; -} // namespace hmac_md5 -} // namespace esphome +} // namespace esphome::hmac_md5 + #endif diff --git a/esphome/components/hmc5883l/hmc5883l.cpp b/esphome/components/hmc5883l/hmc5883l.cpp index bee52821255..7930df7a38c 100644 --- a/esphome/components/hmc5883l/hmc5883l.cpp +++ b/esphome/components/hmc5883l/hmc5883l.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace hmc5883l { +namespace esphome::hmc5883l { static const char *const TAG = "hmc5883l"; static const uint8_t HMC5883L_ADDRESS = 0x1E; @@ -140,5 +139,4 @@ void HMC5883LComponent::update() { this->heading_sensor_->publish_state(heading); } -} // namespace hmc5883l -} // namespace esphome +} // namespace esphome::hmc5883l diff --git a/esphome/components/hmc5883l/hmc5883l.h b/esphome/components/hmc5883l/hmc5883l.h index b5cf93e62b8..4f170d74015 100644 --- a/esphome/components/hmc5883l/hmc5883l.h +++ b/esphome/components/hmc5883l/hmc5883l.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace hmc5883l { +namespace esphome::hmc5883l { enum HMC5883LOversampling { HMC5883L_OVERSAMPLING_1 = 0b000, @@ -65,5 +64,4 @@ class HMC5883LComponent : public PollingComponent, public i2c::I2CDevice { HighFrequencyLoopRequester high_freq_; }; -} // namespace hmc5883l -} // namespace esphome +} // namespace esphome::hmc5883l diff --git a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp index b0d91358220..735fb9f5da1 100644 --- a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp +++ b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.binary_sensor"; @@ -43,5 +42,4 @@ void HomeassistantBinarySensor::dump_config() { } float HomeassistantBinarySensor::get_setup_priority() const { return setup_priority::AFTER_WIFI; } -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.h b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.h index 9aec61a3701..6d95ea2c609 100644 --- a/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.h +++ b/esphome/components/homeassistant/binary_sensor/homeassistant_binary_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantBinarySensor : public binary_sensor::BinarySensor, public Component { public: @@ -20,5 +19,4 @@ class HomeassistantBinarySensor : public binary_sensor::BinarySensor, public Com bool initial_{true}; }; -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/number/homeassistant_number.cpp b/esphome/components/homeassistant/number/homeassistant_number.cpp index da802b7fe9f..965f91d202b 100644 --- a/esphome/components/homeassistant/number/homeassistant_number.cpp +++ b/esphome/components/homeassistant/number/homeassistant_number.cpp @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.number"; @@ -103,5 +102,4 @@ void HomeassistantNumber::control(float value) { api::global_api_server->send_homeassistant_action(resp); } -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/number/homeassistant_number.h b/esphome/components/homeassistant/number/homeassistant_number.h index 275d2d5f03f..a1e351fdf45 100644 --- a/esphome/components/homeassistant/number/homeassistant_number.h +++ b/esphome/components/homeassistant/number/homeassistant_number.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantNumber : public number::Number, public Component { public: @@ -25,5 +24,4 @@ class HomeassistantNumber : public number::Number, public Component { const char *entity_id_{nullptr}; }; -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp b/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp index 66300ebba54..112795a4ff8 100644 --- a/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp +++ b/esphome/components/homeassistant/sensor/homeassistant_sensor.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.sensor"; @@ -34,5 +33,4 @@ void HomeassistantSensor::dump_config() { } float HomeassistantSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; } -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/sensor/homeassistant_sensor.h b/esphome/components/homeassistant/sensor/homeassistant_sensor.h index d89fc069ff2..afc49355378 100644 --- a/esphome/components/homeassistant/sensor/homeassistant_sensor.h +++ b/esphome/components/homeassistant/sensor/homeassistant_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantSensor : public sensor::Sensor, public Component { public: @@ -19,5 +18,4 @@ class HomeassistantSensor : public sensor::Sensor, public Component { const char *attribute_{nullptr}; }; -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/switch/homeassistant_switch.cpp b/esphome/components/homeassistant/switch/homeassistant_switch.cpp index cc3d582bf30..8a4ea19f2e5 100644 --- a/esphome/components/homeassistant/switch/homeassistant_switch.cpp +++ b/esphome/components/homeassistant/switch/homeassistant_switch.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.switch"; @@ -60,5 +59,4 @@ void HomeassistantSwitch::write_state(bool state) { api::global_api_server->send_homeassistant_action(resp); } -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/switch/homeassistant_switch.h b/esphome/components/homeassistant/switch/homeassistant_switch.h index c180b7f98a1..c6c178c205b 100644 --- a/esphome/components/homeassistant/switch/homeassistant_switch.h +++ b/esphome/components/homeassistant/switch/homeassistant_switch.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/core/component.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantSwitch : public switch_::Switch, public Component { public: @@ -18,5 +17,4 @@ class HomeassistantSwitch : public switch_::Switch, public Component { const char *entity_id_{nullptr}; }; -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp index 109574e0c8e..40d7455ece1 100644 --- a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp +++ b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/string_ref.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.text_sensor"; @@ -26,5 +25,4 @@ void HomeassistantTextSensor::dump_config() { } } float HomeassistantTextSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; } -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.h b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.h index 4d66c65a17a..8af81cefcb7 100644 --- a/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.h +++ b/esphome/components/homeassistant/text_sensor/homeassistant_text_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantTextSensor : public text_sensor::TextSensor, public Component { public: @@ -19,5 +18,4 @@ class HomeassistantTextSensor : public text_sensor::TextSensor, public Component const char *attribute_{nullptr}; }; -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/time/homeassistant_time.cpp b/esphome/components/homeassistant/time/homeassistant_time.cpp index d0398920736..c08bd73d625 100644 --- a/esphome/components/homeassistant/time/homeassistant_time.cpp +++ b/esphome/components/homeassistant/time/homeassistant_time.cpp @@ -1,8 +1,7 @@ #include "homeassistant_time.h" #include "esphome/core/log.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { static const char *const TAG = "homeassistant.time"; @@ -16,5 +15,4 @@ void HomeassistantTime::setup() { global_homeassistant_time = this; } void HomeassistantTime::update() { api::global_api_server->request_time(); } HomeassistantTime *global_homeassistant_time = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/homeassistant/time/homeassistant_time.h b/esphome/components/homeassistant/time/homeassistant_time.h index 455ded20226..77edb50cd09 100644 --- a/esphome/components/homeassistant/time/homeassistant_time.h +++ b/esphome/components/homeassistant/time/homeassistant_time.h @@ -4,8 +4,7 @@ #include "esphome/components/time/real_time_clock.h" #include "esphome/components/api/api_server.h" -namespace esphome { -namespace homeassistant { +namespace esphome::homeassistant { class HomeassistantTime final : public time::RealTimeClock { public: @@ -17,5 +16,4 @@ class HomeassistantTime final : public time::RealTimeClock { extern HomeassistantTime *global_homeassistant_time; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace homeassistant -} // namespace esphome +} // namespace esphome::homeassistant diff --git a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp index 904672d1369..7f075847fdc 100644 --- a/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp +++ b/esphome/components/honeywell_hih_i2c/honeywell_hih.cpp @@ -5,8 +5,7 @@ #include "honeywell_hih.h" #include "esphome/core/log.h" -namespace esphome { -namespace honeywell_hih_i2c { +namespace esphome::honeywell_hih_i2c { static const char *const TAG = "honeywell_hih.i2c"; @@ -91,5 +90,4 @@ void HoneywellHIComponent::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace honeywell_hih_i2c -} // namespace esphome +} // namespace esphome::honeywell_hih_i2c diff --git a/esphome/components/honeywell_hih_i2c/honeywell_hih.h b/esphome/components/honeywell_hih_i2c/honeywell_hih.h index 79140f7399e..d9ea6401ce0 100644 --- a/esphome/components/honeywell_hih_i2c/honeywell_hih.h +++ b/esphome/components/honeywell_hih_i2c/honeywell_hih.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace honeywell_hih_i2c { +namespace esphome::honeywell_hih_i2c { class HoneywellHIComponent : public PollingComponent, public i2c::I2CDevice { public: @@ -29,5 +28,4 @@ class HoneywellHIComponent : public PollingComponent, public i2c::I2CDevice { void measurement_timeout_(); }; -} // namespace honeywell_hih_i2c -} // namespace esphome +} // namespace esphome::honeywell_hih_i2c diff --git a/esphome/components/honeywellabp/honeywellabp.cpp b/esphome/components/honeywellabp/honeywellabp.cpp index 58c5df230f4..8bfc5e4f4f8 100644 --- a/esphome/components/honeywellabp/honeywellabp.cpp +++ b/esphome/components/honeywellabp/honeywellabp.cpp @@ -1,8 +1,7 @@ #include "honeywellabp.h" #include "esphome/core/log.h" -namespace esphome { -namespace honeywellabp { +namespace esphome::honeywellabp { static const char *const TAG = "honeywellabp"; @@ -96,5 +95,4 @@ void HONEYWELLABPSensor::set_honeywellabp_max_pressure(float max_pressure) { this->honeywellabp_max_pressure_ = max_pressure; } -} // namespace honeywellabp -} // namespace esphome +} // namespace esphome::honeywellabp diff --git a/esphome/components/honeywellabp/honeywellabp.h b/esphome/components/honeywellabp/honeywellabp.h index 98f6f08c4a3..3c31968c490 100644 --- a/esphome/components/honeywellabp/honeywellabp.h +++ b/esphome/components/honeywellabp/honeywellabp.h @@ -6,8 +6,7 @@ #include "esphome/components/spi/spi.h" #include "esphome/core/component.h" -namespace esphome { -namespace honeywellabp { +namespace esphome::honeywellabp { class HONEYWELLABPSensor : public PollingComponent, public spi::SPIDevicecheck_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); } -} // namespace hrxl_maxsonar_wr -} // namespace esphome +} // namespace esphome::hrxl_maxsonar_wr diff --git a/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.h b/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.h index efb8bc5f4b2..e98eeea723b 100644 --- a/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.h +++ b/esphome/components/hrxl_maxsonar_wr/hrxl_maxsonar_wr.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace hrxl_maxsonar_wr { +namespace esphome::hrxl_maxsonar_wr { class HrxlMaxsonarWrComponent : public sensor::Sensor, public Component, public uart::UARTDevice { public: @@ -21,5 +20,4 @@ class HrxlMaxsonarWrComponent : public sensor::Sensor, public Component, public std::string buffer_; }; -} // namespace hrxl_maxsonar_wr -} // namespace esphome +} // namespace esphome::hrxl_maxsonar_wr diff --git a/esphome/components/hte501/hte501.cpp b/esphome/components/hte501/hte501.cpp index ef9ef1fabf7..67bfb1917eb 100644 --- a/esphome/components/hte501/hte501.cpp +++ b/esphome/components/hte501/hte501.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace hte501 { +namespace esphome::hte501 { static const char *const TAG = "hte501"; @@ -71,5 +70,4 @@ void HTE501Component::update() { this->status_clear_warning(); }); } -} // namespace hte501 -} // namespace esphome +} // namespace esphome::hte501 diff --git a/esphome/components/hte501/hte501.h b/esphome/components/hte501/hte501.h index 7f29885f49d..310073f88b9 100644 --- a/esphome/components/hte501/hte501.h +++ b/esphome/components/hte501/hte501.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace hte501 { +namespace esphome::hte501 { /// This class implements support for the hte501 of temperature i2c sensors. class HTE501Component : public PollingComponent, public i2c::I2CDevice { @@ -24,5 +23,4 @@ class HTE501Component : public PollingComponent, public i2c::I2CDevice { enum ErrorCode { NONE = 0, COMMUNICATION_FAILED, CRC_CHECK_FAILED } error_code_{NONE}; }; -} // namespace hte501 -} // namespace esphome +} // namespace esphome::hte501 diff --git a/esphome/components/http_request/ota/automation.h b/esphome/components/http_request/ota/automation.h index 6c50bb9b0d9..f6f49b14b1a 100644 --- a/esphome/components/http_request/ota/automation.h +++ b/esphome/components/http_request/ota/automation.h @@ -3,8 +3,7 @@ #include "esphome/core/automation.h" -namespace esphome { -namespace http_request { +namespace esphome::http_request { template class OtaHttpRequestComponentFlashAction : public Action { public: @@ -38,5 +37,4 @@ template class OtaHttpRequestComponentFlashAction : public Actio OtaHttpRequestComponent *parent_; }; -} // namespace http_request -} // namespace esphome +} // namespace esphome::http_request diff --git a/esphome/components/http_request/ota/ota_http_request.cpp b/esphome/components/http_request/ota/ota_http_request.cpp index 5dd21c314c6..8893b96c65b 100644 --- a/esphome/components/http_request/ota/ota_http_request.cpp +++ b/esphome/components/http_request/ota/ota_http_request.cpp @@ -9,8 +9,7 @@ #include "esphome/components/md5/md5.h" #include "esphome/components/watchdog/watchdog.h" -namespace esphome { -namespace http_request { +namespace esphome::http_request { static const char *const TAG = "http_request.ota"; @@ -297,5 +296,4 @@ bool OtaHttpRequestComponent::validate_url_(const std::string &url) { return true; } -} // namespace http_request -} // namespace esphome +} // namespace esphome::http_request diff --git a/esphome/components/http_request/ota/ota_http_request.h b/esphome/components/http_request/ota/ota_http_request.h index 70e4559fa7c..a706331d9ac 100644 --- a/esphome/components/http_request/ota/ota_http_request.h +++ b/esphome/components/http_request/ota/ota_http_request.h @@ -11,8 +11,7 @@ #include "../http_request.h" -namespace esphome { -namespace http_request { +namespace esphome::http_request { static const uint8_t MD5_SIZE = 32; @@ -56,5 +55,4 @@ class OtaHttpRequestComponent final : public ota::OTAComponent, public Parented< static const uint16_t HTTP_RECV_BUFFER = 256; // the firmware GET chunk size }; -} // namespace http_request -} // namespace esphome +} // namespace esphome::http_request diff --git a/esphome/components/http_request/update/http_request_update.cpp b/esphome/components/http_request/update/http_request_update.cpp index 1c52a281059..57dc86d55cf 100644 --- a/esphome/components/http_request/update/http_request_update.cpp +++ b/esphome/components/http_request/update/http_request_update.cpp @@ -6,8 +6,7 @@ #include "esphome/components/json/json_util.h" #include "esphome/components/network/util.h" -namespace esphome { -namespace http_request { +namespace esphome::http_request { // The update function runs in a task only on ESP32s. #ifdef USE_ESP32 @@ -258,5 +257,4 @@ void HttpRequestUpdate::perform(bool force) { this->defer([this]() { this->ota_parent_->flash(); }); } -} // namespace http_request -} // namespace esphome +} // namespace esphome::http_request diff --git a/esphome/components/http_request/update/http_request_update.h b/esphome/components/http_request/update/http_request_update.h index b8350346f9e..be9fbf72bfd 100644 --- a/esphome/components/http_request/update/http_request_update.h +++ b/esphome/components/http_request/update/http_request_update.h @@ -11,8 +11,7 @@ #include #endif -namespace esphome { -namespace http_request { +namespace esphome::http_request { class HttpRequestUpdate final : public update::UpdateEntity, public PollingComponent, public ota::OTAStateListener { public: @@ -43,5 +42,4 @@ class HttpRequestUpdate final : public update::UpdateEntity, public PollingCompo uint8_t initial_check_remaining_{0}; }; -} // namespace http_request -} // namespace esphome +} // namespace esphome::http_request diff --git a/esphome/components/htu21d/htu21d.cpp b/esphome/components/htu21d/htu21d.cpp index 58a28b213f7..8a3b2cb5d5c 100644 --- a/esphome/components/htu21d/htu21d.cpp +++ b/esphome/components/htu21d/htu21d.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace htu21d { +namespace esphome::htu21d { static const char *const TAG = "htu21d"; @@ -143,5 +142,4 @@ uint8_t HTU21DComponent::get_heater_level() { return raw_heater & 0xF; } -} // namespace htu21d -} // namespace esphome +} // namespace esphome::htu21d diff --git a/esphome/components/htu21d/htu21d.h b/esphome/components/htu21d/htu21d.h index 594be783261..a111722dc79 100644 --- a/esphome/components/htu21d/htu21d.h +++ b/esphome/components/htu21d/htu21d.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/automation.h" -namespace esphome { -namespace htu21d { +namespace esphome::htu21d { enum HTU21DSensorModels { HTU21D_SENSOR_MODEL_HTU21D = 0, HTU21D_SENSOR_MODEL_SI7021, HTU21D_SENSOR_MODEL_SHT21 }; @@ -57,5 +56,4 @@ template class SetHeaterAction : public Action, public Pa } }; -} // namespace htu21d -} // namespace esphome +} // namespace esphome::htu21d diff --git a/esphome/components/htu31d/htu31d.cpp b/esphome/components/htu31d/htu31d.cpp index 4bb38a11a20..0b679bf2b77 100644 --- a/esphome/components/htu31d/htu31d.cpp +++ b/esphome/components/htu31d/htu31d.cpp @@ -14,8 +14,7 @@ #include -namespace esphome { -namespace htu31d { +namespace esphome::htu31d { /** Logging prefix */ static const char *const TAG = "htu31d"; @@ -259,5 +258,4 @@ void HTU31DComponent::set_heater_state(bool desired) { } } -} // namespace htu31d -} // namespace esphome +} // namespace esphome::htu31d diff --git a/esphome/components/htu31d/htu31d.h b/esphome/components/htu31d/htu31d.h index 24d85243cc1..451918cb3bc 100644 --- a/esphome/components/htu31d/htu31d.h +++ b/esphome/components/htu31d/htu31d.h @@ -5,8 +5,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -namespace esphome { -namespace htu31d { +namespace esphome::htu31d { class HTU31DComponent : public PollingComponent, public i2c::I2CDevice { public: @@ -27,5 +26,4 @@ class HTU31DComponent : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *temperature_{nullptr}; sensor::Sensor *humidity_{nullptr}; }; -} // namespace htu31d -} // namespace esphome +} // namespace esphome::htu31d diff --git a/esphome/components/hx711/hx711.cpp b/esphome/components/hx711/hx711.cpp index f2e3234127d..fe2fb4c350b 100644 --- a/esphome/components/hx711/hx711.cpp +++ b/esphome/components/hx711/hx711.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace hx711 { +namespace esphome::hx711 { static const char *const TAG = "hx711"; @@ -77,5 +76,4 @@ bool HX711Sensor::read_sensor_(uint32_t *result) { return true; } -} // namespace hx711 -} // namespace esphome +} // namespace esphome::hx711 diff --git a/esphome/components/hx711/hx711.h b/esphome/components/hx711/hx711.h index 37723ee81fc..43ab4c0f562 100644 --- a/esphome/components/hx711/hx711.h +++ b/esphome/components/hx711/hx711.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace hx711 { +namespace esphome::hx711 { enum HX711Gain : uint8_t { HX711_GAIN_128 = 1, @@ -33,5 +32,4 @@ class HX711Sensor : public sensor::Sensor, public PollingComponent { HX711Gain gain_{HX711_GAIN_128}; }; -} // namespace hx711 -} // namespace esphome +} // namespace esphome::hx711 diff --git a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp index 983a0a66493..695a823cb7a 100644 --- a/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp +++ b/esphome/components/hydreon_rgxx/hydreon_rgxx.cpp @@ -1,8 +1,7 @@ #include "hydreon_rgxx.h" #include "esphome/core/log.h" -namespace esphome { -namespace hydreon_rgxx { +namespace esphome::hydreon_rgxx { static const char *const TAG = "hydreon_rgxx.sensor"; static const int MAX_DATA_LENGTH_BYTES = 80; @@ -284,5 +283,4 @@ void HydreonRGxxComponent::process_line_() { } } -} // namespace hydreon_rgxx -} // namespace esphome +} // namespace esphome::hydreon_rgxx diff --git a/esphome/components/hydreon_rgxx/hydreon_rgxx.h b/esphome/components/hydreon_rgxx/hydreon_rgxx.h index e3f9798a937..2ae46907c15 100644 --- a/esphome/components/hydreon_rgxx/hydreon_rgxx.h +++ b/esphome/components/hydreon_rgxx/hydreon_rgxx.h @@ -8,8 +8,7 @@ #endif #include "esphome/components/uart/uart.h" -namespace esphome { -namespace hydreon_rgxx { +namespace esphome::hydreon_rgxx { enum RGModel { RG9 = 1, @@ -92,5 +91,4 @@ class HydreonRGxxBinaryComponent : public Component { HydreonRGxxBinaryComponent(HydreonRGxxComponent *parent) {} }; -} // namespace hydreon_rgxx -} // namespace esphome +} // namespace esphome::hydreon_rgxx diff --git a/esphome/components/hyt271/hyt271.cpp b/esphome/components/hyt271/hyt271.cpp index 4c0e3cd96e0..7b2c960a5f9 100644 --- a/esphome/components/hyt271/hyt271.cpp +++ b/esphome/components/hyt271/hyt271.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace hyt271 { +namespace esphome::hyt271 { static const char *const TAG = "hyt271"; @@ -46,5 +45,4 @@ void HYT271Component::update() { this->status_clear_warning(); }); } -} // namespace hyt271 -} // namespace esphome +} // namespace esphome::hyt271 diff --git a/esphome/components/hyt271/hyt271.h b/esphome/components/hyt271/hyt271.h index 19409d830cb..d08b3779ad3 100644 --- a/esphome/components/hyt271/hyt271.h +++ b/esphome/components/hyt271/hyt271.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace hyt271 { +namespace esphome::hyt271 { class HYT271Component : public PollingComponent, public i2c::I2CDevice { public: @@ -21,5 +20,4 @@ class HYT271Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *humidity_{nullptr}; }; -} // namespace hyt271 -} // namespace esphome +} // namespace esphome::hyt271 From 56ef35716235e6e6c503e3f74a9399543ac647af Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 May 2026 17:51:30 -0500 Subject: [PATCH 04/52] Bump github/codeql-action from 4.35.3 to 4.35.4 (#16299) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5429434a7f3..949e45e45c9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -58,7 +58,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 + uses: github/codeql-action/init@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -86,6 +86,6 @@ jobs: exit 1 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.35.3 + uses: github/codeql-action/analyze@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4 with: category: "/language:${{matrix.language}}" From cbe192df49f2a2aa3f10ae1b5e9a14cb267b662e Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 19:00:17 -0400 Subject: [PATCH 05/52] [clang-tidy] Concatenate nested namespaces (3/7: components i-m) (#16297) --- esphome/components/i2c_device/i2c_device.cpp | 6 ++---- esphome/components/i2c_device/i2c_device.h | 6 ++---- esphome/components/i2s_audio/i2s_audio.h | 6 ++---- .../i2s_audio/microphone/i2s_audio_microphone.cpp | 6 ++---- .../i2s_audio/microphone/i2s_audio_microphone.h | 6 ++---- esphome/components/iaqcore/iaqcore.cpp | 6 ++---- esphome/components/iaqcore/iaqcore.h | 6 ++---- esphome/components/ili9xxx/ili9xxx_defines.h | 6 ++---- esphome/components/ili9xxx/ili9xxx_display.cpp | 6 ++---- esphome/components/ili9xxx/ili9xxx_display.h | 6 ++---- esphome/components/ili9xxx/ili9xxx_init.h | 6 ++---- esphome/components/image/image.cpp | 6 ++---- esphome/components/image/image.h | 6 ++---- esphome/components/improv_base/improv_base.cpp | 6 ++---- esphome/components/improv_base/improv_base.h | 6 ++---- .../components/improv_serial/improv_serial_component.cpp | 7 +++---- .../components/improv_serial/improv_serial_component.h | 7 +++---- esphome/components/ina219/ina219.cpp | 6 ++---- esphome/components/ina219/ina219.h | 6 ++---- esphome/components/ina226/ina226.cpp | 6 ++---- esphome/components/ina226/ina226.h | 6 ++---- esphome/components/ina260/ina260.cpp | 6 ++---- esphome/components/ina260/ina260.h | 6 ++---- esphome/components/ina2xx_base/ina2xx_base.cpp | 6 ++---- esphome/components/ina2xx_base/ina2xx_base.h | 6 ++---- esphome/components/ina2xx_i2c/ina2xx_i2c.cpp | 6 ++---- esphome/components/ina2xx_i2c/ina2xx_i2c.h | 6 ++---- esphome/components/ina2xx_spi/ina2xx_spi.cpp | 6 ++---- esphome/components/ina2xx_spi/ina2xx_spi.h | 6 ++---- esphome/components/ina3221/ina3221.cpp | 6 ++---- esphome/components/ina3221/ina3221.h | 6 ++---- .../inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp | 6 ++---- .../components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.h | 6 ++---- esphome/components/inkplate/inkplate.cpp | 6 ++---- esphome/components/inkplate/inkplate.h | 6 ++---- esphome/components/integration/integration_sensor.cpp | 6 ++---- esphome/components/integration/integration_sensor.h | 6 ++---- esphome/components/interval/interval.h | 6 ++---- esphome/components/jsn_sr04t/jsn_sr04t.cpp | 6 ++---- esphome/components/jsn_sr04t/jsn_sr04t.h | 6 ++---- esphome/components/json/json_util.cpp | 6 ++---- esphome/components/json/json_util.h | 6 ++---- esphome/components/kamstrup_kmp/kamstrup_kmp.cpp | 6 ++---- esphome/components/kamstrup_kmp/kamstrup_kmp.h | 6 ++---- esphome/components/key_collector/key_collector.cpp | 6 ++---- esphome/components/key_collector/key_collector.h | 6 ++---- esphome/components/key_provider/key_provider.cpp | 6 ++---- esphome/components/key_provider/key_provider.h | 6 ++---- esphome/components/kmeteriso/kmeteriso.cpp | 6 ++---- esphome/components/kmeteriso/kmeteriso.h | 6 ++---- esphome/components/kuntze/kuntze.cpp | 6 ++---- esphome/components/kuntze/kuntze.h | 6 ++---- esphome/components/lc709203f/lc709203f.cpp | 6 ++---- esphome/components/lc709203f/lc709203f.h | 6 ++---- esphome/components/lcd_base/lcd_display.cpp | 6 ++---- esphome/components/lcd_base/lcd_display.h | 6 ++---- esphome/components/lcd_gpio/gpio_lcd_display.cpp | 6 ++---- esphome/components/lcd_gpio/gpio_lcd_display.h | 6 ++---- esphome/components/lcd_menu/lcd_menu.cpp | 6 ++---- esphome/components/lcd_menu/lcd_menu.h | 6 ++---- esphome/components/lcd_pcf8574/pcf8574_display.cpp | 6 ++---- esphome/components/lcd_pcf8574/pcf8574_display.h | 6 ++---- esphome/components/lightwaverf/LwRx.h | 6 ++---- esphome/components/lightwaverf/LwTx.h | 6 ++---- .../lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp | 6 ++---- .../lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.h | 6 ++---- esphome/components/lm75b/lm75b.cpp | 6 ++---- esphome/components/lm75b/lm75b.h | 6 ++---- esphome/components/lps22/lps22.cpp | 6 ++---- esphome/components/lps22/lps22.h | 6 ++---- esphome/components/ltr390/ltr390.cpp | 6 ++---- esphome/components/ltr390/ltr390.h | 6 ++---- esphome/components/ltr501/ltr501.cpp | 6 ++---- esphome/components/ltr501/ltr501.h | 6 ++---- esphome/components/ltr501/ltr_definitions_501.h | 6 ++---- esphome/components/ltr_als_ps/ltr_als_ps.cpp | 6 ++---- esphome/components/ltr_als_ps/ltr_als_ps.h | 6 ++---- esphome/components/ltr_als_ps/ltr_definitions.h | 6 ++---- esphome/components/lvgl/light/lvgl_light.h | 6 ++---- esphome/components/lvgl/lvgl_proxy.h | 6 ++---- esphome/components/lvgl/number/lvgl_number.h | 6 ++---- esphome/components/lvgl/select/lvgl_select.h | 6 ++---- esphome/components/lvgl/switch/lvgl_switch.h | 6 ++---- esphome/components/lvgl/text/lvgl_text.h | 6 ++---- .../binary_sensor/m5stack_8angle_binary_sensor.cpp | 6 ++---- .../binary_sensor/m5stack_8angle_binary_sensor.h | 6 ++---- .../m5stack_8angle/light/m5stack_8angle_light.cpp | 6 ++---- .../m5stack_8angle/light/m5stack_8angle_light.h | 6 ++---- esphome/components/m5stack_8angle/m5stack_8angle.cpp | 6 ++---- esphome/components/m5stack_8angle/m5stack_8angle.h | 6 ++---- .../m5stack_8angle/sensor/m5stack_8angle_sensor.cpp | 6 ++---- .../m5stack_8angle/sensor/m5stack_8angle_sensor.h | 6 ++---- .../binary_sensor/matrix_keypad_binary_sensor.h | 6 ++---- esphome/components/matrix_keypad/matrix_keypad.cpp | 6 ++---- esphome/components/matrix_keypad/matrix_keypad.h | 6 ++---- esphome/components/max17043/automation.h | 6 ++---- esphome/components/max17043/max17043.cpp | 6 ++---- esphome/components/max17043/max17043.h | 6 ++---- esphome/components/max31855/max31855.cpp | 6 ++---- esphome/components/max31855/max31855.h | 6 ++---- esphome/components/max31856/max31856.cpp | 6 ++---- esphome/components/max31856/max31856.h | 6 ++---- esphome/components/max31865/max31865.cpp | 6 ++---- esphome/components/max31865/max31865.h | 6 ++---- esphome/components/max44009/max44009.cpp | 6 ++---- esphome/components/max44009/max44009.h | 6 ++---- esphome/components/max6675/max6675.cpp | 6 ++---- esphome/components/max6675/max6675.h | 6 ++---- esphome/components/max6956/automation.h | 6 ++---- esphome/components/max6956/max6956.cpp | 6 ++---- esphome/components/max6956/max6956.h | 6 ++---- esphome/components/max6956/output/max6956_led_output.cpp | 6 ++---- esphome/components/max6956/output/max6956_led_output.h | 6 ++---- esphome/components/max7219digit/automation.h | 6 ++---- esphome/components/max7219digit/max7219digit.cpp | 6 ++---- esphome/components/max7219digit/max7219digit.h | 6 ++---- esphome/components/max7219digit/max7219font.h | 6 ++---- esphome/components/max9611/max9611.cpp | 7 +++---- esphome/components/max9611/max9611.h | 6 ++---- esphome/components/mcp23008/mcp23008.cpp | 6 ++---- esphome/components/mcp23008/mcp23008.h | 6 ++---- esphome/components/mcp23016/mcp23016.cpp | 6 ++---- esphome/components/mcp23016/mcp23016.h | 6 ++---- esphome/components/mcp23017/mcp23017.cpp | 6 ++---- esphome/components/mcp23017/mcp23017.h | 6 ++---- esphome/components/mcp23s08/mcp23s08.cpp | 6 ++---- esphome/components/mcp23s08/mcp23s08.h | 6 ++---- esphome/components/mcp23s17/mcp23s17.cpp | 6 ++---- esphome/components/mcp23s17/mcp23s17.h | 6 ++---- esphome/components/mcp23x08_base/mcp23x08_base.cpp | 6 ++---- esphome/components/mcp23x08_base/mcp23x08_base.h | 6 ++---- esphome/components/mcp23x17_base/mcp23x17_base.cpp | 6 ++---- esphome/components/mcp23x17_base/mcp23x17_base.h | 6 ++---- esphome/components/mcp23xxx_base/mcp23xxx_base.cpp | 6 ++---- esphome/components/mcp23xxx_base/mcp23xxx_base.h | 6 ++---- esphome/components/mcp2515/mcp2515.cpp | 6 ++---- esphome/components/mcp2515/mcp2515.h | 6 ++---- esphome/components/mcp2515/mcp2515_defs.h | 6 ++---- esphome/components/mcp3008/mcp3008.cpp | 6 ++---- esphome/components/mcp3008/mcp3008.h | 6 ++---- esphome/components/mcp3008/sensor/mcp3008_sensor.cpp | 6 ++---- esphome/components/mcp3008/sensor/mcp3008_sensor.h | 6 ++---- esphome/components/mcp3204/mcp3204.cpp | 6 ++---- esphome/components/mcp3204/mcp3204.h | 6 ++---- esphome/components/mcp3204/sensor/mcp3204_sensor.cpp | 6 ++---- esphome/components/mcp3204/sensor/mcp3204_sensor.h | 6 ++---- esphome/components/mcp3221/mcp3221_sensor.cpp | 6 ++---- esphome/components/mcp3221/mcp3221_sensor.h | 6 ++---- esphome/components/mcp4461/mcp4461.cpp | 6 ++---- esphome/components/mcp4461/mcp4461.h | 6 ++---- esphome/components/mcp4461/output/mcp4461_output.cpp | 6 ++---- esphome/components/mcp4461/output/mcp4461_output.h | 6 ++---- esphome/components/mcp4725/mcp4725.cpp | 6 ++---- esphome/components/mcp4725/mcp4725.h | 6 ++---- esphome/components/mcp4728/mcp4728.cpp | 6 ++---- esphome/components/mcp4728/mcp4728.h | 6 ++---- esphome/components/mcp4728/output/mcp4728_output.cpp | 6 ++---- esphome/components/mcp4728/output/mcp4728_output.h | 6 ++---- esphome/components/mcp47a1/mcp47a1.cpp | 6 ++---- esphome/components/mcp47a1/mcp47a1.h | 6 ++---- esphome/components/mcp9600/mcp9600.cpp | 6 ++---- esphome/components/mcp9600/mcp9600.h | 6 ++---- esphome/components/mcp9808/mcp9808.cpp | 6 ++---- esphome/components/mcp9808/mcp9808.h | 6 ++---- esphome/components/md5/md5.cpp | 7 +++---- esphome/components/md5/md5.h | 7 +++---- esphome/components/media_player/automation.h | 7 ++----- esphome/components/media_player/media_player.cpp | 6 ++---- esphome/components/media_player/media_player.h | 6 ++---- esphome/components/micro_wake_word/automation.h | 8 ++++---- esphome/components/micro_wake_word/micro_wake_word.cpp | 6 ++---- esphome/components/micro_wake_word/micro_wake_word.h | 6 ++---- .../components/micro_wake_word/preprocessor_settings.h | 6 ++---- esphome/components/micro_wake_word/streaming_model.cpp | 6 ++---- esphome/components/micro_wake_word/streaming_model.h | 6 ++---- esphome/components/microphone/automation.h | 6 ++---- esphome/components/microphone/microphone.h | 6 ++---- esphome/components/microphone/microphone_source.cpp | 6 ++---- esphome/components/microphone/microphone_source.h | 6 ++---- esphome/components/mics_4514/mics_4514.cpp | 6 ++---- esphome/components/mics_4514/mics_4514.h | 6 ++---- esphome/components/midea/ac_adapter.cpp | 8 ++------ esphome/components/midea/ac_adapter.h | 8 ++------ esphome/components/midea/ac_automations.h | 8 ++------ esphome/components/midea/air_conditioner.cpp | 8 ++------ esphome/components/midea/air_conditioner.h | 8 ++------ esphome/components/midea/appliance_base.h | 6 ++---- esphome/components/midea_ir/midea_data.h | 6 ++---- esphome/components/midea_ir/midea_ir.cpp | 6 ++---- esphome/components/midea_ir/midea_ir.h | 6 ++---- esphome/components/mipi_spi/mipi_spi.h | 6 ++---- esphome/components/mitsubishi/mitsubishi.cpp | 6 ++---- esphome/components/mitsubishi/mitsubishi.h | 6 ++---- esphome/components/mixer/speaker/automation.h | 6 ++---- esphome/components/mlx90393/sensor_mlx90393.cpp | 6 ++---- esphome/components/mlx90393/sensor_mlx90393.h | 6 ++---- esphome/components/mlx90614/mlx90614.cpp | 6 ++---- esphome/components/mlx90614/mlx90614.h | 6 ++---- esphome/components/mmc5603/mmc5603.cpp | 6 ++---- esphome/components/mmc5603/mmc5603.h | 6 ++---- esphome/components/mmc5983/mmc5983.cpp | 6 ++---- esphome/components/mmc5983/mmc5983.h | 6 ++---- esphome/components/modbus/modbus.cpp | 6 ++---- esphome/components/modbus/modbus.h | 6 ++---- esphome/components/modbus/modbus_definitions.h | 6 ++---- .../binary_sensor/modbus_binarysensor.cpp | 6 ++---- .../modbus_controller/binary_sensor/modbus_binarysensor.h | 6 ++---- .../components/modbus_controller/modbus_controller.cpp | 6 ++---- esphome/components/modbus_controller/modbus_controller.h | 6 ++---- .../components/modbus_controller/number/modbus_number.cpp | 6 ++---- .../components/modbus_controller/number/modbus_number.h | 6 ++---- .../components/modbus_controller/output/modbus_output.cpp | 6 ++---- .../components/modbus_controller/output/modbus_output.h | 6 ++---- .../components/modbus_controller/select/modbus_select.cpp | 6 ++---- .../components/modbus_controller/select/modbus_select.h | 6 ++---- .../components/modbus_controller/sensor/modbus_sensor.cpp | 6 ++---- .../components/modbus_controller/sensor/modbus_sensor.h | 6 ++---- .../components/modbus_controller/switch/modbus_switch.cpp | 7 +++---- .../components/modbus_controller/switch/modbus_switch.h | 6 ++---- .../modbus_controller/text_sensor/modbus_textsensor.cpp | 6 ++---- .../modbus_controller/text_sensor/modbus_textsensor.h | 6 ++---- .../components/monochromatic/monochromatic_light_output.h | 6 ++---- esphome/components/mopeka_ble/mopeka_ble.cpp | 6 ++---- esphome/components/mopeka_ble/mopeka_ble.h | 6 ++---- esphome/components/mopeka_pro_check/mopeka_pro_check.cpp | 6 ++---- esphome/components/mopeka_pro_check/mopeka_pro_check.h | 6 ++---- esphome/components/mopeka_std_check/mopeka_std_check.cpp | 6 ++---- esphome/components/mopeka_std_check/mopeka_std_check.h | 6 ++---- esphome/components/mpl3115a2/mpl3115a2.cpp | 6 ++---- esphome/components/mpl3115a2/mpl3115a2.h | 6 ++---- .../mpr121/binary_sensor/mpr121_binary_sensor.cpp | 6 ++---- .../mpr121/binary_sensor/mpr121_binary_sensor.h | 6 ++---- esphome/components/mpr121/mpr121.cpp | 6 ++---- esphome/components/mpr121/mpr121.h | 6 ++---- esphome/components/mpu6050/mpu6050.cpp | 6 ++---- esphome/components/mpu6050/mpu6050.h | 7 ++----- esphome/components/mpu6886/mpu6886.cpp | 6 ++---- esphome/components/mpu6886/mpu6886.h | 7 ++----- .../mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp | 6 ++---- .../mqtt_subscribe/sensor/mqtt_subscribe_sensor.h | 6 ++---- .../text_sensor/mqtt_subscribe_text_sensor.cpp | 6 ++---- .../text_sensor/mqtt_subscribe_text_sensor.h | 6 ++---- esphome/components/ms5611/ms5611.cpp | 6 ++---- esphome/components/ms5611/ms5611.h | 6 ++---- esphome/components/ms8607/ms8607.cpp | 6 ++---- esphome/components/ms8607/ms8607.h | 6 ++---- esphome/components/msa3xx/msa3xx.cpp | 6 ++---- esphome/components/msa3xx/msa3xx.h | 6 ++---- esphome/components/my9231/my9231.cpp | 6 ++---- esphome/components/my9231/my9231.h | 6 ++---- 250 files changed, 508 insertions(+), 1013 deletions(-) diff --git a/esphome/components/i2c_device/i2c_device.cpp b/esphome/components/i2c_device/i2c_device.cpp index 455c68fbed3..2f68a9e96a5 100644 --- a/esphome/components/i2c_device/i2c_device.cpp +++ b/esphome/components/i2c_device/i2c_device.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace i2c_device { +namespace esphome::i2c_device { static const char *const TAG = "i2c_device"; @@ -13,5 +12,4 @@ void I2CDeviceComponent::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace i2c_device -} // namespace esphome +} // namespace esphome::i2c_device diff --git a/esphome/components/i2c_device/i2c_device.h b/esphome/components/i2c_device/i2c_device.h index 9944ca92045..aeae622c2e8 100644 --- a/esphome/components/i2c_device/i2c_device.h +++ b/esphome/components/i2c_device/i2c_device.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace i2c_device { +namespace esphome::i2c_device { class I2CDeviceComponent : public Component, public i2c::I2CDevice { public: @@ -13,5 +12,4 @@ class I2CDeviceComponent : public Component, public i2c::I2CDevice { protected: }; -} // namespace i2c_device -} // namespace esphome +} // namespace esphome::i2c_device diff --git a/esphome/components/i2s_audio/i2s_audio.h b/esphome/components/i2s_audio/i2s_audio.h index 5b260fa7ede..6b32b556d9b 100644 --- a/esphome/components/i2s_audio/i2s_audio.h +++ b/esphome/components/i2s_audio/i2s_audio.h @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace i2s_audio { +namespace esphome::i2s_audio { class I2SAudioComponent; @@ -77,7 +76,6 @@ class I2SAudioComponent : public Component { int port_{}; }; -} // namespace i2s_audio -} // namespace esphome +} // namespace esphome::i2s_audio #endif // USE_ESP32 diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp index d697808c998..66ca32b8303 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp @@ -10,8 +10,7 @@ #include "esphome/components/audio/audio.h" -namespace esphome { -namespace i2s_audio { +namespace esphome::i2s_audio { static const UBaseType_t MAX_LISTENERS = 16; @@ -426,7 +425,6 @@ void I2SAudioMicrophone::loop() { } } -} // namespace i2s_audio -} // namespace esphome +} // namespace esphome::i2s_audio #endif // USE_ESP32 diff --git a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h index e277409262a..06f2de76107 100644 --- a/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +++ b/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h @@ -12,8 +12,7 @@ #include #include -namespace esphome { -namespace i2s_audio { +namespace esphome::i2s_audio { class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, public Component { public: @@ -65,7 +64,6 @@ class I2SAudioMicrophone : public I2SAudioIn, public microphone::Microphone, pub int32_t dc_offset_prev_output_{0}; }; -} // namespace i2s_audio -} // namespace esphome +} // namespace esphome::i2s_audio #endif // USE_ESP32 diff --git a/esphome/components/iaqcore/iaqcore.cpp b/esphome/components/iaqcore/iaqcore.cpp index c414eb8f608..7397d0975cf 100644 --- a/esphome/components/iaqcore/iaqcore.cpp +++ b/esphome/components/iaqcore/iaqcore.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace iaqcore { +namespace esphome::iaqcore { static const char *const TAG = "iaqcore"; @@ -97,5 +96,4 @@ void IAQCore::dump_config() { LOG_SENSOR(" ", "TVOC", this->tvoc_); } -} // namespace iaqcore -} // namespace esphome +} // namespace esphome::iaqcore diff --git a/esphome/components/iaqcore/iaqcore.h b/esphome/components/iaqcore/iaqcore.h index bb0bfcc7544..39f290e1205 100644 --- a/esphome/components/iaqcore/iaqcore.h +++ b/esphome/components/iaqcore/iaqcore.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace iaqcore { +namespace esphome::iaqcore { class IAQCore : public PollingComponent, public i2c::I2CDevice { public: @@ -23,5 +22,4 @@ class IAQCore : public PollingComponent, public i2c::I2CDevice { void publish_nans_(); }; -} // namespace iaqcore -} // namespace esphome +} // namespace esphome::iaqcore diff --git a/esphome/components/ili9xxx/ili9xxx_defines.h b/esphome/components/ili9xxx/ili9xxx_defines.h index 70e0937f790..c9b54c0f0ed 100644 --- a/esphome/components/ili9xxx/ili9xxx_defines.h +++ b/esphome/components/ili9xxx/ili9xxx_defines.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace ili9xxx { +namespace esphome::ili9xxx { // Color definitions // clang-format off @@ -98,5 +97,4 @@ static const uint8_t ILI9XXX_DELAY_FLAG = 0xFF; // special marker for delay - command byte reprents ms, length byte is an impossible value #define ILI9XXX_DELAY(ms) ((uint8_t) ((ms) | 0x80)), ILI9XXX_DELAY_FLAG -} // namespace ili9xxx -} // namespace esphome +} // namespace esphome::ili9xxx diff --git a/esphome/components/ili9xxx/ili9xxx_display.cpp b/esphome/components/ili9xxx/ili9xxx_display.cpp index 11acb8a73a4..e8840c0cf19 100644 --- a/esphome/components/ili9xxx/ili9xxx_display.cpp +++ b/esphome/components/ili9xxx/ili9xxx_display.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ili9xxx { +namespace esphome::ili9xxx { static const uint16_t SPI_SETUP_US = 100; // estimated fixed overhead in microseconds for an SPI write static const uint16_t SPI_MAX_BLOCK_SIZE = 4092; // Max size of continuous SPI transfer @@ -470,5 +469,4 @@ void ILI9XXXDisplay::invert_colors(bool invert) { int ILI9XXXDisplay::get_width_internal() { return this->width_; } int ILI9XXXDisplay::get_height_internal() { return this->height_; } -} // namespace ili9xxx -} // namespace esphome +} // namespace esphome::ili9xxx diff --git a/esphome/components/ili9xxx/ili9xxx_display.h b/esphome/components/ili9xxx/ili9xxx_display.h index 629bbb41cb6..2529e54021b 100644 --- a/esphome/components/ili9xxx/ili9xxx_display.h +++ b/esphome/components/ili9xxx/ili9xxx_display.h @@ -5,8 +5,7 @@ #include "ili9xxx_defines.h" #include "ili9xxx_init.h" -namespace esphome { -namespace ili9xxx { +namespace esphome::ili9xxx { static const char *const TAG = "ili9xxx"; const size_t ILI9XXX_TRANSFER_BUFFER_SIZE = 126; // ensure this is divisible by 6 @@ -283,5 +282,4 @@ class ILI9XXXST7735 : public ILI9XXXDisplay { ILI9XXXST7735() : ILI9XXXDisplay(INITCMD_ST7735, 128, 160) {} }; -} // namespace ili9xxx -} // namespace esphome +} // namespace esphome::ili9xxx diff --git a/esphome/components/ili9xxx/ili9xxx_init.h b/esphome/components/ili9xxx/ili9xxx_init.h index f0c6a94a656..529571022ae 100644 --- a/esphome/components/ili9xxx/ili9xxx_init.h +++ b/esphome/components/ili9xxx/ili9xxx_init.h @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace ili9xxx { +namespace esphome::ili9xxx { // clang-format off static constexpr uint8_t PROGMEM INITCMD_M5STACK[] = { @@ -478,5 +477,4 @@ static constexpr uint8_t PROGMEM INITCMD_ST7735[] = { }; // clang-format on -} // namespace ili9xxx -} // namespace esphome +} // namespace esphome::ili9xxx diff --git a/esphome/components/image/image.cpp b/esphome/components/image/image.cpp index 5b4ed6968c6..c95b693cf0b 100644 --- a/esphome/components/image/image.cpp +++ b/esphome/components/image/image.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace image { +namespace esphome::image { void Image::draw(int x, int y, display::Display *display, Color color_on, Color color_off) { int img_x0 = 0; @@ -243,5 +242,4 @@ Image::Image(const uint8_t *data_start, int width, int height, ImageType type, T } } -} // namespace image -} // namespace esphome +} // namespace esphome::image diff --git a/esphome/components/image/image.h b/esphome/components/image/image.h index d4865570e40..ccc2f23f200 100644 --- a/esphome/components/image/image.h +++ b/esphome/components/image/image.h @@ -6,8 +6,7 @@ #include "esphome/components/lvgl/lvgl_proxy.h" #endif // USE_LVGL -namespace esphome { -namespace image { +namespace esphome::image { enum ImageType { IMAGE_TYPE_BINARY = 0, @@ -61,5 +60,4 @@ class Image : public display::BaseImage { #endif }; -} // namespace image -} // namespace esphome +} // namespace esphome::image diff --git a/esphome/components/improv_base/improv_base.cpp b/esphome/components/improv_base/improv_base.cpp index d0340344a6c..fa1b855d6c4 100644 --- a/esphome/components/improv_base/improv_base.cpp +++ b/esphome/components/improv_base/improv_base.cpp @@ -5,8 +5,7 @@ #include "esphome/core/application.h" #include "esphome/core/defines.h" -namespace esphome { -namespace improv_base { +namespace esphome::improv_base { #if defined(USE_ESP32_IMPROV_NEXT_URL) || defined(USE_IMPROV_SERIAL_NEXT_URL) static constexpr const char DEVICE_NAME_PLACEHOLDER[] = "{{device_name}}"; @@ -65,5 +64,4 @@ size_t ImprovBase::get_formatted_next_url_(char *buffer, size_t buffer_size) { } #endif -} // namespace improv_base -} // namespace esphome +} // namespace esphome::improv_base diff --git a/esphome/components/improv_base/improv_base.h b/esphome/components/improv_base/improv_base.h index ebc8f38d60b..9dded85a468 100644 --- a/esphome/components/improv_base/improv_base.h +++ b/esphome/components/improv_base/improv_base.h @@ -3,8 +3,7 @@ #include #include "esphome/core/defines.h" -namespace esphome { -namespace improv_base { +namespace esphome::improv_base { class ImprovBase { public: @@ -20,5 +19,4 @@ class ImprovBase { #endif }; -} // namespace improv_base -} // namespace esphome +} // namespace esphome::improv_base diff --git a/esphome/components/improv_serial/improv_serial_component.cpp b/esphome/components/improv_serial/improv_serial_component.cpp index 003328d535e..18d0b44701d 100644 --- a/esphome/components/improv_serial/improv_serial_component.cpp +++ b/esphome/components/improv_serial/improv_serial_component.cpp @@ -8,8 +8,7 @@ #include "esphome/components/logger/logger.h" -namespace esphome { -namespace improv_serial { +namespace esphome::improv_serial { static const char *const TAG = "improv_serial"; @@ -329,6 +328,6 @@ void ImprovSerialComponent::on_wifi_connect_timeout_() { ImprovSerialComponent *global_improv_serial_component = // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace improv_serial -} // namespace esphome +} // namespace esphome::improv_serial + #endif diff --git a/esphome/components/improv_serial/improv_serial_component.h b/esphome/components/improv_serial/improv_serial_component.h index dd8f5e47191..2f1d0136a44 100644 --- a/esphome/components/improv_serial/improv_serial_component.h +++ b/esphome/components/improv_serial/improv_serial_component.h @@ -23,8 +23,7 @@ #include #endif -namespace esphome { -namespace improv_serial { +namespace esphome::improv_serial { // TX buffer layout constants static constexpr uint8_t TX_HEADER_SIZE = 6; // Bytes 0-5 = "IMPROV" @@ -99,6 +98,6 @@ class ImprovSerialComponent : public Component, public improv_base::ImprovBase { extern ImprovSerialComponent *global_improv_serial_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace improv_serial -} // namespace esphome +} // namespace esphome::improv_serial + #endif diff --git a/esphome/components/ina219/ina219.cpp b/esphome/components/ina219/ina219.cpp index 278017651bb..85da1965848 100644 --- a/esphome/components/ina219/ina219.cpp +++ b/esphome/components/ina219/ina219.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ina219 { +namespace esphome::ina219 { static const char *const TAG = "ina219"; @@ -196,5 +195,4 @@ void INA219Component::update() { this->status_clear_warning(); } -} // namespace ina219 -} // namespace esphome +} // namespace esphome::ina219 diff --git a/esphome/components/ina219/ina219.h b/esphome/components/ina219/ina219.h index bcadb65e36b..7462c072724 100644 --- a/esphome/components/ina219/ina219.h +++ b/esphome/components/ina219/ina219.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace ina219 { +namespace esphome::ina219 { class INA219Component : public PollingComponent, public i2c::I2CDevice { public: @@ -35,5 +34,4 @@ class INA219Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *power_sensor_{nullptr}; }; -} // namespace ina219 -} // namespace esphome +} // namespace esphome::ina219 diff --git a/esphome/components/ina226/ina226.cpp b/esphome/components/ina226/ina226.cpp index cbc44c9a1aa..695de57c617 100644 --- a/esphome/components/ina226/ina226.cpp +++ b/esphome/components/ina226/ina226.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace ina226 { +namespace esphome::ina226 { static const char *const TAG = "ina226"; @@ -161,5 +160,4 @@ int32_t INA226Component::twos_complement_(int32_t val, uint8_t bits) { return val; } -} // namespace ina226 -} // namespace esphome +} // namespace esphome::ina226 diff --git a/esphome/components/ina226/ina226.h b/esphome/components/ina226/ina226.h index 0aa66ff765f..7d6b526f40f 100644 --- a/esphome/components/ina226/ina226.h +++ b/esphome/components/ina226/ina226.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ina226 { +namespace esphome::ina226 { enum AdcTime : uint16_t { ADC_TIME_140US = 0, @@ -73,5 +72,4 @@ class INA226Component : public PollingComponent, public i2c::I2CDevice { int32_t twos_complement_(int32_t val, uint8_t bits); }; -} // namespace ina226 -} // namespace esphome +} // namespace esphome::ina226 diff --git a/esphome/components/ina260/ina260.cpp b/esphome/components/ina260/ina260.cpp index 4d6acf400cc..05039f0e331 100644 --- a/esphome/components/ina260/ina260.cpp +++ b/esphome/components/ina260/ina260.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ina260 { +namespace esphome::ina260 { static const char *const TAG = "ina260"; @@ -122,5 +121,4 @@ void INA260Component::update() { this->status_clear_warning(); } -} // namespace ina260 -} // namespace esphome +} // namespace esphome::ina260 diff --git a/esphome/components/ina260/ina260.h b/esphome/components/ina260/ina260.h index 6cbc157cf34..856e715774c 100644 --- a/esphome/components/ina260/ina260.h +++ b/esphome/components/ina260/ina260.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ina260 { +namespace esphome::ina260 { class INA260Component : public PollingComponent, public i2c::I2CDevice { public: @@ -33,5 +32,4 @@ class INA260Component : public PollingComponent, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace ina260 -} // namespace esphome +} // namespace esphome::ina260 diff --git a/esphome/components/ina2xx_base/ina2xx_base.cpp b/esphome/components/ina2xx_base/ina2xx_base.cpp index 2d08562e542..d3acf00eef6 100644 --- a/esphome/components/ina2xx_base/ina2xx_base.cpp +++ b/esphome/components/ina2xx_base/ina2xx_base.cpp @@ -5,8 +5,7 @@ #include #include -namespace esphome { -namespace ina2xx_base { +namespace esphome::ina2xx_base { static const char *const TAG = "ina2xx"; @@ -600,5 +599,4 @@ bool INA2XX::read_unsigned_16_(uint8_t reg, uint16_t &out) { int64_t INA2XX::two_complement_(uint64_t value, uint8_t bits) { return (int64_t) (value << (64 - bits)) >> (64 - bits); } -} // namespace ina2xx_base -} // namespace esphome +} // namespace esphome::ina2xx_base diff --git a/esphome/components/ina2xx_base/ina2xx_base.h b/esphome/components/ina2xx_base/ina2xx_base.h index 104c384a0d2..beb158944bb 100644 --- a/esphome/components/ina2xx_base/ina2xx_base.h +++ b/esphome/components/ina2xx_base/ina2xx_base.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace ina2xx_base { +namespace esphome::ina2xx_base { enum RegisterMap : uint8_t { REG_CONFIG = 0x00, @@ -250,5 +249,4 @@ class INA2XX : public PollingComponent { virtual bool read_ina_register(uint8_t a_register, uint8_t *data, size_t len) = 0; virtual bool write_ina_register(uint8_t a_register, const uint8_t *data, size_t len) = 0; }; -} // namespace ina2xx_base -} // namespace esphome +} // namespace esphome::ina2xx_base diff --git a/esphome/components/ina2xx_i2c/ina2xx_i2c.cpp b/esphome/components/ina2xx_i2c/ina2xx_i2c.cpp index a363a9c12f4..4fc3b00a215 100644 --- a/esphome/components/ina2xx_i2c/ina2xx_i2c.cpp +++ b/esphome/components/ina2xx_i2c/ina2xx_i2c.cpp @@ -1,8 +1,7 @@ #include "ina2xx_i2c.h" #include "esphome/core/log.h" -namespace esphome { -namespace ina2xx_i2c { +namespace esphome::ina2xx_i2c { static const char *const TAG = "ina2xx_i2c"; @@ -35,5 +34,4 @@ bool INA2XXI2C::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) } return ret == i2c::ERROR_OK; } -} // namespace ina2xx_i2c -} // namespace esphome +} // namespace esphome::ina2xx_i2c diff --git a/esphome/components/ina2xx_i2c/ina2xx_i2c.h b/esphome/components/ina2xx_i2c/ina2xx_i2c.h index c90b9bf1903..783723b3961 100644 --- a/esphome/components/ina2xx_i2c/ina2xx_i2c.h +++ b/esphome/components/ina2xx_i2c/ina2xx_i2c.h @@ -4,8 +4,7 @@ #include "esphome/components/ina2xx_base/ina2xx_base.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ina2xx_i2c { +namespace esphome::ina2xx_i2c { class INA2XXI2C : public ina2xx_base::INA2XX, public i2c::I2CDevice { public: @@ -17,5 +16,4 @@ class INA2XXI2C : public ina2xx_base::INA2XX, public i2c::I2CDevice { bool write_ina_register(uint8_t reg, const uint8_t *data, size_t len) override; }; -} // namespace ina2xx_i2c -} // namespace esphome +} // namespace esphome::ina2xx_i2c diff --git a/esphome/components/ina2xx_spi/ina2xx_spi.cpp b/esphome/components/ina2xx_spi/ina2xx_spi.cpp index 3e04a876656..43eb6762367 100644 --- a/esphome/components/ina2xx_spi/ina2xx_spi.cpp +++ b/esphome/components/ina2xx_spi/ina2xx_spi.cpp @@ -1,8 +1,7 @@ #include "ina2xx_spi.h" #include "esphome/core/log.h" -namespace esphome { -namespace ina2xx_spi { +namespace esphome::ina2xx_spi { static const char *const TAG = "ina2xx_spi"; @@ -34,5 +33,4 @@ bool INA2XXSPI::write_ina_register(uint8_t reg, const uint8_t *data, size_t len) this->disable(); return true; } -} // namespace ina2xx_spi -} // namespace esphome +} // namespace esphome::ina2xx_spi diff --git a/esphome/components/ina2xx_spi/ina2xx_spi.h b/esphome/components/ina2xx_spi/ina2xx_spi.h index 3b21518d34d..8e065de8169 100644 --- a/esphome/components/ina2xx_spi/ina2xx_spi.h +++ b/esphome/components/ina2xx_spi/ina2xx_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ina2xx_base/ina2xx_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ina2xx_spi { +namespace esphome::ina2xx_spi { class INA2XXSPI : public ina2xx_base::INA2XX, public spi::SPIDevicebus_voltage_sensor_ != nullptr || this->power_sensor_ != nullptr; } -} // namespace ina3221 -} // namespace esphome +} // namespace esphome::ina3221 diff --git a/esphome/components/ina3221/ina3221.h b/esphome/components/ina3221/ina3221.h index 3769df77aa8..9d9762caf37 100644 --- a/esphome/components/ina3221/ina3221.h +++ b/esphome/components/ina3221/ina3221.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ina3221 { +namespace esphome::ina3221 { class INA3221Component : public PollingComponent, public i2c::I2CDevice { public: @@ -35,5 +34,4 @@ class INA3221Component : public PollingComponent, public i2c::I2CDevice { } channels_[3]; }; -} // namespace ina3221 -} // namespace esphome +} // namespace esphome::ina3221 diff --git a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp index c53d8e50298..4df22aa9de9 100644 --- a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp +++ b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace inkbird_ibsth1_mini { +namespace esphome::inkbird_ibsth1_mini { static const char *const TAG = "inkbird_ibsth1_mini"; @@ -104,7 +103,6 @@ bool InkbirdIbstH1Mini::parse_device(const esp32_ble_tracker::ESPBTDevice &devic return true; } -} // namespace inkbird_ibsth1_mini -} // namespace esphome +} // namespace esphome::inkbird_ibsth1_mini #endif diff --git a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.h b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.h index cd2ea99717d..37e50943f33 100644 --- a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.h +++ b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.h @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace inkbird_ibsth1_mini { +namespace esphome::inkbird_ibsth1_mini { class InkbirdIbstH1Mini : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -29,7 +28,6 @@ class InkbirdIbstH1Mini : public Component, public esp32_ble_tracker::ESPBTDevic sensor::Sensor *battery_level_{nullptr}; }; -} // namespace inkbird_ibsth1_mini -} // namespace esphome +} // namespace esphome::inkbird_ibsth1_mini #endif diff --git a/esphome/components/inkplate/inkplate.cpp b/esphome/components/inkplate/inkplate.cpp index 0511b451a83..39110ca83b9 100644 --- a/esphome/components/inkplate/inkplate.cpp +++ b/esphome/components/inkplate/inkplate.cpp @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace inkplate { +namespace esphome::inkplate { static const char *const TAG = "inkplate"; @@ -820,5 +819,4 @@ void Inkplate::pins_as_outputs_() { this->display_data_7_pin_->pin_mode(gpio::FLAG_OUTPUT); } -} // namespace inkplate -} // namespace esphome +} // namespace esphome::inkplate diff --git a/esphome/components/inkplate/inkplate.h b/esphome/components/inkplate/inkplate.h index bcd56b829a0..40e32c4cc44 100644 --- a/esphome/components/inkplate/inkplate.h +++ b/esphome/components/inkplate/inkplate.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace inkplate { +namespace esphome::inkplate { enum InkplateModel : uint8_t { INKPLATE_6 = 0, @@ -210,5 +209,4 @@ class Inkplate : public display::DisplayBuffer, public i2c::I2CDevice { GPIOPin *wakeup_pin_; }; -} // namespace inkplate -} // namespace esphome +} // namespace esphome::inkplate diff --git a/esphome/components/integration/integration_sensor.cpp b/esphome/components/integration/integration_sensor.cpp index b084801d3b0..bc26fb0f193 100644 --- a/esphome/components/integration/integration_sensor.cpp +++ b/esphome/components/integration/integration_sensor.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace integration { +namespace esphome::integration { static const char *const TAG = "integration"; @@ -47,5 +46,4 @@ void IntegrationSensor::process_sensor_value_(float value) { this->publish_and_save_(this->result_ + area); } -} // namespace integration -} // namespace esphome +} // namespace esphome::integration diff --git a/esphome/components/integration/integration_sensor.h b/esphome/components/integration/integration_sensor.h index 6c4ef7049bb..1c5edfcba54 100644 --- a/esphome/components/integration/integration_sensor.h +++ b/esphome/components/integration/integration_sensor.h @@ -6,8 +6,7 @@ #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace integration { +namespace esphome::integration { enum IntegrationSensorTime { INTEGRATION_SENSOR_TIME_MILLISECOND = 0, @@ -84,5 +83,4 @@ template class SetValueAction : public Action, public Par void play(const Ts &...x) override { this->parent_->set_value(this->value_.value(x...)); } }; -} // namespace integration -} // namespace esphome +} // namespace esphome::integration diff --git a/esphome/components/interval/interval.h b/esphome/components/interval/interval.h index e419841e6c6..c9d4e8ea3e8 100644 --- a/esphome/components/interval/interval.h +++ b/esphome/components/interval/interval.h @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/automation.h" -namespace esphome { -namespace interval { +namespace esphome::interval { class IntervalTrigger : public Trigger<>, public PollingComponent { public: @@ -24,5 +23,4 @@ class IntervalTrigger : public Trigger<>, public PollingComponent { uint32_t startup_delay_{0}; }; -} // namespace interval -} // namespace esphome +} // namespace esphome::interval diff --git a/esphome/components/jsn_sr04t/jsn_sr04t.cpp b/esphome/components/jsn_sr04t/jsn_sr04t.cpp index 6fd8b1bd655..c67771a0b60 100644 --- a/esphome/components/jsn_sr04t/jsn_sr04t.cpp +++ b/esphome/components/jsn_sr04t/jsn_sr04t.cpp @@ -4,8 +4,7 @@ // Very basic support for JSN_SR04T V3.0 distance sensor in mode 2 -namespace esphome { -namespace jsn_sr04t { +namespace esphome::jsn_sr04t { static const char *const TAG = "jsn_sr04t.sensor"; @@ -62,5 +61,4 @@ void Jsnsr04tComponent::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace jsn_sr04t -} // namespace esphome +} // namespace esphome::jsn_sr04t diff --git a/esphome/components/jsn_sr04t/jsn_sr04t.h b/esphome/components/jsn_sr04t/jsn_sr04t.h index 2a22ff92ecb..f9d07ea5393 100644 --- a/esphome/components/jsn_sr04t/jsn_sr04t.h +++ b/esphome/components/jsn_sr04t/jsn_sr04t.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace jsn_sr04t { +namespace esphome::jsn_sr04t { enum Model { JSN_SR04T, @@ -30,5 +29,4 @@ class Jsnsr04tComponent : public sensor::Sensor, public PollingComponent, public std::vector buffer_; }; -} // namespace jsn_sr04t -} // namespace esphome +} // namespace esphome::jsn_sr04t diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index ec1490be1ff..984134b95f9 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -3,8 +3,7 @@ // ArduinoJson::Allocator is included via ArduinoJson.h in json_util.h -namespace esphome { -namespace json { +namespace esphome::json { static const char *const TAG = "json"; @@ -149,5 +148,4 @@ SerializationBuffer<> JsonBuilder::serialize() { return result; } -} // namespace json -} // namespace esphome +} // namespace esphome::json diff --git a/esphome/components/json/json_util.h b/esphome/components/json/json_util.h index 0dc9ff883cc..9f51d9927b8 100644 --- a/esphome/components/json/json_util.h +++ b/esphome/components/json/json_util.h @@ -13,8 +13,7 @@ #include -namespace esphome { -namespace json { +namespace esphome::json { /// Buffer for JSON serialization that uses stack allocation for small payloads. /// Template parameter STACK_SIZE specifies the stack buffer size (default 512 bytes). @@ -192,5 +191,4 @@ class JsonBuilder { bool root_created_{false}; }; -} // namespace json -} // namespace esphome +} // namespace esphome::json diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp index 9bebd4cd56d..ed03c4d6df4 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace kamstrup_kmp { +namespace esphome::kamstrup_kmp { static const char *const TAG = "kamstrup_kmp"; @@ -303,5 +302,4 @@ uint16_t crc16_ccitt(const uint8_t *buffer, int len) { return (uint16_t) reg; } -} // namespace kamstrup_kmp -} // namespace esphome +} // namespace esphome::kamstrup_kmp diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.h b/esphome/components/kamstrup_kmp/kamstrup_kmp.h index 725cf20abfa..a05a0ee17af 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.h +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.h @@ -5,8 +5,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/core/component.h" -namespace esphome { -namespace kamstrup_kmp { +namespace esphome::kamstrup_kmp { /* =========================================================================== @@ -127,5 +126,4 @@ class KamstrupKMPComponent : public PollingComponent, public uart::UARTDevice { // "true" CCITT CRC-16 uint16_t crc16_ccitt(const uint8_t *buffer, int len); -} // namespace kamstrup_kmp -} // namespace esphome +} // namespace esphome::kamstrup_kmp diff --git a/esphome/components/key_collector/key_collector.cpp b/esphome/components/key_collector/key_collector.cpp index 68d1c60bf94..cb7d47b7f0d 100644 --- a/esphome/components/key_collector/key_collector.cpp +++ b/esphome/components/key_collector/key_collector.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace key_collector { +namespace esphome::key_collector { static const char *const TAG = "key_collector"; @@ -102,5 +101,4 @@ void KeyCollector::send_key(uint8_t key) { this->progress_callbacks_.call(this->result_, this->start_key_); } -} // namespace key_collector -} // namespace esphome +} // namespace esphome::key_collector diff --git a/esphome/components/key_collector/key_collector.h b/esphome/components/key_collector/key_collector.h index 014e2034bd3..27209c50df5 100644 --- a/esphome/components/key_collector/key_collector.h +++ b/esphome/components/key_collector/key_collector.h @@ -5,8 +5,7 @@ #include "esphome/core/automation.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace key_collector { +namespace esphome::key_collector { class KeyCollector : public Component { public: @@ -63,5 +62,4 @@ template class DisableAction : public Action, public Pare void play(const Ts &...x) override { this->parent_->set_enabled(false); } }; -} // namespace key_collector -} // namespace esphome +} // namespace esphome::key_collector diff --git a/esphome/components/key_provider/key_provider.cpp b/esphome/components/key_provider/key_provider.cpp index 64b0729d4d1..0efeeff0068 100644 --- a/esphome/components/key_provider/key_provider.cpp +++ b/esphome/components/key_provider/key_provider.cpp @@ -1,9 +1,7 @@ #include "key_provider.h" -namespace esphome { -namespace key_provider { +namespace esphome::key_provider { void KeyProvider::send_key_(uint8_t key) { this->key_callback_.call(key); } -} // namespace key_provider -} // namespace esphome +} // namespace esphome::key_provider diff --git a/esphome/components/key_provider/key_provider.h b/esphome/components/key_provider/key_provider.h index 97403427512..85c27523846 100644 --- a/esphome/components/key_provider/key_provider.h +++ b/esphome/components/key_provider/key_provider.h @@ -3,8 +3,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -namespace esphome { -namespace key_provider { +namespace esphome::key_provider { /// interface for components that provide keypresses class KeyProvider { @@ -17,5 +16,4 @@ class KeyProvider { CallbackManager key_callback_{}; }; -} // namespace key_provider -} // namespace esphome +} // namespace esphome::key_provider diff --git a/esphome/components/kmeteriso/kmeteriso.cpp b/esphome/components/kmeteriso/kmeteriso.cpp index 186686e472a..d6934a97ac0 100644 --- a/esphome/components/kmeteriso/kmeteriso.cpp +++ b/esphome/components/kmeteriso/kmeteriso.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace kmeteriso { +namespace esphome::kmeteriso { static const char *const TAG = "kmeteriso.sensor"; @@ -74,5 +73,4 @@ void KMeterISOComponent::update() { } } -} // namespace kmeteriso -} // namespace esphome +} // namespace esphome::kmeteriso diff --git a/esphome/components/kmeteriso/kmeteriso.h b/esphome/components/kmeteriso/kmeteriso.h index 6f1978105fb..d5a2f9a01b1 100644 --- a/esphome/components/kmeteriso/kmeteriso.h +++ b/esphome/components/kmeteriso/kmeteriso.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/i2c/i2c_bus.h" -namespace esphome { -namespace kmeteriso { +namespace esphome::kmeteriso { /// This class implements support for the KMeterISO thermocouple sensor. class KMeterISOComponent : public PollingComponent, public i2c::I2CDevice { @@ -29,5 +28,4 @@ class KMeterISOComponent : public PollingComponent, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace kmeteriso -} // namespace esphome +} // namespace esphome::kmeteriso diff --git a/esphome/components/kuntze/kuntze.cpp b/esphome/components/kuntze/kuntze.cpp index 1b772d062ca..6df114e93c0 100644 --- a/esphome/components/kuntze/kuntze.cpp +++ b/esphome/components/kuntze/kuntze.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace kuntze { +namespace esphome::kuntze { static const char *const TAG = "kuntze"; @@ -97,5 +96,4 @@ void Kuntze::dump_config() { LOG_SENSOR("", "OCI", this->oci_sensor_); } -} // namespace kuntze -} // namespace esphome +} // namespace esphome::kuntze diff --git a/esphome/components/kuntze/kuntze.h b/esphome/components/kuntze/kuntze.h index aad7c1cbbf0..bbd93a22cec 100644 --- a/esphome/components/kuntze/kuntze.h +++ b/esphome/components/kuntze/kuntze.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/modbus/modbus.h" -namespace esphome { -namespace kuntze { +namespace esphome::kuntze { class Kuntze : public PollingComponent, public modbus::ModbusDevice { public: @@ -38,5 +37,4 @@ class Kuntze : public PollingComponent, public modbus::ModbusDevice { sensor::Sensor *oci_sensor_{nullptr}; }; -} // namespace kuntze -} // namespace esphome +} // namespace esphome::kuntze diff --git a/esphome/components/lc709203f/lc709203f.cpp b/esphome/components/lc709203f/lc709203f.cpp index 8c7018124a7..cbd733b6113 100644 --- a/esphome/components/lc709203f/lc709203f.cpp +++ b/esphome/components/lc709203f/lc709203f.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace lc709203f { +namespace esphome::lc709203f { static const char *const TAG = "lc709203f.sensor"; @@ -279,5 +278,4 @@ void Lc709203f::set_thermistor_b_constant(uint16_t b_constant) { this->b_constan void Lc709203f::set_pack_voltage(LC709203FBatteryVoltage pack_voltage) { this->pack_voltage_ = pack_voltage; } -} // namespace lc709203f -} // namespace esphome +} // namespace esphome::lc709203f diff --git a/esphome/components/lc709203f/lc709203f.h b/esphome/components/lc709203f/lc709203f.h index 59988a00793..42aa9a15a10 100644 --- a/esphome/components/lc709203f/lc709203f.h +++ b/esphome/components/lc709203f/lc709203f.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace lc709203f { +namespace esphome::lc709203f { enum LC709203FState { STATE_INIT, @@ -50,5 +49,4 @@ class Lc709203f : public sensor::Sensor, public PollingComponent, public i2c::I2 uint16_t pack_voltage_; }; -} // namespace lc709203f -} // namespace esphome +} // namespace esphome::lc709203f diff --git a/esphome/components/lcd_base/lcd_display.cpp b/esphome/components/lcd_base/lcd_display.cpp index 1f0ba482d74..0890da85c13 100644 --- a/esphome/components/lcd_base/lcd_display.cpp +++ b/esphome/components/lcd_base/lcd_display.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace lcd_base { +namespace esphome::lcd_base { static const char *const TAG = "lcd"; @@ -173,5 +172,4 @@ void LCDDisplay::loadchar(uint8_t location, uint8_t charmap[]) { } } -} // namespace lcd_base -} // namespace esphome +} // namespace esphome::lcd_base diff --git a/esphome/components/lcd_base/lcd_display.h b/esphome/components/lcd_base/lcd_display.h index 473acb0bd35..4b3413e3289 100644 --- a/esphome/components/lcd_base/lcd_display.h +++ b/esphome/components/lcd_base/lcd_display.h @@ -6,8 +6,7 @@ #include #include -namespace esphome { -namespace lcd_base { +namespace esphome::lcd_base { class LCDDisplay; @@ -62,5 +61,4 @@ class LCDDisplay : public PollingComponent { std::map > user_defined_chars_; }; -} // namespace lcd_base -} // namespace esphome +} // namespace esphome::lcd_base diff --git a/esphome/components/lcd_gpio/gpio_lcd_display.cpp b/esphome/components/lcd_gpio/gpio_lcd_display.cpp index ae6e1194b8f..213fc8637e7 100644 --- a/esphome/components/lcd_gpio/gpio_lcd_display.cpp +++ b/esphome/components/lcd_gpio/gpio_lcd_display.cpp @@ -1,8 +1,7 @@ #include "gpio_lcd_display.h" #include "esphome/core/log.h" -namespace esphome { -namespace lcd_gpio { +namespace esphome::lcd_gpio { static const char *const TAG = "lcd_gpio"; @@ -63,5 +62,4 @@ void GPIOLCDDisplay::send(uint8_t value, bool rs) { } } -} // namespace lcd_gpio -} // namespace esphome +} // namespace esphome::lcd_gpio diff --git a/esphome/components/lcd_gpio/gpio_lcd_display.h b/esphome/components/lcd_gpio/gpio_lcd_display.h index 81e4dc51a0c..dd9ea5929cd 100644 --- a/esphome/components/lcd_gpio/gpio_lcd_display.h +++ b/esphome/components/lcd_gpio/gpio_lcd_display.h @@ -4,8 +4,7 @@ #include "esphome/components/lcd_base/lcd_display.h" #include "esphome/components/display/display.h" -namespace esphome { -namespace lcd_gpio { +namespace esphome::lcd_gpio { class GPIOLCDDisplay; @@ -51,5 +50,4 @@ class GPIOLCDDisplay : public lcd_base::LCDDisplay { gpio_lcd_writer_t writer_; }; -} // namespace lcd_gpio -} // namespace esphome +} // namespace esphome::lcd_gpio diff --git a/esphome/components/lcd_menu/lcd_menu.cpp b/esphome/components/lcd_menu/lcd_menu.cpp index c664b394bf4..f731817bdb4 100644 --- a/esphome/components/lcd_menu/lcd_menu.cpp +++ b/esphome/components/lcd_menu/lcd_menu.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace lcd_menu { +namespace esphome::lcd_menu { static const char *const TAG = "lcd_menu"; @@ -72,5 +71,4 @@ void LCDCharacterMenuComponent::draw_item(const display_menu_base::MenuItem *ite this->display_->print(0, row, data); } -} // namespace lcd_menu -} // namespace esphome +} // namespace esphome::lcd_menu diff --git a/esphome/components/lcd_menu/lcd_menu.h b/esphome/components/lcd_menu/lcd_menu.h index d0dbca7b2fc..ae1c2502fea 100644 --- a/esphome/components/lcd_menu/lcd_menu.h +++ b/esphome/components/lcd_menu/lcd_menu.h @@ -6,8 +6,7 @@ #include #include -namespace esphome { -namespace lcd_menu { +namespace esphome::lcd_menu { /** Class to display a hierarchical menu. * @@ -41,5 +40,4 @@ class LCDCharacterMenuComponent : public display_menu_base::DisplayMenuComponent char mark_back_; }; -} // namespace lcd_menu -} // namespace esphome +} // namespace esphome::lcd_menu diff --git a/esphome/components/lcd_pcf8574/pcf8574_display.cpp b/esphome/components/lcd_pcf8574/pcf8574_display.cpp index d582eead913..d5fc6835985 100644 --- a/esphome/components/lcd_pcf8574/pcf8574_display.cpp +++ b/esphome/components/lcd_pcf8574/pcf8574_display.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace lcd_pcf8574 { +namespace esphome::lcd_pcf8574 { static const char *const TAG = "lcd_pcf8574"; @@ -56,5 +55,4 @@ void PCF8574LCDDisplay::no_backlight() { this->write_bytes(this->backlight_value_, nullptr, 0); } -} // namespace lcd_pcf8574 -} // namespace esphome +} // namespace esphome::lcd_pcf8574 diff --git a/esphome/components/lcd_pcf8574/pcf8574_display.h b/esphome/components/lcd_pcf8574/pcf8574_display.h index 672b6090368..9ec5ad71af1 100644 --- a/esphome/components/lcd_pcf8574/pcf8574_display.h +++ b/esphome/components/lcd_pcf8574/pcf8574_display.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/display/display.h" -namespace esphome { -namespace lcd_pcf8574 { +namespace esphome::lcd_pcf8574 { class PCF8574LCDDisplay; @@ -32,5 +31,4 @@ class PCF8574LCDDisplay : public lcd_base::LCDDisplay, public i2c::I2CDevice { pcf8574_lcd_writer_t writer_; }; -} // namespace lcd_pcf8574 -} // namespace esphome +} // namespace esphome::lcd_pcf8574 diff --git a/esphome/components/lightwaverf/LwRx.h b/esphome/components/lightwaverf/LwRx.h index 8b34de9fbbd..1e005ab44cf 100644 --- a/esphome/components/lightwaverf/LwRx.h +++ b/esphome/components/lightwaverf/LwRx.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { // LwRx.h // @@ -138,5 +137,4 @@ class LwRx { InternalGPIOPin *rx_pin_; }; -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf diff --git a/esphome/components/lightwaverf/LwTx.h b/esphome/components/lightwaverf/LwTx.h index 9192426440f..2d0019c0957 100644 --- a/esphome/components/lightwaverf/LwTx.h +++ b/esphome/components/lightwaverf/LwTx.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { // LxTx.h // @@ -90,5 +89,4 @@ class LwTx { uint32_t duty_off_; }; -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf diff --git a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp index ee6c2ee4718..87319235e9b 100644 --- a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp +++ b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace lilygo_t5_47 { +namespace esphome::lilygo_t5_47 { static const char *const TAG = "lilygo_t5_47.touchscreen"; @@ -104,5 +103,4 @@ void LilygoT547Touchscreen::dump_config() { LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_); } -} // namespace lilygo_t5_47 -} // namespace esphome +} // namespace esphome::lilygo_t5_47 diff --git a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.h b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.h index 6767bf0a71c..8b345515ab0 100644 --- a/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.h +++ b/esphome/components/lilygo_t5_47/touchscreen/lilygo_t5_47_touchscreen.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace lilygo_t5_47 { +namespace esphome::lilygo_t5_47 { using namespace touchscreen; @@ -27,5 +26,4 @@ class LilygoT547Touchscreen : public Touchscreen, public i2c::I2CDevice { InternalGPIOPin *interrupt_pin_; }; -} // namespace lilygo_t5_47 -} // namespace esphome +} // namespace esphome::lilygo_t5_47 diff --git a/esphome/components/lm75b/lm75b.cpp b/esphome/components/lm75b/lm75b.cpp index 19398eda853..2e8b9d3cfe1 100644 --- a/esphome/components/lm75b/lm75b.cpp +++ b/esphome/components/lm75b/lm75b.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace lm75b { +namespace esphome::lm75b { static const char *const TAG = "lm75b"; @@ -35,5 +34,4 @@ void LM75BComponent::update() { } } -} // namespace lm75b -} // namespace esphome +} // namespace esphome::lm75b diff --git a/esphome/components/lm75b/lm75b.h b/esphome/components/lm75b/lm75b.h index 79d9fa3f32d..eaf1b46550e 100644 --- a/esphome/components/lm75b/lm75b.h +++ b/esphome/components/lm75b/lm75b.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace lm75b { +namespace esphome::lm75b { static const uint8_t LM75B_REG_TEMPERATURE = 0x00; @@ -15,5 +14,4 @@ class LM75BComponent : public PollingComponent, public i2c::I2CDevice, public se void update() override; }; -} // namespace lm75b -} // namespace esphome +} // namespace esphome::lm75b diff --git a/esphome/components/lps22/lps22.cpp b/esphome/components/lps22/lps22.cpp index 592b7faaf0f..020add695c1 100644 --- a/esphome/components/lps22/lps22.cpp +++ b/esphome/components/lps22/lps22.cpp @@ -1,7 +1,6 @@ #include "lps22.h" -namespace esphome { -namespace lps22 { +namespace esphome::lps22 { static constexpr const char *const TAG = "lps22"; @@ -78,5 +77,4 @@ void LPS22Component::try_read_() { } } -} // namespace lps22 -} // namespace esphome +} // namespace esphome::lps22 diff --git a/esphome/components/lps22/lps22.h b/esphome/components/lps22/lps22.h index 95ee4ad4427..c6746f23433 100644 --- a/esphome/components/lps22/lps22.h +++ b/esphome/components/lps22/lps22.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace lps22 { +namespace esphome::lps22 { class LPS22Component : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { public: @@ -24,5 +23,4 @@ class LPS22Component : public sensor::Sensor, public PollingComponent, public i2 uint8_t read_attempts_remaining_{0}; }; -} // namespace lps22 -} // namespace esphome +} // namespace esphome::lps22 diff --git a/esphome/components/ltr390/ltr390.cpp b/esphome/components/ltr390/ltr390.cpp index 033f31a3d17..62a0d2290ae 100644 --- a/esphome/components/ltr390/ltr390.cpp +++ b/esphome/components/ltr390/ltr390.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace ltr390 { +namespace esphome::ltr390 { static const char *const TAG = "ltr390"; @@ -203,5 +202,4 @@ void LTR390Component::update() { this->read_mode_((this->enabled_modes_ & ENABLED_MODE_ALS) ? LTR390_MODE_ALS : LTR390_MODE_UVS); } -} // namespace ltr390 -} // namespace esphome +} // namespace esphome::ltr390 diff --git a/esphome/components/ltr390/ltr390.h b/esphome/components/ltr390/ltr390.h index 47884b91667..1ead84b4a86 100644 --- a/esphome/components/ltr390/ltr390.h +++ b/esphome/components/ltr390/ltr390.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/optional.h" -namespace esphome { -namespace ltr390 { +namespace esphome::ltr390 { enum LTR390CTRL { LTR390_CTRL_EN = 1, @@ -85,5 +84,4 @@ class LTR390Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *uv_sensor_{nullptr}; }; -} // namespace ltr390 -} // namespace esphome +} // namespace esphome::ltr390 diff --git a/esphome/components/ltr501/ltr501.cpp b/esphome/components/ltr501/ltr501.cpp index 4c9006be1d9..9cba06e483b 100644 --- a/esphome/components/ltr501/ltr501.cpp +++ b/esphome/components/ltr501/ltr501.cpp @@ -6,8 +6,7 @@ using esphome::i2c::ErrorCode; -namespace esphome { -namespace ltr501 { +namespace esphome::ltr501 { static const char *const TAG = "ltr501"; @@ -542,5 +541,4 @@ void LTRAlsPs501Component::publish_data_part_2_(AlsReadings &data) { this->actual_integration_time_sensor_->publish_state(get_itime_ms(data.integration_time)); } } -} // namespace ltr501 -} // namespace esphome +} // namespace esphome::ltr501 diff --git a/esphome/components/ltr501/ltr501.h b/esphome/components/ltr501/ltr501.h index 2b914631087..c7eccbeea96 100644 --- a/esphome/components/ltr501/ltr501.h +++ b/esphome/components/ltr501/ltr501.h @@ -8,8 +8,7 @@ #include "ltr_definitions_501.h" -namespace esphome { -namespace ltr501 { +namespace esphome::ltr501 { enum LtrDataAvail : uint8_t { LTR_NO_DATA, LTR_BAD_DATA, LTR_DATA_OK }; @@ -162,5 +161,4 @@ class LTRAlsPs501Component : public PollingComponent, public i2c::I2CDevice { CallbackManager on_ps_high_trigger_callback_; CallbackManager on_ps_low_trigger_callback_; }; -} // namespace ltr501 -} // namespace esphome +} // namespace esphome::ltr501 diff --git a/esphome/components/ltr501/ltr_definitions_501.h b/esphome/components/ltr501/ltr_definitions_501.h index 604bd92b680..c92fad2d66e 100644 --- a/esphome/components/ltr501/ltr_definitions_501.h +++ b/esphome/components/ltr501/ltr_definitions_501.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace ltr501 { +namespace esphome::ltr501 { enum class CommandRegisters : uint8_t { ALS_CONTR = 0x80, // ALS operation mode control and SW reset @@ -256,5 +255,4 @@ union InterruptPersistRegister { } __attribute__((packed)); }; -} // namespace ltr501 -} // namespace esphome +} // namespace esphome::ltr501 diff --git a/esphome/components/ltr_als_ps/ltr_als_ps.cpp b/esphome/components/ltr_als_ps/ltr_als_ps.cpp index ff335fe34c6..b7fad2e8767 100644 --- a/esphome/components/ltr_als_ps/ltr_als_ps.cpp +++ b/esphome/components/ltr_als_ps/ltr_als_ps.cpp @@ -6,8 +6,7 @@ using esphome::i2c::ErrorCode; -namespace esphome { -namespace ltr_als_ps { +namespace esphome::ltr_als_ps { static const char *const TAG = "ltr_als_ps"; @@ -521,5 +520,4 @@ void LTRAlsPsComponent::publish_data_part_2_(AlsReadings &data) { this->actual_integration_time_sensor_->publish_state(get_itime_ms(data.integration_time)); } } -} // namespace ltr_als_ps -} // namespace esphome +} // namespace esphome::ltr_als_ps diff --git a/esphome/components/ltr_als_ps/ltr_als_ps.h b/esphome/components/ltr_als_ps/ltr_als_ps.h index 8aa5c9f24b1..67d8fddad22 100644 --- a/esphome/components/ltr_als_ps/ltr_als_ps.h +++ b/esphome/components/ltr_als_ps/ltr_als_ps.h @@ -8,8 +8,7 @@ #include "ltr_definitions.h" -namespace esphome { -namespace ltr_als_ps { +namespace esphome::ltr_als_ps { enum LtrDataAvail : uint8_t { LTR_NO_DATA, LTR_BAD_DATA, LTR_DATA_OK }; @@ -162,5 +161,4 @@ class LTRAlsPsComponent : public PollingComponent, public i2c::I2CDevice { CallbackManager on_ps_high_trigger_callback_; CallbackManager on_ps_low_trigger_callback_; }; -} // namespace ltr_als_ps -} // namespace esphome +} // namespace esphome::ltr_als_ps diff --git a/esphome/components/ltr_als_ps/ltr_definitions.h b/esphome/components/ltr_als_ps/ltr_definitions.h index 739445e9a0e..c70c2f1804e 100644 --- a/esphome/components/ltr_als_ps/ltr_definitions.h +++ b/esphome/components/ltr_als_ps/ltr_definitions.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace ltr_als_ps { +namespace esphome::ltr_als_ps { enum class CommandRegisters : uint8_t { ALS_CONTR = 0x80, // ALS operation mode control and SW reset @@ -271,5 +270,4 @@ union InterruptPersistRegister { } __attribute__((packed)); }; -} // namespace ltr_als_ps -} // namespace esphome +} // namespace esphome::ltr_als_ps diff --git a/esphome/components/lvgl/light/lvgl_light.h b/esphome/components/lvgl/light/lvgl_light.h index 7309df97638..50da7af6021 100644 --- a/esphome/components/lvgl/light/lvgl_light.h +++ b/esphome/components/lvgl/light/lvgl_light.h @@ -4,8 +4,7 @@ #include "esphome/components/light/light_output.h" #include "../lvgl_esphome.h" -namespace esphome { -namespace lvgl { +namespace esphome::lvgl { class LVLight : public light::LightOutput { public: @@ -44,5 +43,4 @@ class LVLight : public light::LightOutput { optional initial_value_{}; }; -} // namespace lvgl -} // namespace esphome +} // namespace esphome::lvgl diff --git a/esphome/components/lvgl/lvgl_proxy.h b/esphome/components/lvgl/lvgl_proxy.h index 0ccd80e541b..499735ad88e 100644 --- a/esphome/components/lvgl/lvgl_proxy.h +++ b/esphome/components/lvgl/lvgl_proxy.h @@ -11,7 +11,5 @@ file is included in the build, LVGL is always included. #endif // LV_CONF_H #include -namespace esphome { -namespace lvgl {} // namespace lvgl -} // namespace esphome -#endif // USE_LVGL +namespace esphome::lvgl {} // namespace esphome::lvgl +#endif // USE_LVGL diff --git a/esphome/components/lvgl/number/lvgl_number.h b/esphome/components/lvgl/number/lvgl_number.h index 44409a0ad53..ba16b1f0b39 100644 --- a/esphome/components/lvgl/number/lvgl_number.h +++ b/esphome/components/lvgl/number/lvgl_number.h @@ -6,8 +6,7 @@ #include "esphome/core/component.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace lvgl { +namespace esphome::lvgl { class LVGLNumber : public number::Number, public Component { public: @@ -48,5 +47,4 @@ class LVGLNumber : public number::Number, public Component { ESPPreferenceObject pref_{}; }; -} // namespace lvgl -} // namespace esphome +} // namespace esphome::lvgl diff --git a/esphome/components/lvgl/select/lvgl_select.h b/esphome/components/lvgl/select/lvgl_select.h index 3b00310b67b..ffbe29d701e 100644 --- a/esphome/components/lvgl/select/lvgl_select.h +++ b/esphome/components/lvgl/select/lvgl_select.h @@ -8,8 +8,7 @@ #include "esphome/core/preferences.h" #include "esphome/components/lvgl/lvgl_esphome.h" -namespace esphome { -namespace lvgl { +namespace esphome::lvgl { class LVGLSelect : public select::Select, public Component { public: @@ -71,5 +70,4 @@ class LVGLSelect : public select::Select, public Component { ESPPreferenceObject pref_{}; }; -} // namespace lvgl -} // namespace esphome +} // namespace esphome::lvgl diff --git a/esphome/components/lvgl/switch/lvgl_switch.h b/esphome/components/lvgl/switch/lvgl_switch.h index 485459691c9..8f5502a7d5e 100644 --- a/esphome/components/lvgl/switch/lvgl_switch.h +++ b/esphome/components/lvgl/switch/lvgl_switch.h @@ -7,8 +7,7 @@ #include "esphome/core/component.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace lvgl { +namespace esphome::lvgl { class LVGLSwitch : public switch_::Switch, public Component { public: @@ -21,5 +20,4 @@ class LVGLSwitch : public switch_::Switch, public Component { std::function state_lambda_{}; }; -} // namespace lvgl -} // namespace esphome +} // namespace esphome::lvgl diff --git a/esphome/components/lvgl/text/lvgl_text.h b/esphome/components/lvgl/text/lvgl_text.h index eacf69b6ec8..fead48d6fe1 100644 --- a/esphome/components/lvgl/text/lvgl_text.h +++ b/esphome/components/lvgl/text/lvgl_text.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -namespace esphome { -namespace lvgl { +namespace esphome::lvgl { class LVGLText : public text::Text { public: @@ -29,5 +28,4 @@ class LVGLText : public text::Text { optional initial_state_{}; }; -} // namespace lvgl -} // namespace esphome +} // namespace esphome::lvgl diff --git a/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.cpp b/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.cpp index 3eeba4a644f..680b3bcd9e7 100644 --- a/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.cpp +++ b/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.cpp @@ -1,7 +1,6 @@ #include "m5stack_8angle_binary_sensor.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { void M5Stack8AngleSwitchBinarySensor::update() { int8_t out = this->parent_->read_switch(); @@ -13,5 +12,4 @@ void M5Stack8AngleSwitchBinarySensor::update() { this->status_clear_warning(); } -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.h b/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.h index b8bb601525e..14400bcea17 100644 --- a/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.h +++ b/esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.h @@ -5,8 +5,7 @@ #include "../m5stack_8angle.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { class M5Stack8AngleSwitchBinarySensor : public binary_sensor::BinarySensor, public PollingComponent, @@ -15,5 +14,4 @@ class M5Stack8AngleSwitchBinarySensor : public binary_sensor::BinarySensor, void update() override; }; -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/light/m5stack_8angle_light.cpp b/esphome/components/m5stack_8angle/light/m5stack_8angle_light.cpp index 0e7b9029198..e132c54daad 100644 --- a/esphome/components/m5stack_8angle/light/m5stack_8angle_light.cpp +++ b/esphome/components/m5stack_8angle/light/m5stack_8angle_light.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { static const char *const TAG = "m5stack_8angle.light"; @@ -41,5 +40,4 @@ light::ESPColorView M5Stack8AngleLightOutput::get_view_internal(int32_t index) c nullptr, this->effect_data_ + index, &this->correction_}; } -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/light/m5stack_8angle_light.h b/esphome/components/m5stack_8angle/light/m5stack_8angle_light.h index 204f2c04c7b..0a5a50f2a86 100644 --- a/esphome/components/m5stack_8angle/light/m5stack_8angle_light.h +++ b/esphome/components/m5stack_8angle/light/m5stack_8angle_light.h @@ -5,8 +5,7 @@ #include "../m5stack_8angle.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { static const uint8_t M5STACK_8ANGLE_NUM_LEDS = 9; static const uint8_t M5STACK_8ANGLE_BYTES_PER_LED = 4; @@ -33,5 +32,4 @@ class M5Stack8AngleLightOutput : public light::AddressableLight, public Parented uint8_t *effect_data_{nullptr}; }; -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/m5stack_8angle.cpp b/esphome/components/m5stack_8angle/m5stack_8angle.cpp index 2de900c21dc..f466fba77e7 100644 --- a/esphome/components/m5stack_8angle/m5stack_8angle.cpp +++ b/esphome/components/m5stack_8angle/m5stack_8angle.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { static const char *const TAG = "m5stack_8angle"; @@ -69,5 +68,4 @@ int8_t M5Stack8AngleComponent::read_switch() { } } -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/m5stack_8angle.h b/esphome/components/m5stack_8angle/m5stack_8angle.h index 49425180540..ab2e232204e 100644 --- a/esphome/components/m5stack_8angle/m5stack_8angle.h +++ b/esphome/components/m5stack_8angle/m5stack_8angle.h @@ -3,8 +3,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/component.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { static const uint8_t M5STACK_8ANGLE_REGISTER_ANALOG_INPUT_12B = 0x00; static const uint8_t M5STACK_8ANGLE_REGISTER_ANALOG_INPUT_8B = 0x10; @@ -29,5 +28,4 @@ class M5Stack8AngleComponent : public i2c::I2CDevice, public Component { uint8_t fw_version_; }; -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.cpp b/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.cpp index d22b3451415..b05e1e68163 100644 --- a/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.cpp +++ b/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.cpp @@ -1,7 +1,6 @@ #include "m5stack_8angle_sensor.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { void M5Stack8AngleKnobSensor::update() { if (this->parent_ != nullptr) { @@ -20,5 +19,4 @@ void M5Stack8AngleKnobSensor::update() { }; } -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.h b/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.h index 4848f8f80f5..418503d7c87 100644 --- a/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.h +++ b/esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.h @@ -5,8 +5,7 @@ #include "../m5stack_8angle.h" -namespace esphome { -namespace m5stack_8angle { +namespace esphome::m5stack_8angle { class M5Stack8AngleKnobSensor : public sensor::Sensor, public PollingComponent, @@ -23,5 +22,4 @@ class M5Stack8AngleKnobSensor : public sensor::Sensor, bool raw_; }; -} // namespace m5stack_8angle -} // namespace esphome +} // namespace esphome::m5stack_8angle diff --git a/esphome/components/matrix_keypad/binary_sensor/matrix_keypad_binary_sensor.h b/esphome/components/matrix_keypad/binary_sensor/matrix_keypad_binary_sensor.h index 2c1ce96f0a6..53ae0b5c03b 100644 --- a/esphome/components/matrix_keypad/binary_sensor/matrix_keypad_binary_sensor.h +++ b/esphome/components/matrix_keypad/binary_sensor/matrix_keypad_binary_sensor.h @@ -3,8 +3,7 @@ #include "esphome/components/matrix_keypad/matrix_keypad.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace matrix_keypad { +namespace esphome::matrix_keypad { class MatrixKeypadBinarySensor : public MatrixKeypadListener, public binary_sensor::BinarySensorInitiallyOff { public: @@ -47,5 +46,4 @@ class MatrixKeypadBinarySensor : public MatrixKeypadListener, public binary_sens int col_; }; -} // namespace matrix_keypad -} // namespace esphome +} // namespace esphome::matrix_keypad diff --git a/esphome/components/matrix_keypad/matrix_keypad.cpp b/esphome/components/matrix_keypad/matrix_keypad.cpp index cc46ba98d63..3b71b50fd87 100644 --- a/esphome/components/matrix_keypad/matrix_keypad.cpp +++ b/esphome/components/matrix_keypad/matrix_keypad.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace matrix_keypad { +namespace esphome::matrix_keypad { static const char *const TAG = "matrix_keypad"; @@ -110,5 +109,4 @@ void MatrixKeypad::register_listener(MatrixKeypadListener *listener) { this->lis void MatrixKeypad::register_key_trigger(MatrixKeyTrigger *trig) { this->key_triggers_.push_back(trig); } -} // namespace matrix_keypad -} // namespace esphome +} // namespace esphome::matrix_keypad diff --git a/esphome/components/matrix_keypad/matrix_keypad.h b/esphome/components/matrix_keypad/matrix_keypad.h index 8963612d0c7..1e263842ea0 100644 --- a/esphome/components/matrix_keypad/matrix_keypad.h +++ b/esphome/components/matrix_keypad/matrix_keypad.h @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace matrix_keypad { +namespace esphome::matrix_keypad { class MatrixKeypadListener { public: @@ -51,5 +50,4 @@ class MatrixKeypad : public key_provider::KeyProvider, public Component { std::vector key_triggers_; }; -} // namespace matrix_keypad -} // namespace esphome +} // namespace esphome::matrix_keypad diff --git a/esphome/components/max17043/automation.h b/esphome/components/max17043/automation.h index ac201a73096..c98516d2593 100644 --- a/esphome/components/max17043/automation.h +++ b/esphome/components/max17043/automation.h @@ -3,8 +3,7 @@ #include "esphome/core/automation.h" #include "max17043.h" -namespace esphome { -namespace max17043 { +namespace esphome::max17043 { template class SleepAction : public Action { public: @@ -16,5 +15,4 @@ template class SleepAction : public Action { MAX17043Component *max17043_; }; -} // namespace max17043 -} // namespace esphome +} // namespace esphome::max17043 diff --git a/esphome/components/max17043/max17043.cpp b/esphome/components/max17043/max17043.cpp index dfd59f1e7df..b59bac7ebf5 100644 --- a/esphome/components/max17043/max17043.cpp +++ b/esphome/components/max17043/max17043.cpp @@ -1,8 +1,7 @@ #include "max17043.h" #include "esphome/core/log.h" -namespace esphome { -namespace max17043 { +namespace esphome::max17043 { // MAX174043 is a 1-Cell Fuel Gauge with ModelGauge and Low-Battery Alert // Consult the datasheet at https://www.analog.com/en/products/max17043.html @@ -90,5 +89,4 @@ void MAX17043Component::sleep_mode() { } } -} // namespace max17043 -} // namespace esphome +} // namespace esphome::max17043 diff --git a/esphome/components/max17043/max17043.h b/esphome/components/max17043/max17043.h index f477ce59487..dd2e35df555 100644 --- a/esphome/components/max17043/max17043.h +++ b/esphome/components/max17043/max17043.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace max17043 { +namespace esphome::max17043 { class MAX17043Component : public PollingComponent, public i2c::I2CDevice { public: @@ -24,5 +23,4 @@ class MAX17043Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *battery_remaining_sensor_{nullptr}; }; -} // namespace max17043 -} // namespace esphome +} // namespace esphome::max17043 diff --git a/esphome/components/max31855/max31855.cpp b/esphome/components/max31855/max31855.cpp index 8370977ce2e..ac6b3cecb42 100644 --- a/esphome/components/max31855/max31855.cpp +++ b/esphome/components/max31855/max31855.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace max31855 { +namespace esphome::max31855 { static const char *const TAG = "max31855"; @@ -100,5 +99,4 @@ void MAX31855Sensor::read_data_() { this->status_clear_warning(); } -} // namespace max31855 -} // namespace esphome +} // namespace esphome::max31855 diff --git a/esphome/components/max31855/max31855.h b/esphome/components/max31855/max31855.h index b755d240f26..dd7a2052686 100644 --- a/esphome/components/max31855/max31855.h +++ b/esphome/components/max31855/max31855.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace max31855 { +namespace esphome::max31855 { class MAX31855Sensor : public sensor::Sensor, public PollingComponent, @@ -26,5 +25,4 @@ class MAX31855Sensor : public sensor::Sensor, sensor::Sensor *temperature_reference_{nullptr}; }; -} // namespace max31855 -} // namespace esphome +} // namespace esphome::max31855 diff --git a/esphome/components/max31856/max31856.cpp b/esphome/components/max31856/max31856.cpp index 35e12309ba3..4062d21beee 100644 --- a/esphome/components/max31856/max31856.cpp +++ b/esphome/components/max31856/max31856.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace max31856 { +namespace esphome::max31856 { static const char *const TAG = "max31856"; @@ -197,5 +196,4 @@ uint32_t MAX31856Sensor::read_register24_(uint8_t reg) { return value; } -} // namespace max31856 -} // namespace esphome +} // namespace esphome::max31856 diff --git a/esphome/components/max31856/max31856.h b/esphome/components/max31856/max31856.h index a27ababa2ea..0a983b72d98 100644 --- a/esphome/components/max31856/max31856.h +++ b/esphome/components/max31856/max31856.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace max31856 { +namespace esphome::max31856 { enum MAX31856RegisterMasks { SPI_WRITE_M = 0x80 }; @@ -98,5 +97,4 @@ class MAX31856Sensor : public sensor::Sensor, void set_noise_filter_(); }; -} // namespace max31856 -} // namespace esphome +} // namespace esphome::max31856 diff --git a/esphome/components/max31865/max31865.cpp b/esphome/components/max31865/max31865.cpp index 8b06a01166e..220fb4e7041 100644 --- a/esphome/components/max31865/max31865.cpp +++ b/esphome/components/max31865/max31865.cpp @@ -4,8 +4,7 @@ #include #include -namespace esphome { -namespace max31865 { +namespace esphome::max31865 { static const char *const TAG = "max31865"; @@ -226,5 +225,4 @@ float MAX31865Sensor::calc_temperature_(float rtd_ratio) { return neg_temp; } -} // namespace max31865 -} // namespace esphome +} // namespace esphome::max31865 diff --git a/esphome/components/max31865/max31865.h b/esphome/components/max31865/max31865.h index 440c6523a6c..3362cd30dee 100644 --- a/esphome/components/max31865/max31865.h +++ b/esphome/components/max31865/max31865.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace max31865 { +namespace esphome::max31865 { enum MAX31865RegisterMasks { SPI_WRITE_M = 0x80 }; enum MAX31865Registers { @@ -53,5 +52,4 @@ class MAX31865Sensor : public sensor::Sensor, float calc_temperature_(float rtd_ratio); }; -} // namespace max31865 -} // namespace esphome +} // namespace esphome::max31865 diff --git a/esphome/components/max44009/max44009.cpp b/esphome/components/max44009/max44009.cpp index cbce0535196..6b8bdc8de5e 100644 --- a/esphome/components/max44009/max44009.cpp +++ b/esphome/components/max44009/max44009.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace max44009 { +namespace esphome::max44009 { static const char *const TAG = "max44009.sensor"; @@ -137,5 +136,4 @@ void MAX44009Sensor::write_(uint8_t reg, uint8_t value) { void MAX44009Sensor::set_mode(MAX44009Mode mode) { this->mode_ = mode; } -} // namespace max44009 -} // namespace esphome +} // namespace esphome::max44009 diff --git a/esphome/components/max44009/max44009.h b/esphome/components/max44009/max44009.h index d0ffd7bc706..12fd0b1ce0f 100644 --- a/esphome/components/max44009/max44009.h +++ b/esphome/components/max44009/max44009.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace max44009 { +namespace esphome::max44009 { enum MAX44009Mode { MAX44009_MODE_AUTO, MAX44009_MODE_LOW_POWER, MAX44009_MODE_CONTINUOUS }; @@ -32,5 +31,4 @@ class MAX44009Sensor : public sensor::Sensor, public PollingComponent, public i2 MAX44009Mode mode_{MAX44009_MODE_AUTO}; }; -} // namespace max44009 -} // namespace esphome +} // namespace esphome::max44009 diff --git a/esphome/components/max6675/max6675.cpp b/esphome/components/max6675/max6675.cpp index b8527c6b1dd..8734405508f 100644 --- a/esphome/components/max6675/max6675.cpp +++ b/esphome/components/max6675/max6675.cpp @@ -1,8 +1,7 @@ #include "max6675.h" #include "esphome/core/log.h" -namespace esphome { -namespace max6675 { +namespace esphome::max6675 { static const char *const TAG = "max6675"; @@ -43,5 +42,4 @@ void MAX6675Sensor::read_data_() { this->status_clear_warning(); } -} // namespace max6675 -} // namespace esphome +} // namespace esphome::max6675 diff --git a/esphome/components/max6675/max6675.h b/esphome/components/max6675/max6675.h index f0db4a6c268..e7b5c4dbde5 100644 --- a/esphome/components/max6675/max6675.h +++ b/esphome/components/max6675/max6675.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace max6675 { +namespace esphome::max6675 { class MAX6675Sensor : public sensor::Sensor, public PollingComponent, @@ -21,5 +20,4 @@ class MAX6675Sensor : public sensor::Sensor, void read_data_(); }; -} // namespace max6675 -} // namespace esphome +} // namespace esphome::max6675 diff --git a/esphome/components/max6956/automation.h b/esphome/components/max6956/automation.h index ca2c3e3ce4d..547ed5a8656 100644 --- a/esphome/components/max6956/automation.h +++ b/esphome/components/max6956/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/max6956/max6956.h" -namespace esphome { -namespace max6956 { +namespace esphome::max6956 { template class SetCurrentGlobalAction : public Action { public: @@ -36,5 +35,4 @@ template class SetCurrentModeAction : public Action { protected: MAX6956 *max6956_; }; -} // namespace max6956 -} // namespace esphome +} // namespace esphome::max6956 diff --git a/esphome/components/max6956/max6956.cpp b/esphome/components/max6956/max6956.cpp index ce45541b635..ccb14496aa8 100644 --- a/esphome/components/max6956/max6956.cpp +++ b/esphome/components/max6956/max6956.cpp @@ -1,8 +1,7 @@ #include "max6956.h" #include "esphome/core/log.h" -namespace esphome { -namespace max6956 { +namespace esphome::max6956 { static const char *const TAG = "max6956"; @@ -167,5 +166,4 @@ size_t MAX6956GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via Max6956", this->pin_); } -} // namespace max6956 -} // namespace esphome +} // namespace esphome::max6956 diff --git a/esphome/components/max6956/max6956.h b/esphome/components/max6956/max6956.h index 31f97c11f8a..83ccfab559f 100644 --- a/esphome/components/max6956/max6956.h +++ b/esphome/components/max6956/max6956.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace max6956 { +namespace esphome::max6956 { /// Modes for MAX6956 pins enum MAX6956GPIOMode : uint8_t { @@ -92,5 +91,4 @@ class MAX6956GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace max6956 -} // namespace esphome +} // namespace esphome::max6956 diff --git a/esphome/components/max6956/output/max6956_led_output.cpp b/esphome/components/max6956/output/max6956_led_output.cpp index 5fa2dd9b344..c53a429d203 100644 --- a/esphome/components/max6956/output/max6956_led_output.cpp +++ b/esphome/components/max6956/output/max6956_led_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace max6956 { +namespace esphome::max6956 { static const char *const TAG = "max6956_led_channel"; @@ -22,5 +21,4 @@ void MAX6956LedChannel::dump_config() { LOG_FLOAT_OUTPUT(this); } -} // namespace max6956 -} // namespace esphome +} // namespace esphome::max6956 diff --git a/esphome/components/max6956/output/max6956_led_output.h b/esphome/components/max6956/output/max6956_led_output.h index b844a7ceee6..49e5b9ef842 100644 --- a/esphome/components/max6956/output/max6956_led_output.h +++ b/esphome/components/max6956/output/max6956_led_output.h @@ -3,8 +3,7 @@ #include "esphome/components/max6956/max6956.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace max6956 { +namespace esphome::max6956 { class MAX6956; @@ -24,5 +23,4 @@ class MAX6956LedChannel : public output::FloatOutput, public Component { uint8_t pin_; }; -} // namespace max6956 -} // namespace esphome +} // namespace esphome::max6956 diff --git a/esphome/components/max7219digit/automation.h b/esphome/components/max7219digit/automation.h index be8245d14d3..485a34075ee 100644 --- a/esphome/components/max7219digit/automation.h +++ b/esphome/components/max7219digit/automation.h @@ -5,8 +5,7 @@ #include "max7219digit.h" -namespace esphome { -namespace max7219digit { +namespace esphome::max7219digit { template class DisplayInvertAction : public Action, public Parented { public: @@ -48,5 +47,4 @@ template class DisplayIntensityAction : public Action, pu } }; -} // namespace max7219digit -} // namespace esphome +} // namespace esphome::max7219digit diff --git a/esphome/components/max7219digit/max7219digit.cpp b/esphome/components/max7219digit/max7219digit.cpp index f9b46cf797d..26c65aa5d34 100644 --- a/esphome/components/max7219digit/max7219digit.cpp +++ b/esphome/components/max7219digit/max7219digit.cpp @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace max7219digit { +namespace esphome::max7219digit { static const char *const TAG = "max7219DIGIT"; @@ -352,5 +351,4 @@ uint8_t MAX7219Component::strftimedigit(const char *format, ESPTime time) { return this->strftimedigit(0, format, time); } -} // namespace max7219digit -} // namespace esphome +} // namespace esphome::max7219digit diff --git a/esphome/components/max7219digit/max7219digit.h b/esphome/components/max7219digit/max7219digit.h index af419b9b382..bbf43059ddc 100644 --- a/esphome/components/max7219digit/max7219digit.h +++ b/esphome/components/max7219digit/max7219digit.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace max7219digit { +namespace esphome::max7219digit { enum ChipLinesStyle { ZIGZAG = 0, @@ -120,5 +119,4 @@ class MAX7219Component : public display::DisplayBuffer, max7219_writer_t writer_local_{}; }; -} // namespace max7219digit -} // namespace esphome +} // namespace esphome::max7219digit diff --git a/esphome/components/max7219digit/max7219font.h b/esphome/components/max7219digit/max7219font.h index 53674dc60f1..a5eea7e20fd 100644 --- a/esphome/components/max7219digit/max7219font.h +++ b/esphome/components/max7219digit/max7219font.h @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" -namespace esphome { -namespace max7219digit { +namespace esphome::max7219digit { // bit patterns for the CP437 font @@ -266,5 +265,4 @@ constexpr uint8_t MAX7219_DOT_MATRIX_FONT[256][8] PROGMEM = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0xFF }; // end of MAX7219_Dot_Matrix_font -} // namespace max7219digit -} // namespace esphome +} // namespace esphome::max7219digit diff --git a/esphome/components/max9611/max9611.cpp b/esphome/components/max9611/max9611.cpp index f00f9d76be4..68ef7c31358 100644 --- a/esphome/components/max9611/max9611.cpp +++ b/esphome/components/max9611/max9611.cpp @@ -1,8 +1,8 @@ #include "max9611.h" #include "esphome/core/log.h" #include "esphome/components/i2c/i2c_bus.h" -namespace esphome { -namespace max9611 { + +namespace esphome::max9611 { using namespace esphome::i2c; // Sign extend // http://graphics.stanford.edu/~seander/bithacks.html#FixedSignExtend @@ -91,5 +91,4 @@ void MAX9611Component::update() { ESP_LOGD(TAG, "V: %f, A: %f, W: %f, Deg C: %f", voltage, amps, watts, temp); } -} // namespace max9611 -} // namespace esphome +} // namespace esphome::max9611 diff --git a/esphome/components/max9611/max9611.h b/esphome/components/max9611/max9611.h index 1eb7542aeee..b6fb5d81273 100644 --- a/esphome/components/max9611/max9611.h +++ b/esphome/components/max9611/max9611.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/hal.h" -namespace esphome { -namespace max9611 { +namespace esphome::max9611 { enum MAX9611Multiplexer { MAX9611_MULTIPLEXER_CSA_GAIN1 = 0b000, @@ -57,5 +56,4 @@ class MAX9611Component : public PollingComponent, public i2c::I2CDevice { MAX9611Multiplexer gain_; }; -} // namespace max9611 -} // namespace esphome +} // namespace esphome::max9611 diff --git a/esphome/components/mcp23008/mcp23008.cpp b/esphome/components/mcp23008/mcp23008.cpp index 5f73e03f6f6..6be5f4c9518 100644 --- a/esphome/components/mcp23008/mcp23008.cpp +++ b/esphome/components/mcp23008/mcp23008.cpp @@ -1,8 +1,7 @@ #include "mcp23008.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp23008 { +namespace esphome::mcp23008 { static const char *const TAG = "mcp23008"; @@ -45,5 +44,4 @@ bool MCP23008::write_reg(uint8_t reg, uint8_t value) { return this->write_byte(reg, value); } -} // namespace mcp23008 -} // namespace esphome +} // namespace esphome::mcp23008 diff --git a/esphome/components/mcp23008/mcp23008.h b/esphome/components/mcp23008/mcp23008.h index 406ce0b419f..ae2f9e1f3c0 100644 --- a/esphome/components/mcp23008/mcp23008.h +++ b/esphome/components/mcp23008/mcp23008.h @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp23008 { +namespace esphome::mcp23008 { class MCP23008 : public mcp23x08_base::MCP23X08Base, public i2c::I2CDevice { public: @@ -20,5 +19,4 @@ class MCP23008 : public mcp23x08_base::MCP23X08Base, public i2c::I2CDevice { bool write_reg(uint8_t reg, uint8_t value) override; }; -} // namespace mcp23008 -} // namespace esphome +} // namespace esphome::mcp23008 diff --git a/esphome/components/mcp23016/mcp23016.cpp b/esphome/components/mcp23016/mcp23016.cpp index b7a9cfd0ce7..126ece3e7b9 100644 --- a/esphome/components/mcp23016/mcp23016.cpp +++ b/esphome/components/mcp23016/mcp23016.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace mcp23016 { +namespace esphome::mcp23016 { static const char *const TAG = "mcp23016"; @@ -101,5 +100,4 @@ size_t MCP23016GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via MCP23016", this->pin_); } -} // namespace mcp23016 -} // namespace esphome +} // namespace esphome::mcp23016 diff --git a/esphome/components/mcp23016/mcp23016.h b/esphome/components/mcp23016/mcp23016.h index 32149ba3e24..4a936a5b02e 100644 --- a/esphome/components/mcp23016/mcp23016.h +++ b/esphome/components/mcp23016/mcp23016.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/gpio_expander/cached_gpio.h" -namespace esphome { -namespace mcp23016 { +namespace esphome::mcp23016 { enum MCP23016GPIORegisters { // 0 side @@ -79,5 +78,4 @@ class MCP23016GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace mcp23016 -} // namespace esphome +} // namespace esphome::mcp23016 diff --git a/esphome/components/mcp23017/mcp23017.cpp b/esphome/components/mcp23017/mcp23017.cpp index 212c15ccf27..9e3d75575ae 100644 --- a/esphome/components/mcp23017/mcp23017.cpp +++ b/esphome/components/mcp23017/mcp23017.cpp @@ -1,8 +1,7 @@ #include "mcp23017.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp23017 { +namespace esphome::mcp23017 { static const char *const TAG = "mcp23017"; @@ -54,5 +53,4 @@ bool MCP23017::write_reg(uint8_t reg, uint8_t value) { return this->write_byte(reg, value); } -} // namespace mcp23017 -} // namespace esphome +} // namespace esphome::mcp23017 diff --git a/esphome/components/mcp23017/mcp23017.h b/esphome/components/mcp23017/mcp23017.h index 8959e06a413..86b84f9ad80 100644 --- a/esphome/components/mcp23017/mcp23017.h +++ b/esphome/components/mcp23017/mcp23017.h @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp23017 { +namespace esphome::mcp23017 { class MCP23017 : public mcp23x17_base::MCP23X17Base, public i2c::I2CDevice { public: @@ -20,5 +19,4 @@ class MCP23017 : public mcp23x17_base::MCP23X17Base, public i2c::I2CDevice { bool write_reg(uint8_t reg, uint8_t value) override; }; -} // namespace mcp23017 -} // namespace esphome +} // namespace esphome::mcp23017 diff --git a/esphome/components/mcp23s08/mcp23s08.cpp b/esphome/components/mcp23s08/mcp23s08.cpp index 983c1aa6008..e7f582f787c 100644 --- a/esphome/components/mcp23s08/mcp23s08.cpp +++ b/esphome/components/mcp23s08/mcp23s08.cpp @@ -1,8 +1,7 @@ #include "mcp23s08.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp23s08 { +namespace esphome::mcp23s08 { static const char *const TAG = "mcp23s08"; @@ -62,5 +61,4 @@ bool MCP23S08::write_reg(uint8_t reg, uint8_t value) { return true; } -} // namespace mcp23s08 -} // namespace esphome +} // namespace esphome::mcp23s08 diff --git a/esphome/components/mcp23s08/mcp23s08.h b/esphome/components/mcp23s08/mcp23s08.h index a2a6be880aa..441525469f7 100644 --- a/esphome/components/mcp23s08/mcp23s08.h +++ b/esphome/components/mcp23s08/mcp23s08.h @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace mcp23s08 { +namespace esphome::mcp23s08 { class MCP23S08 : public mcp23x08_base::MCP23X08Base, public spi::SPIDevice { uint8_t input_mask_{0x00}; }; -} // namespace mcp23x08_base -} // namespace esphome +} // namespace esphome::mcp23x08_base diff --git a/esphome/components/mcp23x17_base/mcp23x17_base.cpp b/esphome/components/mcp23x17_base/mcp23x17_base.cpp index efed7f5f17e..870c6c165f5 100644 --- a/esphome/components/mcp23x17_base/mcp23x17_base.cpp +++ b/esphome/components/mcp23x17_base/mcp23x17_base.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp23x17_base { +namespace esphome::mcp23x17_base { static const char *const TAG = "mcp23x17_base"; @@ -108,5 +107,4 @@ void MCP23X17Base::update_reg(uint8_t pin, bool pin_value, uint8_t reg_addr) { } } -} // namespace mcp23x17_base -} // namespace esphome +} // namespace esphome::mcp23x17_base diff --git a/esphome/components/mcp23x17_base/mcp23x17_base.h b/esphome/components/mcp23x17_base/mcp23x17_base.h index bdd66503e2c..bddfff132de 100644 --- a/esphome/components/mcp23x17_base/mcp23x17_base.h +++ b/esphome/components/mcp23x17_base/mcp23x17_base.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace mcp23x17_base { +namespace esphome::mcp23x17_base { enum MCP23X17GPIORegisters { // A side @@ -53,5 +52,4 @@ class MCP23X17Base : public mcp23xxx_base::MCP23XXXBase<16> { uint16_t input_mask_{0x00}; }; -} // namespace mcp23x17_base -} // namespace esphome +} // namespace esphome::mcp23x17_base diff --git a/esphome/components/mcp23xxx_base/mcp23xxx_base.cpp b/esphome/components/mcp23xxx_base/mcp23xxx_base.cpp index 4c1daac5623..b8032fcec8c 100644 --- a/esphome/components/mcp23xxx_base/mcp23xxx_base.cpp +++ b/esphome/components/mcp23xxx_base/mcp23xxx_base.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp23xxx_base { +namespace esphome::mcp23xxx_base { template void MCP23XXXGPIOPin::setup() { this->pin_mode(flags_); @@ -28,5 +27,4 @@ template size_t MCP23XXXGPIOPin::dump_summary(char *buffer, size_t template class MCP23XXXGPIOPin<8>; template class MCP23XXXGPIOPin<16>; -} // namespace mcp23xxx_base -} // namespace esphome +} // namespace esphome::mcp23xxx_base diff --git a/esphome/components/mcp23xxx_base/mcp23xxx_base.h b/esphome/components/mcp23xxx_base/mcp23xxx_base.h index 8a87dac1433..5904a1eef62 100644 --- a/esphome/components/mcp23xxx_base/mcp23xxx_base.h +++ b/esphome/components/mcp23xxx_base/mcp23xxx_base.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace mcp23xxx_base { +namespace esphome::mcp23xxx_base { enum MCP23XXXInterruptMode : uint8_t { MCP23XXX_NO_INTERRUPT = 0, MCP23XXX_CHANGE, MCP23XXX_RISING, MCP23XXX_FALLING }; @@ -81,5 +80,4 @@ template class MCP23XXXGPIOPin : public GPIOPin { MCP23XXXInterruptMode interrupt_mode_; }; -} // namespace mcp23xxx_base -} // namespace esphome +} // namespace esphome::mcp23xxx_base diff --git a/esphome/components/mcp2515/mcp2515.cpp b/esphome/components/mcp2515/mcp2515.cpp index c2db9228c8b..f8c5e9f0685 100644 --- a/esphome/components/mcp2515/mcp2515.cpp +++ b/esphome/components/mcp2515/mcp2515.cpp @@ -1,8 +1,7 @@ #include "mcp2515.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp2515 { +namespace esphome::mcp2515 { static const char *const TAG = "mcp2515"; @@ -707,5 +706,4 @@ canbus::Error MCP2515::set_bitrate_(canbus::CanSpeed can_speed, CanClock can_clo return canbus::ERROR_FAIL; } } -} // namespace mcp2515 -} // namespace esphome +} // namespace esphome::mcp2515 diff --git a/esphome/components/mcp2515/mcp2515.h b/esphome/components/mcp2515/mcp2515.h index c77480ce7de..b77d9a25828 100644 --- a/esphome/components/mcp2515/mcp2515.h +++ b/esphome/components/mcp2515/mcp2515.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "mcp2515_defs.h" -namespace esphome { -namespace mcp2515 { +namespace esphome::mcp2515 { static const uint32_t SPI_CLOCK = 10000000; // 10MHz static const int N_TXBUFFERS = 3; @@ -108,5 +107,4 @@ class MCP2515 : public canbus::Canbus, void clear_merr_(); void clear_errif_(); }; -} // namespace mcp2515 -} // namespace esphome +} // namespace esphome::mcp2515 diff --git a/esphome/components/mcp2515/mcp2515_defs.h b/esphome/components/mcp2515/mcp2515_defs.h index b33adcbba67..e2a7b97bd67 100644 --- a/esphome/components/mcp2515/mcp2515_defs.h +++ b/esphome/components/mcp2515/mcp2515_defs.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace mcp2515 { +namespace esphome::mcp2515 { static const uint8_t CANCTRL_REQOP = 0xE0; static const uint8_t CANCTRL_ABAT = 0x10; @@ -371,5 +370,4 @@ static const uint8_t MCP_20MHZ_33K3BPS_CFG1 = 0x0B; static const uint8_t MCP_20MHZ_33K3BPS_CFG2 = 0xFF; static const uint8_t MCP_20MHZ_33K3BPS_CFG3 = 0x87; -} // namespace mcp2515 -} // namespace esphome +} // namespace esphome::mcp2515 diff --git a/esphome/components/mcp3008/mcp3008.cpp b/esphome/components/mcp3008/mcp3008.cpp index 812a3b0c83d..e65e249f529 100644 --- a/esphome/components/mcp3008/mcp3008.cpp +++ b/esphome/components/mcp3008/mcp3008.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp3008 { +namespace esphome::mcp3008 { static const char *const TAG = "mcp3008"; @@ -36,5 +35,4 @@ float MCP3008::read_data(uint8_t pin) { return data / 1023.0f; } -} // namespace mcp3008 -} // namespace esphome +} // namespace esphome::mcp3008 diff --git a/esphome/components/mcp3008/mcp3008.h b/esphome/components/mcp3008/mcp3008.h index baf8d7c152d..1b1b50c7935 100644 --- a/esphome/components/mcp3008/mcp3008.h +++ b/esphome/components/mcp3008/mcp3008.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace mcp3008 { +namespace esphome::mcp3008 { class MCP3008 : public Component, public spi::SPIDevicepublish_state(this->sample()); } -} // namespace mcp3008 -} // namespace esphome +} // namespace esphome::mcp3008 diff --git a/esphome/components/mcp3008/sensor/mcp3008_sensor.h b/esphome/components/mcp3008/sensor/mcp3008_sensor.h index 9478d38e747..9267f80ea83 100644 --- a/esphome/components/mcp3008/sensor/mcp3008_sensor.h +++ b/esphome/components/mcp3008/sensor/mcp3008_sensor.h @@ -6,8 +6,7 @@ #include "../mcp3008.h" -namespace esphome { -namespace mcp3008 { +namespace esphome::mcp3008 { class MCP3008Sensor : public PollingComponent, public sensor::Sensor, @@ -26,5 +25,4 @@ class MCP3008Sensor : public PollingComponent, float reference_voltage_; }; -} // namespace mcp3008 -} // namespace esphome +} // namespace esphome::mcp3008 diff --git a/esphome/components/mcp3204/mcp3204.cpp b/esphome/components/mcp3204/mcp3204.cpp index abefcad0eb1..5351d6a2cb9 100644 --- a/esphome/components/mcp3204/mcp3204.cpp +++ b/esphome/components/mcp3204/mcp3204.cpp @@ -1,8 +1,7 @@ #include "mcp3204.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp3204 { +namespace esphome::mcp3204 { static const char *const TAG = "mcp3204"; @@ -35,5 +34,4 @@ float MCP3204::read_data(uint8_t pin, bool differential) { return float(digital_value) / 4096.000 * this->reference_voltage_; // in V } -} // namespace mcp3204 -} // namespace esphome +} // namespace esphome::mcp3204 diff --git a/esphome/components/mcp3204/mcp3204.h b/esphome/components/mcp3204/mcp3204.h index 6287263a2a7..8ce592f3866 100644 --- a/esphome/components/mcp3204/mcp3204.h +++ b/esphome/components/mcp3204/mcp3204.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace mcp3204 { +namespace esphome::mcp3204 { class MCP3204 : public Component, public spi::SPIDeviceparent_->read_data(this->pin_, this->differential_mode_); } void MCP3204Sensor::update() { this->publish_state(this->sample()); } -} // namespace mcp3204 -} // namespace esphome +} // namespace esphome::mcp3204 diff --git a/esphome/components/mcp3204/sensor/mcp3204_sensor.h b/esphome/components/mcp3204/sensor/mcp3204_sensor.h index 2bf75a9c1e5..5fe5f54d1b8 100644 --- a/esphome/components/mcp3204/sensor/mcp3204_sensor.h +++ b/esphome/components/mcp3204/sensor/mcp3204_sensor.h @@ -7,8 +7,7 @@ #include "../mcp3204.h" -namespace esphome { -namespace mcp3204 { +namespace esphome::mcp3204 { class MCP3204Sensor : public PollingComponent, public Parented, @@ -26,5 +25,4 @@ class MCP3204Sensor : public PollingComponent, bool differential_mode_; }; -} // namespace mcp3204 -} // namespace esphome +} // namespace esphome::mcp3204 diff --git a/esphome/components/mcp3221/mcp3221_sensor.cpp b/esphome/components/mcp3221/mcp3221_sensor.cpp index c04b1c0b935..1b794ba9663 100644 --- a/esphome/components/mcp3221/mcp3221_sensor.cpp +++ b/esphome/components/mcp3221/mcp3221_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp3221 { +namespace esphome::mcp3221 { static const char *const TAG = "mcp3221"; @@ -27,5 +26,4 @@ void MCP3221Sensor::update() { this->publish_state(v); } -} // namespace mcp3221 -} // namespace esphome +} // namespace esphome::mcp3221 diff --git a/esphome/components/mcp3221/mcp3221_sensor.h b/esphome/components/mcp3221/mcp3221_sensor.h index c83caccabfe..deef14e14d8 100644 --- a/esphome/components/mcp3221/mcp3221_sensor.h +++ b/esphome/components/mcp3221/mcp3221_sensor.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace mcp3221 { +namespace esphome::mcp3221 { class MCP3221Sensor : public sensor::Sensor, public PollingComponent, @@ -24,5 +23,4 @@ class MCP3221Sensor : public sensor::Sensor, float reference_voltage_; }; -} // namespace mcp3221 -} // namespace esphome +} // namespace esphome::mcp3221 diff --git a/esphome/components/mcp4461/mcp4461.cpp b/esphome/components/mcp4461/mcp4461.cpp index 48d90377df8..45735536642 100644 --- a/esphome/components/mcp4461/mcp4461.cpp +++ b/esphome/components/mcp4461/mcp4461.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace mcp4461 { +namespace esphome::mcp4461 { static const char *const TAG = "mcp4461"; constexpr uint8_t EEPROM_WRITE_TIMEOUT_MS = 10; @@ -628,5 +627,4 @@ bool Mcp4461Component::mcp4461_write_(uint8_t addr, uint16_t data, bool nonvolat } return this->write_byte(reg, value_byte); } -} // namespace mcp4461 -} // namespace esphome +} // namespace esphome::mcp4461 diff --git a/esphome/components/mcp4461/mcp4461.h b/esphome/components/mcp4461/mcp4461.h index 59f6358a567..3a76f855b86 100644 --- a/esphome/components/mcp4461/mcp4461.h +++ b/esphome/components/mcp4461/mcp4461.h @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp4461 { +namespace esphome::mcp4461 { struct WiperState { bool enabled = true; @@ -168,5 +167,4 @@ class Mcp4461Component : public Component, public i2c::I2CDevice { bool wiper_2_disabled_{false}; bool wiper_3_disabled_{false}; }; -} // namespace mcp4461 -} // namespace esphome +} // namespace esphome::mcp4461 diff --git a/esphome/components/mcp4461/output/mcp4461_output.cpp b/esphome/components/mcp4461/output/mcp4461_output.cpp index 2d85a5df61e..6912ad5f36f 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.cpp +++ b/esphome/components/mcp4461/output/mcp4461_output.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp4461 { +namespace esphome::mcp4461 { static const char *const TAG = "mcp4461.output"; @@ -69,5 +68,4 @@ void Mcp4461Wiper::enable_terminal(char terminal) { this->parent_->enable_termin void Mcp4461Wiper::disable_terminal(char terminal) { this->parent_->disable_terminal_(this->wiper_, terminal); } -} // namespace mcp4461 -} // namespace esphome +} // namespace esphome::mcp4461 diff --git a/esphome/components/mcp4461/output/mcp4461_output.h b/esphome/components/mcp4461/output/mcp4461_output.h index 4055cef30a5..73eadceb502 100644 --- a/esphome/components/mcp4461/output/mcp4461_output.h +++ b/esphome/components/mcp4461/output/mcp4461_output.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp4461 { +namespace esphome::mcp4461 { class Mcp4461Wiper : public output::FloatOutput, public Parented { public: @@ -45,5 +44,4 @@ class Mcp4461Wiper : public output::FloatOutput, public Parentedwrite_byte_16(64, value << 4); } -} // namespace mcp4725 -} // namespace esphome +} // namespace esphome::mcp4725 diff --git a/esphome/components/mcp4725/mcp4725.h b/esphome/components/mcp4725/mcp4725.h index d6fa52e323e..1acefc3ee4f 100644 --- a/esphome/components/mcp4725/mcp4725.h +++ b/esphome/components/mcp4725/mcp4725.h @@ -7,8 +7,7 @@ static const uint8_t MCP4725_ADDR = 0x60; static const uint8_t MCP4725_RES = 12; -namespace esphome { -namespace mcp4725 { +namespace esphome::mcp4725 { class MCP4725 : public Component, public output::FloatOutput, public i2c::I2CDevice { public: void setup() override; @@ -19,5 +18,4 @@ class MCP4725 : public Component, public output::FloatOutput, public i2c::I2CDev enum ErrorCode { NONE = 0, COMMUNICATION_FAILED } error_code_{NONE}; }; -} // namespace mcp4725 -} // namespace esphome +} // namespace esphome::mcp4725 diff --git a/esphome/components/mcp4728/mcp4728.cpp b/esphome/components/mcp4728/mcp4728.cpp index bab94cb2338..1b15ca05100 100644 --- a/esphome/components/mcp4728/mcp4728.cpp +++ b/esphome/components/mcp4728/mcp4728.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp4728 { +namespace esphome::mcp4728 { static const char *const TAG = "mcp4728"; @@ -109,5 +108,4 @@ void MCP4728Component::select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain) this->update_ = true; } -} // namespace mcp4728 -} // namespace esphome +} // namespace esphome::mcp4728 diff --git a/esphome/components/mcp4728/mcp4728.h b/esphome/components/mcp4728/mcp4728.h index d6574080810..13076b3c4cf 100644 --- a/esphome/components/mcp4728/mcp4728.h +++ b/esphome/components/mcp4728/mcp4728.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp4728 { +namespace esphome::mcp4728 { enum class CMD { FAST_WRITE = 0x00, @@ -63,5 +62,4 @@ class MCP4728Component : public Component, public i2c::I2CDevice { bool update_ = false; }; -} // namespace mcp4728 -} // namespace esphome +} // namespace esphome::mcp4728 diff --git a/esphome/components/mcp4728/output/mcp4728_output.cpp b/esphome/components/mcp4728/output/mcp4728_output.cpp index b587e8801b1..7cd5d9d2524 100644 --- a/esphome/components/mcp4728/output/mcp4728_output.cpp +++ b/esphome/components/mcp4728/output/mcp4728_output.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp4728 { +namespace esphome::mcp4728 { void MCP4728Channel::write_state(float state) { const uint16_t max_duty = 4095; @@ -13,5 +12,4 @@ void MCP4728Channel::write_state(float state) { this->parent_->set_channel_value_(this->channel_, duty); } -} // namespace mcp4728 -} // namespace esphome +} // namespace esphome::mcp4728 diff --git a/esphome/components/mcp4728/output/mcp4728_output.h b/esphome/components/mcp4728/output/mcp4728_output.h index 453d632f4c6..3ea65ecc7b0 100644 --- a/esphome/components/mcp4728/output/mcp4728_output.h +++ b/esphome/components/mcp4728/output/mcp4728_output.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp4728 { +namespace esphome::mcp4728 { class MCP4728Channel : public output::FloatOutput { public: @@ -28,5 +27,4 @@ class MCP4728Channel : public output::FloatOutput { MCP4728ChannelIdx channel_; }; -} // namespace mcp4728 -} // namespace esphome +} // namespace esphome::mcp4728 diff --git a/esphome/components/mcp47a1/mcp47a1.cpp b/esphome/components/mcp47a1/mcp47a1.cpp index 58f3b2ac729..e2b0fa5575d 100644 --- a/esphome/components/mcp47a1/mcp47a1.cpp +++ b/esphome/components/mcp47a1/mcp47a1.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp47a1 { +namespace esphome::mcp47a1 { static const char *const TAG = "mcp47a1"; @@ -17,5 +16,4 @@ void MCP47A1::write_state(float state) { this->write_byte(0, value); } -} // namespace mcp47a1 -} // namespace esphome +} // namespace esphome::mcp47a1 diff --git a/esphome/components/mcp47a1/mcp47a1.h b/esphome/components/mcp47a1/mcp47a1.h index 5c02e062ad4..da9794e5aa1 100644 --- a/esphome/components/mcp47a1/mcp47a1.h +++ b/esphome/components/mcp47a1/mcp47a1.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/core/component.h" -namespace esphome { -namespace mcp47a1 { +namespace esphome::mcp47a1 { class MCP47A1 : public Component, public output::FloatOutput, public i2c::I2CDevice { public: @@ -13,5 +12,4 @@ class MCP47A1 : public Component, public output::FloatOutput, public i2c::I2CDev void write_state(float state) override; }; -} // namespace mcp47a1 -} // namespace esphome +} // namespace esphome::mcp47a1 diff --git a/esphome/components/mcp9600/mcp9600.cpp b/esphome/components/mcp9600/mcp9600.cpp index 0c5362b4bad..0e9b472be27 100644 --- a/esphome/components/mcp9600/mcp9600.cpp +++ b/esphome/components/mcp9600/mcp9600.cpp @@ -1,8 +1,7 @@ #include "mcp9600.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp9600 { +namespace esphome::mcp9600 { static const char *const TAG = "mcp9600"; @@ -109,5 +108,4 @@ void MCP9600Component::update() { this->status_clear_warning(); } -} // namespace mcp9600 -} // namespace esphome +} // namespace esphome::mcp9600 diff --git a/esphome/components/mcp9600/mcp9600.h b/esphome/components/mcp9600/mcp9600.h index c414653ea65..b7c0c834abe 100644 --- a/esphome/components/mcp9600/mcp9600.h +++ b/esphome/components/mcp9600/mcp9600.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp9600 { +namespace esphome::mcp9600 { enum MCP9600ThermocoupleType : uint8_t { MCP9600_THERMOCOUPLE_TYPE_K = 0b000, @@ -45,5 +44,4 @@ class MCP9600Component : public PollingComponent, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace mcp9600 -} // namespace esphome +} // namespace esphome::mcp9600 diff --git a/esphome/components/mcp9808/mcp9808.cpp b/esphome/components/mcp9808/mcp9808.cpp index ed12e522395..10e26ed7097 100644 --- a/esphome/components/mcp9808/mcp9808.cpp +++ b/esphome/components/mcp9808/mcp9808.cpp @@ -1,8 +1,7 @@ #include "mcp9808.h" #include "esphome/core/log.h" -namespace esphome { -namespace mcp9808 { +namespace esphome::mcp9808 { static const uint8_t MCP9808_REG_AMBIENT_TEMP = 0x05; static const uint8_t MCP9808_REG_MANUF_ID = 0x06; @@ -74,5 +73,4 @@ void MCP9808Sensor::update() { this->status_clear_warning(); } -} // namespace mcp9808 -} // namespace esphome +} // namespace esphome::mcp9808 diff --git a/esphome/components/mcp9808/mcp9808.h b/esphome/components/mcp9808/mcp9808.h index 894e4599d0a..89530d9ed0f 100644 --- a/esphome/components/mcp9808/mcp9808.h +++ b/esphome/components/mcp9808/mcp9808.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mcp9808 { +namespace esphome::mcp9808 { class MCP9808Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { public: @@ -15,5 +14,4 @@ class MCP9808Sensor : public sensor::Sensor, public PollingComponent, public i2c void update() override; }; -} // namespace mcp9808 -} // namespace esphome +} // namespace esphome::mcp9808 diff --git a/esphome/components/md5/md5.cpp b/esphome/components/md5/md5.cpp index 26554e4d3c1..10c81aac399 100644 --- a/esphome/components/md5/md5.cpp +++ b/esphome/components/md5/md5.cpp @@ -3,8 +3,7 @@ #ifdef USE_MD5 #include "esphome/core/helpers.h" -namespace esphome { -namespace md5 { +namespace esphome::md5 { #if defined(USE_ARDUINO) && !defined(USE_RP2040) && !defined(USE_ESP32) void MD5Digest::init() { @@ -77,6 +76,6 @@ void MD5Digest::calculate() { MD5Digest::~MD5Digest() = default; #endif // USE_HOST -} // namespace md5 -} // namespace esphome +} // namespace esphome::md5 + #endif diff --git a/esphome/components/md5/md5.h b/esphome/components/md5/md5.h index 80e74d188ef..5e841edd838 100644 --- a/esphome/components/md5/md5.h +++ b/esphome/components/md5/md5.h @@ -29,8 +29,7 @@ #define MD5_CTX_TYPE LT_MD5_CTX_T #endif -namespace esphome { -namespace md5 { +namespace esphome::md5 { class MD5Digest final : public HashBase { public: @@ -59,6 +58,6 @@ class MD5Digest final : public HashBase { #endif }; -} // namespace md5 -} // namespace esphome +} // namespace esphome::md5 + #endif diff --git a/esphome/components/media_player/automation.h b/esphome/components/media_player/automation.h index 14ce3c6aedb..9319335872a 100644 --- a/esphome/components/media_player/automation.h +++ b/esphome/components/media_player/automation.h @@ -3,9 +3,7 @@ #include "esphome/core/automation.h" #include "media_player.h" -namespace esphome { - -namespace media_player { +namespace esphome::media_player { template class MediaPlayerCommandAction : public Action, public Parented { @@ -136,5 +134,4 @@ template class IsMutedCondition : public Condition, publi bool check(const Ts &...x) override { return this->parent_->is_muted(); } }; -} // namespace media_player -} // namespace esphome +} // namespace esphome::media_player diff --git a/esphome/components/media_player/media_player.cpp b/esphome/components/media_player/media_player.cpp index 48d23fa0b12..7dce74117a9 100644 --- a/esphome/components/media_player/media_player.cpp +++ b/esphome/components/media_player/media_player.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/progmem.h" -namespace esphome { -namespace media_player { +namespace esphome::media_player { static const char *const TAG = "media_player"; @@ -205,5 +204,4 @@ void MediaPlayer::publish_state() { #endif } -} // namespace media_player -} // namespace esphome +} // namespace esphome::media_player diff --git a/esphome/components/media_player/media_player.h b/esphome/components/media_player/media_player.h index d5d00207970..73de6036923 100644 --- a/esphome/components/media_player/media_player.h +++ b/esphome/components/media_player/media_player.h @@ -3,8 +3,7 @@ #include "esphome/core/entity_base.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace media_player { +namespace esphome::media_player { enum MediaPlayerEntityFeature : uint32_t { PAUSE = 1 << 0, @@ -171,5 +170,4 @@ class MediaPlayer : public EntityBase { LazyCallbackManager state_callback_{}; }; -} // namespace media_player -} // namespace esphome +} // namespace esphome::media_player diff --git a/esphome/components/micro_wake_word/automation.h b/esphome/components/micro_wake_word/automation.h index 218ce9e4bcc..e3b35583fb1 100644 --- a/esphome/components/micro_wake_word/automation.h +++ b/esphome/components/micro_wake_word/automation.h @@ -4,8 +4,8 @@ #include "streaming_model.h" #ifdef USE_ESP32 -namespace esphome { -namespace micro_wake_word { + +namespace esphome::micro_wake_word { template class StartAction : public Action, public Parented { public: @@ -49,6 +49,6 @@ template class ModelIsEnabledCondition : public Condition WakeWordModel *wake_word_model_; }; -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word + #endif diff --git a/esphome/components/micro_wake_word/micro_wake_word.cpp b/esphome/components/micro_wake_word/micro_wake_word.cpp index f1aac875f13..1568fc6373b 100644 --- a/esphome/components/micro_wake_word/micro_wake_word.cpp +++ b/esphome/components/micro_wake_word/micro_wake_word.cpp @@ -13,8 +13,7 @@ #include "esphome/components/ota/ota_backend.h" #endif -namespace esphome { -namespace micro_wake_word { +namespace esphome::micro_wake_word { static const char *const TAG = "micro_wake_word"; @@ -468,7 +467,6 @@ bool MicroWakeWord::update_model_probabilities_(const int8_t audio_features[PREP return success; } -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word #endif // USE_ESP32 diff --git a/esphome/components/micro_wake_word/micro_wake_word.h b/esphome/components/micro_wake_word/micro_wake_word.h index 44d5d893728..79a1226fba6 100644 --- a/esphome/components/micro_wake_word/micro_wake_word.h +++ b/esphome/components/micro_wake_word/micro_wake_word.h @@ -21,8 +21,7 @@ #include #include -namespace esphome { -namespace micro_wake_word { +namespace esphome::micro_wake_word { enum State { STARTING, @@ -137,7 +136,6 @@ class MicroWakeWord : public Component bool update_model_probabilities_(const int8_t audio_features[PREPROCESSOR_FEATURE_SIZE]); }; -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word #endif // USE_ESP32 diff --git a/esphome/components/micro_wake_word/preprocessor_settings.h b/esphome/components/micro_wake_word/preprocessor_settings.h index c9d195b49b2..fa0bfffbebd 100644 --- a/esphome/components/micro_wake_word/preprocessor_settings.h +++ b/esphome/components/micro_wake_word/preprocessor_settings.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace micro_wake_word { +namespace esphome::micro_wake_word { // Settings for controlling the spectrogram feature generation by the preprocessor. // These must match the settings used when training a particular model. @@ -31,7 +30,6 @@ static const uint8_t PCAN_GAIN_CONTROL_GAIN_BITS = 21; static const bool LOG_SCALE_ENABLE_LOG = true; static const uint8_t LOG_SCALE_SCALE_SHIFT = 6; -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word #endif diff --git a/esphome/components/micro_wake_word/streaming_model.cpp b/esphome/components/micro_wake_word/streaming_model.cpp index e761e4866fd..1cdc06b3520 100644 --- a/esphome/components/micro_wake_word/streaming_model.cpp +++ b/esphome/components/micro_wake_word/streaming_model.cpp @@ -7,8 +7,7 @@ static const char *const TAG = "micro_wake_word"; -namespace esphome { -namespace micro_wake_word { +namespace esphome::micro_wake_word { void WakeWordModel::log_model_config() { ESP_LOGCONFIG(TAG, @@ -387,7 +386,6 @@ bool StreamingModel::register_streaming_ops_(tflite::MicroMutableOpResolver<20> return true; } -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word #endif diff --git a/esphome/components/micro_wake_word/streaming_model.h b/esphome/components/micro_wake_word/streaming_model.h index fc9eeb5e2d8..07ba78d1f44 100644 --- a/esphome/components/micro_wake_word/streaming_model.h +++ b/esphome/components/micro_wake_word/streaming_model.h @@ -10,8 +10,7 @@ #include #include -namespace esphome { -namespace micro_wake_word { +namespace esphome::micro_wake_word { static const uint8_t MIN_SLICES_BEFORE_DETECTION = 100; static const uint32_t STREAMING_MODEL_VARIABLE_ARENA_SIZE = 1024; @@ -155,7 +154,6 @@ class VADModel final : public StreamingModel { DetectionEvent determine_detected() override; }; -} // namespace micro_wake_word -} // namespace esphome +} // namespace esphome::micro_wake_word #endif diff --git a/esphome/components/microphone/automation.h b/esphome/components/microphone/automation.h index a6c4bdae663..1dfd91f903a 100644 --- a/esphome/components/microphone/automation.h +++ b/esphome/components/microphone/automation.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace microphone { +namespace esphome::microphone { template class CaptureAction : public Action, public Parented { void play(const Ts &...x) override { this->parent_->start(); } @@ -40,5 +39,4 @@ template class IsMutedCondition : public Condition, publi bool check(const Ts &...x) override { return this->parent_->get_mute_state(); } }; -} // namespace microphone -} // namespace esphome +} // namespace esphome::microphone diff --git a/esphome/components/microphone/microphone.h b/esphome/components/microphone/microphone.h index 50ce1a72818..d89b9a83629 100644 --- a/esphome/components/microphone/microphone.h +++ b/esphome/components/microphone/microphone.h @@ -7,8 +7,7 @@ #include #include "esphome/core/helpers.h" -namespace esphome { -namespace microphone { +namespace esphome::microphone { enum State : uint8_t { STATE_STOPPED = 0, @@ -48,5 +47,4 @@ class Microphone { CallbackManager &)> data_callbacks_{}; }; -} // namespace microphone -} // namespace esphome +} // namespace esphome::microphone diff --git a/esphome/components/microphone/microphone_source.cpp b/esphome/components/microphone/microphone_source.cpp index fb4ebc4a042..288e9f8c8e5 100644 --- a/esphome/components/microphone/microphone_source.cpp +++ b/esphome/components/microphone/microphone_source.cpp @@ -1,7 +1,6 @@ #include "microphone_source.h" -namespace esphome { -namespace microphone { +namespace esphome::microphone { static const int32_t Q25_MAX_VALUE = (1 << 25) - 1; static const int32_t Q25_MIN_VALUE = ~Q25_MAX_VALUE; @@ -73,5 +72,4 @@ void MicrophoneSource::process_audio_(const std::vector &data, std::vec } } -} // namespace microphone -} // namespace esphome +} // namespace esphome::microphone diff --git a/esphome/components/microphone/microphone_source.h b/esphome/components/microphone/microphone_source.h index 5c8053e502e..c3c675e854b 100644 --- a/esphome/components/microphone/microphone_source.h +++ b/esphome/components/microphone/microphone_source.h @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace microphone { +namespace esphome::microphone { static const int32_t MAX_GAIN_FACTOR = 64; @@ -89,5 +88,4 @@ class MicrophoneSource { bool passive_; // Only pass audio if ``mic_`` is already running }; -} // namespace microphone -} // namespace esphome +} // namespace esphome::microphone diff --git a/esphome/components/mics_4514/mics_4514.cpp b/esphome/components/mics_4514/mics_4514.cpp index ce63a7d062b..d99d4fd7723 100644 --- a/esphome/components/mics_4514/mics_4514.cpp +++ b/esphome/components/mics_4514/mics_4514.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mics_4514 { +namespace esphome::mics_4514 { static const char *const TAG = "mics_4514"; @@ -131,5 +130,4 @@ void MICS4514Component::update() { } } -} // namespace mics_4514 -} // namespace esphome +} // namespace esphome::mics_4514 diff --git a/esphome/components/mics_4514/mics_4514.h b/esphome/components/mics_4514/mics_4514.h index e7271314c82..4f8b970f067 100644 --- a/esphome/components/mics_4514/mics_4514.h +++ b/esphome/components/mics_4514/mics_4514.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace mics_4514 { +namespace esphome::mics_4514 { class MICS4514Component : public PollingComponent, public i2c::I2CDevice { SUB_SENSOR(carbon_monoxide) @@ -29,5 +28,4 @@ class MICS4514Component : public PollingComponent, public i2c::I2CDevice { float red_calibration_{0}; }; -} // namespace mics_4514 -} // namespace esphome +} // namespace esphome::mics_4514 diff --git a/esphome/components/midea/ac_adapter.cpp b/esphome/components/midea/ac_adapter.cpp index 8b20a562c8b..ec9dc102970 100644 --- a/esphome/components/midea/ac_adapter.cpp +++ b/esphome/components/midea/ac_adapter.cpp @@ -3,9 +3,7 @@ #include "esphome/core/log.h" #include "ac_adapter.h" -namespace esphome { -namespace midea { -namespace ac { +namespace esphome::midea::ac { const char *const Constants::TAG = "midea"; const char *const Constants::FREEZE_PROTECTION = "freeze protection"; @@ -172,8 +170,6 @@ void Converters::to_climate_traits(ClimateTraits &traits, const dudanov::midea:: // since custom presets are stored on the Climate base class } -} // namespace ac -} // namespace midea -} // namespace esphome +} // namespace esphome::midea::ac #endif // USE_ARDUINO diff --git a/esphome/components/midea/ac_adapter.h b/esphome/components/midea/ac_adapter.h index b0589a37f9b..a7924ae51e4 100644 --- a/esphome/components/midea/ac_adapter.h +++ b/esphome/components/midea/ac_adapter.h @@ -8,9 +8,7 @@ #include "esphome/components/climate/climate_traits.h" #include "air_conditioner.h" -namespace esphome { -namespace midea { -namespace ac { +namespace esphome::midea::ac { using MideaMode = dudanov::midea::ac::Mode; using MideaSwingMode = dudanov::midea::ac::SwingMode; @@ -44,8 +42,6 @@ class Converters { static void to_climate_traits(ClimateTraits &traits, const dudanov::midea::ac::Capabilities &capabilities); }; -} // namespace ac -} // namespace midea -} // namespace esphome +} // namespace esphome::midea::ac #endif // USE_ARDUINO diff --git a/esphome/components/midea/ac_automations.h b/esphome/components/midea/ac_automations.h index 760737be87e..acd91919162 100644 --- a/esphome/components/midea/ac_automations.h +++ b/esphome/components/midea/ac_automations.h @@ -5,9 +5,7 @@ #include "esphome/core/automation.h" #include "air_conditioner.h" -namespace esphome { -namespace midea { -namespace ac { +namespace esphome::midea::ac { template class MideaActionBase : public Action { public: @@ -63,8 +61,6 @@ template class PowerToggleAction : public MideaActionBase void play(const Ts &...x) override { this->parent_->do_power_toggle(); } }; -} // namespace ac -} // namespace midea -} // namespace esphome +} // namespace esphome::midea::ac #endif // USE_ARDUINO diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index 69e0d46d2d8..594f7fa661b 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -7,9 +7,7 @@ #include #include -namespace esphome { -namespace midea { -namespace ac { +namespace esphome::midea::ac { static void set_sensor(Sensor *sensor, float value) { if (sensor != nullptr && (!sensor->has_state() || sensor->get_raw_state() != value)) @@ -197,8 +195,6 @@ void AirConditioner::do_display_toggle() { } } -} // namespace ac -} // namespace midea -} // namespace esphome +} // namespace esphome::midea::ac #endif // USE_ARDUINO diff --git a/esphome/components/midea/air_conditioner.h b/esphome/components/midea/air_conditioner.h index 8dbc71b4226..6ed5a82ff57 100644 --- a/esphome/components/midea/air_conditioner.h +++ b/esphome/components/midea/air_conditioner.h @@ -8,9 +8,7 @@ #include "appliance_base.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace midea { -namespace ac { +namespace esphome::midea::ac { using sensor::Sensor; using climate::ClimateCall; @@ -61,8 +59,6 @@ class AirConditioner : public ApplianceBase, Sensor *power_sensor_{nullptr}; }; -} // namespace ac -} // namespace midea -} // namespace esphome +} // namespace esphome::midea::ac #endif // USE_ARDUINO diff --git a/esphome/components/midea/appliance_base.h b/esphome/components/midea/appliance_base.h index c7737ba7d69..d36f5a322cd 100644 --- a/esphome/components/midea/appliance_base.h +++ b/esphome/components/midea/appliance_base.h @@ -15,8 +15,7 @@ #include "esphome/components/climate/climate.h" #include "ir_transmitter.h" -namespace esphome { -namespace midea { +namespace esphome::midea { /* Stream from UART component */ class UARTStream : public Stream { @@ -98,7 +97,6 @@ template class ApplianceBase : public Component { #endif }; -} // namespace midea -} // namespace esphome +} // namespace esphome::midea #endif // USE_ARDUINO diff --git a/esphome/components/midea_ir/midea_data.h b/esphome/components/midea_ir/midea_data.h index 0f7e24907db..1fe65b958f1 100644 --- a/esphome/components/midea_ir/midea_data.h +++ b/esphome/components/midea_ir/midea_data.h @@ -3,8 +3,7 @@ #include "esphome/components/remote_base/midea_protocol.h" #include "esphome/components/climate/climate_mode.h" -namespace esphome { -namespace midea_ir { +namespace esphome::midea_ir { using climate::ClimateMode; using climate::ClimateFanMode; @@ -88,5 +87,4 @@ class SpecialData : public MideaData { static const uint8_t TURBO_TOGGLE = 9; }; -} // namespace midea_ir -} // namespace esphome +} // namespace esphome::midea_ir diff --git a/esphome/components/midea_ir/midea_ir.cpp b/esphome/components/midea_ir/midea_ir.cpp index 220bb3f414d..de25c4652cb 100644 --- a/esphome/components/midea_ir/midea_ir.cpp +++ b/esphome/components/midea_ir/midea_ir.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/components/coolix/coolix.h" -namespace esphome { -namespace midea_ir { +namespace esphome::midea_ir { static const char *const TAG = "midea_ir.climate"; @@ -204,5 +203,4 @@ bool MideaIR::on_midea_(const MideaData &data) { return false; } -} // namespace midea_ir -} // namespace esphome +} // namespace esphome::midea_ir diff --git a/esphome/components/midea_ir/midea_ir.h b/esphome/components/midea_ir/midea_ir.h index b89b2a7efcc..dd883172d4d 100644 --- a/esphome/components/midea_ir/midea_ir.h +++ b/esphome/components/midea_ir/midea_ir.h @@ -3,8 +3,7 @@ #include "esphome/components/climate_ir/climate_ir.h" #include "midea_data.h" -namespace esphome { -namespace midea_ir { +namespace esphome::midea_ir { // Temperature const uint8_t MIDEA_TEMPC_MIN = 17; // Celsius @@ -43,5 +42,4 @@ class MideaIR : public climate_ir::ClimateIR { bool boost_{false}; }; -} // namespace midea_ir -} // namespace esphome +} // namespace esphome::midea_ir diff --git a/esphome/components/mipi_spi/mipi_spi.h b/esphome/components/mipi_spi/mipi_spi.h index f2923458937..5023cf80891 100644 --- a/esphome/components/mipi_spi/mipi_spi.h +++ b/esphome/components/mipi_spi/mipi_spi.h @@ -7,8 +7,7 @@ #include "esphome/components/display/display_color_utils.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace mipi_spi { +namespace esphome::mipi_spi { constexpr static const char *const TAG = "display.mipi_spi"; @@ -672,5 +671,4 @@ class MipiSpiBuffer : public MipiSpi -namespace esphome { -namespace mitsubishi { +namespace esphome::mitsubishi { // Temperature const uint8_t MITSUBISHI_TEMP_MIN = 16; // Celsius @@ -79,5 +78,4 @@ class MitsubishiClimate : public climate_ir::ClimateIR { climate::ClimateTraits traits() override; }; -} // namespace mitsubishi -} // namespace esphome +} // namespace esphome::mitsubishi diff --git a/esphome/components/mixer/speaker/automation.h b/esphome/components/mixer/speaker/automation.h index 4fa38535833..cdfda0c700f 100644 --- a/esphome/components/mixer/speaker/automation.h +++ b/esphome/components/mixer/speaker/automation.h @@ -5,8 +5,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mixer_speaker { +namespace esphome::mixer_speaker { template class DuckingApplyAction : public Action, public Parented { TEMPLATABLE_VALUE(uint8_t, decibel_reduction); TEMPLATABLE_VALUE(uint32_t, duration); @@ -14,7 +13,6 @@ template class DuckingApplyAction : public Action, public this->parent_->apply_ducking(this->decibel_reduction_.value(x...), this->duration_.value(x...)); } }; -} // namespace mixer_speaker -} // namespace esphome +} // namespace esphome::mixer_speaker #endif diff --git a/esphome/components/mlx90393/sensor_mlx90393.cpp b/esphome/components/mlx90393/sensor_mlx90393.cpp index 01084e50df7..70483021243 100644 --- a/esphome/components/mlx90393/sensor_mlx90393.cpp +++ b/esphome/components/mlx90393/sensor_mlx90393.cpp @@ -1,8 +1,7 @@ #include "sensor_mlx90393.h" #include "esphome/core/log.h" -namespace esphome { -namespace mlx90393 { +namespace esphome::mlx90393 { static const char *const TAG = "mlx90393"; @@ -270,5 +269,4 @@ void MLX90393Cls::verify_settings_timeout_(MLX90393Setting stage) { this->set_timeout("verify settings", 3000, [this, next_stage]() { this->verify_settings_timeout_(next_stage); }); } -} // namespace mlx90393 -} // namespace esphome +} // namespace esphome::mlx90393 diff --git a/esphome/components/mlx90393/sensor_mlx90393.h b/esphome/components/mlx90393/sensor_mlx90393.h index 845ae87e09f..28053216e22 100644 --- a/esphome/components/mlx90393/sensor_mlx90393.h +++ b/esphome/components/mlx90393/sensor_mlx90393.h @@ -7,8 +7,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace mlx90393 { +namespace esphome::mlx90393 { enum MLX90393Setting { MLX90393_GAIN_SEL = 0, @@ -76,5 +75,4 @@ class MLX90393Cls : public PollingComponent, public i2c::I2CDevice, public MLX90 void verify_settings_timeout_(MLX90393Setting stage); }; -} // namespace mlx90393 -} // namespace esphome +} // namespace esphome::mlx90393 diff --git a/esphome/components/mlx90614/mlx90614.cpp b/esphome/components/mlx90614/mlx90614.cpp index 8a514cbc260..2d3b6631bc6 100644 --- a/esphome/components/mlx90614/mlx90614.cpp +++ b/esphome/components/mlx90614/mlx90614.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mlx90614 { +namespace esphome::mlx90614 { static const uint8_t MLX90614_RAW_IR_1 = 0x04; static const uint8_t MLX90614_RAW_IR_2 = 0x05; @@ -101,5 +100,4 @@ void MLX90614Component::update() { this->status_clear_warning(); } -} // namespace mlx90614 -} // namespace esphome +} // namespace esphome::mlx90614 diff --git a/esphome/components/mlx90614/mlx90614.h b/esphome/components/mlx90614/mlx90614.h index bf081c3e907..12081f20acc 100644 --- a/esphome/components/mlx90614/mlx90614.h +++ b/esphome/components/mlx90614/mlx90614.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace mlx90614 { +namespace esphome::mlx90614 { class MLX90614Component : public PollingComponent, public i2c::I2CDevice { public: @@ -28,5 +27,4 @@ class MLX90614Component : public PollingComponent, public i2c::I2CDevice { float emissivity_{NAN}; }; -} // namespace mlx90614 -} // namespace esphome +} // namespace esphome::mlx90614 diff --git a/esphome/components/mmc5603/mmc5603.cpp b/esphome/components/mmc5603/mmc5603.cpp index 51b94eb7671..79c580c6b78 100644 --- a/esphome/components/mmc5603/mmc5603.cpp +++ b/esphome/components/mmc5603/mmc5603.cpp @@ -1,8 +1,7 @@ #include "mmc5603.h" #include "esphome/core/log.h" -namespace esphome { -namespace mmc5603 { +namespace esphome::mmc5603 { static const char *const TAG = "mmc5603"; static const uint8_t MMC5603_ADDRESS = 0x30; @@ -157,5 +156,4 @@ void MMC5603Component::update() { this->heading_sensor_->publish_state(heading); } -} // namespace mmc5603 -} // namespace esphome +} // namespace esphome::mmc5603 diff --git a/esphome/components/mmc5603/mmc5603.h b/esphome/components/mmc5603/mmc5603.h index 9a77b78bc19..0d8eb152a72 100644 --- a/esphome/components/mmc5603/mmc5603.h +++ b/esphome/components/mmc5603/mmc5603.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mmc5603 { +namespace esphome::mmc5603 { enum MMC5603Datarate { MMC5603_DATARATE_75_0_HZ, @@ -40,5 +39,4 @@ class MMC5603Component : public PollingComponent, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace mmc5603 -} // namespace esphome +} // namespace esphome::mmc5603 diff --git a/esphome/components/mmc5983/mmc5983.cpp b/esphome/components/mmc5983/mmc5983.cpp index b038084a72d..a99df36a705 100644 --- a/esphome/components/mmc5983/mmc5983.cpp +++ b/esphome/components/mmc5983/mmc5983.cpp @@ -4,8 +4,7 @@ #include "mmc5983.h" #include "esphome/core/log.h" -namespace esphome { -namespace mmc5983 { +namespace esphome::mmc5983 { static const char *const TAG = "mmc5983"; @@ -133,5 +132,4 @@ void MMC5983Component::dump_config() { LOG_SENSOR(" ", "Z", this->z_sensor_); } -} // namespace mmc5983 -} // namespace esphome +} // namespace esphome::mmc5983 diff --git a/esphome/components/mmc5983/mmc5983.h b/esphome/components/mmc5983/mmc5983.h index 3e87e54daa6..020d3b2e4c1 100644 --- a/esphome/components/mmc5983/mmc5983.h +++ b/esphome/components/mmc5983/mmc5983.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mmc5983 { +namespace esphome::mmc5983 { class MMC5983Component : public PollingComponent, public i2c::I2CDevice { public: @@ -23,5 +22,4 @@ class MMC5983Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *z_sensor_{nullptr}; }; -} // namespace mmc5983 -} // namespace esphome +} // namespace esphome::mmc5983 diff --git a/esphome/components/modbus/modbus.cpp b/esphome/components/modbus/modbus.cpp index 3b1a038be34..679ec34c0f5 100644 --- a/esphome/components/modbus/modbus.cpp +++ b/esphome/components/modbus/modbus.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus { +namespace esphome::modbus { static const char *const TAG = "modbus"; @@ -425,5 +424,4 @@ void Modbus::clear_rx_buffer_(const LogString *reason, bool warn) { } } -} // namespace modbus -} // namespace esphome +} // namespace esphome::modbus diff --git a/esphome/components/modbus/modbus.h b/esphome/components/modbus/modbus.h index c90d4c78ae2..26f64401be0 100644 --- a/esphome/components/modbus/modbus.h +++ b/esphome/components/modbus/modbus.h @@ -10,8 +10,7 @@ #include #include -namespace esphome { -namespace modbus { +namespace esphome::modbus { static constexpr uint16_t MODBUS_TX_BUFFER_SIZE = 15; @@ -122,5 +121,4 @@ class ModbusDevice { uint8_t address_; }; -} // namespace modbus -} // namespace esphome +} // namespace esphome::modbus diff --git a/esphome/components/modbus/modbus_definitions.h b/esphome/components/modbus/modbus_definitions.h index c86d548578a..fb8c011259f 100644 --- a/esphome/components/modbus/modbus_definitions.h +++ b/esphome/components/modbus/modbus_definitions.h @@ -2,8 +2,7 @@ #include "esphome/core/component.h" -namespace esphome { -namespace modbus { +namespace esphome::modbus { /// Modbus definitions from specs: /// https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf @@ -84,5 +83,4 @@ const uint8_t MAX_NUM_OF_REGISTERS_TO_READ = 125; // 0x7D static constexpr uint16_t MAX_FRAME_SIZE = 256; /// End of Modbus definitions -} // namespace modbus -} // namespace esphome +} // namespace esphome::modbus diff --git a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.cpp b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.cpp index 1ea3041b4d5..60c19bb66a3 100644 --- a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.cpp +++ b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.cpp @@ -1,8 +1,7 @@ #include "modbus_binarysensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.binary_sensor"; @@ -34,5 +33,4 @@ void ModbusBinarySensor::parse_and_publish(const std::vector &data) { this->publish_state(value); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h index 119f4fdd5a2..98c6840e15f 100644 --- a/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h +++ b/esphome/components/modbus_controller/binary_sensor/modbus_binarysensor.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusBinarySensor : public Component, public binary_sensor::BinarySensor, public SensorItem { public: @@ -40,5 +39,4 @@ class ModbusBinarySensor : public Component, public binary_sensor::BinarySensor, optional transform_func_{nullopt}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/modbus_controller.cpp b/esphome/components/modbus_controller/modbus_controller.cpp index dabed7136b9..6604276cc20 100644 --- a/esphome/components/modbus_controller/modbus_controller.cpp +++ b/esphome/components/modbus_controller/modbus_controller.cpp @@ -2,8 +2,7 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller"; @@ -539,5 +538,4 @@ bool ModbusCommandItem::is_equal(const ModbusCommandItem &other) { other.register_type == this->register_type && other.function_code == this->function_code; } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/modbus_controller.h b/esphome/components/modbus_controller/modbus_controller.h index 40139f055b4..ba86c2cd166 100644 --- a/esphome/components/modbus_controller/modbus_controller.h +++ b/esphome/components/modbus_controller/modbus_controller.h @@ -12,8 +12,7 @@ #include #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusController; @@ -391,5 +390,4 @@ inline float payload_to_float(const std::vector &data, const SensorItem return float_value; } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/number/modbus_number.cpp b/esphome/components/modbus_controller/number/modbus_number.cpp index ed5d91ec5b6..2c81dd6830c 100644 --- a/esphome/components/modbus_controller/number/modbus_number.cpp +++ b/esphome/components/modbus_controller/number/modbus_number.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus.number"; @@ -90,5 +89,4 @@ void ModbusNumber::control(float value) { } void ModbusNumber::dump_config() { LOG_NUMBER(TAG, "Modbus Number", this); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/number/modbus_number.h b/esphome/components/modbus_controller/number/modbus_number.h index 169f85ff36c..dd8f418bfc1 100644 --- a/esphome/components/modbus_controller/number/modbus_number.h +++ b/esphome/components/modbus_controller/number/modbus_number.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { using value_to_data_t = std::function(float); @@ -46,5 +45,4 @@ class ModbusNumber : public number::Number, public Component, public SensorItem bool use_write_multiple_{false}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/output/modbus_output.cpp b/esphome/components/modbus_controller/output/modbus_output.cpp index e7f1a39716e..504e09a0931 100644 --- a/esphome/components/modbus_controller/output/modbus_output.cpp +++ b/esphome/components/modbus_controller/output/modbus_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.output"; @@ -118,5 +117,4 @@ void ModbusBinaryOutput::dump_config() { this->start_address, this->register_count, static_cast(this->sensor_value_type)); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/output/modbus_output.h b/esphome/components/modbus_controller/output/modbus_output.h index 3f3cadfe2fb..c5323e3bf30 100644 --- a/esphome/components/modbus_controller/output/modbus_output.h +++ b/esphome/components/modbus_controller/output/modbus_output.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusFloatOutput : public output::FloatOutput, public Component, public SensorItem { public: @@ -72,5 +71,4 @@ class ModbusBinaryOutput : public output::BinaryOutput, public Component, public bool use_write_multiple_{false}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/select/modbus_select.cpp b/esphome/components/modbus_controller/select/modbus_select.cpp index 2cff7e89ee8..859828f5f68 100644 --- a/esphome/components/modbus_controller/select/modbus_select.cpp +++ b/esphome/components/modbus_controller/select/modbus_select.cpp @@ -1,8 +1,7 @@ #include "modbus_select.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.select"; @@ -86,5 +85,4 @@ void ModbusSelect::control(size_t index) { this->publish_state(index); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/select/modbus_select.h b/esphome/components/modbus_controller/select/modbus_select.h index fde441f2bcf..a736abd0dbc 100644 --- a/esphome/components/modbus_controller/select/modbus_select.h +++ b/esphome/components/modbus_controller/select/modbus_select.h @@ -7,8 +7,7 @@ #include "esphome/components/select/select.h" #include "esphome/core/component.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusSelect : public Component, public select::Select, public SensorItem { public: @@ -49,5 +48,4 @@ class ModbusSelect : public Component, public select::Select, public SensorItem optional write_transform_func_{nullopt}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/sensor/modbus_sensor.cpp b/esphome/components/modbus_controller/sensor/modbus_sensor.cpp index a21fd910326..559724057a6 100644 --- a/esphome/components/modbus_controller/sensor/modbus_sensor.cpp +++ b/esphome/components/modbus_controller/sensor/modbus_sensor.cpp @@ -2,8 +2,7 @@ #include "modbus_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.sensor"; @@ -27,5 +26,4 @@ void ModbusSensor::parse_and_publish(const std::vector &data) { this->publish_state(result); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/sensor/modbus_sensor.h b/esphome/components/modbus_controller/sensor/modbus_sensor.h index ba943c873c6..2e6967b07cd 100644 --- a/esphome/components/modbus_controller/sensor/modbus_sensor.h +++ b/esphome/components/modbus_controller/sensor/modbus_sensor.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusSensor : public Component, public sensor::Sensor, public SensorItem { public: @@ -33,5 +32,4 @@ class ModbusSensor : public Component, public sensor::Sensor, public SensorItem optional transform_func_{nullopt}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/switch/modbus_switch.cpp b/esphome/components/modbus_controller/switch/modbus_switch.cpp index dbaff04cc69..044ca2f8cc2 100644 --- a/esphome/components/modbus_controller/switch/modbus_switch.cpp +++ b/esphome/components/modbus_controller/switch/modbus_switch.cpp @@ -2,8 +2,8 @@ #include "modbus_switch.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { + +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.switch"; @@ -112,5 +112,4 @@ void ModbusSwitch::write_state(bool state) { this->publish_state(state); } // ModbusSwitch end -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/switch/modbus_switch.h b/esphome/components/modbus_controller/switch/modbus_switch.h index 301c2bf5489..541a23706d1 100644 --- a/esphome/components/modbus_controller/switch/modbus_switch.h +++ b/esphome/components/modbus_controller/switch/modbus_switch.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { class ModbusSwitch : public Component, public switch_::Switch, public SensorItem { public: @@ -49,5 +48,4 @@ class ModbusSwitch : public Component, public switch_::Switch, public SensorItem bool assumed_state_{false}; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp b/esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp index b26411b72e7..56265156385 100644 --- a/esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp +++ b/esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp @@ -2,8 +2,7 @@ #include "modbus_textsensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { static const char *const TAG = "modbus_controller.text_sensor"; @@ -56,5 +55,4 @@ void ModbusTextSensor::parse_and_publish(const std::vector &data) { this->publish_state(output_str); } -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/modbus_controller/text_sensor/modbus_textsensor.h b/esphome/components/modbus_controller/text_sensor/modbus_textsensor.h index 6666aea9767..a99fea58609 100644 --- a/esphome/components/modbus_controller/text_sensor/modbus_textsensor.h +++ b/esphome/components/modbus_controller/text_sensor/modbus_textsensor.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace modbus_controller { +namespace esphome::modbus_controller { enum class RawEncoding { NONE = 0, HEXBYTES = 1, COMMA = 2, ANSI = 3 }; @@ -39,5 +38,4 @@ class ModbusTextSensor : public Component, public text_sensor::TextSensor, publi RawEncoding encode_; }; -} // namespace modbus_controller -} // namespace esphome +} // namespace esphome::modbus_controller diff --git a/esphome/components/monochromatic/monochromatic_light_output.h b/esphome/components/monochromatic/monochromatic_light_output.h index f1708ae70bc..458140ef09c 100644 --- a/esphome/components/monochromatic/monochromatic_light_output.h +++ b/esphome/components/monochromatic/monochromatic_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace monochromatic { +namespace esphome::monochromatic { class MonochromaticLightOutput : public light::LightOutput { public: @@ -25,5 +24,4 @@ class MonochromaticLightOutput : public light::LightOutput { output::FloatOutput *output_; }; -} // namespace monochromatic -} // namespace esphome +} // namespace esphome::monochromatic diff --git a/esphome/components/mopeka_ble/mopeka_ble.cpp b/esphome/components/mopeka_ble/mopeka_ble.cpp index b926beaff20..ff5dd8d61b9 100644 --- a/esphome/components/mopeka_ble/mopeka_ble.cpp +++ b/esphome/components/mopeka_ble/mopeka_ble.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_ble { +namespace esphome::mopeka_ble { static const char *const TAG = "mopeka_ble"; @@ -86,7 +85,6 @@ bool MopekaListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return false; } -} // namespace mopeka_ble -} // namespace esphome +} // namespace esphome::mopeka_ble #endif diff --git a/esphome/components/mopeka_ble/mopeka_ble.h b/esphome/components/mopeka_ble/mopeka_ble.h index b7d0c5a9c54..cc91ef17d67 100644 --- a/esphome/components/mopeka_ble/mopeka_ble.h +++ b/esphome/components/mopeka_ble/mopeka_ble.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_ble { +namespace esphome::mopeka_ble { class MopekaListener : public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -21,7 +20,6 @@ class MopekaListener : public esp32_ble_tracker::ESPBTDeviceListener { bool show_sensors_without_sync_; }; -} // namespace mopeka_ble -} // namespace esphome +} // namespace esphome::mopeka_ble #endif diff --git a/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp b/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp index 9bc9900a5ac..ab0ff9a113e 100644 --- a/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp +++ b/esphome/components/mopeka_pro_check/mopeka_pro_check.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_pro_check { +namespace esphome::mopeka_pro_check { static const char *const TAG = "mopeka_pro_check"; static const uint8_t MANUFACTURER_DATA_LENGTH = 10; @@ -154,7 +153,6 @@ SensorReadQuality MopekaProCheck::parse_read_quality_(const std::vector return static_cast(message[4] >> 6); } -} // namespace mopeka_pro_check -} // namespace esphome +} // namespace esphome::mopeka_pro_check #endif diff --git a/esphome/components/mopeka_pro_check/mopeka_pro_check.h b/esphome/components/mopeka_pro_check/mopeka_pro_check.h index 41fb3121529..bfdfe80c486 100644 --- a/esphome/components/mopeka_pro_check/mopeka_pro_check.h +++ b/esphome/components/mopeka_pro_check/mopeka_pro_check.h @@ -9,8 +9,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_pro_check { +namespace esphome::mopeka_pro_check { enum SensorType { STANDARD_BOTTOM_UP = 0x03, @@ -65,7 +64,6 @@ class MopekaProCheck : public Component, public esp32_ble_tracker::ESPBTDeviceLi SensorReadQuality parse_read_quality_(const std::vector &message); }; -} // namespace mopeka_pro_check -} // namespace esphome +} // namespace esphome::mopeka_pro_check #endif diff --git a/esphome/components/mopeka_std_check/mopeka_std_check.cpp b/esphome/components/mopeka_std_check/mopeka_std_check.cpp index a4a31b82608..519a45fcb59 100644 --- a/esphome/components/mopeka_std_check/mopeka_std_check.cpp +++ b/esphome/components/mopeka_std_check/mopeka_std_check.cpp @@ -5,8 +5,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_std_check { +namespace esphome::mopeka_std_check { static const char *const TAG = "mopeka_std_check"; static const uint16_t SERVICE_UUID = 0xADA0; @@ -232,7 +231,6 @@ int8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) { } } -} // namespace mopeka_std_check -} // namespace esphome +} // namespace esphome::mopeka_std_check #endif diff --git a/esphome/components/mopeka_std_check/mopeka_std_check.h b/esphome/components/mopeka_std_check/mopeka_std_check.h index c0a02f27f20..a38abeabf03 100644 --- a/esphome/components/mopeka_std_check/mopeka_std_check.h +++ b/esphome/components/mopeka_std_check/mopeka_std_check.h @@ -9,8 +9,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace mopeka_std_check { +namespace esphome::mopeka_std_check { enum SensorType { STANDARD = 0x02, @@ -74,7 +73,6 @@ class MopekaStdCheck : public Component, public esp32_ble_tracker::ESPBTDeviceLi int8_t parse_temperature_(const mopeka_std_package *message); }; -} // namespace mopeka_std_check -} // namespace esphome +} // namespace esphome::mopeka_std_check #endif diff --git a/esphome/components/mpl3115a2/mpl3115a2.cpp b/esphome/components/mpl3115a2/mpl3115a2.cpp index a689149c892..d7994327b1c 100644 --- a/esphome/components/mpl3115a2/mpl3115a2.cpp +++ b/esphome/components/mpl3115a2/mpl3115a2.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace mpl3115a2 { +namespace esphome::mpl3115a2 { static const char *const TAG = "mpl3115a2"; @@ -94,5 +93,4 @@ void MPL3115A2Component::update() { this->status_clear_warning(); } -} // namespace mpl3115a2 -} // namespace esphome +} // namespace esphome::mpl3115a2 diff --git a/esphome/components/mpl3115a2/mpl3115a2.h b/esphome/components/mpl3115a2/mpl3115a2.h index 05da71f8300..d78c9d571c8 100644 --- a/esphome/components/mpl3115a2/mpl3115a2.h +++ b/esphome/components/mpl3115a2/mpl3115a2.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mpl3115a2 { +namespace esphome::mpl3115a2 { // enums from https://github.com/adafruit/Adafruit_MPL3115A2_Library/ /** MPL3115A2 registers **/ @@ -102,5 +101,4 @@ class MPL3115A2Component : public PollingComponent, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace mpl3115a2 -} // namespace esphome +} // namespace esphome::mpl3115a2 diff --git a/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.cpp b/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.cpp index dce0e73b9a4..4f500f4e050 100644 --- a/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.cpp +++ b/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.cpp @@ -1,7 +1,6 @@ #include "mpr121_binary_sensor.h" -namespace esphome { -namespace mpr121 { +namespace esphome::mpr121 { void MPR121BinarySensor::setup() { uint8_t touch_threshold = this->touch_threshold_.value_or(this->parent_->get_touch_threshold()); @@ -16,5 +15,4 @@ void MPR121BinarySensor::process(uint16_t data) { this->publish_state(new_state); } -} // namespace mpr121 -} // namespace esphome +} // namespace esphome::mpr121 diff --git a/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.h b/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.h index 577ba828939..5fa10bf5980 100644 --- a/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.h +++ b/esphome/components/mpr121/binary_sensor/mpr121_binary_sensor.h @@ -4,8 +4,7 @@ #include "../mpr121.h" -namespace esphome { -namespace mpr121 { +namespace esphome::mpr121 { class MPR121BinarySensor : public binary_sensor::BinarySensor, public MPR121Channel, public Parented { public: @@ -22,5 +21,4 @@ class MPR121BinarySensor : public binary_sensor::BinarySensor, public MPR121Chan optional release_threshold_{}; }; -} // namespace mpr121 -} // namespace esphome +} // namespace esphome::mpr121 diff --git a/esphome/components/mpr121/mpr121.cpp b/esphome/components/mpr121/mpr121.cpp index cd9c81fe034..6b183233d1e 100644 --- a/esphome/components/mpr121/mpr121.cpp +++ b/esphome/components/mpr121/mpr121.cpp @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace mpr121 { +namespace esphome::mpr121 { static const char *const TAG = "mpr121"; @@ -157,5 +156,4 @@ size_t MPR121GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "ELE%u on MPR121", this->pin_); } -} // namespace mpr121 -} // namespace esphome +} // namespace esphome::mpr121 diff --git a/esphome/components/mpr121/mpr121.h b/esphome/components/mpr121/mpr121.h index 085018fff06..54b5c8abf46 100644 --- a/esphome/components/mpr121/mpr121.h +++ b/esphome/components/mpr121/mpr121.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace mpr121 { +namespace esphome::mpr121 { enum { MPR121_TOUCHSTATUS_L = 0x00, @@ -125,5 +124,4 @@ class MPR121GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace mpr121 -} // namespace esphome +} // namespace esphome::mpr121 diff --git a/esphome/components/mpu6050/mpu6050.cpp b/esphome/components/mpu6050/mpu6050.cpp index 91a84d061ad..8784e8caf81 100644 --- a/esphome/components/mpu6050/mpu6050.cpp +++ b/esphome/components/mpu6050/mpu6050.cpp @@ -1,8 +1,7 @@ #include "mpu6050.h" #include "esphome/core/log.h" -namespace esphome { -namespace mpu6050 { +namespace esphome::mpu6050 { static const char *const TAG = "mpu6050"; @@ -141,5 +140,4 @@ void MPU6050Component::update() { this->status_clear_warning(); } -} // namespace mpu6050 -} // namespace esphome +} // namespace esphome::mpu6050 diff --git a/esphome/components/mpu6050/mpu6050.h b/esphome/components/mpu6050/mpu6050.h index cc7c3620df7..bac07cb4a5e 100644 --- a/esphome/components/mpu6050/mpu6050.h +++ b/esphome/components/mpu6050/mpu6050.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mpu6050 { +namespace esphome::mpu6050 { class MPU6050Component : public PollingComponent, public i2c::I2CDevice { public: @@ -31,7 +30,5 @@ class MPU6050Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *gyro_y_sensor_{nullptr}; sensor::Sensor *gyro_z_sensor_{nullptr}; }; -; -} // namespace mpu6050 -} // namespace esphome +} // namespace esphome::mpu6050 diff --git a/esphome/components/mpu6886/mpu6886.cpp b/esphome/components/mpu6886/mpu6886.cpp index 02747da3064..b8cbd4635ac 100644 --- a/esphome/components/mpu6886/mpu6886.cpp +++ b/esphome/components/mpu6886/mpu6886.cpp @@ -1,8 +1,7 @@ #include "mpu6886.h" #include "esphome/core/log.h" -namespace esphome { -namespace mpu6886 { +namespace esphome::mpu6886 { static const char *const TAG = "mpu6886"; @@ -146,5 +145,4 @@ void MPU6886Component::update() { this->status_clear_warning(); } -} // namespace mpu6886 -} // namespace esphome +} // namespace esphome::mpu6886 diff --git a/esphome/components/mpu6886/mpu6886.h b/esphome/components/mpu6886/mpu6886.h index 96e2bf61a16..a23858a7b7c 100644 --- a/esphome/components/mpu6886/mpu6886.h +++ b/esphome/components/mpu6886/mpu6886.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace mpu6886 { +namespace esphome::mpu6886 { class MPU6886Component : public PollingComponent, public i2c::I2CDevice { public: @@ -31,7 +30,5 @@ class MPU6886Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *gyro_y_sensor_{nullptr}; sensor::Sensor *gyro_z_sensor_{nullptr}; }; -; -} // namespace mpu6886 -} // namespace esphome +} // namespace esphome::mpu6886 diff --git a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp index 273de103765..40b5b46e1d2 100644 --- a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp +++ b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace mqtt_subscribe { +namespace esphome::mqtt_subscribe { static const char *const TAG = "mqtt_subscribe.sensor"; @@ -32,7 +31,6 @@ void MQTTSubscribeSensor::dump_config() { ESP_LOGCONFIG(TAG, " Topic: %s", this->topic_.c_str()); } -} // namespace mqtt_subscribe -} // namespace esphome +} // namespace esphome::mqtt_subscribe #endif // USE_MQTT diff --git a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.h b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.h index 0619326ac93..229c0586ab7 100644 --- a/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.h +++ b/esphome/components/mqtt_subscribe/sensor/mqtt_subscribe_sensor.h @@ -8,8 +8,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/mqtt/mqtt_client.h" -namespace esphome { -namespace mqtt_subscribe { +namespace esphome::mqtt_subscribe { class MQTTSubscribeSensor : public sensor::Sensor, public Component { public: @@ -27,7 +26,6 @@ class MQTTSubscribeSensor : public sensor::Sensor, public Component { uint8_t qos_{0}; }; -} // namespace mqtt_subscribe -} // namespace esphome +} // namespace esphome::mqtt_subscribe #endif // USE_MQTT diff --git a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp index 8aa094a2d4c..edc197671e6 100644 --- a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp +++ b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.cpp @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace mqtt_subscribe { +namespace esphome::mqtt_subscribe { static const char *const TAG = "mqtt_subscribe.text_sensor"; @@ -22,7 +21,6 @@ void MQTTSubscribeTextSensor::dump_config() { ESP_LOGCONFIG(TAG, " Topic: %s", this->topic_.c_str()); } -} // namespace mqtt_subscribe -} // namespace esphome +} // namespace esphome::mqtt_subscribe #endif // USE_MQTT diff --git a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.h b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.h index 9f8e5c63cce..f218bf2a8a3 100644 --- a/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.h +++ b/esphome/components/mqtt_subscribe/text_sensor/mqtt_subscribe_text_sensor.h @@ -8,8 +8,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "esphome/components/mqtt/mqtt_client.h" -namespace esphome { -namespace mqtt_subscribe { +namespace esphome::mqtt_subscribe { class MQTTSubscribeTextSensor : public text_sensor::TextSensor, public Component { public: @@ -26,7 +25,6 @@ class MQTTSubscribeTextSensor : public text_sensor::TextSensor, public Component uint8_t qos_{}; }; -} // namespace mqtt_subscribe -} // namespace esphome +} // namespace esphome::mqtt_subscribe #endif // USE_MQTT diff --git a/esphome/components/ms5611/ms5611.cpp b/esphome/components/ms5611/ms5611.cpp index d47ca245b84..9b7dcbe653e 100644 --- a/esphome/components/ms5611/ms5611.cpp +++ b/esphome/components/ms5611/ms5611.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace ms5611 { +namespace esphome::ms5611 { static const char *const TAG = "ms5611"; @@ -123,5 +122,4 @@ void MS5611Component::calculate_values_(uint32_t raw_temperature, uint32_t raw_p this->status_clear_warning(); } -} // namespace ms5611 -} // namespace esphome +} // namespace esphome::ms5611 diff --git a/esphome/components/ms5611/ms5611.h b/esphome/components/ms5611/ms5611.h index 7e4806f3194..c6ad5b231ae 100644 --- a/esphome/components/ms5611/ms5611.h +++ b/esphome/components/ms5611/ms5611.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ms5611 { +namespace esphome::ms5611 { class MS5611Component : public PollingComponent, public i2c::I2CDevice { public: @@ -26,5 +25,4 @@ class MS5611Component : public PollingComponent, public i2c::I2CDevice { uint16_t prom_[6]; }; -} // namespace ms5611 -} // namespace esphome +} // namespace esphome::ms5611 diff --git a/esphome/components/ms8607/ms8607.cpp b/esphome/components/ms8607/ms8607.cpp index d141dcb1916..f733a8349d4 100644 --- a/esphome/components/ms8607/ms8607.cpp +++ b/esphome/components/ms8607/ms8607.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace ms8607 { +namespace esphome::ms8607 { /// TAG used for logging calls static const char *const TAG = "ms8607"; @@ -438,5 +437,4 @@ void MS8607Component::calculate_values_(uint32_t d2_raw_temperature, uint32_t d1 } } -} // namespace ms8607 -} // namespace esphome +} // namespace esphome::ms8607 diff --git a/esphome/components/ms8607/ms8607.h b/esphome/components/ms8607/ms8607.h index 2888b6cdd24..8f9cc9cb883 100644 --- a/esphome/components/ms8607/ms8607.h +++ b/esphome/components/ms8607/ms8607.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ms8607 { +namespace esphome::ms8607 { /** Class for I2CDevice used to communicate with the Humidity sensor @@ -108,5 +107,4 @@ class MS8607Component : public PollingComponent, public i2c::I2CDevice { uint8_t reset_attempts_remaining_{0}; }; -} // namespace ms8607 -} // namespace esphome +} // namespace esphome::ms8607 diff --git a/esphome/components/msa3xx/msa3xx.cpp b/esphome/components/msa3xx/msa3xx.cpp index 6d6b21e6af2..f23fcfc8eac 100644 --- a/esphome/components/msa3xx/msa3xx.cpp +++ b/esphome/components/msa3xx/msa3xx.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace msa3xx { +namespace esphome::msa3xx { static const char *const TAG = "msa3xx"; @@ -410,5 +409,4 @@ void MSA3xxComponent::process_motions_(RegMotionInterrupt old) { } } -} // namespace msa3xx -} // namespace esphome +} // namespace esphome::msa3xx diff --git a/esphome/components/msa3xx/msa3xx.h b/esphome/components/msa3xx/msa3xx.h index 439d3b5f4dc..345afc50abb 100644 --- a/esphome/components/msa3xx/msa3xx.h +++ b/esphome/components/msa3xx/msa3xx.h @@ -14,8 +14,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #endif -namespace esphome { -namespace msa3xx { +namespace esphome::msa3xx { // Combined register map of MSA301 and MSA311 // Differences @@ -305,5 +304,4 @@ class MSA3xxComponent : public PollingComponent, public i2c::I2CDevice { void process_motions_(RegMotionInterrupt old); }; -} // namespace msa3xx -} // namespace esphome +} // namespace esphome::msa3xx diff --git a/esphome/components/my9231/my9231.cpp b/esphome/components/my9231/my9231.cpp index 25f7e6925d3..0072f7196e7 100644 --- a/esphome/components/my9231/my9231.cpp +++ b/esphome/components/my9231/my9231.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace my9231 { +namespace esphome::my9231 { static const char *const TAG = "my9231.output"; @@ -123,5 +122,4 @@ void MY9231OutputComponent::send_dcki_pulses_(uint8_t count) { } } -} // namespace my9231 -} // namespace esphome +} // namespace esphome::my9231 diff --git a/esphome/components/my9231/my9231.h b/esphome/components/my9231/my9231.h index dff68d247c3..60b113079ef 100644 --- a/esphome/components/my9231/my9231.h +++ b/esphome/components/my9231/my9231.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include -namespace esphome { -namespace my9231 { +namespace esphome::my9231 { /// MY9231 float output component. class MY9231OutputComponent : public Component { @@ -60,5 +59,4 @@ class MY9231OutputComponent : public Component { bool update_{true}; }; -} // namespace my9231 -} // namespace esphome +} // namespace esphome::my9231 From ab1d2de78e407fad54077606d48d4be86c8b1d6c Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 19:28:30 -0400 Subject: [PATCH 06/52] [clang-tidy] Concatenate nested namespaces (4/7: components n-r) (#16301) --- esphome/components/nau7802/nau7802.cpp | 6 ++---- esphome/components/nau7802/nau7802.h | 6 ++---- esphome/components/nfc/automation.cpp | 6 ++---- esphome/components/nfc/automation.h | 6 ++---- esphome/components/nfc/binary_sensor/nfc_binary_sensor.cpp | 6 ++---- esphome/components/nfc/binary_sensor/nfc_binary_sensor.h | 6 ++---- esphome/components/nfc/nci_core.h | 6 ++---- esphome/components/nfc/nci_message.cpp | 6 ++---- esphome/components/nfc/nci_message.h | 6 ++---- esphome/components/nfc/ndef_message.cpp | 6 ++---- esphome/components/nfc/ndef_message.h | 6 ++---- esphome/components/nfc/ndef_record.cpp | 6 ++---- esphome/components/nfc/ndef_record.h | 6 ++---- esphome/components/nfc/ndef_record_text.cpp | 6 ++---- esphome/components/nfc/ndef_record_text.h | 6 ++---- esphome/components/nfc/ndef_record_uri.cpp | 6 ++---- esphome/components/nfc/ndef_record_uri.h | 6 ++---- esphome/components/nfc/nfc.cpp | 6 ++---- esphome/components/nfc/nfc.h | 6 ++---- esphome/components/nfc/nfc_helpers.cpp | 6 ++---- esphome/components/nfc/nfc_helpers.h | 6 ++---- esphome/components/nfc/nfc_tag.cpp | 6 ++---- esphome/components/nfc/nfc_tag.h | 6 ++---- esphome/components/noblex/noblex.cpp | 6 ++---- esphome/components/noblex/noblex.h | 6 ++---- esphome/components/npi19/npi19.cpp | 6 ++---- esphome/components/npi19/npi19.h | 6 ++---- esphome/components/ntc/ntc.cpp | 6 ++---- esphome/components/ntc/ntc.h | 6 ++---- esphome/components/one_wire/one_wire.cpp | 6 ++---- esphome/components/one_wire/one_wire.h | 6 ++---- esphome/components/one_wire/one_wire_bus.cpp | 6 ++---- esphome/components/one_wire/one_wire_bus.h | 6 ++---- esphome/components/opentherm/automation.h | 6 ++---- esphome/components/opentherm/hub.cpp | 6 ++---- esphome/components/opentherm/hub.h | 6 ++---- esphome/components/opentherm/input.h | 6 ++---- esphome/components/opentherm/number/opentherm_number.cpp | 6 ++---- esphome/components/opentherm/number/opentherm_number.h | 6 ++---- esphome/components/opentherm/opentherm.cpp | 6 ++---- esphome/components/opentherm/opentherm.h | 6 ++---- esphome/components/opentherm/opentherm_macros.h | 7 +++---- esphome/components/opentherm/output/opentherm_output.cpp | 6 ++---- esphome/components/opentherm/output/opentherm_output.h | 6 ++---- esphome/components/opentherm/switch/opentherm_switch.cpp | 6 ++---- esphome/components/opentherm/switch/opentherm_switch.h | 6 ++---- esphome/components/opt3001/opt3001.cpp | 6 ++---- esphome/components/opt3001/opt3001.h | 6 ++---- esphome/components/output/automation.cpp | 6 ++---- esphome/components/output/automation.h | 6 ++---- esphome/components/output/binary_output.h | 6 ++---- esphome/components/output/button/output_button.cpp | 6 ++---- esphome/components/output/button/output_button.h | 6 ++---- esphome/components/output/float_output.cpp | 6 ++---- esphome/components/output/float_output.h | 6 ++---- esphome/components/output/lock/output_lock.cpp | 6 ++---- esphome/components/output/lock/output_lock.h | 6 ++---- esphome/components/output/switch/output_switch.cpp | 6 ++---- esphome/components/output/switch/output_switch.h | 6 ++---- esphome/components/packet_transport/packet_transport.cpp | 6 ++---- esphome/components/packet_transport/packet_transport.h | 6 ++---- esphome/components/partition/light_partition.cpp | 6 ++---- esphome/components/partition/light_partition.h | 6 ++---- esphome/components/pca6416a/pca6416a.cpp | 6 ++---- esphome/components/pca6416a/pca6416a.h | 6 ++---- esphome/components/pca9554/pca9554.cpp | 6 ++---- esphome/components/pca9554/pca9554.h | 6 ++---- esphome/components/pca9685/pca9685_output.cpp | 6 ++---- esphome/components/pca9685/pca9685_output.h | 6 ++---- esphome/components/pcd8544/pcd_8544.cpp | 6 ++---- esphome/components/pcd8544/pcd_8544.h | 6 ++---- esphome/components/pcf85063/pcf85063.cpp | 6 ++---- esphome/components/pcf85063/pcf85063.h | 6 ++---- esphome/components/pcf8563/pcf8563.cpp | 6 ++---- esphome/components/pcf8563/pcf8563.h | 6 ++---- esphome/components/pcf8574/pcf8574.cpp | 6 ++---- esphome/components/pcf8574/pcf8574.h | 6 ++---- esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp | 6 ++---- esphome/components/pi4ioe5v6408/pi4ioe5v6408.h | 6 ++---- esphome/components/pid/pid_autotuner.cpp | 6 ++---- esphome/components/pid/pid_autotuner.h | 6 ++---- esphome/components/pid/pid_climate.cpp | 6 ++---- esphome/components/pid/pid_climate.h | 6 ++---- esphome/components/pid/pid_controller.cpp | 6 ++---- esphome/components/pid/pid_controller.h | 6 ++---- esphome/components/pid/sensor/pid_climate_sensor.cpp | 6 ++---- esphome/components/pid/sensor/pid_climate_sensor.h | 6 ++---- esphome/components/pipsolar/output/pipsolar_output.cpp | 6 ++---- esphome/components/pipsolar/output/pipsolar_output.h | 6 ++---- esphome/components/pipsolar/pipsolar.cpp | 6 ++---- esphome/components/pipsolar/pipsolar.h | 6 ++---- esphome/components/pipsolar/switch/pipsolar_switch.cpp | 6 ++---- esphome/components/pipsolar/switch/pipsolar_switch.h | 6 ++---- esphome/components/pm1006/pm1006.cpp | 6 ++---- esphome/components/pm1006/pm1006.h | 6 ++---- esphome/components/pm2005/pm2005.cpp | 6 ++---- esphome/components/pm2005/pm2005.h | 6 ++---- esphome/components/pmsa003i/pmsa003i.cpp | 6 ++---- esphome/components/pmsa003i/pmsa003i.h | 6 ++---- esphome/components/pmwcs3/pmwcs3.cpp | 6 ++---- esphome/components/pmwcs3/pmwcs3.h | 6 ++---- esphome/components/pn532/pn532.cpp | 6 ++---- esphome/components/pn532/pn532.h | 6 ++---- esphome/components/pn532/pn532_mifare_classic.cpp | 6 ++---- esphome/components/pn532/pn532_mifare_ultralight.cpp | 6 ++---- esphome/components/pn532_i2c/pn532_i2c.cpp | 6 ++---- esphome/components/pn532_i2c/pn532_i2c.h | 6 ++---- esphome/components/pn532_spi/pn532_spi.cpp | 6 ++---- esphome/components/pn532_spi/pn532_spi.h | 6 ++---- esphome/components/pn7150/automation.h | 6 ++---- esphome/components/pn7150/pn7150.cpp | 6 ++---- esphome/components/pn7150/pn7150.h | 6 ++---- esphome/components/pn7150/pn7150_mifare_classic.cpp | 6 ++---- esphome/components/pn7150/pn7150_mifare_ultralight.cpp | 6 ++---- esphome/components/pn7150_i2c/pn7150_i2c.cpp | 6 ++---- esphome/components/pn7150_i2c/pn7150_i2c.h | 6 ++---- esphome/components/pn7160/automation.h | 6 ++---- esphome/components/pn7160/pn7160.cpp | 6 ++---- esphome/components/pn7160/pn7160.h | 6 ++---- esphome/components/pn7160/pn7160_mifare_classic.cpp | 6 ++---- esphome/components/pn7160/pn7160_mifare_ultralight.cpp | 6 ++---- esphome/components/pn7160_i2c/pn7160_i2c.cpp | 6 ++---- esphome/components/pn7160_i2c/pn7160_i2c.h | 6 ++---- esphome/components/pn7160_spi/pn7160_spi.cpp | 6 ++---- esphome/components/pn7160_spi/pn7160_spi.h | 6 ++---- esphome/components/power_supply/power_supply.cpp | 6 ++---- esphome/components/power_supply/power_supply.h | 6 ++---- esphome/components/preferences/syncer.h | 6 ++---- esphome/components/prometheus/prometheus_handler.cpp | 7 +++---- esphome/components/prometheus/prometheus_handler.h | 7 +++---- esphome/components/psram/psram.cpp | 6 ++---- esphome/components/psram/psram.h | 6 ++---- esphome/components/pulse_counter/automation.h | 7 ++----- esphome/components/pulse_counter/pulse_counter_sensor.cpp | 6 ++---- esphome/components/pulse_counter/pulse_counter_sensor.h | 6 ++---- esphome/components/pulse_meter/automation.h | 7 ++----- esphome/components/pulse_meter/pulse_meter_sensor.cpp | 6 ++---- esphome/components/pulse_meter/pulse_meter_sensor.h | 6 ++---- esphome/components/pulse_width/pulse_width.cpp | 6 ++---- esphome/components/pulse_width/pulse_width.h | 6 ++---- .../components/pvvx_mithermometer/display/pvvx_display.cpp | 7 +++---- .../components/pvvx_mithermometer/display/pvvx_display.h | 6 ++---- .../components/pvvx_mithermometer/pvvx_mithermometer.cpp | 6 ++---- esphome/components/pvvx_mithermometer/pvvx_mithermometer.h | 6 ++---- esphome/components/pylontech/pylontech.cpp | 6 ++---- esphome/components/pylontech/pylontech.h | 6 ++---- esphome/components/pylontech/sensor/pylontech_sensor.cpp | 6 ++---- esphome/components/pylontech/sensor/pylontech_sensor.h | 6 ++---- .../pylontech/text_sensor/pylontech_text_sensor.cpp | 6 ++---- .../pylontech/text_sensor/pylontech_text_sensor.h | 6 ++---- esphome/components/pzem004t/pzem004t.cpp | 6 ++---- esphome/components/pzem004t/pzem004t.h | 6 ++---- esphome/components/pzemac/pzemac.cpp | 6 ++---- esphome/components/pzemac/pzemac.h | 6 ++---- esphome/components/pzemdc/pzemdc.cpp | 6 ++---- esphome/components/pzemdc/pzemdc.h | 6 ++---- esphome/components/qmc5883l/qmc5883l.cpp | 6 ++---- esphome/components/qmc5883l/qmc5883l.h | 6 ++---- esphome/components/qmp6988/qmp6988.cpp | 6 ++---- esphome/components/qmp6988/qmp6988.h | 6 ++---- esphome/components/qr_code/qr_code.cpp | 6 ++---- esphome/components/qwiic_pir/qwiic_pir.cpp | 6 ++---- esphome/components/qwiic_pir/qwiic_pir.h | 6 ++---- esphome/components/radon_eye_ble/radon_eye_listener.cpp | 6 ++---- esphome/components/radon_eye_ble/radon_eye_listener.h | 6 ++---- esphome/components/radon_eye_rd200/radon_eye_rd200.cpp | 6 ++---- esphome/components/radon_eye_rd200/radon_eye_rd200.h | 6 ++---- esphome/components/rc522/rc522.cpp | 6 ++---- esphome/components/rc522/rc522.h | 6 ++---- esphome/components/rc522_i2c/rc522_i2c.cpp | 6 ++---- esphome/components/rc522_i2c/rc522_i2c.h | 6 ++---- esphome/components/rc522_spi/rc522_spi.cpp | 6 ++---- esphome/components/rc522_spi/rc522_spi.h | 6 ++---- esphome/components/rdm6300/rdm6300.cpp | 6 ++---- esphome/components/rdm6300/rdm6300.h | 6 ++---- esphome/components/remote_base/abbwelcome_protocol.cpp | 6 ++---- esphome/components/remote_base/abbwelcome_protocol.h | 6 ++---- esphome/components/remote_base/aeha_protocol.cpp | 6 ++---- esphome/components/remote_base/aeha_protocol.h | 6 ++---- esphome/components/remote_base/beo4_protocol.cpp | 6 ++---- esphome/components/remote_base/beo4_protocol.h | 6 ++---- esphome/components/remote_base/byronsx_protocol.cpp | 6 ++---- esphome/components/remote_base/byronsx_protocol.h | 6 ++---- esphome/components/remote_base/canalsat_protocol.cpp | 6 ++---- esphome/components/remote_base/canalsat_protocol.h | 6 ++---- esphome/components/remote_base/coolix_protocol.cpp | 6 ++---- esphome/components/remote_base/coolix_protocol.h | 6 ++---- esphome/components/remote_base/dish_protocol.cpp | 6 ++---- esphome/components/remote_base/dish_protocol.h | 6 ++---- esphome/components/remote_base/dooya_protocol.cpp | 6 ++---- esphome/components/remote_base/dooya_protocol.h | 6 ++---- esphome/components/remote_base/drayton_protocol.cpp | 6 ++---- esphome/components/remote_base/drayton_protocol.h | 6 ++---- esphome/components/remote_base/dyson_protocol.cpp | 6 ++---- esphome/components/remote_base/dyson_protocol.h | 6 ++---- esphome/components/remote_base/gobox_protocol.cpp | 6 ++---- esphome/components/remote_base/gobox_protocol.h | 6 ++---- esphome/components/remote_base/haier_protocol.cpp | 6 ++---- esphome/components/remote_base/haier_protocol.h | 6 ++---- esphome/components/remote_base/jvc_protocol.cpp | 6 ++---- esphome/components/remote_base/jvc_protocol.h | 6 ++---- esphome/components/remote_base/keeloq_protocol.cpp | 6 ++---- esphome/components/remote_base/keeloq_protocol.h | 6 ++---- esphome/components/remote_base/lg_protocol.cpp | 6 ++---- esphome/components/remote_base/lg_protocol.h | 6 ++---- esphome/components/remote_base/magiquest_protocol.cpp | 6 ++---- esphome/components/remote_base/magiquest_protocol.h | 6 ++---- esphome/components/remote_base/midea_protocol.cpp | 6 ++---- esphome/components/remote_base/midea_protocol.h | 6 ++---- esphome/components/remote_base/mirage_protocol.cpp | 6 ++---- esphome/components/remote_base/mirage_protocol.h | 6 ++---- esphome/components/remote_base/nec_protocol.cpp | 6 ++---- esphome/components/remote_base/nec_protocol.h | 6 ++---- esphome/components/remote_base/nexa_protocol.cpp | 6 ++---- esphome/components/remote_base/nexa_protocol.h | 6 ++---- esphome/components/remote_base/panasonic_protocol.cpp | 6 ++---- esphome/components/remote_base/panasonic_protocol.h | 6 ++---- esphome/components/remote_base/pioneer_protocol.cpp | 6 ++---- esphome/components/remote_base/pioneer_protocol.h | 6 ++---- esphome/components/remote_base/pronto_protocol.cpp | 6 ++---- esphome/components/remote_base/pronto_protocol.h | 6 ++---- esphome/components/remote_base/raw_protocol.cpp | 6 ++---- esphome/components/remote_base/raw_protocol.h | 6 ++---- esphome/components/remote_base/rc5_protocol.cpp | 6 ++---- esphome/components/remote_base/rc5_protocol.h | 6 ++---- esphome/components/remote_base/rc6_protocol.cpp | 6 ++---- esphome/components/remote_base/rc6_protocol.h | 6 ++---- esphome/components/remote_base/rc_switch_protocol.cpp | 6 ++---- esphome/components/remote_base/rc_switch_protocol.h | 6 ++---- esphome/components/remote_base/remote_base.cpp | 6 ++---- esphome/components/remote_base/remote_base.h | 6 ++---- esphome/components/remote_base/roomba_protocol.cpp | 6 ++---- esphome/components/remote_base/roomba_protocol.h | 6 ++---- esphome/components/remote_base/samsung36_protocol.cpp | 6 ++---- esphome/components/remote_base/samsung36_protocol.h | 6 ++---- esphome/components/remote_base/samsung_protocol.cpp | 6 ++---- esphome/components/remote_base/samsung_protocol.h | 6 ++---- esphome/components/remote_base/sony_protocol.cpp | 6 ++---- esphome/components/remote_base/sony_protocol.h | 6 ++---- esphome/components/remote_base/symphony_protocol.cpp | 6 ++---- esphome/components/remote_base/symphony_protocol.h | 6 ++---- esphome/components/remote_base/toshiba_ac_protocol.cpp | 6 ++---- esphome/components/remote_base/toshiba_ac_protocol.h | 6 ++---- esphome/components/remote_base/toto_protocol.cpp | 6 ++---- esphome/components/remote_base/toto_protocol.h | 6 ++---- esphome/components/resampler/speaker/resampler_speaker.cpp | 6 ++---- esphome/components/resampler/speaker/resampler_speaker.h | 6 ++---- esphome/components/resistance/resistance_sensor.cpp | 6 ++---- esphome/components/resistance/resistance_sensor.h | 6 ++---- esphome/components/restart/button/restart_button.cpp | 6 ++---- esphome/components/restart/button/restart_button.h | 6 ++---- esphome/components/restart/switch/restart_switch.cpp | 6 ++---- esphome/components/restart/switch/restart_switch.h | 6 ++---- esphome/components/rf_bridge/rf_bridge.cpp | 6 ++---- esphome/components/rf_bridge/rf_bridge.h | 6 ++---- esphome/components/rgb/rgb_light_output.h | 6 ++---- esphome/components/rgbct/rgbct_light_output.h | 6 ++---- esphome/components/rgbw/rgbw_light_output.h | 6 ++---- esphome/components/rgbww/rgbww_light_output.h | 6 ++---- esphome/components/rotary_encoder/rotary_encoder.cpp | 6 ++---- esphome/components/rotary_encoder/rotary_encoder.h | 6 ++---- esphome/components/ruuvi_ble/ruuvi_ble.cpp | 6 ++---- esphome/components/ruuvi_ble/ruuvi_ble.h | 6 ++---- esphome/components/ruuvitag/ruuvitag.cpp | 6 ++---- esphome/components/ruuvitag/ruuvitag.h | 6 ++---- esphome/components/rx8130/rx8130.cpp | 6 ++---- esphome/components/rx8130/rx8130.h | 6 ++---- 267 files changed, 538 insertions(+), 1070 deletions(-) diff --git a/esphome/components/nau7802/nau7802.cpp b/esphome/components/nau7802/nau7802.cpp index 66d36dd7416..4d73ed6dd0f 100644 --- a/esphome/components/nau7802/nau7802.cpp +++ b/esphome/components/nau7802/nau7802.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace nau7802 { +namespace esphome::nau7802 { static const char *const TAG = "nau7802"; @@ -313,5 +312,4 @@ void NAU7802Sensor::update() { bool NAU7802Sensor::is_data_ready_() { return this->reg(PU_CTRL_REG).get() & PU_CTRL_CYCLE_READY; } -} // namespace nau7802 -} // namespace esphome +} // namespace esphome::nau7802 diff --git a/esphome/components/nau7802/nau7802.h b/esphome/components/nau7802/nau7802.h index ae39e167a4d..67f36ca6772 100644 --- a/esphome/components/nau7802/nau7802.h +++ b/esphome/components/nau7802/nau7802.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace nau7802 { +namespace esphome::nau7802 { enum NAU7802Gain { NAU7802_GAIN_128 = 0b111, @@ -114,5 +113,4 @@ template class NAU7802CalbrateGainAction : public Action, void play(const Ts &...x) override { this->parent_->calibrate_gain(); } }; -} // namespace nau7802 -} // namespace esphome +} // namespace esphome::nau7802 diff --git a/esphome/components/nfc/automation.cpp b/esphome/components/nfc/automation.cpp index e2956e4c123..7129aaf2af9 100644 --- a/esphome/components/nfc/automation.cpp +++ b/esphome/components/nfc/automation.cpp @@ -1,13 +1,11 @@ #include "automation.h" #include "nfc.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { void NfcOnTagTrigger::process(const std::unique_ptr &tag) { char uid_buf[FORMAT_UID_BUFFER_SIZE]; this->trigger(std::string(format_uid_to(uid_buf, tag->get_uid())), *tag); } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/automation.h b/esphome/components/nfc/automation.h index 565b71bdd97..0ac3e3b8b67 100644 --- a/esphome/components/nfc/automation.h +++ b/esphome/components/nfc/automation.h @@ -5,13 +5,11 @@ #include "nfc.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { class NfcOnTagTrigger : public Trigger { public: void process(const std::unique_ptr &tag); }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/binary_sensor/nfc_binary_sensor.cpp b/esphome/components/nfc/binary_sensor/nfc_binary_sensor.cpp index 524ad5a413e..6e8162fc912 100644 --- a/esphome/components/nfc/binary_sensor/nfc_binary_sensor.cpp +++ b/esphome/components/nfc/binary_sensor/nfc_binary_sensor.cpp @@ -3,8 +3,7 @@ #include "../nfc_helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.binary_sensor"; @@ -112,5 +111,4 @@ void NfcTagBinarySensor::tag_on(NfcTag &tag) { } } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/binary_sensor/nfc_binary_sensor.h b/esphome/components/nfc/binary_sensor/nfc_binary_sensor.h index 0a7ca0ca76a..b3448a57ccd 100644 --- a/esphome/components/nfc/binary_sensor/nfc_binary_sensor.h +++ b/esphome/components/nfc/binary_sensor/nfc_binary_sensor.h @@ -6,8 +6,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { class NfcTagBinarySensor : public binary_sensor::BinarySensor, public Component, @@ -34,5 +33,4 @@ class NfcTagBinarySensor : public binary_sensor::BinarySensor, NfcTagUid uid_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nci_core.h b/esphome/components/nfc/nci_core.h index 6b42070ed02..dd4bc547f61 100644 --- a/esphome/components/nfc/nci_core.h +++ b/esphome/components/nfc/nci_core.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { // Header info static constexpr uint8_t NCI_PKT_HEADER_SIZE = 3; // NCI packet (pkt) headers are always three bytes @@ -140,5 +139,4 @@ static constexpr uint8_t RF_INTF_ACTIVATED_NTF_INIT_CRED = 5 + NCI_PKT_HEADER_SI static constexpr uint8_t RF_INTF_ACTIVATED_NTF_RF_TECH_LENGTH = 6 + NCI_PKT_HEADER_SIZE; static constexpr uint8_t RF_INTF_ACTIVATED_NTF_RF_TECH_PARAMS = 7 + NCI_PKT_HEADER_SIZE; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nci_message.cpp b/esphome/components/nfc/nci_message.cpp index c6b21f6ae07..0b60fd0aded 100644 --- a/esphome/components/nfc/nci_message.cpp +++ b/esphome/components/nfc/nci_message.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "NciMessage"; @@ -162,5 +161,4 @@ void NciMessage::set_payload(const std::vector &payload) { this->nci_message_ = message; } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nci_message.h b/esphome/components/nfc/nci_message.h index 0c5c871f740..8e8b1103363 100644 --- a/esphome/components/nfc/nci_message.h +++ b/esphome/components/nfc/nci_message.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { class NciMessage { public: @@ -46,5 +45,4 @@ class NciMessage { std::vector nci_message_{0, 0, 0}; // three bytes, MT/PBF/GID, OID, payload length/size }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_message.cpp b/esphome/components/nfc/ndef_message.cpp index 35028555c55..ba3aa77e340 100644 --- a/esphome/components/nfc/ndef_message.cpp +++ b/esphome/components/nfc/ndef_message.cpp @@ -1,8 +1,7 @@ #include "ndef_message.h" #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.ndef_message"; @@ -120,5 +119,4 @@ std::vector NdefMessage::encode() { return data; } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_message.h b/esphome/components/nfc/ndef_message.h index 48f79b88548..7d431b22963 100644 --- a/esphome/components/nfc/ndef_message.h +++ b/esphome/components/nfc/ndef_message.h @@ -9,8 +9,7 @@ #include "ndef_record_text.h" #include "ndef_record_uri.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static constexpr uint8_t MAX_NDEF_RECORDS = 4; @@ -38,5 +37,4 @@ class NdefMessage { std::vector> records_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record.cpp b/esphome/components/nfc/ndef_record.cpp index 540ba629408..8b9e7023ed6 100644 --- a/esphome/components/nfc/ndef_record.cpp +++ b/esphome/components/nfc/ndef_record.cpp @@ -1,7 +1,6 @@ #include "ndef_record.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.ndef_record"; @@ -61,5 +60,4 @@ uint8_t NdefRecord::create_flag_byte(bool first, bool last, size_t payload_size) return value; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record.h b/esphome/components/nfc/ndef_record.h index 1a7c24aee9c..fc9fe254024 100644 --- a/esphome/components/nfc/ndef_record.h +++ b/esphome/components/nfc/ndef_record.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { static constexpr uint8_t TNF_EMPTY = 0x00; static constexpr uint8_t TNF_WELL_KNOWN = 0x01; @@ -53,5 +52,4 @@ class NdefRecord { std::string payload_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record_text.cpp b/esphome/components/nfc/ndef_record_text.cpp index 8a9a2cb014f..8ad687daf8c 100644 --- a/esphome/components/nfc/ndef_record_text.cpp +++ b/esphome/components/nfc/ndef_record_text.cpp @@ -1,8 +1,7 @@ #include "ndef_record_text.h" #include "ndef_record.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.ndef_record_text"; @@ -41,5 +40,4 @@ std::vector NdefRecordText::get_encoded_payload() { return data; } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record_text.h b/esphome/components/nfc/ndef_record_text.h index e6c15704f0f..ceee585e892 100644 --- a/esphome/components/nfc/ndef_record_text.h +++ b/esphome/components/nfc/ndef_record_text.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { class NdefRecordText : public NdefRecord { public: @@ -39,5 +38,4 @@ class NdefRecordText : public NdefRecord { std::string language_code_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record_uri.cpp b/esphome/components/nfc/ndef_record_uri.cpp index 9064f04f296..e2c6d21a34e 100644 --- a/esphome/components/nfc/ndef_record_uri.cpp +++ b/esphome/components/nfc/ndef_record_uri.cpp @@ -1,7 +1,6 @@ #include "ndef_record_uri.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.ndef_record_uri"; @@ -44,5 +43,4 @@ std::vector NdefRecordUri::get_encoded_payload() { return data; } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/ndef_record_uri.h b/esphome/components/nfc/ndef_record_uri.h index 2f7790a9a9a..619cdf7cf38 100644 --- a/esphome/components/nfc/ndef_record_uri.h +++ b/esphome/components/nfc/ndef_record_uri.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { static constexpr uint8_t PAYLOAD_IDENTIFIERS_COUNT = 0x23; static const char *const PAYLOAD_IDENTIFIERS[] = {"", @@ -74,5 +73,4 @@ class NdefRecordUri : public NdefRecord { std::string uri_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc.cpp b/esphome/components/nfc/nfc.cpp index 55543cd292a..99e476dbdfd 100644 --- a/esphome/components/nfc/nfc.cpp +++ b/esphome/components/nfc/nfc.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc"; @@ -108,5 +107,4 @@ bool mifare_classic_is_trailer_block(uint8_t block_num) { } } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc.h b/esphome/components/nfc/nfc.h index 8ca5cb7ea44..42ef9939136 100644 --- a/esphome/components/nfc/nfc.h +++ b/esphome/components/nfc/nfc.h @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace nfc { +namespace esphome::nfc { static constexpr uint8_t MIFARE_CLASSIC_BLOCK_SIZE = 16; static constexpr uint8_t MIFARE_CLASSIC_LONG_TLV_SIZE = 4; @@ -95,5 +94,4 @@ class Nfcc { std::vector tag_listeners_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc_helpers.cpp b/esphome/components/nfc/nfc_helpers.cpp index fb0954a8333..6c8a5b626d5 100644 --- a/esphome/components/nfc/nfc_helpers.cpp +++ b/esphome/components/nfc/nfc_helpers.cpp @@ -1,7 +1,6 @@ #include "nfc_helpers.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.helpers"; @@ -43,5 +42,4 @@ std::string get_random_ha_tag_ndef() { return uri; } -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc_helpers.h b/esphome/components/nfc/nfc_helpers.h index 74f5beba134..dedc602bf19 100644 --- a/esphome/components/nfc/nfc_helpers.h +++ b/esphome/components/nfc/nfc_helpers.h @@ -2,8 +2,7 @@ #include "nfc_tag.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char HA_TAG_ID_EXT_RECORD_TYPE[] = "android.com:pkg"; static const char HA_TAG_ID_EXT_RECORD_PAYLOAD[] = "io.homeassistant.companion.android"; @@ -13,5 +12,4 @@ std::string get_ha_tag_ndef(NfcTag &tag); std::string get_random_ha_tag_ndef(); bool has_ha_tag_ndef(NfcTag &tag); -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc_tag.cpp b/esphome/components/nfc/nfc_tag.cpp index c5c15b00ec8..c43210517dc 100644 --- a/esphome/components/nfc/nfc_tag.cpp +++ b/esphome/components/nfc/nfc_tag.cpp @@ -1,9 +1,7 @@ #include "nfc_tag.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { static const char *const TAG = "nfc.tag"; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/nfc/nfc_tag.h b/esphome/components/nfc/nfc_tag.h index 0ded4cd6ee2..6cc1a00c627 100644 --- a/esphome/components/nfc/nfc_tag.h +++ b/esphome/components/nfc/nfc_tag.h @@ -7,8 +7,7 @@ #include "esphome/core/log.h" #include "ndef_message.h" -namespace esphome { -namespace nfc { +namespace esphome::nfc { // NFC UIDs are 4, 7, or 10 bytes depending on tag type static constexpr size_t NFC_UID_MAX_LENGTH = 10; @@ -54,5 +53,4 @@ class NfcTag { std::shared_ptr ndef_message_; }; -} // namespace nfc -} // namespace esphome +} // namespace esphome::nfc diff --git a/esphome/components/noblex/noblex.cpp b/esphome/components/noblex/noblex.cpp index e7e421d1776..ac8d2641fea 100644 --- a/esphome/components/noblex/noblex.cpp +++ b/esphome/components/noblex/noblex.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace noblex { +namespace esphome::noblex { static const char *const TAG = "noblex.climate"; @@ -299,5 +298,4 @@ bool NoblexClimate::on_receive(remote_base::RemoteReceiveData data) { return true; } // end on_receive() -} // namespace noblex -} // namespace esphome +} // namespace esphome::noblex diff --git a/esphome/components/noblex/noblex.h b/esphome/components/noblex/noblex.h index 3d52a1a5389..62070e5deed 100644 --- a/esphome/components/noblex/noblex.h +++ b/esphome/components/noblex/noblex.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace noblex { +namespace esphome::noblex { // Temperature const uint8_t NOBLEX_TEMP_MIN = 16; // Celsius @@ -45,5 +44,4 @@ class NoblexClimate : public climate_ir::ClimateIR { uint8_t remote_state_[8]{}; }; -} // namespace noblex -} // namespace esphome +} // namespace esphome::noblex diff --git a/esphome/components/npi19/npi19.cpp b/esphome/components/npi19/npi19.cpp index 995abdff376..207acc9d991 100644 --- a/esphome/components/npi19/npi19.cpp +++ b/esphome/components/npi19/npi19.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace npi19 { +namespace esphome::npi19 { static const char *const TAG = "npi19"; @@ -101,5 +100,4 @@ void NPI19Component::update() { this->status_clear_warning(); } -} // namespace npi19 -} // namespace esphome +} // namespace esphome::npi19 diff --git a/esphome/components/npi19/npi19.h b/esphome/components/npi19/npi19.h index 8e6a8e3bfa5..d1f74141ac7 100644 --- a/esphome/components/npi19/npi19.h +++ b/esphome/components/npi19/npi19.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace npi19 { +namespace esphome::npi19 { /// This class implements support for the npi19 pressure and temperature i2c sensors. class NPI19Component : public PollingComponent, public i2c::I2CDevice { @@ -25,5 +24,4 @@ class NPI19Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *raw_pressure_sensor_{nullptr}; }; -} // namespace npi19 -} // namespace esphome +} // namespace esphome::npi19 diff --git a/esphome/components/ntc/ntc.cpp b/esphome/components/ntc/ntc.cpp index e2097bdd770..49a42e858e5 100644 --- a/esphome/components/ntc/ntc.cpp +++ b/esphome/components/ntc/ntc.cpp @@ -1,8 +1,7 @@ #include "ntc.h" #include "esphome/core/log.h" -namespace esphome { -namespace ntc { +namespace esphome::ntc { static const char *const TAG = "ntc"; @@ -26,5 +25,4 @@ void NTC::process_(float value) { this->publish_state(temp); } -} // namespace ntc -} // namespace esphome +} // namespace esphome::ntc diff --git a/esphome/components/ntc/ntc.h b/esphome/components/ntc/ntc.h index a0c72340dee..466d03f789f 100644 --- a/esphome/components/ntc/ntc.h +++ b/esphome/components/ntc/ntc.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace ntc { +namespace esphome::ntc { class NTC : public Component, public sensor::Sensor { public: @@ -24,5 +23,4 @@ class NTC : public Component, public sensor::Sensor { double c_; }; -} // namespace ntc -} // namespace esphome +} // namespace esphome::ntc diff --git a/esphome/components/one_wire/one_wire.cpp b/esphome/components/one_wire/one_wire.cpp index d14c1c92bdd..aeab821f6ad 100644 --- a/esphome/components/one_wire/one_wire.cpp +++ b/esphome/components/one_wire/one_wire.cpp @@ -1,7 +1,6 @@ #include "one_wire.h" -namespace esphome { -namespace one_wire { +namespace esphome::one_wire { static const char *const TAG = "one_wire"; @@ -51,5 +50,4 @@ bool OneWireDevice::check_address_or_index_() { return true; } -} // namespace one_wire -} // namespace esphome +} // namespace esphome::one_wire diff --git a/esphome/components/one_wire/one_wire.h b/esphome/components/one_wire/one_wire.h index 324e46cd55d..4dbbe117927 100644 --- a/esphome/components/one_wire/one_wire.h +++ b/esphome/components/one_wire/one_wire.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace one_wire { +namespace esphome::one_wire { #define LOG_ONE_WIRE_DEVICE(this) \ ESP_LOGCONFIG(TAG, " Address: %s (%s)", this->get_address_name().c_str(), \ @@ -43,5 +42,4 @@ class OneWireDevice { bool send_command_(uint8_t cmd); }; -} // namespace one_wire -} // namespace esphome +} // namespace esphome::one_wire diff --git a/esphome/components/one_wire/one_wire_bus.cpp b/esphome/components/one_wire/one_wire_bus.cpp index 99e1f352fb5..c7ea59050c4 100644 --- a/esphome/components/one_wire/one_wire_bus.cpp +++ b/esphome/components/one_wire/one_wire_bus.cpp @@ -1,8 +1,7 @@ #include "one_wire_bus.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace one_wire { +namespace esphome::one_wire { static const char *const TAG = "one_wire"; @@ -93,5 +92,4 @@ void OneWireBus::dump_devices_(const char *tag) { } } -} // namespace one_wire -} // namespace esphome +} // namespace esphome::one_wire diff --git a/esphome/components/one_wire/one_wire_bus.h b/esphome/components/one_wire/one_wire_bus.h index 6302fcee7b9..00f5a6462ee 100644 --- a/esphome/components/one_wire/one_wire_bus.h +++ b/esphome/components/one_wire/one_wire_bus.h @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace one_wire { +namespace esphome::one_wire { class OneWireBus { public: @@ -64,5 +63,4 @@ class OneWireBus { virtual uint64_t search_int() = 0; }; -} // namespace one_wire -} // namespace esphome +} // namespace esphome::one_wire diff --git a/esphome/components/opentherm/automation.h b/esphome/components/opentherm/automation.h index acbe33ac8f9..aa20a4ec5a4 100644 --- a/esphome/components/opentherm/automation.h +++ b/esphome/components/opentherm/automation.h @@ -4,8 +4,7 @@ #include "hub.h" #include "opentherm.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { class BeforeSendTrigger : public Trigger { public: @@ -21,5 +20,4 @@ class BeforeProcessResponseTrigger : public Trigger { } }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/hub.cpp b/esphome/components/opentherm/hub.cpp index 7a0cdc7f801..e2828a9e305 100644 --- a/esphome/components/opentherm/hub.cpp +++ b/esphome/components/opentherm/hub.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { static const char *const TAG = "opentherm"; namespace message_data { @@ -419,5 +418,4 @@ void OpenthermHub::dump_config() { } } -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/hub.h b/esphome/components/opentherm/hub.h index 960e23d6dd3..26381376686 100644 --- a/esphome/components/opentherm/hub.h +++ b/esphome/components/opentherm/hub.h @@ -35,8 +35,7 @@ #include "opentherm_macros.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { static const uint8_t REPEATING_MESSAGE_ORDER = 255; static const uint8_t INITIAL_UNORDERED_MESSAGE_ORDER = 254; @@ -175,5 +174,4 @@ class OpenthermHub : public Component { void dump_config() override; }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/input.h b/esphome/components/opentherm/input.h index 35671387926..f196d490375 100644 --- a/esphome/components/opentherm/input.h +++ b/esphome/components/opentherm/input.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { class OpenthermInput { public: @@ -14,5 +13,4 @@ class OpenthermInput { virtual void set_auto_max_value(bool auto_max_value) { this->auto_max_value = auto_max_value; } }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/number/opentherm_number.cpp b/esphome/components/opentherm/number/opentherm_number.cpp index bdb02a605c1..d78c6eb38a1 100644 --- a/esphome/components/opentherm/number/opentherm_number.cpp +++ b/esphome/components/opentherm/number/opentherm_number.cpp @@ -1,7 +1,6 @@ #include "opentherm_number.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { static const char *const TAG = "opentherm.number"; @@ -38,5 +37,4 @@ void OpenthermNumber::dump_config() { this->restore_value_, this->initial_value_, this->state); } -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/number/opentherm_number.h b/esphome/components/opentherm/number/opentherm_number.h index 6f860727540..c110bed2eb2 100644 --- a/esphome/components/opentherm/number/opentherm_number.h +++ b/esphome/components/opentherm/number/opentherm_number.h @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include "esphome/components/opentherm/input.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { // Just a simple number, which stores the number class OpenthermNumber : public number::Number, public Component, public OpenthermInput { @@ -27,5 +26,4 @@ class OpenthermNumber : public number::Number, public Component, public Openther void set_restore_value(bool restore_value) { this->restore_value_ = restore_value; } }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/opentherm.cpp b/esphome/components/opentherm/opentherm.cpp index 97cf83a5aa2..1ee4c9191bc 100644 --- a/esphome/components/opentherm/opentherm.cpp +++ b/esphome/components/opentherm/opentherm.cpp @@ -16,8 +16,7 @@ #endif #include -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { using std::string; @@ -566,5 +565,4 @@ void OpenthermData::s16(int16_t value) { this->valueHB = (value >> 8) & 0xFF; } -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/opentherm.h b/esphome/components/opentherm/opentherm.h index eb8c5b3ad6c..3078e92c9da 100644 --- a/esphome/components/opentherm/opentherm.h +++ b/esphome/components/opentherm/opentherm.h @@ -16,8 +16,7 @@ #include "driver/gptimer.h" #endif -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { template constexpr T read_bit(T value, uint8_t bit) { return (value >> bit) & 0x01; } @@ -403,5 +402,4 @@ class OpenTherm { #endif }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/opentherm_macros.h b/esphome/components/opentherm/opentherm_macros.h index 398c64aa8f2..c5ed02a50bc 100644 --- a/esphome/components/opentherm/opentherm_macros.h +++ b/esphome/components/opentherm/opentherm_macros.h @@ -1,6 +1,6 @@ #pragma once -namespace esphome { -namespace opentherm { + +namespace esphome::opentherm { // ===== hub.h macros ===== @@ -158,5 +158,4 @@ namespace opentherm { #define SHOW_INNER(x) #x #define SHOW(x) SHOW_INNER(x) -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/output/opentherm_output.cpp b/esphome/components/opentherm/output/opentherm_output.cpp index ff82ddd72c2..2735c85d069 100644 --- a/esphome/components/opentherm/output/opentherm_output.cpp +++ b/esphome/components/opentherm/output/opentherm_output.cpp @@ -1,8 +1,7 @@ #include "esphome/core/helpers.h" // for clamp() and lerp() #include "opentherm_output.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { static const char *const TAG = "opentherm.output"; @@ -14,5 +13,4 @@ void opentherm::OpenthermOutput::write_state(float state) { this->has_state_ = true; ESP_LOGD(TAG, "Output %s set to %.2f", this->id_, this->state); } -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/output/opentherm_output.h b/esphome/components/opentherm/output/opentherm_output.h index 8d6a0ee4bae..e789d727022 100644 --- a/esphome/components/opentherm/output/opentherm_output.h +++ b/esphome/components/opentherm/output/opentherm_output.h @@ -4,8 +4,7 @@ #include "esphome/components/opentherm/input.h" #include "esphome/core/log.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { class OpenthermOutput : public output::FloatOutput, public Component, public OpenthermInput { protected: @@ -29,5 +28,4 @@ class OpenthermOutput : public output::FloatOutput, public Component, public Ope float get_max_value() { return this->max_value_; } }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/switch/opentherm_switch.cpp b/esphome/components/opentherm/switch/opentherm_switch.cpp index 5c5d62e68e5..2fc99e793e8 100644 --- a/esphome/components/opentherm/switch/opentherm_switch.cpp +++ b/esphome/components/opentherm/switch/opentherm_switch.cpp @@ -1,7 +1,6 @@ #include "opentherm_switch.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { static const char *const TAG = "opentherm.switch"; @@ -24,5 +23,4 @@ void OpenthermSwitch::dump_config() { ESP_LOGCONFIG(TAG, " Current state: %d", this->state); } -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opentherm/switch/opentherm_switch.h b/esphome/components/opentherm/switch/opentherm_switch.h index 0c20a0d9edd..ca930d4f7c1 100644 --- a/esphome/components/opentherm/switch/opentherm_switch.h +++ b/esphome/components/opentherm/switch/opentherm_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/core/log.h" -namespace esphome { -namespace opentherm { +namespace esphome::opentherm { class OpenthermSwitch : public switch_::Switch, public Component { protected: @@ -16,5 +15,4 @@ class OpenthermSwitch : public switch_::Switch, public Component { void dump_config() override; }; -} // namespace opentherm -} // namespace esphome +} // namespace esphome::opentherm diff --git a/esphome/components/opt3001/opt3001.cpp b/esphome/components/opt3001/opt3001.cpp index a942e450355..ce5fbdfd826 100644 --- a/esphome/components/opt3001/opt3001.cpp +++ b/esphome/components/opt3001/opt3001.cpp @@ -1,8 +1,7 @@ #include "opt3001.h" #include "esphome/core/log.h" -namespace esphome { -namespace opt3001 { +namespace esphome::opt3001 { static const char *const TAG = "opt3001.sensor"; @@ -116,5 +115,4 @@ void OPT3001Sensor::update() { }); } -} // namespace opt3001 -} // namespace esphome +} // namespace esphome::opt3001 diff --git a/esphome/components/opt3001/opt3001.h b/esphome/components/opt3001/opt3001.h index 3bce9f0aeb0..e5de5363537 100644 --- a/esphome/components/opt3001/opt3001.h +++ b/esphome/components/opt3001/opt3001.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace opt3001 { +namespace esphome::opt3001 { /// This class implements support for the i2c-based OPT3001 ambient light sensor. class OPT3001Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { @@ -22,5 +21,4 @@ class OPT3001Sensor : public sensor::Sensor, public PollingComponent, public i2c bool updating_{false}; }; -} // namespace opt3001 -} // namespace esphome +} // namespace esphome::opt3001 diff --git a/esphome/components/output/automation.cpp b/esphome/components/output/automation.cpp index 5533a6bee4c..610da897d93 100644 --- a/esphome/components/output/automation.cpp +++ b/esphome/components/output/automation.cpp @@ -1,10 +1,8 @@ #include "automation.h" #include "esphome/core/log.h" -namespace esphome { -namespace output { +namespace esphome::output { static const char *const TAG = "output.automation"; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/automation.h b/esphome/components/output/automation.h index 537226a143d..301f568388a 100644 --- a/esphome/components/output/automation.h +++ b/esphome/components/output/automation.h @@ -6,8 +6,7 @@ #include "esphome/components/output/binary_output.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace output { +namespace esphome::output { template class TurnOffAction : public Action { public: @@ -67,5 +66,4 @@ template class SetMaxPowerAction : public Action { }; #endif // USE_OUTPUT_FLOAT_POWER_SCALING -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/binary_output.h b/esphome/components/output/binary_output.h index 7a15bc7b51c..74ca3ad594d 100644 --- a/esphome/components/output/binary_output.h +++ b/esphome/components/output/binary_output.h @@ -7,8 +7,7 @@ #include "esphome/components/power_supply/power_supply.h" #endif -namespace esphome { -namespace output { +namespace esphome::output { #define LOG_BINARY_OUTPUT(this) \ if (this->inverted_) { \ @@ -69,5 +68,4 @@ class BinaryOutput { #endif }; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/button/output_button.cpp b/esphome/components/output/button/output_button.cpp index 4dd7ec249b1..5833743586f 100644 --- a/esphome/components/output/button/output_button.cpp +++ b/esphome/components/output/button/output_button.cpp @@ -1,8 +1,7 @@ #include "output_button.h" #include "esphome/core/log.h" -namespace esphome { -namespace output { +namespace esphome::output { static const char *const TAG = "output.button"; @@ -17,5 +16,4 @@ void OutputButton::press_action() { this->set_timeout("reset", this->duration_, [this]() { this->output_->turn_off(); }); } -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/button/output_button.h b/esphome/components/output/button/output_button.h index 8802c9754dc..1a2997bdcf9 100644 --- a/esphome/components/output/button/output_button.h +++ b/esphome/components/output/button/output_button.h @@ -4,8 +4,7 @@ #include "esphome/components/button/button.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace output { +namespace esphome::output { class OutputButton : public button::Button, public Component { public: @@ -21,5 +20,4 @@ class OutputButton : public button::Button, public Component { uint32_t duration_; }; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/float_output.cpp b/esphome/components/output/float_output.cpp index 35629c828af..e2b029f3687 100644 --- a/esphome/components/output/float_output.cpp +++ b/esphome/components/output/float_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace output { +namespace esphome::output { static const char *const TAG = "output.float"; @@ -40,5 +39,4 @@ void FloatOutput::set_level(float state) { void FloatOutput::write_state(bool state) { this->set_level(state != this->inverted_ ? 1.0f : 0.0f); } -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/float_output.h b/esphome/components/output/float_output.h index 3e1bd839686..673f4235728 100644 --- a/esphome/components/output/float_output.h +++ b/esphome/components/output/float_output.h @@ -4,8 +4,7 @@ #include "esphome/core/defines.h" #include "binary_output.h" -namespace esphome { -namespace output { +namespace esphome::output { #ifdef USE_OUTPUT_FLOAT_POWER_SCALING #define LOG_FLOAT_OUTPUT(this) \ @@ -130,5 +129,4 @@ class FloatOutput : public BinaryOutput { #endif }; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/lock/output_lock.cpp b/esphome/components/output/lock/output_lock.cpp index c373cd7b7c9..ee9d9185425 100644 --- a/esphome/components/output/lock/output_lock.cpp +++ b/esphome/components/output/lock/output_lock.cpp @@ -1,8 +1,7 @@ #include "output_lock.h" #include "esphome/core/log.h" -namespace esphome { -namespace output { +namespace esphome::output { static const char *const TAG = "output.lock"; @@ -21,5 +20,4 @@ void OutputLock::control(const lock::LockCall &call) { this->publish_state(state); } -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/lock/output_lock.h b/esphome/components/output/lock/output_lock.h index c183c3a3ea9..7be96e1e824 100644 --- a/esphome/components/output/lock/output_lock.h +++ b/esphome/components/output/lock/output_lock.h @@ -4,8 +4,7 @@ #include "esphome/components/lock/lock.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace output { +namespace esphome::output { class OutputLock : public lock::Lock, public Component { public: @@ -20,5 +19,4 @@ class OutputLock : public lock::Lock, public Component { output::BinaryOutput *output_; }; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/switch/output_switch.cpp b/esphome/components/output/switch/output_switch.cpp index 54260ba37af..7cee2a86398 100644 --- a/esphome/components/output/switch/output_switch.cpp +++ b/esphome/components/output/switch/output_switch.cpp @@ -1,8 +1,7 @@ #include "output_switch.h" #include "esphome/core/log.h" -namespace esphome { -namespace output { +namespace esphome::output { static const char *const TAG = "output.switch"; @@ -25,5 +24,4 @@ void OutputSwitch::write_state(bool state) { this->publish_state(state); } -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/output/switch/output_switch.h b/esphome/components/output/switch/output_switch.h index a184a342fe6..b0d85678be0 100644 --- a/esphome/components/output/switch/output_switch.h +++ b/esphome/components/output/switch/output_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace output { +namespace esphome::output { class OutputSwitch : public switch_::Switch, public Component { public: @@ -21,5 +20,4 @@ class OutputSwitch : public switch_::Switch, public Component { output::BinaryOutput *output_; }; -} // namespace output -} // namespace esphome +} // namespace esphome::output diff --git a/esphome/components/packet_transport/packet_transport.cpp b/esphome/components/packet_transport/packet_transport.cpp index a2199977aa0..a21f0e2f63c 100644 --- a/esphome/components/packet_transport/packet_transport.cpp +++ b/esphome/components/packet_transport/packet_transport.cpp @@ -7,8 +7,7 @@ #include "esphome/components/xxtea/xxtea.h" -namespace esphome { -namespace packet_transport { +namespace esphome::packet_transport { // Maximum bytes to log in hex output (168 * 3 = 504, under TX buffer size of 512) static constexpr size_t PACKET_MAX_LOG_BYTES = 168; @@ -609,5 +608,4 @@ void PacketTransport::send_ping_pong_request_() { this->resend_ping_key_ = false; ESP_LOGV(TAG, "Sent new ping request %08X", (unsigned) this->ping_key_); } -} // namespace packet_transport -} // namespace esphome +} // namespace esphome::packet_transport diff --git a/esphome/components/packet_transport/packet_transport.h b/esphome/components/packet_transport/packet_transport.h index 836775bc855..3938054c159 100644 --- a/esphome/components/packet_transport/packet_transport.h +++ b/esphome/components/packet_transport/packet_transport.h @@ -22,8 +22,7 @@ * On receipt of a data packet, it should call `this->process_()` with the data. */ -namespace esphome { -namespace packet_transport { +namespace esphome::packet_transport { // std::less provides allocation-free comparison with const char * template using string_map_t = std::map>; @@ -168,5 +167,4 @@ class PacketTransport : public PollingComponent { bool is_encrypted_() const { return !this->encryption_key_.empty(); } }; -} // namespace packet_transport -} // namespace esphome +} // namespace esphome::packet_transport diff --git a/esphome/components/partition/light_partition.cpp b/esphome/components/partition/light_partition.cpp index 63c0d0186e7..2755f82294a 100644 --- a/esphome/components/partition/light_partition.cpp +++ b/esphome/components/partition/light_partition.cpp @@ -1,10 +1,8 @@ #include "light_partition.h" #include "esphome/core/log.h" -namespace esphome { -namespace partition { +namespace esphome::partition { static const char *const TAG = "partition.light"; -} // namespace partition -} // namespace esphome +} // namespace esphome::partition diff --git a/esphome/components/partition/light_partition.h b/esphome/components/partition/light_partition.h index bd90b4c4f1b..7a2f3678c18 100644 --- a/esphome/components/partition/light_partition.h +++ b/esphome/components/partition/light_partition.h @@ -6,8 +6,7 @@ #include "esphome/core/component.h" #include "esphome/components/light/addressable_light.h" -namespace esphome { -namespace partition { +namespace esphome::partition { class AddressableSegment { public: @@ -93,5 +92,4 @@ class PartitionLightOutput : public light::AddressableLight { std::vector segments_; }; -} // namespace partition -} // namespace esphome +} // namespace esphome::partition diff --git a/esphome/components/pca6416a/pca6416a.cpp b/esphome/components/pca6416a/pca6416a.cpp index d617336e7e2..4c19feab6eb 100644 --- a/esphome/components/pca6416a/pca6416a.cpp +++ b/esphome/components/pca6416a/pca6416a.cpp @@ -1,8 +1,7 @@ #include "pca6416a.h" #include "esphome/core/log.h" -namespace esphome { -namespace pca6416a { +namespace esphome::pca6416a { enum PCA6416AGPIORegisters { // 0 side @@ -205,5 +204,4 @@ size_t PCA6416AGPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via PCA6416A", this->pin_); } -} // namespace pca6416a -} // namespace esphome +} // namespace esphome::pca6416a diff --git a/esphome/components/pca6416a/pca6416a.h b/esphome/components/pca6416a/pca6416a.h index 4d2e6b219e4..3170033b286 100644 --- a/esphome/components/pca6416a/pca6416a.h +++ b/esphome/components/pca6416a/pca6416a.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/gpio_expander/cached_gpio.h" -namespace esphome { -namespace pca6416a { +namespace esphome::pca6416a { class PCA6416AComponent : public Component, public i2c::I2CDevice, @@ -72,5 +71,4 @@ class PCA6416AGPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace pca6416a -} // namespace esphome +} // namespace esphome::pca6416a diff --git a/esphome/components/pca9554/pca9554.cpp b/esphome/components/pca9554/pca9554.cpp index 393bbfd61ef..c3ea6a3c0ce 100644 --- a/esphome/components/pca9554/pca9554.cpp +++ b/esphome/components/pca9554/pca9554.cpp @@ -1,8 +1,7 @@ #include "pca9554.h" #include "esphome/core/log.h" -namespace esphome { -namespace pca9554 { +namespace esphome::pca9554 { // for 16 bit expanders, these addresses will be doubled. const uint8_t INPUT_REG = 0; @@ -152,5 +151,4 @@ size_t PCA9554GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via PCA9554", this->pin_); } -} // namespace pca9554 -} // namespace esphome +} // namespace esphome::pca9554 diff --git a/esphome/components/pca9554/pca9554.h b/esphome/components/pca9554/pca9554.h index f33f9d4592c..9fa398cf293 100644 --- a/esphome/components/pca9554/pca9554.h +++ b/esphome/components/pca9554/pca9554.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/gpio_expander/cached_gpio.h" -namespace esphome { -namespace pca9554 { +namespace esphome::pca9554 { class PCA9554Component : public Component, public i2c::I2CDevice, @@ -76,5 +75,4 @@ class PCA9554GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace pca9554 -} // namespace esphome +} // namespace esphome::pca9554 diff --git a/esphome/components/pca9685/pca9685_output.cpp b/esphome/components/pca9685/pca9685_output.cpp index 89a6bcdcc0b..533b3391b14 100644 --- a/esphome/components/pca9685/pca9685_output.cpp +++ b/esphome/components/pca9685/pca9685_output.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pca9685 { +namespace esphome::pca9685 { static const char *const TAG = "pca9685"; @@ -160,5 +159,4 @@ void PCA9685Channel::write_state(float state) { this->parent_->set_channel_value_(this->channel_, duty); } -} // namespace pca9685 -} // namespace esphome +} // namespace esphome::pca9685 diff --git a/esphome/components/pca9685/pca9685_output.h b/esphome/components/pca9685/pca9685_output.h index 785cc974dae..33819f23ee0 100644 --- a/esphome/components/pca9685/pca9685_output.h +++ b/esphome/components/pca9685/pca9685_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace pca9685 { +namespace esphome::pca9685 { enum class PhaseBalancer { NONE = 0x00, @@ -76,5 +75,4 @@ class PCA9685Output : public Component, public i2c::I2CDevice { bool update_{true}; }; -} // namespace pca9685 -} // namespace esphome +} // namespace esphome::pca9685 diff --git a/esphome/components/pcd8544/pcd_8544.cpp b/esphome/components/pcd8544/pcd_8544.cpp index 95d91ff18a8..c80283ffc98 100644 --- a/esphome/components/pcd8544/pcd_8544.cpp +++ b/esphome/components/pcd8544/pcd_8544.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pcd8544 { +namespace esphome::pcd8544 { static const char *const TAG = "pcd_8544"; @@ -128,5 +127,4 @@ void PCD8544::fill(Color color) { this->buffer_[i] = fill; } -} // namespace pcd8544 -} // namespace esphome +} // namespace esphome::pcd8544 diff --git a/esphome/components/pcd8544/pcd_8544.h b/esphome/components/pcd8544/pcd_8544.h index cfdb96de619..9e4ee930356 100644 --- a/esphome/components/pcd8544/pcd_8544.h +++ b/esphome/components/pcd8544/pcd_8544.h @@ -4,8 +4,7 @@ #include "esphome/components/spi/spi.h" #include "esphome/components/display/display_buffer.h" -namespace esphome { -namespace pcd8544 { +namespace esphome::pcd8544 { class PCD8544 : public display::DisplayBuffer, public spi::SPIDevice class ReadAction : public Action, public Parente public: void play(const Ts &...x) override { this->parent_->read_time(); } }; -} // namespace pcf85063 -} // namespace esphome +} // namespace esphome::pcf85063 diff --git a/esphome/components/pcf8563/pcf8563.cpp b/esphome/components/pcf8563/pcf8563.cpp index 50003ca378b..93c0f2bdf27 100644 --- a/esphome/components/pcf8563/pcf8563.cpp +++ b/esphome/components/pcf8563/pcf8563.cpp @@ -4,8 +4,7 @@ // Datasheet: // - https://nl.mouser.com/datasheet/2/302/PCF8563-1127619.pdf -namespace esphome { -namespace pcf8563 { +namespace esphome::pcf8563 { static const char *const TAG = "PCF8563"; @@ -99,5 +98,4 @@ bool PCF8563Component::write_rtc_() { pcf8563_.reg.day, ONOFF(!pcf8563_.reg.stop), pcf8563_.reg.clkout_enabled); return true; } -} // namespace pcf8563 -} // namespace esphome +} // namespace esphome::pcf8563 diff --git a/esphome/components/pcf8563/pcf8563.h b/esphome/components/pcf8563/pcf8563.h index cd37d05816d..72b600d9ba7 100644 --- a/esphome/components/pcf8563/pcf8563.h +++ b/esphome/components/pcf8563/pcf8563.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/time/real_time_clock.h" -namespace esphome { -namespace pcf8563 { +namespace esphome::pcf8563 { class PCF8563Component : public time::RealTimeClock, public i2c::I2CDevice { public: @@ -119,5 +118,4 @@ template class ReadAction : public Action, public Parente public: void play(const Ts &...x) override { this->parent_->read_time(); } }; -} // namespace pcf8563 -} // namespace esphome +} // namespace esphome::pcf8563 diff --git a/esphome/components/pcf8574/pcf8574.cpp b/esphome/components/pcf8574/pcf8574.cpp index 8fe8526797b..2e054b0683a 100644 --- a/esphome/components/pcf8574/pcf8574.cpp +++ b/esphome/components/pcf8574/pcf8574.cpp @@ -1,8 +1,7 @@ #include "pcf8574.h" #include "esphome/core/log.h" -namespace esphome { -namespace pcf8574 { +namespace esphome::pcf8574 { static const char *const TAG = "pcf8574"; @@ -131,5 +130,4 @@ size_t PCF8574GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via PCF8574", this->pin_); } -} // namespace pcf8574 -} // namespace esphome +} // namespace esphome::pcf8574 diff --git a/esphome/components/pcf8574/pcf8574.h b/esphome/components/pcf8574/pcf8574.h index cae2e930b74..ece472c4bbb 100644 --- a/esphome/components/pcf8574/pcf8574.h +++ b/esphome/components/pcf8574/pcf8574.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/gpio_expander/cached_gpio.h" -namespace esphome { -namespace pcf8574 { +namespace esphome::pcf8574 { // PCF8574(8 pins)/PCF8575(16 pins) always read/write all pins in a single I2C transaction // so we use uint16_t as bank type to ensure all pins are in one bank and cached together @@ -72,5 +71,4 @@ class PCF8574GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace pcf8574 -} // namespace esphome +} // namespace esphome::pcf8574 diff --git a/esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp b/esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp index 00f29983be8..e8e9530dba7 100644 --- a/esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp +++ b/esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp @@ -1,8 +1,7 @@ #include "pi4ioe5v6408.h" #include "esphome/core/log.h" -namespace esphome { -namespace pi4ioe5v6408 { +namespace esphome::pi4ioe5v6408 { static const uint8_t PI4IOE5V6408_REGISTER_DEVICE_ID = 0x01; static const uint8_t PI4IOE5V6408_REGISTER_IO_DIR = 0x03; @@ -204,5 +203,4 @@ size_t PI4IOE5V6408GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via PI4IOE5V6408", this->pin_); } -} // namespace pi4ioe5v6408 -} // namespace esphome +} // namespace esphome::pi4ioe5v6408 diff --git a/esphome/components/pi4ioe5v6408/pi4ioe5v6408.h b/esphome/components/pi4ioe5v6408/pi4ioe5v6408.h index ff2474fe994..6225956430a 100644 --- a/esphome/components/pi4ioe5v6408/pi4ioe5v6408.h +++ b/esphome/components/pi4ioe5v6408/pi4ioe5v6408.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace pi4ioe5v6408 { +namespace esphome::pi4ioe5v6408 { class PI4IOE5V6408Component : public Component, public i2c::I2CDevice, public gpio_expander::CachedGpioExpander { @@ -70,5 +69,4 @@ class PI4IOE5V6408GPIOPin : public GPIOPin, public Parented -namespace esphome { -namespace pid { +namespace esphome::pid { class PIDAutotuner { public: @@ -110,5 +109,4 @@ class PIDAutotuner { std::string id_; }; -} // namespace pid -} // namespace esphome +} // namespace esphome::pid diff --git a/esphome/components/pid/pid_climate.cpp b/esphome/components/pid/pid_climate.cpp index 54b7a688b41..8c9231fda61 100644 --- a/esphome/components/pid/pid_climate.cpp +++ b/esphome/components/pid/pid_climate.cpp @@ -1,8 +1,7 @@ #include "pid_climate.h" #include "esphome/core/log.h" -namespace esphome { -namespace pid { +namespace esphome::pid { static const char *const TAG = "pid.climate"; @@ -186,5 +185,4 @@ void PIDClimate::start_autotune(std::unique_ptr &&autotune) { void PIDClimate::reset_integral_term() { this->controller_.reset_accumulated_integral(); } -} // namespace pid -} // namespace esphome +} // namespace esphome::pid diff --git a/esphome/components/pid/pid_climate.h b/esphome/components/pid/pid_climate.h index 479a0e48ee4..9e3c89ca4d9 100644 --- a/esphome/components/pid/pid_climate.h +++ b/esphome/components/pid/pid_climate.h @@ -9,8 +9,7 @@ #include "pid_controller.h" #include "pid_autotuner.h" -namespace esphome { -namespace pid { +namespace esphome::pid { class PIDClimate : public climate::Climate, public Component { public: @@ -164,5 +163,4 @@ template class PIDSetControlParametersAction : public Action -namespace esphome { -namespace pid { +namespace esphome::pid { struct PIDController { float update(float setpoint, float process_value); @@ -71,5 +70,4 @@ struct PIDController { FixedRingBuffer output_window_; }; // Struct PIDController -} // namespace pid -} // namespace esphome +} // namespace esphome::pid diff --git a/esphome/components/pid/sensor/pid_climate_sensor.cpp b/esphome/components/pid/sensor/pid_climate_sensor.cpp index 41ca027d8d7..4e963168e68 100644 --- a/esphome/components/pid/sensor/pid_climate_sensor.cpp +++ b/esphome/components/pid/sensor/pid_climate_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pid { +namespace esphome::pid { static const char *const TAG = "pid.sensor"; @@ -55,5 +54,4 @@ void PIDClimateSensor::update_from_parent_() { } void PIDClimateSensor::dump_config() { LOG_SENSOR("", "PID Climate Sensor", this); } -} // namespace pid -} // namespace esphome +} // namespace esphome::pid diff --git a/esphome/components/pid/sensor/pid_climate_sensor.h b/esphome/components/pid/sensor/pid_climate_sensor.h index f3774610f80..d6bdc66a465 100644 --- a/esphome/components/pid/sensor/pid_climate_sensor.h +++ b/esphome/components/pid/sensor/pid_climate_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/pid/pid_climate.h" -namespace esphome { -namespace pid { +namespace esphome::pid { enum PIDClimateSensorType { PID_SENSOR_TYPE_RESULT, @@ -33,5 +32,4 @@ class PIDClimateSensor : public sensor::Sensor, public Component { PIDClimateSensorType type_; }; -} // namespace pid -} // namespace esphome +} // namespace esphome::pid diff --git a/esphome/components/pipsolar/output/pipsolar_output.cpp b/esphome/components/pipsolar/output/pipsolar_output.cpp index 60f63427591..1af753fce33 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.cpp +++ b/esphome/components/pipsolar/output/pipsolar_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { static const char *const TAG = "pipsolar.output"; @@ -18,5 +17,4 @@ void PipsolarOutput::write_state(float state) { ESP_LOGD(TAG, "Will not write: %s as it is not in list of allowed values", tmp); } } -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pipsolar/output/pipsolar_output.h b/esphome/components/pipsolar/output/pipsolar_output.h index 66eda8e3916..4a6e4c29d77 100644 --- a/esphome/components/pipsolar/output/pipsolar_output.h +++ b/esphome/components/pipsolar/output/pipsolar_output.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { class Pipsolar; @@ -40,5 +39,4 @@ template class SetOutputAction : public Action { PipsolarOutput *output_; }; -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pipsolar/pipsolar.cpp b/esphome/components/pipsolar/pipsolar.cpp index 5123d8d9d33..bd5733fe747 100644 --- a/esphome/components/pipsolar/pipsolar.cpp +++ b/esphome/components/pipsolar/pipsolar.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { static const char *const TAG = "pipsolar"; @@ -811,5 +810,4 @@ uint16_t Pipsolar::pipsolar_crc_(uint8_t *msg, uint8_t len) { return crc; } -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pipsolar/pipsolar.h b/esphome/components/pipsolar/pipsolar.h index beae67a4e06..59332080cf4 100644 --- a/esphome/components/pipsolar/pipsolar.h +++ b/esphome/components/pipsolar/pipsolar.h @@ -9,8 +9,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { enum ENUMPollingCommand { POLLING_QPIRI = 0, @@ -246,5 +245,4 @@ class Pipsolar : public uart::UARTDevice, public PollingComponent { PollingCommand enabled_polling_commands_[POLLING_COMMANDS_MAX]; }; -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.cpp b/esphome/components/pipsolar/switch/pipsolar_switch.cpp index 512587511b1..1eedfed0fd3 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.cpp +++ b/esphome/components/pipsolar/switch/pipsolar_switch.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { static const char *const TAG = "pipsolar.switch"; @@ -15,5 +14,4 @@ void PipsolarSwitch::write_state(bool state) { } } -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pipsolar/switch/pipsolar_switch.h b/esphome/components/pipsolar/switch/pipsolar_switch.h index bb62d4794a5..20d2640d90e 100644 --- a/esphome/components/pipsolar/switch/pipsolar_switch.h +++ b/esphome/components/pipsolar/switch/pipsolar_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/core/component.h" -namespace esphome { -namespace pipsolar { +namespace esphome::pipsolar { class Pipsolar; class PipsolarSwitch : public switch_::Switch, public Component { public: @@ -24,5 +23,4 @@ class PipsolarSwitch : public switch_::Switch, public Component { Pipsolar *parent_; }; -} // namespace pipsolar -} // namespace esphome +} // namespace esphome::pipsolar diff --git a/esphome/components/pm1006/pm1006.cpp b/esphome/components/pm1006/pm1006.cpp index fe8890e7774..6a325c57dc8 100644 --- a/esphome/components/pm1006/pm1006.cpp +++ b/esphome/components/pm1006/pm1006.cpp @@ -1,8 +1,7 @@ #include "pm1006.h" #include "esphome/core/log.h" -namespace esphome { -namespace pm1006 { +namespace esphome::pm1006 { static const char *const TAG = "pm1006"; @@ -93,5 +92,4 @@ void PM1006Component::parse_data_() { } } -} // namespace pm1006 -} // namespace esphome +} // namespace esphome::pm1006 diff --git a/esphome/components/pm1006/pm1006.h b/esphome/components/pm1006/pm1006.h index 6b6332e1e33..38ab284f476 100644 --- a/esphome/components/pm1006/pm1006.h +++ b/esphome/components/pm1006/pm1006.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace pm1006 { +namespace esphome::pm1006 { class PM1006Component : public PollingComponent, public uart::UARTDevice { public: @@ -33,5 +32,4 @@ class PM1006Component : public PollingComponent, public uart::UARTDevice { uint32_t last_transmission_{0}; }; -} // namespace pm1006 -} // namespace esphome +} // namespace esphome::pm1006 diff --git a/esphome/components/pm2005/pm2005.cpp b/esphome/components/pm2005/pm2005.cpp index d8e253a7717..54a98bf3adb 100644 --- a/esphome/components/pm2005/pm2005.cpp +++ b/esphome/components/pm2005/pm2005.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "pm2005.h" -namespace esphome { -namespace pm2005 { +namespace esphome::pm2005 { static const char *const TAG = "pm2005"; @@ -117,5 +116,4 @@ void PM2005Component::dump_config() { LOG_SENSOR(" ", "PM10 ", this->pm_10_0_sensor_); } -} // namespace pm2005 -} // namespace esphome +} // namespace esphome::pm2005 diff --git a/esphome/components/pm2005/pm2005.h b/esphome/components/pm2005/pm2005.h index e788569b7e0..9661d082d1b 100644 --- a/esphome/components/pm2005/pm2005.h +++ b/esphome/components/pm2005/pm2005.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace pm2005 { +namespace esphome::pm2005 { enum SensorType { PM2005, @@ -40,5 +39,4 @@ class PM2005Component : public PollingComponent, public i2c::I2CDevice { uint8_t measuring_value_index_{10}; }; -} // namespace pm2005 -} // namespace esphome +} // namespace esphome::pm2005 diff --git a/esphome/components/pmsa003i/pmsa003i.cpp b/esphome/components/pmsa003i/pmsa003i.cpp index 4a618586f8d..15f5d3e8793 100644 --- a/esphome/components/pmsa003i/pmsa003i.cpp +++ b/esphome/components/pmsa003i/pmsa003i.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace pmsa003i { +namespace esphome::pmsa003i { static const char *const TAG = "pmsa003i"; @@ -131,5 +130,4 @@ bool PMSA003IComponent::read_data_(PM25AQIData *data) { return true; } -} // namespace pmsa003i -} // namespace esphome +} // namespace esphome::pmsa003i diff --git a/esphome/components/pmsa003i/pmsa003i.h b/esphome/components/pmsa003i/pmsa003i.h index cd106704a66..aebe80b711d 100644 --- a/esphome/components/pmsa003i/pmsa003i.h +++ b/esphome/components/pmsa003i/pmsa003i.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace pmsa003i { +namespace esphome::pmsa003i { /**! Structure holding Plantower's standard packet **/ // From https://github.com/adafruit/Adafruit_PM25AQI @@ -63,5 +62,4 @@ class PMSA003IComponent : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *pmc_10_0_sensor_{nullptr}; }; -} // namespace pmsa003i -} // namespace esphome +} // namespace esphome::pmsa003i diff --git a/esphome/components/pmwcs3/pmwcs3.cpp b/esphome/components/pmwcs3/pmwcs3.cpp index 2ed7789c53d..94c0c307665 100644 --- a/esphome/components/pmwcs3/pmwcs3.cpp +++ b/esphome/components/pmwcs3/pmwcs3.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace pmwcs3 { +namespace esphome::pmwcs3 { static const uint8_t PMWCS3_I2C_ADDRESS = 0x63; static const uint8_t PMWCS3_REG_READ_START = 0x01; @@ -106,5 +105,4 @@ void PMWCS3Component::read_data_() { }); } -} // namespace pmwcs3 -} // namespace esphome +} // namespace esphome::pmwcs3 diff --git a/esphome/components/pmwcs3/pmwcs3.h b/esphome/components/pmwcs3/pmwcs3.h index b1e26eec4fd..d6691478197 100644 --- a/esphome/components/pmwcs3/pmwcs3.h +++ b/esphome/components/pmwcs3/pmwcs3.h @@ -7,8 +7,7 @@ // ref: // https://github.com/tinovi/i2cArduino/blob/master/i2cArduino.h -namespace esphome { -namespace pmwcs3 { +namespace esphome::pmwcs3 { class PMWCS3Component : public PollingComponent, public i2c::I2CDevice { public: @@ -64,5 +63,4 @@ template class PMWCS3NewI2cAddressAction : public Action PMWCS3Component *parent_; }; -} // namespace pmwcs3 -} // namespace esphome +} // namespace esphome::pmwcs3 diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 3017b78414d..8ef77217262 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -9,8 +9,7 @@ // - https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf // - https://www.nxp.com/docs/en/nxp/application-notes/153710.pdf -namespace esphome { -namespace pn532 { +namespace esphome::pn532 { static const char *const TAG = "pn532"; @@ -458,5 +457,4 @@ bool PN532BinarySensor::process(const nfc::NfcTagUid &data) { return true; } -} // namespace pn532 -} // namespace esphome +} // namespace esphome::pn532 diff --git a/esphome/components/pn532/pn532.h b/esphome/components/pn532/pn532.h index b76cbb19462..a26f27ed54c 100644 --- a/esphome/components/pn532/pn532.h +++ b/esphome/components/pn532/pn532.h @@ -10,8 +10,7 @@ #include #include -namespace esphome { -namespace pn532 { +namespace esphome::pn532 { static const uint8_t PN532_COMMAND_VERSION_DATA = 0x02; static const uint8_t PN532_COMMAND_SAMCONFIGURATION = 0x14; @@ -138,5 +137,4 @@ template class PN532IsWritingCondition : public Condition bool check(const Ts &...x) override { return this->parent_->is_writing(); } }; -} // namespace pn532 -} // namespace esphome +} // namespace esphome::pn532 diff --git a/esphome/components/pn532/pn532_mifare_classic.cpp b/esphome/components/pn532/pn532_mifare_classic.cpp index cca6acd96d1..37674080d83 100644 --- a/esphome/components/pn532/pn532_mifare_classic.cpp +++ b/esphome/components/pn532/pn532_mifare_classic.cpp @@ -4,8 +4,7 @@ #include "pn532.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn532 { +namespace esphome::pn532 { static const char *const TAG = "pn532.mifare_classic"; @@ -258,5 +257,4 @@ bool PN532::write_mifare_classic_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *mes return true; } -} // namespace pn532 -} // namespace esphome +} // namespace esphome::pn532 diff --git a/esphome/components/pn532/pn532_mifare_ultralight.cpp b/esphome/components/pn532/pn532_mifare_ultralight.cpp index 0e0dc1542f4..eb3d13a7e06 100644 --- a/esphome/components/pn532/pn532_mifare_ultralight.cpp +++ b/esphome/components/pn532/pn532_mifare_ultralight.cpp @@ -4,8 +4,7 @@ #include "pn532.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn532 { +namespace esphome::pn532 { static const char *const TAG = "pn532.mifare_ultralight"; @@ -189,5 +188,4 @@ bool PN532::write_mifare_ultralight_page_(uint8_t page_num, const uint8_t *write return true; } -} // namespace pn532 -} // namespace esphome +} // namespace esphome::pn532 diff --git a/esphome/components/pn532_i2c/pn532_i2c.cpp b/esphome/components/pn532_i2c/pn532_i2c.cpp index 41f0f079aae..7f4d78461be 100644 --- a/esphome/components/pn532_i2c/pn532_i2c.cpp +++ b/esphome/components/pn532_i2c/pn532_i2c.cpp @@ -7,8 +7,7 @@ // - https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf // - https://www.nxp.com/docs/en/nxp/application-notes/153710.pdf -namespace esphome { -namespace pn532_i2c { +namespace esphome::pn532_i2c { static const char *const TAG = "pn532_i2c"; @@ -125,5 +124,4 @@ void PN532I2C::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace pn532_i2c -} // namespace esphome +} // namespace esphome::pn532_i2c diff --git a/esphome/components/pn532_i2c/pn532_i2c.h b/esphome/components/pn532_i2c/pn532_i2c.h index 00c0df206d6..b2a2ac2e189 100644 --- a/esphome/components/pn532_i2c/pn532_i2c.h +++ b/esphome/components/pn532_i2c/pn532_i2c.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace pn532_i2c { +namespace esphome::pn532_i2c { class PN532I2C : public pn532::PN532, public i2c::I2CDevice { public: @@ -21,5 +20,4 @@ class PN532I2C : public pn532::PN532, public i2c::I2CDevice { uint8_t read_response_length_(); }; -} // namespace pn532_i2c -} // namespace esphome +} // namespace esphome::pn532_i2c diff --git a/esphome/components/pn532_spi/pn532_spi.cpp b/esphome/components/pn532_spi/pn532_spi.cpp index 553c6d26a6a..13d9aebc20c 100644 --- a/esphome/components/pn532_spi/pn532_spi.cpp +++ b/esphome/components/pn532_spi/pn532_spi.cpp @@ -7,8 +7,7 @@ // - https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf // - https://www.nxp.com/docs/en/nxp/application-notes/153710.pdf -namespace esphome { -namespace pn532_spi { +namespace esphome::pn532_spi { static const char *const TAG = "pn532_spi"; @@ -151,5 +150,4 @@ void PN532Spi::dump_config() { LOG_PIN(" CS Pin: ", this->cs_); } -} // namespace pn532_spi -} // namespace esphome +} // namespace esphome::pn532_spi diff --git a/esphome/components/pn532_spi/pn532_spi.h b/esphome/components/pn532_spi/pn532_spi.h index b7adca22e97..2bfd4accf7d 100644 --- a/esphome/components/pn532_spi/pn532_spi.h +++ b/esphome/components/pn532_spi/pn532_spi.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace pn532_spi { +namespace esphome::pn532_spi { class PN532Spi : public pn532::PN532, public spi::SPIDevice &data) override; }; -} // namespace pn532_spi -} // namespace esphome +} // namespace esphome::pn532_spi diff --git a/esphome/components/pn7150/automation.h b/esphome/components/pn7150/automation.h index a8c65ae633a..0b2e5f5d247 100644 --- a/esphome/components/pn7150/automation.h +++ b/esphome/components/pn7150/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/components/pn7150/pn7150.h" -namespace esphome { -namespace pn7150 { +namespace esphome::pn7150 { template class PN7150IsWritingCondition : public Condition, public Parented { public: @@ -64,5 +63,4 @@ template class SetWriteModeAction : public Action, public void play(const Ts &...x) override { this->parent_->write_mode(); } }; -} // namespace pn7150 -} // namespace esphome +} // namespace esphome::pn7150 diff --git a/esphome/components/pn7150/pn7150.cpp b/esphome/components/pn7150/pn7150.cpp index d68bea41b3d..2a2724f56b5 100644 --- a/esphome/components/pn7150/pn7150.cpp +++ b/esphome/components/pn7150/pn7150.cpp @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7150 { +namespace esphome::pn7150 { static const char *const TAG = "pn7150"; @@ -1160,5 +1159,4 @@ uint8_t PN7150::wait_for_irq_(uint16_t timeout, bool pin_state) { return nfc::STATUS_FAILED; } -} // namespace pn7150 -} // namespace esphome +} // namespace esphome::pn7150 diff --git a/esphome/components/pn7150/pn7150.h b/esphome/components/pn7150/pn7150.h index a468d80943e..fa38c5c3134 100644 --- a/esphome/components/pn7150/pn7150.h +++ b/esphome/components/pn7150/pn7150.h @@ -11,8 +11,7 @@ #include -namespace esphome { -namespace pn7150 { +namespace esphome::pn7150 { static constexpr uint16_t NFCC_DEFAULT_TIMEOUT = 10; static constexpr uint16_t NFCC_INIT_TIMEOUT = 50; @@ -292,5 +291,4 @@ class PN7150 : public nfc::Nfcc, public Component { std::vector triggers_ontagremoved_; }; -} // namespace pn7150 -} // namespace esphome +} // namespace esphome::pn7150 diff --git a/esphome/components/pn7150/pn7150_mifare_classic.cpp b/esphome/components/pn7150/pn7150_mifare_classic.cpp index 61434cdb285..f1832d95f18 100644 --- a/esphome/components/pn7150/pn7150_mifare_classic.cpp +++ b/esphome/components/pn7150/pn7150_mifare_classic.cpp @@ -4,8 +4,7 @@ #include "pn7150.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7150 { +namespace esphome::pn7150 { static const char *const TAG = "pn7150.mifare_classic"; @@ -324,5 +323,4 @@ uint8_t PN7150::halt_mifare_classic_tag_() { return nfc::STATUS_OK; } -} // namespace pn7150 -} // namespace esphome +} // namespace esphome::pn7150 diff --git a/esphome/components/pn7150/pn7150_mifare_ultralight.cpp b/esphome/components/pn7150/pn7150_mifare_ultralight.cpp index 854ddd1be18..ef594144d92 100644 --- a/esphome/components/pn7150/pn7150_mifare_ultralight.cpp +++ b/esphome/components/pn7150/pn7150_mifare_ultralight.cpp @@ -5,8 +5,7 @@ #include "pn7150.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7150 { +namespace esphome::pn7150 { static const char *const TAG = "pn7150.mifare_ultralight"; @@ -183,5 +182,4 @@ uint8_t PN7150::write_mifare_ultralight_page_(uint8_t page_num, const uint8_t *w return nfc::STATUS_OK; } -} // namespace pn7150 -} // namespace esphome +} // namespace esphome::pn7150 diff --git a/esphome/components/pn7150_i2c/pn7150_i2c.cpp b/esphome/components/pn7150_i2c/pn7150_i2c.cpp index 4ae884595bb..a61bd27c64e 100644 --- a/esphome/components/pn7150_i2c/pn7150_i2c.cpp +++ b/esphome/components/pn7150_i2c/pn7150_i2c.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace pn7150_i2c { +namespace esphome::pn7150_i2c { static const char *const TAG = "pn7150_i2c"; @@ -46,5 +45,4 @@ void PN7150I2C::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace pn7150_i2c -} // namespace esphome +} // namespace esphome::pn7150_i2c diff --git a/esphome/components/pn7150_i2c/pn7150_i2c.h b/esphome/components/pn7150_i2c/pn7150_i2c.h index 9308dddd26b..2ea8c8f75ce 100644 --- a/esphome/components/pn7150_i2c/pn7150_i2c.h +++ b/esphome/components/pn7150_i2c/pn7150_i2c.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace pn7150_i2c { +namespace esphome::pn7150_i2c { class PN7150I2C : public pn7150::PN7150, public i2c::I2CDevice { public: @@ -18,5 +17,4 @@ class PN7150I2C : public pn7150::PN7150, public i2c::I2CDevice { uint8_t write_nfcc(nfc::NciMessage &tx) override; }; -} // namespace pn7150_i2c -} // namespace esphome +} // namespace esphome::pn7150_i2c diff --git a/esphome/components/pn7160/automation.h b/esphome/components/pn7160/automation.h index 7759da8f532..7300c4a8d6e 100644 --- a/esphome/components/pn7160/automation.h +++ b/esphome/components/pn7160/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/components/pn7160/pn7160.h" -namespace esphome { -namespace pn7160 { +namespace esphome::pn7160 { template class PN7160IsWritingCondition : public Condition, public Parented { public: @@ -64,5 +63,4 @@ template class SetWriteModeAction : public Action, public void play(const Ts &...x) override { this->parent_->write_mode(); } }; -} // namespace pn7160 -} // namespace esphome +} // namespace esphome::pn7160 diff --git a/esphome/components/pn7160/pn7160.cpp b/esphome/components/pn7160/pn7160.cpp index 5f0f8d0629c..7abd89b3714 100644 --- a/esphome/components/pn7160/pn7160.cpp +++ b/esphome/components/pn7160/pn7160.cpp @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7160 { +namespace esphome::pn7160 { static const char *const TAG = "pn7160"; @@ -1186,5 +1185,4 @@ uint8_t PN7160::wait_for_irq_(uint16_t timeout, bool pin_state) { return nfc::STATUS_FAILED; } -} // namespace pn7160 -} // namespace esphome +} // namespace esphome::pn7160 diff --git a/esphome/components/pn7160/pn7160.h b/esphome/components/pn7160/pn7160.h index 44f7eb07965..da4577874ca 100644 --- a/esphome/components/pn7160/pn7160.h +++ b/esphome/components/pn7160/pn7160.h @@ -11,8 +11,7 @@ #include -namespace esphome { -namespace pn7160 { +namespace esphome::pn7160 { static constexpr uint16_t NFCC_DEFAULT_TIMEOUT = 10; static constexpr uint16_t NFCC_INIT_TIMEOUT = 50; @@ -311,5 +310,4 @@ class PN7160 : public nfc::Nfcc, public Component { std::vector triggers_ontagremoved_; }; -} // namespace pn7160 -} // namespace esphome +} // namespace esphome::pn7160 diff --git a/esphome/components/pn7160/pn7160_mifare_classic.cpp b/esphome/components/pn7160/pn7160_mifare_classic.cpp index 710a7198c6b..0dc8bbdfe46 100644 --- a/esphome/components/pn7160/pn7160_mifare_classic.cpp +++ b/esphome/components/pn7160/pn7160_mifare_classic.cpp @@ -4,8 +4,7 @@ #include "pn7160.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7160 { +namespace esphome::pn7160 { static const char *const TAG = "pn7160.mifare_classic"; @@ -324,5 +323,4 @@ uint8_t PN7160::halt_mifare_classic_tag_() { return nfc::STATUS_OK; } -} // namespace pn7160 -} // namespace esphome +} // namespace esphome::pn7160 diff --git a/esphome/components/pn7160/pn7160_mifare_ultralight.cpp b/esphome/components/pn7160/pn7160_mifare_ultralight.cpp index 8ca0fa2c11b..e319a4cb2eb 100644 --- a/esphome/components/pn7160/pn7160_mifare_ultralight.cpp +++ b/esphome/components/pn7160/pn7160_mifare_ultralight.cpp @@ -5,8 +5,7 @@ #include "pn7160.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7160 { +namespace esphome::pn7160 { static const char *const TAG = "pn7160.mifare_ultralight"; @@ -183,5 +182,4 @@ uint8_t PN7160::write_mifare_ultralight_page_(uint8_t page_num, const uint8_t *w return nfc::STATUS_OK; } -} // namespace pn7160 -} // namespace esphome +} // namespace esphome::pn7160 diff --git a/esphome/components/pn7160_i2c/pn7160_i2c.cpp b/esphome/components/pn7160_i2c/pn7160_i2c.cpp index e33c6c793d0..c34cf90e68c 100644 --- a/esphome/components/pn7160_i2c/pn7160_i2c.cpp +++ b/esphome/components/pn7160_i2c/pn7160_i2c.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace pn7160_i2c { +namespace esphome::pn7160_i2c { static const char *const TAG = "pn7160_i2c"; @@ -46,5 +45,4 @@ void PN7160I2C::dump_config() { LOG_I2C_DEVICE(this); } -} // namespace pn7160_i2c -} // namespace esphome +} // namespace esphome::pn7160_i2c diff --git a/esphome/components/pn7160_i2c/pn7160_i2c.h b/esphome/components/pn7160_i2c/pn7160_i2c.h index eb253085eb7..d29fd04fac4 100644 --- a/esphome/components/pn7160_i2c/pn7160_i2c.h +++ b/esphome/components/pn7160_i2c/pn7160_i2c.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace pn7160_i2c { +namespace esphome::pn7160_i2c { class PN7160I2C : public pn7160::PN7160, public i2c::I2CDevice { public: @@ -18,5 +17,4 @@ class PN7160I2C : public pn7160::PN7160, public i2c::I2CDevice { uint8_t write_nfcc(nfc::NciMessage &tx) override; }; -} // namespace pn7160_i2c -} // namespace esphome +} // namespace esphome::pn7160_i2c diff --git a/esphome/components/pn7160_spi/pn7160_spi.cpp b/esphome/components/pn7160_spi/pn7160_spi.cpp index 09f673f700c..f3c413e9520 100644 --- a/esphome/components/pn7160_spi/pn7160_spi.cpp +++ b/esphome/components/pn7160_spi/pn7160_spi.cpp @@ -1,8 +1,7 @@ #include "pn7160_spi.h" #include "esphome/core/log.h" -namespace esphome { -namespace pn7160_spi { +namespace esphome::pn7160_spi { static const char *const TAG = "pn7160_spi"; @@ -50,5 +49,4 @@ void PN7160Spi::dump_config() { LOG_PIN(" CS Pin: ", this->cs_); } -} // namespace pn7160_spi -} // namespace esphome +} // namespace esphome::pn7160_spi diff --git a/esphome/components/pn7160_spi/pn7160_spi.h b/esphome/components/pn7160_spi/pn7160_spi.h index 9b6e21fa2a8..2d9c1fda117 100644 --- a/esphome/components/pn7160_spi/pn7160_spi.h +++ b/esphome/components/pn7160_spi/pn7160_spi.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace pn7160_spi { +namespace esphome::pn7160_spi { static constexpr uint8_t TDD_SPI_READ = 0xFF; static constexpr uint8_t TDD_SPI_WRITE = 0x0A; @@ -26,5 +25,4 @@ class PN7160Spi : public pn7160::PN7160, uint8_t write_nfcc(nfc::NciMessage &tx) override; }; -} // namespace pn7160_spi -} // namespace esphome +} // namespace esphome::pn7160_spi diff --git a/esphome/components/power_supply/power_supply.cpp b/esphome/components/power_supply/power_supply.cpp index 5db2122412d..4da73e76ae0 100644 --- a/esphome/components/power_supply/power_supply.cpp +++ b/esphome/components/power_supply/power_supply.cpp @@ -1,8 +1,7 @@ #include "power_supply.h" #include "esphome/core/log.h" -namespace esphome { -namespace power_supply { +namespace esphome::power_supply { static const char *const TAG = "power_supply"; @@ -54,5 +53,4 @@ void PowerSupply::on_powerdown() { this->pin_->digital_write(false); } -} // namespace power_supply -} // namespace esphome +} // namespace esphome::power_supply diff --git a/esphome/components/power_supply/power_supply.h b/esphome/components/power_supply/power_supply.h index 0387074eb87..e096f69e3bc 100644 --- a/esphome/components/power_supply/power_supply.h +++ b/esphome/components/power_supply/power_supply.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace power_supply { +namespace esphome::power_supply { class PowerSupply : public Component { public: @@ -63,5 +62,4 @@ class PowerSupplyRequester { bool requested_{false}; }; -} // namespace power_supply -} // namespace esphome +} // namespace esphome::power_supply diff --git a/esphome/components/preferences/syncer.h b/esphome/components/preferences/syncer.h index e28cc8c8d54..cee02394b48 100644 --- a/esphome/components/preferences/syncer.h +++ b/esphome/components/preferences/syncer.h @@ -3,8 +3,7 @@ #include "esphome/core/preferences.h" #include "esphome/core/component.h" -namespace esphome { -namespace preferences { +namespace esphome::preferences { class IntervalSyncer final : public Component { public: @@ -25,5 +24,4 @@ class IntervalSyncer final : public Component { #endif }; -} // namespace preferences -} // namespace esphome +} // namespace esphome::preferences diff --git a/esphome/components/prometheus/prometheus_handler.cpp b/esphome/components/prometheus/prometheus_handler.cpp index e2639a22983..0412d8a8422 100644 --- a/esphome/components/prometheus/prometheus_handler.cpp +++ b/esphome/components/prometheus/prometheus_handler.cpp @@ -2,8 +2,7 @@ #ifdef USE_NETWORK #include "esphome/core/application.h" -namespace esphome { -namespace prometheus { +namespace esphome::prometheus { void PrometheusHandler::handleRequest(AsyncWebServerRequest *req) { AsyncResponseStream *stream = req->beginResponseStream("text/plain; version=0.0.4; charset=utf-8"); @@ -1098,6 +1097,6 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima } #endif -} // namespace prometheus -} // namespace esphome +} // namespace esphome::prometheus + #endif diff --git a/esphome/components/prometheus/prometheus_handler.h b/esphome/components/prometheus/prometheus_handler.h index 7aecab99d1b..53326e94722 100644 --- a/esphome/components/prometheus/prometheus_handler.h +++ b/esphome/components/prometheus/prometheus_handler.h @@ -12,8 +12,7 @@ #include "esphome/core/log.h" #endif -namespace esphome { -namespace prometheus { +namespace esphome::prometheus { class PrometheusHandler : public AsyncWebHandler, public Component { public: @@ -218,6 +217,6 @@ class PrometheusHandler : public AsyncWebHandler, public Component { std::map relabel_map_name_; }; -} // namespace prometheus -} // namespace esphome +} // namespace esphome::prometheus + #endif diff --git a/esphome/components/psram/psram.cpp b/esphome/components/psram/psram.cpp index 6c110a577d4..ab680c96955 100644 --- a/esphome/components/psram/psram.cpp +++ b/esphome/components/psram/psram.cpp @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace psram { +namespace esphome::psram { static const char *const TAG = "psram"; void PsramComponent::dump_config() { @@ -25,7 +24,6 @@ void PsramComponent::dump_config() { } } -} // namespace psram -} // namespace esphome +} // namespace esphome::psram #endif diff --git a/esphome/components/psram/psram.h b/esphome/components/psram/psram.h index 8c891feee95..22a49588b42 100644 --- a/esphome/components/psram/psram.h +++ b/esphome/components/psram/psram.h @@ -4,14 +4,12 @@ #include "esphome/core/component.h" -namespace esphome { -namespace psram { +namespace esphome::psram { class PsramComponent : public Component { void dump_config() override; }; -} // namespace psram -} // namespace esphome +} // namespace esphome::psram #endif diff --git a/esphome/components/pulse_counter/automation.h b/esphome/components/pulse_counter/automation.h index 0c0dc2552d1..14264e87b36 100644 --- a/esphome/components/pulse_counter/automation.h +++ b/esphome/components/pulse_counter/automation.h @@ -4,9 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/pulse_counter/pulse_counter_sensor.h" -namespace esphome { - -namespace pulse_counter { +namespace esphome::pulse_counter { template class SetTotalPulsesAction : public Action { public: @@ -20,5 +18,4 @@ template class SetTotalPulsesAction : public Action { PulseCounterSensor *pulse_counter_; }; -} // namespace pulse_counter -} // namespace esphome +} // namespace esphome::pulse_counter diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.cpp b/esphome/components/pulse_counter/pulse_counter_sensor.cpp index 5d73bef7da0..13bf3baf832 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.cpp +++ b/esphome/components/pulse_counter/pulse_counter_sensor.cpp @@ -7,8 +7,7 @@ #include #endif -namespace esphome { -namespace pulse_counter { +namespace esphome::pulse_counter { static const char *const TAG = "pulse_counter"; @@ -210,5 +209,4 @@ void PulseCounterSensor::update() { this->last_time_ = now; } -} // namespace pulse_counter -} // namespace esphome +} // namespace esphome::pulse_counter diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.h b/esphome/components/pulse_counter/pulse_counter_sensor.h index 7a68858099c..4f23ef15483 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.h +++ b/esphome/components/pulse_counter/pulse_counter_sensor.h @@ -14,8 +14,7 @@ #endif // defined(SOC_PCNT_SUPPORTED) && __has_include() #endif // USE_ESP32 -namespace esphome { -namespace pulse_counter { +namespace esphome::pulse_counter { enum PulseCounterCountMode { PULSE_COUNTER_DISABLE = 0, @@ -85,5 +84,4 @@ class PulseCounterSensor : public sensor::Sensor, public PollingComponent { sensor::Sensor *total_sensor_{nullptr}; }; -} // namespace pulse_counter -} // namespace esphome +} // namespace esphome::pulse_counter diff --git a/esphome/components/pulse_meter/automation.h b/esphome/components/pulse_meter/automation.h index bf0768b7af5..1def89c3d30 100644 --- a/esphome/components/pulse_meter/automation.h +++ b/esphome/components/pulse_meter/automation.h @@ -4,9 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/pulse_meter/pulse_meter_sensor.h" -namespace esphome { - -namespace pulse_meter { +namespace esphome::pulse_meter { template class SetTotalPulsesAction : public Action { public: @@ -20,5 +18,4 @@ template class SetTotalPulsesAction : public Action { PulseMeterSensor *pulse_meter_; }; -} // namespace pulse_meter -} // namespace esphome +} // namespace esphome::pulse_meter diff --git a/esphome/components/pulse_meter/pulse_meter_sensor.cpp b/esphome/components/pulse_meter/pulse_meter_sensor.cpp index 433e1f0b7e3..3fe1c722ebb 100644 --- a/esphome/components/pulse_meter/pulse_meter_sensor.cpp +++ b/esphome/components/pulse_meter/pulse_meter_sensor.cpp @@ -2,8 +2,7 @@ #include #include "esphome/core/log.h" -namespace esphome { -namespace pulse_meter { +namespace esphome::pulse_meter { static const char *const TAG = "pulse_meter"; @@ -186,5 +185,4 @@ void IRAM_ATTR PulseMeterSensor::pulse_intr(PulseMeterSensor *sensor) { sensor->last_pin_val_ = pin_val; } -} // namespace pulse_meter -} // namespace esphome +} // namespace esphome::pulse_meter diff --git a/esphome/components/pulse_meter/pulse_meter_sensor.h b/esphome/components/pulse_meter/pulse_meter_sensor.h index e46f1e615ff..243a64bf053 100644 --- a/esphome/components/pulse_meter/pulse_meter_sensor.h +++ b/esphome/components/pulse_meter/pulse_meter_sensor.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace pulse_meter { +namespace esphome::pulse_meter { class PulseMeterSensor : public sensor::Sensor, public Component { public: @@ -77,5 +76,4 @@ class PulseMeterSensor : public sensor::Sensor, public Component { PulseState pulse_state_{}; }; -} // namespace pulse_meter -} // namespace esphome +} // namespace esphome::pulse_meter diff --git a/esphome/components/pulse_width/pulse_width.cpp b/esphome/components/pulse_width/pulse_width.cpp index d083d48b328..5209ed5352a 100644 --- a/esphome/components/pulse_width/pulse_width.cpp +++ b/esphome/components/pulse_width/pulse_width.cpp @@ -1,8 +1,7 @@ #include "pulse_width.h" #include "esphome/core/log.h" -namespace esphome { -namespace pulse_width { +namespace esphome::pulse_width { static const char *const TAG = "pulse_width"; @@ -27,5 +26,4 @@ void PulseWidthSensor::update() { this->publish_state(width); } -} // namespace pulse_width -} // namespace esphome +} // namespace esphome::pulse_width diff --git a/esphome/components/pulse_width/pulse_width.h b/esphome/components/pulse_width/pulse_width.h index c6b896988db..f77766a9615 100644 --- a/esphome/components/pulse_width/pulse_width.h +++ b/esphome/components/pulse_width/pulse_width.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace pulse_width { +namespace esphome::pulse_width { /// Store data in a class that doesn't use multiple-inheritance (vtables in flash) class PulseWidthSensorStore { @@ -39,5 +38,4 @@ class PulseWidthSensor : public sensor::Sensor, public PollingComponent { InternalGPIOPin *pin_; }; -} // namespace pulse_width -} // namespace esphome +} // namespace esphome::pulse_width diff --git a/esphome/components/pvvx_mithermometer/display/pvvx_display.cpp b/esphome/components/pvvx_mithermometer/display/pvvx_display.cpp index 4d4a5466bb2..7a6be40d6c3 100644 --- a/esphome/components/pvvx_mithermometer/display/pvvx_display.cpp +++ b/esphome/components/pvvx_mithermometer/display/pvvx_display.cpp @@ -3,8 +3,8 @@ #include "esphome/core/log.h" #ifdef USE_ESP32 -namespace esphome { -namespace pvvx_mithermometer { + +namespace esphome::pvvx_mithermometer { static const char *const TAG = "display.pvvx_mithermometer"; @@ -186,7 +186,6 @@ void PVVXDisplay::sync_time_() { } #endif -} // namespace pvvx_mithermometer -} // namespace esphome +} // namespace esphome::pvvx_mithermometer #endif diff --git a/esphome/components/pvvx_mithermometer/display/pvvx_display.h b/esphome/components/pvvx_mithermometer/display/pvvx_display.h index 06837b94abf..e1aebae7a5d 100644 --- a/esphome/components/pvvx_mithermometer/display/pvvx_display.h +++ b/esphome/components/pvvx_mithermometer/display/pvvx_display.h @@ -13,8 +13,7 @@ #include "esphome/components/time/real_time_clock.h" #endif -namespace esphome { -namespace pvvx_mithermometer { +namespace esphome::pvvx_mithermometer { class PVVXDisplay; @@ -130,7 +129,6 @@ class PVVXDisplay : public ble_client::BLEClientNode, public PollingComponent { pvvx_writer_t writer_{}; }; -} // namespace pvvx_mithermometer -} // namespace esphome +} // namespace esphome::pvvx_mithermometer #endif diff --git a/esphome/components/pvvx_mithermometer/pvvx_mithermometer.cpp b/esphome/components/pvvx_mithermometer/pvvx_mithermometer.cpp index 35badf48bb6..f674fc36949 100644 --- a/esphome/components/pvvx_mithermometer/pvvx_mithermometer.cpp +++ b/esphome/components/pvvx_mithermometer/pvvx_mithermometer.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace pvvx_mithermometer { +namespace esphome::pvvx_mithermometer { static const char *const TAG = "pvvx_mithermometer"; @@ -140,7 +139,6 @@ bool PVVXMiThermometer::report_results_(const optional &result, con return true; } -} // namespace pvvx_mithermometer -} // namespace esphome +} // namespace esphome::pvvx_mithermometer #endif diff --git a/esphome/components/pvvx_mithermometer/pvvx_mithermometer.h b/esphome/components/pvvx_mithermometer/pvvx_mithermometer.h index 09b5e91a16b..b5d6da21eff 100644 --- a/esphome/components/pvvx_mithermometer/pvvx_mithermometer.h +++ b/esphome/components/pvvx_mithermometer/pvvx_mithermometer.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace pvvx_mithermometer { +namespace esphome::pvvx_mithermometer { struct ParseResult { optional temperature; @@ -46,7 +45,6 @@ class PVVXMiThermometer : public Component, public esp32_ble_tracker::ESPBTDevic bool report_results_(const optional &result, const char *address); }; -} // namespace pvvx_mithermometer -} // namespace esphome +} // namespace esphome::pvvx_mithermometer #endif diff --git a/esphome/components/pylontech/pylontech.cpp b/esphome/components/pylontech/pylontech.cpp index 7eb89d5b321..0973699da8c 100644 --- a/esphome/components/pylontech/pylontech.cpp +++ b/esphome/components/pylontech/pylontech.cpp @@ -24,8 +24,7 @@ } \ } -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { static const char *const TAG = "pylontech"; static const int MAX_DATA_LENGTH_BYTES = 256; @@ -198,8 +197,7 @@ void PylontechComponent::process_line_(std::string &buffer) { } } -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech #undef PARSE_INT #undef PARSE_STR diff --git a/esphome/components/pylontech/pylontech.h b/esphome/components/pylontech/pylontech.h index 5727928a60e..1d86803cc23 100644 --- a/esphome/components/pylontech/pylontech.h +++ b/esphome/components/pylontech/pylontech.h @@ -4,8 +4,7 @@ #include "esphome/core/defines.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { static const uint8_t NUM_BUFFERS = 20; static const uint8_t TEXT_SENSOR_MAX_LEN = 14; @@ -48,5 +47,4 @@ class PylontechComponent : public PollingComponent, public uart::UARTDevice { std::vector listeners_{}; }; -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech diff --git a/esphome/components/pylontech/sensor/pylontech_sensor.cpp b/esphome/components/pylontech/sensor/pylontech_sensor.cpp index 11437369edf..e2def28be54 100644 --- a/esphome/components/pylontech/sensor/pylontech_sensor.cpp +++ b/esphome/components/pylontech/sensor/pylontech_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { static const char *const TAG = "pylontech.sensor"; @@ -58,5 +57,4 @@ void PylontechSensor::on_line_read(PylontechListener::LineContents *line) { } } -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech diff --git a/esphome/components/pylontech/sensor/pylontech_sensor.h b/esphome/components/pylontech/sensor/pylontech_sensor.h index 25e71606a4d..36576e83327 100644 --- a/esphome/components/pylontech/sensor/pylontech_sensor.h +++ b/esphome/components/pylontech/sensor/pylontech_sensor.h @@ -3,8 +3,7 @@ #include "../pylontech.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { class PylontechSensor : public PylontechListener { public: @@ -28,5 +27,4 @@ class PylontechSensor : public PylontechListener { int8_t bat_num_; }; -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech diff --git a/esphome/components/pylontech/text_sensor/pylontech_text_sensor.cpp b/esphome/components/pylontech/text_sensor/pylontech_text_sensor.cpp index 8175477cb2d..a7c9db15996 100644 --- a/esphome/components/pylontech/text_sensor/pylontech_text_sensor.cpp +++ b/esphome/components/pylontech/text_sensor/pylontech_text_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { static const char *const TAG = "pylontech.textsensor"; @@ -38,5 +37,4 @@ void PylontechTextSensor::on_line_read(PylontechListener::LineContents *line) { } } -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech diff --git a/esphome/components/pylontech/text_sensor/pylontech_text_sensor.h b/esphome/components/pylontech/text_sensor/pylontech_text_sensor.h index 27a3993b3e9..30921b13f4f 100644 --- a/esphome/components/pylontech/text_sensor/pylontech_text_sensor.h +++ b/esphome/components/pylontech/text_sensor/pylontech_text_sensor.h @@ -3,8 +3,7 @@ #include "../pylontech.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace pylontech { +namespace esphome::pylontech { class PylontechTextSensor : public PylontechListener { public: @@ -22,5 +21,4 @@ class PylontechTextSensor : public PylontechListener { int8_t bat_num_; }; -} // namespace pylontech -} // namespace esphome +} // namespace esphome::pylontech diff --git a/esphome/components/pzem004t/pzem004t.cpp b/esphome/components/pzem004t/pzem004t.cpp index d0f96d6d1e5..a28b448340a 100644 --- a/esphome/components/pzem004t/pzem004t.cpp +++ b/esphome/components/pzem004t/pzem004t.cpp @@ -3,8 +3,7 @@ #include "esphome/core/application.h" #include -namespace esphome { -namespace pzem004t { +namespace esphome::pzem004t { static const char *const TAG = "pzem004t"; @@ -126,5 +125,4 @@ void PZEM004T::dump_config() { LOG_SENSOR("", "Power", this->power_sensor_); } -} // namespace pzem004t -} // namespace esphome +} // namespace esphome::pzem004t diff --git a/esphome/components/pzem004t/pzem004t.h b/esphome/components/pzem004t/pzem004t.h index e18413f35c1..71fc1e70ad1 100644 --- a/esphome/components/pzem004t/pzem004t.h +++ b/esphome/components/pzem004t/pzem004t.h @@ -4,8 +4,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace pzem004t { +namespace esphome::pzem004t { class PZEM004T : public PollingComponent, public uart::UARTDevice { public: @@ -42,5 +41,4 @@ class PZEM004T : public PollingComponent, public uart::UARTDevice { uint32_t last_read_{0}; }; -} // namespace pzem004t -} // namespace esphome +} // namespace esphome::pzem004t diff --git a/esphome/components/pzemac/pzemac.cpp b/esphome/components/pzemac/pzemac.cpp index 0dbe0e761d6..d36e5d02504 100644 --- a/esphome/components/pzemac/pzemac.cpp +++ b/esphome/components/pzemac/pzemac.cpp @@ -1,8 +1,7 @@ #include "pzemac.h" #include "esphome/core/log.h" -namespace esphome { -namespace pzemac { +namespace esphome::pzemac { static const char *const TAG = "pzemac"; @@ -83,5 +82,4 @@ void PZEMAC::reset_energy_() { this->send_raw(cmd); } -} // namespace pzemac -} // namespace esphome +} // namespace esphome::pzemac diff --git a/esphome/components/pzemac/pzemac.h b/esphome/components/pzemac/pzemac.h index e5b96115f93..264604fedce 100644 --- a/esphome/components/pzemac/pzemac.h +++ b/esphome/components/pzemac/pzemac.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace pzemac { +namespace esphome::pzemac { template class ResetEnergyAction; @@ -49,5 +48,4 @@ template class ResetEnergyAction : public Action { PZEMAC *pzemac_; }; -} // namespace pzemac -} // namespace esphome +} // namespace esphome::pzemac diff --git a/esphome/components/pzemdc/pzemdc.cpp b/esphome/components/pzemdc/pzemdc.cpp index 428bcc1fcf9..6ded9b3a34c 100644 --- a/esphome/components/pzemdc/pzemdc.cpp +++ b/esphome/components/pzemdc/pzemdc.cpp @@ -1,8 +1,7 @@ #include "pzemdc.h" #include "esphome/core/log.h" -namespace esphome { -namespace pzemdc { +namespace esphome::pzemdc { static const char *const TAG = "pzemdc"; @@ -71,5 +70,4 @@ void PZEMDC::reset_energy() { this->send_raw(cmd); } -} // namespace pzemdc -} // namespace esphome +} // namespace esphome::pzemdc diff --git a/esphome/components/pzemdc/pzemdc.h b/esphome/components/pzemdc/pzemdc.h index 2e6c26a10cf..6a7e8404480 100644 --- a/esphome/components/pzemdc/pzemdc.h +++ b/esphome/components/pzemdc/pzemdc.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace pzemdc { +namespace esphome::pzemdc { class PZEMDC : public PollingComponent, public modbus::ModbusDevice { public: @@ -42,5 +41,4 @@ template class ResetEnergyAction : public Action { PZEMDC *pzemdc_; }; -} // namespace pzemdc -} // namespace esphome +} // namespace esphome::pzemdc diff --git a/esphome/components/qmc5883l/qmc5883l.cpp b/esphome/components/qmc5883l/qmc5883l.cpp index 44bd006c1ae..5b04a904b54 100644 --- a/esphome/components/qmc5883l/qmc5883l.cpp +++ b/esphome/components/qmc5883l/qmc5883l.cpp @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace qmc5883l { +namespace esphome::qmc5883l { static const char *const TAG = "qmc5883l"; @@ -213,5 +212,4 @@ i2c::ErrorCode QMC5883LComponent::read_bytes_16_le_(uint8_t a_register, uint16_t return err; } -} // namespace qmc5883l -} // namespace esphome +} // namespace esphome::qmc5883l diff --git a/esphome/components/qmc5883l/qmc5883l.h b/esphome/components/qmc5883l/qmc5883l.h index 2ab6aa3e9f0..6b8ffa0f40c 100644 --- a/esphome/components/qmc5883l/qmc5883l.h +++ b/esphome/components/qmc5883l/qmc5883l.h @@ -5,8 +5,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/hal.h" -namespace esphome { -namespace qmc5883l { +namespace esphome::qmc5883l { enum QMC5883LDatarate { QMC5883L_DATARATE_10_HZ = 0b00, @@ -66,5 +65,4 @@ class QMC5883LComponent : public PollingComponent, public i2c::I2CDevice { HighFrequencyLoopRequester high_freq_; }; -} // namespace qmc5883l -} // namespace esphome +} // namespace esphome::qmc5883l diff --git a/esphome/components/qmp6988/qmp6988.cpp b/esphome/components/qmp6988/qmp6988.cpp index 976efe79103..8c8a04c5b71 100644 --- a/esphome/components/qmp6988/qmp6988.cpp +++ b/esphome/components/qmp6988/qmp6988.cpp @@ -3,8 +3,7 @@ #include #include -namespace esphome { -namespace qmp6988 { +namespace esphome::qmp6988 { static const uint8_t QMP6988_CHIP_ID = 0x5C; @@ -351,5 +350,4 @@ void QMP6988Component::update() { this->pressure_sensor_->publish_state(pressurehectopascals); } -} // namespace qmp6988 -} // namespace esphome +} // namespace esphome::qmp6988 diff --git a/esphome/components/qmp6988/qmp6988.h b/esphome/components/qmp6988/qmp6988.h index 5b0f80c77e1..26f858b5d21 100644 --- a/esphome/components/qmp6988/qmp6988.h +++ b/esphome/components/qmp6988/qmp6988.h @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace qmp6988 { +namespace esphome::qmp6988 { /* oversampling */ enum QMP6988Oversampling : uint8_t { @@ -106,5 +105,4 @@ class QMP6988Component : public PollingComponent, public i2c::I2CDevice { int16_t get_compensated_temperature_(qmp6988_ik_data_t *ik, int32_t dt); }; -} // namespace qmp6988 -} // namespace esphome +} // namespace esphome::qmp6988 diff --git a/esphome/components/qr_code/qr_code.cpp b/esphome/components/qr_code/qr_code.cpp index 0322c8a1412..edb78b98e1e 100644 --- a/esphome/components/qr_code/qr_code.cpp +++ b/esphome/components/qr_code/qr_code.cpp @@ -3,8 +3,7 @@ #include "esphome/core/color.h" #include "esphome/core/log.h" -namespace esphome { -namespace qr_code { +namespace esphome::qr_code { static const char *const TAG = "qr_code"; @@ -74,5 +73,4 @@ uint8_t QrCode::get_size() { return size; } -} // namespace qr_code -} // namespace esphome +} // namespace esphome::qr_code diff --git a/esphome/components/qwiic_pir/qwiic_pir.cpp b/esphome/components/qwiic_pir/qwiic_pir.cpp index c04c0fcc183..baf8dc122df 100644 --- a/esphome/components/qwiic_pir/qwiic_pir.cpp +++ b/esphome/components/qwiic_pir/qwiic_pir.cpp @@ -1,8 +1,7 @@ #include "qwiic_pir.h" #include "esphome/core/log.h" -namespace esphome { -namespace qwiic_pir { +namespace esphome::qwiic_pir { static const char *const TAG = "qwiic_pir"; @@ -129,5 +128,4 @@ void QwiicPIRComponent::clear_events_() { ESP_LOGW(TAG, "Failed to clear events"); } -} // namespace qwiic_pir -} // namespace esphome +} // namespace esphome::qwiic_pir diff --git a/esphome/components/qwiic_pir/qwiic_pir.h b/esphome/components/qwiic_pir/qwiic_pir.h index 797ded2cc62..339632a508a 100644 --- a/esphome/components/qwiic_pir/qwiic_pir.h +++ b/esphome/components/qwiic_pir/qwiic_pir.h @@ -12,8 +12,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace qwiic_pir { +namespace esphome::qwiic_pir { // Qwiic PIR I2C Register Addresses enum { @@ -65,5 +64,4 @@ class QwiicPIRComponent : public Component, public i2c::I2CDevice, public binary void clear_events_(); }; -} // namespace qwiic_pir -} // namespace esphome +} // namespace esphome::qwiic_pir diff --git a/esphome/components/radon_eye_ble/radon_eye_listener.cpp b/esphome/components/radon_eye_ble/radon_eye_listener.cpp index 2c3ef77adda..7e7263d73fc 100644 --- a/esphome/components/radon_eye_ble/radon_eye_listener.cpp +++ b/esphome/components/radon_eye_ble/radon_eye_listener.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace radon_eye_ble { +namespace esphome::radon_eye_ble { static const char *const TAG = "radon_eye_ble"; @@ -19,7 +18,6 @@ bool RadonEyeListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device return false; } -} // namespace radon_eye_ble -} // namespace esphome +} // namespace esphome::radon_eye_ble #endif diff --git a/esphome/components/radon_eye_ble/radon_eye_listener.h b/esphome/components/radon_eye_ble/radon_eye_listener.h index 26d0233c56e..ceca736e78c 100644 --- a/esphome/components/radon_eye_ble/radon_eye_listener.h +++ b/esphome/components/radon_eye_ble/radon_eye_listener.h @@ -5,15 +5,13 @@ #include "esphome/core/component.h" #include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h" -namespace esphome { -namespace radon_eye_ble { +namespace esphome::radon_eye_ble { class RadonEyeListener : public esp32_ble_tracker::ESPBTDeviceListener { public: bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; }; -} // namespace radon_eye_ble -} // namespace esphome +} // namespace esphome::radon_eye_ble #endif diff --git a/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp b/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp index f2d32d51dea..de5bd3d8d58 100644 --- a/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp +++ b/esphome/components/radon_eye_rd200/radon_eye_rd200.cpp @@ -5,8 +5,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace radon_eye_rd200 { +namespace esphome::radon_eye_rd200 { static const char *const TAG = "radon_eye_rd200"; @@ -211,7 +210,6 @@ void RadonEyeRD200::dump_config() { RadonEyeRD200::RadonEyeRD200() : PollingComponent(10000) {} -} // namespace radon_eye_rd200 -} // namespace esphome +} // namespace esphome::radon_eye_rd200 #endif // USE_ESP32 diff --git a/esphome/components/radon_eye_rd200/radon_eye_rd200.h b/esphome/components/radon_eye_rd200/radon_eye_rd200.h index f874c815f85..48e075c2d66 100644 --- a/esphome/components/radon_eye_rd200/radon_eye_rd200.h +++ b/esphome/components/radon_eye_rd200/radon_eye_rd200.h @@ -11,8 +11,7 @@ #include "esphome/core/component.h" #include "esphome/core/log.h" -namespace esphome { -namespace radon_eye_rd200 { +namespace esphome::radon_eye_rd200 { class RadonEyeRD200 : public PollingComponent, public ble_client::BLEClientNode { public: @@ -41,7 +40,6 @@ class RadonEyeRD200 : public PollingComponent, public ble_client::BLEClientNode esp32_ble_tracker::ESPBTUUID sensors_read_characteristic_uuid_; }; -} // namespace radon_eye_rd200 -} // namespace esphome +} // namespace esphome::radon_eye_rd200 #endif // USE_ESP32 diff --git a/esphome/components/rc522/rc522.cpp b/esphome/components/rc522/rc522.cpp index c5f7ec2cd41..7c1b6ae3148 100644 --- a/esphome/components/rc522/rc522.cpp +++ b/esphome/components/rc522/rc522.cpp @@ -5,8 +5,7 @@ // Based on: // - https://github.com/miguelbalboa/rfid -namespace esphome { -namespace rc522 { +namespace esphome::rc522 { static const uint8_t WAIT_I_RQ = 0x30; // RxIRq and IdleIRq @@ -498,5 +497,4 @@ void RC522Trigger::process(std::vector &data) { this->trigger(format_hex_pretty_to(uid_buf, data.data(), data.size(), '-')); } -} // namespace rc522 -} // namespace esphome +} // namespace esphome::rc522 diff --git a/esphome/components/rc522/rc522.h b/esphome/components/rc522/rc522.h index 437cea808bc..45473e04b06 100644 --- a/esphome/components/rc522/rc522.h +++ b/esphome/components/rc522/rc522.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace rc522 { +namespace esphome::rc522 { class RC522BinarySensor; class RC522Trigger; @@ -275,5 +274,4 @@ class RC522Trigger : public Trigger { void process(std::vector &data); }; -} // namespace rc522 -} // namespace esphome +} // namespace esphome::rc522 diff --git a/esphome/components/rc522_i2c/rc522_i2c.cpp b/esphome/components/rc522_i2c/rc522_i2c.cpp index 6a3d8d24861..dbc86ff8e78 100644 --- a/esphome/components/rc522_i2c/rc522_i2c.cpp +++ b/esphome/components/rc522_i2c/rc522_i2c.cpp @@ -1,8 +1,7 @@ #include "rc522_i2c.h" #include "esphome/core/log.h" -namespace esphome { -namespace rc522_i2c { +namespace esphome::rc522_i2c { static const char *const TAG = "rc522_i2c"; @@ -66,5 +65,4 @@ void RC522I2C::pcd_write_register(PcdRegister reg, ///< The register to write t write_bytes(reg >> 1, values, count); } -} // namespace rc522_i2c -} // namespace esphome +} // namespace esphome::rc522_i2c diff --git a/esphome/components/rc522_i2c/rc522_i2c.h b/esphome/components/rc522_i2c/rc522_i2c.h index 8d8b0a07164..bd6f2269d8c 100644 --- a/esphome/components/rc522_i2c/rc522_i2c.h +++ b/esphome/components/rc522_i2c/rc522_i2c.h @@ -4,8 +4,7 @@ #include "esphome/components/rc522/rc522.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace rc522_i2c { +namespace esphome::rc522_i2c { class RC522I2C : public rc522::RC522, public i2c::I2CDevice { public: @@ -38,5 +37,4 @@ class RC522I2C : public rc522::RC522, public i2c::I2CDevice { ) override; }; -} // namespace rc522_i2c -} // namespace esphome +} // namespace esphome::rc522_i2c diff --git a/esphome/components/rc522_spi/rc522_spi.cpp b/esphome/components/rc522_spi/rc522_spi.cpp index 40da4498148..b63ad1cfdc1 100644 --- a/esphome/components/rc522_spi/rc522_spi.cpp +++ b/esphome/components/rc522_spi/rc522_spi.cpp @@ -5,8 +5,7 @@ // Based on: // - https://github.com/miguelbalboa/rfid -namespace esphome { -namespace rc522_spi { +namespace esphome::rc522_spi { static const char *const TAG = "rc522_spi"; @@ -136,5 +135,4 @@ void RC522Spi::pcd_write_register(PcdRegister reg, ///< The register to write t ESP_LOGVV(TAG, "write_register_(%d, %d) -> %s", reg, count, buf.c_str()); } -} // namespace rc522_spi -} // namespace esphome +} // namespace esphome::rc522_spi diff --git a/esphome/components/rc522_spi/rc522_spi.h b/esphome/components/rc522_spi/rc522_spi.h index 0ccbcd7588f..54caf5c1171 100644 --- a/esphome/components/rc522_spi/rc522_spi.h +++ b/esphome/components/rc522_spi/rc522_spi.h @@ -4,7 +4,6 @@ #include "esphome/components/rc522/rc522.h" #include "esphome/components/spi/spi.h" -namespace esphome { /** * Library based on https://github.com/miguelbalboa/rfid * and adapted to ESPHome by @glmnet @@ -13,7 +12,7 @@ namespace esphome { * * */ -namespace rc522_spi { +namespace esphome::rc522_spi { class RC522Spi : public rc522::RC522, public spi::SPIDevice #include -namespace esphome { -namespace rdm6300 { +namespace esphome::rdm6300 { class RDM6300BinarySensor; class RDM6300Trigger; @@ -52,5 +51,4 @@ class RDM6300Trigger : public Trigger { void process(uint32_t uid) { this->trigger(uid); } }; -} // namespace rdm6300 -} // namespace esphome +} // namespace esphome::rdm6300 diff --git a/esphome/components/remote_base/abbwelcome_protocol.cpp b/esphome/components/remote_base/abbwelcome_protocol.cpp index a67ca48dbeb..2000148ca8f 100644 --- a/esphome/components/remote_base/abbwelcome_protocol.cpp +++ b/esphome/components/remote_base/abbwelcome_protocol.cpp @@ -1,8 +1,7 @@ #include "abbwelcome_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.abbwelcome"; @@ -123,5 +122,4 @@ void ABBWelcomeProtocol::dump(const ABBWelcomeData &data) { ESP_LOGD(TAG, "Received ABBWelcome: %s", data.format_to(buf)); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/abbwelcome_protocol.h b/esphome/components/remote_base/abbwelcome_protocol.h index 66664a89f3b..7ff32923bef 100644 --- a/esphome/components/remote_base/abbwelcome_protocol.h +++ b/esphome/components/remote_base/abbwelcome_protocol.h @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static constexpr uint8_t MAX_DATA_LENGTH = 15; static constexpr uint8_t DATA_LENGTH_MASK = 0x3f; @@ -272,5 +271,4 @@ template class ABBWelcomeAction : public RemoteTransmitterAction } data_; }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/aeha_protocol.cpp b/esphome/components/remote_base/aeha_protocol.cpp index f40cff7623d..69f91ba90e4 100644 --- a/esphome/components/remote_base/aeha_protocol.cpp +++ b/esphome/components/remote_base/aeha_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.aeha"; @@ -98,5 +97,4 @@ void AEHAProtocol::dump(const AEHAData &data) { ESP_LOGI(TAG, "Received AEHA: address=0x%04X, data=[%s]", data.address, data_str.c_str()); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/aeha_protocol.h b/esphome/components/remote_base/aeha_protocol.h index 51718eefcb0..3f4e98bd438 100644 --- a/esphome/components/remote_base/aeha_protocol.h +++ b/esphome/components/remote_base/aeha_protocol.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct AEHAData { uint16_t address; @@ -42,5 +41,4 @@ template class AEHAAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.beo4"; @@ -149,5 +148,4 @@ void Beo4Protocol::dump(const Beo4Data &data) { ESP_LOGI(TAG, "Beo4: source=0x%02x command=0x%02x repeats=%d ", data.source, data.command, data.repeats); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/beo4_protocol.h b/esphome/components/remote_base/beo4_protocol.h index 445e792cbc0..30b99dbeb77 100644 --- a/esphome/components/remote_base/beo4_protocol.h +++ b/esphome/components/remote_base/beo4_protocol.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct Beo4Data { uint8_t source; // beoSource, e.g. video, audio, light... @@ -39,5 +38,4 @@ template class Beo4Action : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.byronsx"; @@ -135,5 +134,4 @@ void ByronSXProtocol::dump(const ByronSXData &data) { ESP_LOGD(TAG, "Received ByronSX: address=0x%08X, command=0x%02x", data.address, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/byronsx_protocol.h b/esphome/components/remote_base/byronsx_protocol.h index 5d23237ab11..674fa99ea10 100644 --- a/esphome/components/remote_base/byronsx_protocol.h +++ b/esphome/components/remote_base/byronsx_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct ByronSXData { uint8_t address; @@ -42,5 +41,4 @@ template class ByronSXAction : public RemoteTransmitterActionBas } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/canalsat_protocol.cpp b/esphome/components/remote_base/canalsat_protocol.cpp index 1468b669395..eafa98ebcc4 100644 --- a/esphome/components/remote_base/canalsat_protocol.cpp +++ b/esphome/components/remote_base/canalsat_protocol.cpp @@ -1,8 +1,7 @@ #include "canalsat_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const CANALSAT_TAG = "remote.canalsat"; static const char *const CANALSATLD_TAG = "remote.canalsatld"; @@ -104,5 +103,4 @@ void CanalSatBaseProtocol::dump(const CanalSatData &data) { } } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/canalsat_protocol.h b/esphome/components/remote_base/canalsat_protocol.h index 180989ef996..5ba9115ea86 100644 --- a/esphome/components/remote_base/canalsat_protocol.h +++ b/esphome/components/remote_base/canalsat_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct CanalSatData { uint8_t device : 7; @@ -74,5 +73,4 @@ template class CanalSatLDAction : public RemoteTransmitterAction } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/coolix_protocol.cpp b/esphome/components/remote_base/coolix_protocol.cpp index 21a9f598b7a..53e1d59f135 100644 --- a/esphome/components/remote_base/coolix_protocol.cpp +++ b/esphome/components/remote_base/coolix_protocol.cpp @@ -1,8 +1,7 @@ #include "coolix_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.coolix"; @@ -109,5 +108,4 @@ void CoolixProtocol::dump(const CoolixData &data) { } } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/coolix_protocol.h b/esphome/components/remote_base/coolix_protocol.h index b66415ff70e..d9441e84178 100644 --- a/esphome/components/remote_base/coolix_protocol.h +++ b/esphome/components/remote_base/coolix_protocol.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct CoolixData { CoolixData() {} @@ -37,5 +36,4 @@ template class CoolixAction : public RemoteTransmitterActionBase } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/dish_protocol.cpp b/esphome/components/remote_base/dish_protocol.cpp index 69226101bf1..9a6420afd56 100644 --- a/esphome/components/remote_base/dish_protocol.cpp +++ b/esphome/components/remote_base/dish_protocol.cpp @@ -1,8 +1,7 @@ #include "dish_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.dish"; @@ -90,5 +89,4 @@ void DishProtocol::dump(const DishData &data) { ESP_LOGI(TAG, "Received Dish: address=0x%02X, command=0x%02X", data.address, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/dish_protocol.h b/esphome/components/remote_base/dish_protocol.h index ca4d04ed342..c89f4e78e11 100644 --- a/esphome/components/remote_base/dish_protocol.h +++ b/esphome/components/remote_base/dish_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct DishData { uint8_t address; @@ -34,5 +33,4 @@ template class DishAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct DooyaData { uint32_t id; @@ -45,5 +44,4 @@ template class DooyaAction : public RemoteTransmitterActionBase< } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/drayton_protocol.cpp b/esphome/components/remote_base/drayton_protocol.cpp index 946bd9cacb1..2261bd04e99 100644 --- a/esphome/components/remote_base/drayton_protocol.cpp +++ b/esphome/components/remote_base/drayton_protocol.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.drayton"; @@ -236,5 +235,4 @@ void DraytonProtocol::dump(const DraytonData &data) { ((data.address << 1) & 0xffff), data.channel, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/drayton_protocol.h b/esphome/components/remote_base/drayton_protocol.h index 75213b91866..693a1bbe85b 100644 --- a/esphome/components/remote_base/drayton_protocol.h +++ b/esphome/components/remote_base/drayton_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct DraytonData { uint16_t address; @@ -42,5 +41,4 @@ template class DraytonAction : public RemoteTransmitterActionBas } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/dyson_protocol.cpp b/esphome/components/remote_base/dyson_protocol.cpp index db4e1135f43..942b40d26fc 100644 --- a/esphome/components/remote_base/dyson_protocol.cpp +++ b/esphome/components/remote_base/dyson_protocol.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.dyson"; @@ -67,5 +66,4 @@ void DysonProtocol::dump(const DysonData &data) { ESP_LOGI(TAG, "Dyson: code=0x%x rolling index=%d", data.code, data.index); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/dyson_protocol.h b/esphome/components/remote_base/dyson_protocol.h index d1c08fefba5..3473a489b2c 100644 --- a/esphome/components/remote_base/dyson_protocol.h +++ b/esphome/components/remote_base/dyson_protocol.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static constexpr uint8_t IGNORE_INDEX = 0xFF; @@ -42,5 +41,4 @@ template class DysonAction : public RemoteTransmitterActionBase< } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/gobox_protocol.cpp b/esphome/components/remote_base/gobox_protocol.cpp index 0e1617659d8..1d67be86b86 100644 --- a/esphome/components/remote_base/gobox_protocol.cpp +++ b/esphome/components/remote_base/gobox_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.gobox"; @@ -128,5 +127,4 @@ void GoboxProtocol::dump(const GoboxData &data) { } } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/gobox_protocol.h b/esphome/components/remote_base/gobox_protocol.h index 7e18b61458d..f6b278771e0 100644 --- a/esphome/components/remote_base/gobox_protocol.h +++ b/esphome/components/remote_base/gobox_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct GoboxData { int code; @@ -50,5 +49,4 @@ template class GoboxAction : public RemoteTransmitterActionBase< } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/haier_protocol.cpp b/esphome/components/remote_base/haier_protocol.cpp index 734f3c77893..fa4cec773ff 100644 --- a/esphome/components/remote_base/haier_protocol.cpp +++ b/esphome/components/remote_base/haier_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.haier"; @@ -84,5 +83,4 @@ void HaierProtocol::dump(const HaierData &data) { ESP_LOGI(TAG, "Received Haier: %s", format_hex_pretty_to(hex_buf, data.data.data(), data.data.size())); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/haier_protocol.h b/esphome/components/remote_base/haier_protocol.h index 7a4ee640e8f..9c45ba1a635 100644 --- a/esphome/components/remote_base/haier_protocol.h +++ b/esphome/components/remote_base/haier_protocol.h @@ -3,8 +3,7 @@ #include "remote_base.h" #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct HaierData { std::vector data; @@ -35,5 +34,4 @@ template class HaierAction : public RemoteTransmitterActionBase< } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/jvc_protocol.cpp b/esphome/components/remote_base/jvc_protocol.cpp index c33cae7a486..86a47e757de 100644 --- a/esphome/components/remote_base/jvc_protocol.cpp +++ b/esphome/components/remote_base/jvc_protocol.cpp @@ -1,8 +1,7 @@ #include "jvc_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.jvc"; @@ -48,5 +47,4 @@ optional JVCProtocol::decode(RemoteReceiveData src) { } void JVCProtocol::dump(const JVCData &data) { ESP_LOGI(TAG, "Received JVC: data=0x%04" PRIX32, data.data); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/jvc_protocol.h b/esphome/components/remote_base/jvc_protocol.h index a17e593ad25..f6e2548dead 100644 --- a/esphome/components/remote_base/jvc_protocol.h +++ b/esphome/components/remote_base/jvc_protocol.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct JVCData { uint32_t data; @@ -33,5 +32,4 @@ template class JVCAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.keeloq"; @@ -190,5 +189,4 @@ void KeeloqProtocol::dump(const KeeloqData &data) { ESP_LOGD(TAG, "Received Keeloq: address=0x%08" PRIx32 ", command=0x%02x", data.address, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/keeloq_protocol.h b/esphome/components/remote_base/keeloq_protocol.h index 47125c151be..432313b87b2 100644 --- a/esphome/components/remote_base/keeloq_protocol.h +++ b/esphome/components/remote_base/keeloq_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct KeeloqData { uint32_t encrypted; // 32 bit encrypted field @@ -49,5 +48,4 @@ template class KeeloqAction : public RemoteTransmitterActionBase } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/lg_protocol.cpp b/esphome/components/remote_base/lg_protocol.cpp index 4c54ff00bd7..e450659b42f 100644 --- a/esphome/components/remote_base/lg_protocol.cpp +++ b/esphome/components/remote_base/lg_protocol.cpp @@ -1,8 +1,7 @@ #include "lg_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.lg"; @@ -54,5 +53,4 @@ void LGProtocol::dump(const LGData &data) { ESP_LOGI(TAG, "Received LG: data=0x%08" PRIX32 ", nbits=%d", data.data, data.nbits); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/lg_protocol.h b/esphome/components/remote_base/lg_protocol.h index e0039d033da..97159749956 100644 --- a/esphome/components/remote_base/lg_protocol.h +++ b/esphome/components/remote_base/lg_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct LGData { uint32_t data; @@ -37,5 +36,4 @@ template class LGAction : public RemoteTransmitterActionBase class MagiQuestAction : public RemoteTransmitterActionB } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/midea_protocol.cpp b/esphome/components/remote_base/midea_protocol.cpp index 4fa717cf088..6889c5d9b4f 100644 --- a/esphome/components/remote_base/midea_protocol.cpp +++ b/esphome/components/remote_base/midea_protocol.cpp @@ -1,8 +1,7 @@ #include "midea_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.midea"; @@ -75,5 +74,4 @@ void MideaProtocol::dump(const MideaData &data) { ESP_LOGI(TAG, "Received Midea: %s", data.to_str(buf)); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/midea_protocol.h b/esphome/components/remote_base/midea_protocol.h index 334e8a7cb31..f21dd40828f 100644 --- a/esphome/components/remote_base/midea_protocol.h +++ b/esphome/components/remote_base/midea_protocol.h @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { class MideaData { public: @@ -88,5 +87,4 @@ template class MideaAction : public RemoteTransmitterActionBase< } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/mirage_protocol.cpp b/esphome/components/remote_base/mirage_protocol.cpp index 2ae877f1931..380cfaecb26 100644 --- a/esphome/components/remote_base/mirage_protocol.cpp +++ b/esphome/components/remote_base/mirage_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.mirage"; @@ -85,5 +84,4 @@ void MirageProtocol::dump(const MirageData &data) { ESP_LOGI(TAG, "Received Mirage: %s", format_hex_pretty_to(hex_buf, data.data.data(), data.data.size())); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/mirage_protocol.h b/esphome/components/remote_base/mirage_protocol.h index 4257f7fa005..c967e72f134 100644 --- a/esphome/components/remote_base/mirage_protocol.h +++ b/esphome/components/remote_base/mirage_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct MirageData { std::vector data; @@ -35,5 +34,4 @@ template class MirageAction : public RemoteTransmitterActionBase } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/nec_protocol.cpp b/esphome/components/remote_base/nec_protocol.cpp index 062f81b4d60..e639248b4e4 100644 --- a/esphome/components/remote_base/nec_protocol.cpp +++ b/esphome/components/remote_base/nec_protocol.cpp @@ -1,8 +1,7 @@ #include "nec_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.nec"; @@ -98,5 +97,4 @@ void NECProtocol::dump(const NECData &data) { data.command_repeats); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/nec_protocol.h b/esphome/components/remote_base/nec_protocol.h index 71e1bccba8f..7b310e8ba5b 100644 --- a/esphome/components/remote_base/nec_protocol.h +++ b/esphome/components/remote_base/nec_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct NECData { uint16_t address; @@ -37,5 +36,4 @@ template class NECAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct NexaData { uint32_t device; @@ -50,5 +49,4 @@ template class NexaAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct PanasonicData { uint16_t address; @@ -37,5 +36,4 @@ template class PanasonicAction : public RemoteTransmitterActionB } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/pioneer_protocol.cpp b/esphome/components/remote_base/pioneer_protocol.cpp index f350ef66aee..f4d6aa4026c 100644 --- a/esphome/components/remote_base/pioneer_protocol.cpp +++ b/esphome/components/remote_base/pioneer_protocol.cpp @@ -1,8 +1,7 @@ #include "pioneer_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.pioneer"; @@ -152,5 +151,4 @@ void PioneerProtocol::dump(const PioneerData &data) { } } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/pioneer_protocol.h b/esphome/components/remote_base/pioneer_protocol.h index 4cac4f9f32c..514ab675016 100644 --- a/esphome/components/remote_base/pioneer_protocol.h +++ b/esphome/components/remote_base/pioneer_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct PioneerData { uint16_t rc_code_1; @@ -34,5 +33,4 @@ template class PioneerAction : public RemoteTransmitterActionBas } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/pronto_protocol.cpp b/esphome/components/remote_base/pronto_protocol.cpp index 6903cd46058..dc128d4622d 100644 --- a/esphome/components/remote_base/pronto_protocol.cpp +++ b/esphome/components/remote_base/pronto_protocol.cpp @@ -35,8 +35,7 @@ #include "pronto_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.pronto"; @@ -243,5 +242,4 @@ void ProntoProtocol::dump(const ProntoData &data) { } while (remaining > 0); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/pronto_protocol.h b/esphome/components/remote_base/pronto_protocol.h index e600834d1ab..f4f6b2144d9 100644 --- a/esphome/components/remote_base/pronto_protocol.h +++ b/esphome/components/remote_base/pronto_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { std::vector encode_pronto(const std::string &str); @@ -51,5 +50,4 @@ template class ProntoAction : public RemoteTransmitterActionBase } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/raw_protocol.cpp b/esphome/components/remote_base/raw_protocol.cpp index 7e6be3b77ed..02c29168496 100644 --- a/esphome/components/remote_base/raw_protocol.cpp +++ b/esphome/components/remote_base/raw_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.raw"; @@ -38,5 +37,4 @@ bool RawDumper::dump(RemoteReceiveData src) { return true; } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/raw_protocol.h b/esphome/components/remote_base/raw_protocol.h index 941b6aab426..1bcf390b628 100644 --- a/esphome/components/remote_base/raw_protocol.h +++ b/esphome/components/remote_base/raw_protocol.h @@ -6,8 +6,7 @@ #include #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { class RawBinarySensor : public RemoteReceiverBinarySensorBase { public: @@ -82,5 +81,4 @@ class RawDumper : public RemoteReceiverDumperBase { bool is_secondary() override { return true; } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/rc5_protocol.cpp b/esphome/components/remote_base/rc5_protocol.cpp index bb6d382d804..c7f79ad84a3 100644 --- a/esphome/components/remote_base/rc5_protocol.cpp +++ b/esphome/components/remote_base/rc5_protocol.cpp @@ -1,8 +1,7 @@ #include "rc5_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.rc5"; @@ -86,5 +85,4 @@ void RC5Protocol::dump(const RC5Data &data) { ESP_LOGI(TAG, "Received RC5: address=0x%02X, command=0x%02X", data.address, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/rc5_protocol.h b/esphome/components/remote_base/rc5_protocol.h index 589c8d42dee..dbb89e41c60 100644 --- a/esphome/components/remote_base/rc5_protocol.h +++ b/esphome/components/remote_base/rc5_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct RC5Data { uint8_t address; @@ -35,5 +34,4 @@ template class RC5Action : public RemoteTransmitterActionBase class RC6Action : public RemoteTransmitterActionBase; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/remote_base.cpp b/esphome/components/remote_base/remote_base.cpp index b4a549f0bed..4d9bc55f216 100644 --- a/esphome/components/remote_base/remote_base.cpp +++ b/esphome/components/remote_base/remote_base.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote_base"; @@ -198,5 +197,4 @@ void RemoteTransmitterBase::send_(uint32_t send_times, uint32_t send_wait) { #endif this->send_internal(send_times, send_wait); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/remote_base.h b/esphome/components/remote_base/remote_base.h index e5e923d7806..0b1109267fa 100644 --- a/esphome/components/remote_base/remote_base.h +++ b/esphome/components/remote_base/remote_base.h @@ -8,8 +8,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { enum ToleranceMode : uint8_t { TOLERANCE_MODE_PERCENTAGE = 0, @@ -317,5 +316,4 @@ template class RemoteReceiverDumper : public RemoteReceiverDumperBas using prefix##Dumper = RemoteReceiverDumper; #define DECLARE_REMOTE_PROTOCOL(prefix) DECLARE_REMOTE_PROTOCOL_(prefix) -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/roomba_protocol.cpp b/esphome/components/remote_base/roomba_protocol.cpp index 6b7d2163748..8053792a60c 100644 --- a/esphome/components/remote_base/roomba_protocol.cpp +++ b/esphome/components/remote_base/roomba_protocol.cpp @@ -1,8 +1,7 @@ #include "roomba_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.roomba"; @@ -52,5 +51,4 @@ optional RoombaProtocol::decode(RemoteReceiveData src) { } void RoombaProtocol::dump(const RoombaData &data) { ESP_LOGD(TAG, "Received Roomba: data=0x%02X", data.data); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/roomba_protocol.h b/esphome/components/remote_base/roomba_protocol.h index f94cb7df1b1..3582dac398b 100644 --- a/esphome/components/remote_base/roomba_protocol.h +++ b/esphome/components/remote_base/roomba_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct RoombaData { uint8_t data; @@ -31,5 +30,4 @@ template class RoombaAction : public RemoteTransmitterActionBase } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/samsung36_protocol.cpp b/esphome/components/remote_base/samsung36_protocol.cpp index 10e8bd2d013..ded8c71aa38 100644 --- a/esphome/components/remote_base/samsung36_protocol.cpp +++ b/esphome/components/remote_base/samsung36_protocol.cpp @@ -1,8 +1,7 @@ #include "samsung36_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.samsung36"; @@ -99,5 +98,4 @@ void Samsung36Protocol::dump(const Samsung36Data &data) { ESP_LOGI(TAG, "Received Samsung36: address=0x%04X, command=0x%08" PRIX32, data.address, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/samsung36_protocol.h b/esphome/components/remote_base/samsung36_protocol.h index aa7fd21609f..4f15d906e76 100644 --- a/esphome/components/remote_base/samsung36_protocol.h +++ b/esphome/components/remote_base/samsung36_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct Samsung36Data { uint16_t address; @@ -37,5 +36,4 @@ template class Samsung36Action : public RemoteTransmitterActionB } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/samsung_protocol.cpp b/esphome/components/remote_base/samsung_protocol.cpp index 2a48cbb918e..7190e974038 100644 --- a/esphome/components/remote_base/samsung_protocol.cpp +++ b/esphome/components/remote_base/samsung_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.samsung"; @@ -61,5 +60,4 @@ void SamsungProtocol::dump(const SamsungData &data) { ESP_LOGI(TAG, "Received Samsung: data=0x%" PRIX64 ", nbits=%d", data.data, data.nbits); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/samsung_protocol.h b/esphome/components/remote_base/samsung_protocol.h index 41434f28892..bb234d681de 100644 --- a/esphome/components/remote_base/samsung_protocol.h +++ b/esphome/components/remote_base/samsung_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct SamsungData { uint64_t data; @@ -35,5 +34,4 @@ template class SamsungAction : public RemoteTransmitterActionBas } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/sony_protocol.cpp b/esphome/components/remote_base/sony_protocol.cpp index 504b3469251..0abb7fc0e02 100644 --- a/esphome/components/remote_base/sony_protocol.cpp +++ b/esphome/components/remote_base/sony_protocol.cpp @@ -1,8 +1,7 @@ #include "sony_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.sony"; @@ -65,5 +64,4 @@ void SonyProtocol::dump(const SonyData &data) { ESP_LOGI(TAG, "Received Sony: data=0x%08" PRIX32 ", nbits=%d", data.data, data.nbits); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/sony_protocol.h b/esphome/components/remote_base/sony_protocol.h index d9e4f37d53f..eb873e8b7dc 100644 --- a/esphome/components/remote_base/sony_protocol.h +++ b/esphome/components/remote_base/sony_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct SonyData { uint32_t data; @@ -37,5 +36,4 @@ template class SonyAction : public RemoteTransmitterActionBase -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.symphony"; @@ -118,5 +117,4 @@ void SymphonyProtocol::dump(const SymphonyData &data) { ESP_LOGI(TAG, "Received Symphony: data=0x%0*" PRIX32 ", nbits=%" PRIu8, hex_width, (uint32_t) data.data, data.nbits); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/symphony_protocol.h b/esphome/components/remote_base/symphony_protocol.h index 7e77a268ba2..7caf5eab867 100644 --- a/esphome/components/remote_base/symphony_protocol.h +++ b/esphome/components/remote_base/symphony_protocol.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct SymphonyData { uint32_t data; @@ -40,5 +39,4 @@ template class SymphonyAction : public RemoteTransmitterActionBa } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/toshiba_ac_protocol.cpp b/esphome/components/remote_base/toshiba_ac_protocol.cpp index a20a29b84a9..077b4340fa6 100644 --- a/esphome/components/remote_base/toshiba_ac_protocol.cpp +++ b/esphome/components/remote_base/toshiba_ac_protocol.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.toshibaac"; @@ -111,5 +110,4 @@ void ToshibaAcProtocol::dump(const ToshibaAcData &data) { } } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/toshiba_ac_protocol.h b/esphome/components/remote_base/toshiba_ac_protocol.h index c69401c3785..8a853005acb 100644 --- a/esphome/components/remote_base/toshiba_ac_protocol.h +++ b/esphome/components/remote_base/toshiba_ac_protocol.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct ToshibaAcData { uint64_t rc_code_1; @@ -35,5 +34,4 @@ template class ToshibaAcAction : public RemoteTransmitterActionB } }; -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/toto_protocol.cpp b/esphome/components/remote_base/toto_protocol.cpp index f08258c4a3e..042efcbc363 100644 --- a/esphome/components/remote_base/toto_protocol.cpp +++ b/esphome/components/remote_base/toto_protocol.cpp @@ -1,8 +1,7 @@ #include "toto_protocol.h" #include "esphome/core/log.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { static const char *const TAG = "remote.toto"; @@ -96,5 +95,4 @@ void TotoProtocol::dump(const TotoData &data) { data.rc_code_2, data.command); } -} // namespace remote_base -} // namespace esphome +} // namespace esphome::remote_base diff --git a/esphome/components/remote_base/toto_protocol.h b/esphome/components/remote_base/toto_protocol.h index 53d453f7e3d..285c9f21257 100644 --- a/esphome/components/remote_base/toto_protocol.h +++ b/esphome/components/remote_base/toto_protocol.h @@ -2,8 +2,7 @@ #include "remote_base.h" -namespace esphome { -namespace remote_base { +namespace esphome::remote_base { struct TotoData { uint8_t rc_code_1 : 4; @@ -39,5 +38,4 @@ template class TotoAction : public RemoteTransmitterActionBase #include -namespace esphome { -namespace resampler { +namespace esphome::resampler { static const UBaseType_t RESAMPLER_TASK_PRIORITY = 1; @@ -373,7 +372,6 @@ void ResamplerSpeaker::resample_task(void *params) { vTaskSuspend(nullptr); // Suspend this task indefinitely until the loop method deletes it } -} // namespace resampler -} // namespace esphome +} // namespace esphome::resampler #endif diff --git a/esphome/components/resampler/speaker/resampler_speaker.h b/esphome/components/resampler/speaker/resampler_speaker.h index cdbc1c22db4..36f39fda97f 100644 --- a/esphome/components/resampler/speaker/resampler_speaker.h +++ b/esphome/components/resampler/speaker/resampler_speaker.h @@ -11,8 +11,7 @@ #include -namespace esphome { -namespace resampler { +namespace esphome::resampler { class ResamplerSpeaker : public Component, public speaker::Speaker { public: @@ -99,7 +98,6 @@ class ResamplerSpeaker : public Component, public speaker::Speaker { uint64_t callback_remainder_{0}; }; -} // namespace resampler -} // namespace esphome +} // namespace esphome::resampler #endif diff --git a/esphome/components/resistance/resistance_sensor.cpp b/esphome/components/resistance/resistance_sensor.cpp index 706a059de35..60565090938 100644 --- a/esphome/components/resistance/resistance_sensor.cpp +++ b/esphome/components/resistance/resistance_sensor.cpp @@ -1,8 +1,7 @@ #include "resistance_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace resistance { +namespace esphome::resistance { static const char *const TAG = "resistance"; @@ -43,5 +42,4 @@ void ResistanceSensor::process_(float value) { this->publish_state(res); } -} // namespace resistance -} // namespace esphome +} // namespace esphome::resistance diff --git a/esphome/components/resistance/resistance_sensor.h b/esphome/components/resistance/resistance_sensor.h index a3b6e92c595..b646fb509a1 100644 --- a/esphome/components/resistance/resistance_sensor.h +++ b/esphome/components/resistance/resistance_sensor.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace resistance { +namespace esphome::resistance { enum ResistanceConfiguration { UPSTREAM, @@ -33,5 +32,4 @@ class ResistanceSensor : public Component, public sensor::Sensor { float reference_voltage_; }; -} // namespace resistance -} // namespace esphome +} // namespace esphome::resistance diff --git a/esphome/components/restart/button/restart_button.cpp b/esphome/components/restart/button/restart_button.cpp index accb1a8356c..d6404315ea9 100644 --- a/esphome/components/restart/button/restart_button.cpp +++ b/esphome/components/restart/button/restart_button.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace restart { +namespace esphome::restart { static const char *const TAG = "restart.button"; @@ -16,5 +15,4 @@ void RestartButton::press_action() { } void RestartButton::dump_config() { LOG_BUTTON("", "Restart Button", this); } -} // namespace restart -} // namespace esphome +} // namespace esphome::restart diff --git a/esphome/components/restart/button/restart_button.h b/esphome/components/restart/button/restart_button.h index fd51282d36d..974db0cec48 100644 --- a/esphome/components/restart/button/restart_button.h +++ b/esphome/components/restart/button/restart_button.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "esphome/core/component.h" -namespace esphome { -namespace restart { +namespace esphome::restart { class RestartButton final : public button::Button, public Component { public: @@ -14,5 +13,4 @@ class RestartButton final : public button::Button, public Component { void press_action() override; }; -} // namespace restart -} // namespace esphome +} // namespace esphome::restart diff --git a/esphome/components/restart/switch/restart_switch.cpp b/esphome/components/restart/switch/restart_switch.cpp index 422e85f4cd7..96a4fc40f5c 100644 --- a/esphome/components/restart/switch/restart_switch.cpp +++ b/esphome/components/restart/switch/restart_switch.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace restart { +namespace esphome::restart { static const char *const TAG = "restart"; @@ -21,5 +20,4 @@ void RestartSwitch::write_state(bool state) { } void RestartSwitch::dump_config() { LOG_SWITCH("", "Restart Switch", this); } -} // namespace restart -} // namespace esphome +} // namespace esphome::restart diff --git a/esphome/components/restart/switch/restart_switch.h b/esphome/components/restart/switch/restart_switch.h index 7f1902ab53c..67b4a2bfd10 100644 --- a/esphome/components/restart/switch/restart_switch.h +++ b/esphome/components/restart/switch/restart_switch.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace restart { +namespace esphome::restart { class RestartSwitch : public switch_::Switch, public Component { public: @@ -14,5 +13,4 @@ class RestartSwitch : public switch_::Switch, public Component { void write_state(bool state) override; }; -} // namespace restart -} // namespace esphome +} // namespace esphome::restart diff --git a/esphome/components/rf_bridge/rf_bridge.cpp b/esphome/components/rf_bridge/rf_bridge.cpp index 5ca629c12b0..cec32e04064 100644 --- a/esphome/components/rf_bridge/rf_bridge.cpp +++ b/esphome/components/rf_bridge/rf_bridge.cpp @@ -5,8 +5,7 @@ #include #include -namespace esphome { -namespace rf_bridge { +namespace esphome::rf_bridge { static const char *const TAG = "rf_bridge"; @@ -243,5 +242,4 @@ void RFBridgeComponent::beep(uint16_t ms) { this->flush(); } -} // namespace rf_bridge -} // namespace esphome +} // namespace esphome::rf_bridge diff --git a/esphome/components/rf_bridge/rf_bridge.h b/esphome/components/rf_bridge/rf_bridge.h index 571ac6c385e..2f91459076f 100644 --- a/esphome/components/rf_bridge/rf_bridge.h +++ b/esphome/components/rf_bridge/rf_bridge.h @@ -7,8 +7,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/core/automation.h" -namespace esphome { -namespace rf_bridge { +namespace esphome::rf_bridge { static const uint8_t RF_MESSAGE_SIZE = 9; static const uint8_t RF_CODE_START = 0xAA; @@ -179,5 +178,4 @@ template class RFBridgeBeepAction : public Action { RFBridgeComponent *parent_; }; -} // namespace rf_bridge -} // namespace esphome +} // namespace esphome::rf_bridge diff --git a/esphome/components/rgb/rgb_light_output.h b/esphome/components/rgb/rgb_light_output.h index 783187667a0..f0d599cf575 100644 --- a/esphome/components/rgb/rgb_light_output.h +++ b/esphome/components/rgb/rgb_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace rgb { +namespace esphome::rgb { class RGBLightOutput : public light::LightOutput { public: @@ -32,5 +31,4 @@ class RGBLightOutput : public light::LightOutput { output::FloatOutput *blue_; }; -} // namespace rgb -} // namespace esphome +} // namespace esphome::rgb diff --git a/esphome/components/rgbct/rgbct_light_output.h b/esphome/components/rgbct/rgbct_light_output.h index 9e23f783ae5..84ecb232cc6 100644 --- a/esphome/components/rgbct/rgbct_light_output.h +++ b/esphome/components/rgbct/rgbct_light_output.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/core/component.h" -namespace esphome { -namespace rgbct { +namespace esphome::rgbct { class RGBCTLightOutput : public light::LightOutput { public: @@ -55,5 +54,4 @@ class RGBCTLightOutput : public light::LightOutput { bool color_interlock_{true}; }; -} // namespace rgbct -} // namespace esphome +} // namespace esphome::rgbct diff --git a/esphome/components/rgbw/rgbw_light_output.h b/esphome/components/rgbw/rgbw_light_output.h index 140726a43c8..ae96eb20246 100644 --- a/esphome/components/rgbw/rgbw_light_output.h +++ b/esphome/components/rgbw/rgbw_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace rgbw { +namespace esphome::rgbw { class RGBWLightOutput : public light::LightOutput { public: @@ -40,5 +39,4 @@ class RGBWLightOutput : public light::LightOutput { bool color_interlock_{false}; }; -} // namespace rgbw -} // namespace esphome +} // namespace esphome::rgbw diff --git a/esphome/components/rgbww/rgbww_light_output.h b/esphome/components/rgbww/rgbww_light_output.h index 96873600595..de5ee993f8c 100644 --- a/esphome/components/rgbww/rgbww_light_output.h +++ b/esphome/components/rgbww/rgbww_light_output.h @@ -4,8 +4,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace rgbww { +namespace esphome::rgbww { class RGBWWLightOutput : public light::LightOutput { public: @@ -51,5 +50,4 @@ class RGBWWLightOutput : public light::LightOutput { bool color_interlock_{false}; }; -} // namespace rgbww -} // namespace esphome +} // namespace esphome::rgbww diff --git a/esphome/components/rotary_encoder/rotary_encoder.cpp b/esphome/components/rotary_encoder/rotary_encoder.cpp index 38fd14375d6..0831822d868 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.cpp +++ b/esphome/components/rotary_encoder/rotary_encoder.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace rotary_encoder { +namespace esphome::rotary_encoder { static const char *const TAG = "rotary_encoder"; @@ -242,5 +241,4 @@ void RotaryEncoderSensor::set_resolution(RotaryEncoderResolution mode) { this->s void RotaryEncoderSensor::set_min_value(int32_t min_value) { this->store_.min_value = min_value; } void RotaryEncoderSensor::set_max_value(int32_t max_value) { this->store_.max_value = max_value; } -} // namespace rotary_encoder -} // namespace esphome +} // namespace esphome::rotary_encoder diff --git a/esphome/components/rotary_encoder/rotary_encoder.h b/esphome/components/rotary_encoder/rotary_encoder.h index 6f4a4fd83ce..8a56da4fe27 100644 --- a/esphome/components/rotary_encoder/rotary_encoder.h +++ b/esphome/components/rotary_encoder/rotary_encoder.h @@ -7,8 +7,7 @@ #include "esphome/core/automation.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace rotary_encoder { +namespace esphome::rotary_encoder { /// All possible restore modes for the rotary encoder enum RotaryEncoderRestoreMode { @@ -118,5 +117,4 @@ template class RotaryEncoderSetValueAction : public Action humidity; @@ -31,7 +30,6 @@ class RuuviListener : public esp32_ble_tracker::ESPBTDeviceListener { bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; }; -} // namespace ruuvi_ble -} // namespace esphome +} // namespace esphome::ruuvi_ble #endif diff --git a/esphome/components/ruuvitag/ruuvitag.cpp b/esphome/components/ruuvitag/ruuvitag.cpp index 9b462b47945..99c6b8ae26e 100644 --- a/esphome/components/ruuvitag/ruuvitag.cpp +++ b/esphome/components/ruuvitag/ruuvitag.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ruuvitag { +namespace esphome::ruuvitag { static const char *const TAG = "ruuvitag"; @@ -23,7 +22,6 @@ void RuuviTag::dump_config() { LOG_SENSOR(" ", "Measurement Sequence Number", this->measurement_sequence_number_); } -} // namespace ruuvitag -} // namespace esphome +} // namespace esphome::ruuvitag #endif diff --git a/esphome/components/ruuvitag/ruuvitag.h b/esphome/components/ruuvitag/ruuvitag.h index dfe393724cc..259675835d5 100644 --- a/esphome/components/ruuvitag/ruuvitag.h +++ b/esphome/components/ruuvitag/ruuvitag.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace ruuvitag { +namespace esphome::ruuvitag { class RuuviTag : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -77,7 +76,6 @@ class RuuviTag : public Component, public esp32_ble_tracker::ESPBTDeviceListener sensor::Sensor *measurement_sequence_number_{nullptr}; }; -} // namespace ruuvitag -} // namespace esphome +} // namespace esphome::ruuvitag #endif diff --git a/esphome/components/rx8130/rx8130.cpp b/esphome/components/rx8130/rx8130.cpp index 0aa6e86d31e..1b5b71f0e0e 100644 --- a/esphome/components/rx8130/rx8130.cpp +++ b/esphome/components/rx8130/rx8130.cpp @@ -3,8 +3,7 @@ // https://download.epsondevice.com/td/pdf/app/RX8130CE_en.pdf -namespace esphome { -namespace rx8130 { +namespace esphome::rx8130 { static const uint8_t RX8130_REG_SEC = 0x10; static const uint8_t RX8130_REG_MIN = 0x11; @@ -121,5 +120,4 @@ void RX8130Component::stop_(bool stop) { } } -} // namespace rx8130 -} // namespace esphome +} // namespace esphome::rx8130 diff --git a/esphome/components/rx8130/rx8130.h b/esphome/components/rx8130/rx8130.h index 979da3e19cb..152bd10f273 100644 --- a/esphome/components/rx8130/rx8130.h +++ b/esphome/components/rx8130/rx8130.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/components/time/real_time_clock.h" -namespace esphome { -namespace rx8130 { +namespace esphome::rx8130 { class RX8130Component : public time::RealTimeClock, public i2c::I2CDevice { public: @@ -29,5 +28,4 @@ template class ReadAction : public Action, public Parente void play(const Ts... x) override { this->parent_->read_time(); } }; -} // namespace rx8130 -} // namespace esphome +} // namespace esphome::rx8130 From ded83812f4b88c04b8a1c6d1985b4c6d73b94fc9 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 20:16:51 -0400 Subject: [PATCH 07/52] [clang-tidy] Concatenate nested namespaces (5/7: components s) (#16302) --- esphome/components/safe_mode/button/safe_mode_button.cpp | 6 ++---- esphome/components/safe_mode/button/safe_mode_button.h | 6 ++---- esphome/components/safe_mode/switch/safe_mode_switch.cpp | 6 ++---- esphome/components/safe_mode/switch/safe_mode_switch.h | 6 ++---- esphome/components/scd30/automation.h | 6 ++---- esphome/components/scd30/scd30.cpp | 6 ++---- esphome/components/scd30/scd30.h | 6 ++---- esphome/components/scd4x/automation.h | 6 ++---- esphome/components/scd4x/scd4x.cpp | 6 ++---- esphome/components/scd4x/scd4x.h | 6 ++---- esphome/components/script/script.cpp | 6 ++---- esphome/components/script/script.h | 7 +++---- esphome/components/sdm_meter/sdm_meter.cpp | 6 ++---- esphome/components/sdm_meter/sdm_meter.h | 6 ++---- esphome/components/sdm_meter/sdm_meter_registers.h | 6 ++---- esphome/components/sdp3x/sdp3x.cpp | 6 ++---- esphome/components/sdp3x/sdp3x.h | 6 ++---- esphome/components/sds011/sds011.cpp | 6 ++---- esphome/components/sds011/sds011.h | 6 ++---- .../seeed_mr24hpc1/button/custom_mode_end_button.cpp | 6 ++---- .../seeed_mr24hpc1/button/custom_mode_end_button.h | 6 ++---- .../components/seeed_mr24hpc1/button/restart_button.cpp | 6 ++---- esphome/components/seeed_mr24hpc1/button/restart_button.h | 6 ++---- .../seeed_mr24hpc1/number/custom_mode_number.cpp | 6 ++---- .../components/seeed_mr24hpc1/number/custom_mode_number.h | 6 ++---- .../seeed_mr24hpc1/number/custom_unman_time_number.cpp | 6 ++---- .../seeed_mr24hpc1/number/custom_unman_time_number.h | 6 ++---- .../seeed_mr24hpc1/number/existence_threshold_number.cpp | 6 ++---- .../seeed_mr24hpc1/number/existence_threshold_number.h | 6 ++---- .../seeed_mr24hpc1/number/motion_threshold_number.cpp | 6 ++---- .../seeed_mr24hpc1/number/motion_threshold_number.h | 6 ++---- .../seeed_mr24hpc1/number/motion_trigger_time_number.cpp | 6 ++---- .../seeed_mr24hpc1/number/motion_trigger_time_number.h | 6 ++---- .../seeed_mr24hpc1/number/motiontorest_time_number.cpp | 6 ++---- .../seeed_mr24hpc1/number/motiontorest_time_number.h | 6 ++---- .../seeed_mr24hpc1/number/sensitivity_number.cpp | 6 ++---- .../components/seeed_mr24hpc1/number/sensitivity_number.h | 6 ++---- esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.cpp | 6 ++---- esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h | 6 ++---- .../components/seeed_mr24hpc1/seeed_mr24hpc1_constants.h | 6 ++---- .../seeed_mr24hpc1/select/existence_boundary_select.cpp | 6 ++---- .../seeed_mr24hpc1/select/existence_boundary_select.h | 6 ++---- .../seeed_mr24hpc1/select/motion_boundary_select.cpp | 6 ++---- .../seeed_mr24hpc1/select/motion_boundary_select.h | 6 ++---- .../seeed_mr24hpc1/select/scene_mode_select.cpp | 6 ++---- .../components/seeed_mr24hpc1/select/scene_mode_select.h | 6 ++---- .../seeed_mr24hpc1/select/unman_time_select.cpp | 6 ++---- .../components/seeed_mr24hpc1/select/unman_time_select.h | 6 ++---- .../seeed_mr24hpc1/switch/underlyFuc_switch.cpp | 6 ++---- .../components/seeed_mr24hpc1/switch/underlyFuc_switch.h | 6 ++---- esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp | 6 ++---- esphome/components/seeed_mr60bha2/seeed_mr60bha2.h | 6 ++---- .../seeed_mr60fda2/button/get_radar_parameters_button.cpp | 6 ++---- .../seeed_mr60fda2/button/get_radar_parameters_button.h | 6 ++---- .../seeed_mr60fda2/button/reset_radar_button.cpp | 6 ++---- .../components/seeed_mr60fda2/button/reset_radar_button.h | 6 ++---- esphome/components/seeed_mr60fda2/seeed_mr60fda2.cpp | 6 ++---- esphome/components/seeed_mr60fda2/seeed_mr60fda2.h | 6 ++---- .../seeed_mr60fda2/select/height_threshold_select.cpp | 6 ++---- .../seeed_mr60fda2/select/height_threshold_select.h | 6 ++---- .../seeed_mr60fda2/select/install_height_select.cpp | 6 ++---- .../seeed_mr60fda2/select/install_height_select.h | 6 ++---- .../seeed_mr60fda2/select/sensitivity_select.cpp | 6 ++---- .../components/seeed_mr60fda2/select/sensitivity_select.h | 6 ++---- esphome/components/selec_meter/selec_meter.cpp | 6 ++---- esphome/components/selec_meter/selec_meter.h | 6 ++---- esphome/components/selec_meter/selec_meter_registers.h | 6 ++---- esphome/components/sen0321/sen0321.cpp | 6 ++---- esphome/components/sen0321/sen0321.h | 6 ++---- esphome/components/sen21231/sen21231.cpp | 6 ++---- esphome/components/sen21231/sen21231.h | 6 ++---- esphome/components/sen5x/automation.h | 6 ++---- esphome/components/sen5x/sen5x.cpp | 6 ++---- esphome/components/sen5x/sen5x.h | 6 ++---- esphome/components/senseair/senseair.cpp | 6 ++---- esphome/components/senseair/senseair.h | 6 ++---- esphome/components/sensirion_common/i2c_sensirion.cpp | 6 ++---- esphome/components/sensirion_common/i2c_sensirion.h | 6 ++---- esphome/components/servo/servo.cpp | 6 ++---- esphome/components/servo/servo.h | 6 ++---- esphome/components/sfa30/sfa30.cpp | 6 ++---- esphome/components/sfa30/sfa30.h | 6 ++---- esphome/components/sgp30/sgp30.cpp | 6 ++---- esphome/components/sgp30/sgp30.h | 6 ++---- esphome/components/sgp4x/sgp4x.cpp | 6 ++---- esphome/components/sgp4x/sgp4x.h | 6 ++---- esphome/components/sht3xd/sht3xd.cpp | 6 ++---- esphome/components/sht3xd/sht3xd.h | 6 ++---- esphome/components/sht4x/sht4x.cpp | 6 ++---- esphome/components/sht4x/sht4x.h | 6 ++---- esphome/components/shutdown/button/shutdown_button.cpp | 6 ++---- esphome/components/shutdown/button/shutdown_button.h | 6 ++---- esphome/components/shutdown/switch/shutdown_switch.cpp | 6 ++---- esphome/components/shutdown/switch/shutdown_switch.h | 6 ++---- .../components/sigma_delta_output/sigma_delta_output.cpp | 6 ++---- .../components/sigma_delta_output/sigma_delta_output.h | 6 ++---- esphome/components/sim800l/sim800l.cpp | 6 ++---- esphome/components/sim800l/sim800l.h | 6 ++---- esphome/components/slow_pwm/slow_pwm_output.cpp | 6 ++---- esphome/components/slow_pwm/slow_pwm_output.h | 6 ++---- esphome/components/sm10bit_base/sm10bit_base.cpp | 6 ++---- esphome/components/sm10bit_base/sm10bit_base.h | 6 ++---- esphome/components/sm16716/sm16716.cpp | 6 ++---- esphome/components/sm16716/sm16716.h | 6 ++---- esphome/components/sm2135/sm2135.cpp | 6 ++---- esphome/components/sm2135/sm2135.h | 6 ++---- esphome/components/sm2235/sm2235.cpp | 6 ++---- esphome/components/sm2235/sm2235.h | 6 ++---- esphome/components/sm2335/sm2335.cpp | 6 ++---- esphome/components/sm2335/sm2335.h | 6 ++---- esphome/components/sm300d2/sm300d2.cpp | 6 ++---- esphome/components/sm300d2/sm300d2.h | 6 ++---- esphome/components/sml/constants.h | 6 ++---- esphome/components/sml/sensor/sml_sensor.cpp | 6 ++---- esphome/components/sml/sensor/sml_sensor.h | 6 ++---- esphome/components/sml/sml.cpp | 6 ++---- esphome/components/sml/sml.h | 6 ++---- esphome/components/sml/sml_parser.cpp | 6 ++---- esphome/components/sml/sml_parser.h | 6 ++---- esphome/components/sml/text_sensor/sml_text_sensor.cpp | 6 ++---- esphome/components/sml/text_sensor/sml_text_sensor.h | 6 ++---- esphome/components/smt100/smt100.cpp | 6 ++---- esphome/components/smt100/smt100.h | 6 ++---- esphome/components/sn74hc165/sn74hc165.cpp | 6 ++---- esphome/components/sn74hc165/sn74hc165.h | 6 ++---- esphome/components/sn74hc595/sn74hc595.cpp | 6 ++---- esphome/components/sn74hc595/sn74hc595.h | 6 ++---- esphome/components/sntp/sntp_component.cpp | 6 ++---- esphome/components/sntp/sntp_component.h | 6 ++---- esphome/components/sonoff_d1/sonoff_d1.cpp | 6 ++---- esphome/components/sonoff_d1/sonoff_d1.h | 6 ++---- esphome/components/sound_level/sound_level.cpp | 6 ++---- esphome/components/sound_level/sound_level.h | 7 +++---- esphome/components/speaker/automation.h | 6 ++---- .../components/speaker/media_player/audio_pipeline.cpp | 6 ++---- esphome/components/speaker/media_player/audio_pipeline.h | 6 ++---- esphome/components/speaker/media_player/automation.h | 6 ++---- .../speaker/media_player/speaker_media_player.cpp | 6 ++---- .../speaker/media_player/speaker_media_player.h | 6 ++---- esphome/components/speaker/speaker.h | 6 ++---- esphome/components/speed/fan/speed_fan.cpp | 6 ++---- esphome/components/speed/fan/speed_fan.h | 6 ++---- esphome/components/spi_device/spi_device.cpp | 6 ++---- esphome/components/spi_device/spi_device.h | 6 ++---- esphome/components/spi_led_strip/spi_led_strip.cpp | 6 ++---- esphome/components/spi_led_strip/spi_led_strip.h | 6 ++---- esphome/components/sps30/automation.h | 6 ++---- esphome/components/sps30/sps30.cpp | 6 ++---- esphome/components/sps30/sps30.h | 6 ++---- esphome/components/ssd1306_base/ssd1306_base.cpp | 6 ++---- esphome/components/ssd1306_base/ssd1306_base.h | 6 ++---- esphome/components/ssd1306_i2c/ssd1306_i2c.cpp | 6 ++---- esphome/components/ssd1306_i2c/ssd1306_i2c.h | 6 ++---- esphome/components/ssd1306_spi/ssd1306_spi.cpp | 6 ++---- esphome/components/ssd1306_spi/ssd1306_spi.h | 6 ++---- esphome/components/ssd1322_base/ssd1322_base.cpp | 6 ++---- esphome/components/ssd1322_base/ssd1322_base.h | 6 ++---- esphome/components/ssd1322_spi/ssd1322_spi.cpp | 6 ++---- esphome/components/ssd1322_spi/ssd1322_spi.h | 6 ++---- esphome/components/ssd1325_base/ssd1325_base.cpp | 6 ++---- esphome/components/ssd1325_base/ssd1325_base.h | 6 ++---- esphome/components/ssd1325_spi/ssd1325_spi.cpp | 6 ++---- esphome/components/ssd1325_spi/ssd1325_spi.h | 6 ++---- esphome/components/ssd1327_base/ssd1327_base.cpp | 6 ++---- esphome/components/ssd1327_base/ssd1327_base.h | 6 ++---- esphome/components/ssd1327_i2c/ssd1327_i2c.cpp | 6 ++---- esphome/components/ssd1327_i2c/ssd1327_i2c.h | 6 ++---- esphome/components/ssd1327_spi/ssd1327_spi.cpp | 6 ++---- esphome/components/ssd1327_spi/ssd1327_spi.h | 6 ++---- esphome/components/ssd1331_base/ssd1331_base.cpp | 6 ++---- esphome/components/ssd1331_base/ssd1331_base.h | 6 ++---- esphome/components/ssd1331_spi/ssd1331_spi.cpp | 6 ++---- esphome/components/ssd1331_spi/ssd1331_spi.h | 6 ++---- esphome/components/ssd1351_base/ssd1351_base.cpp | 6 ++---- esphome/components/ssd1351_base/ssd1351_base.h | 6 ++---- esphome/components/ssd1351_spi/ssd1351_spi.cpp | 6 ++---- esphome/components/ssd1351_spi/ssd1351_spi.h | 6 ++---- esphome/components/st7567_base/st7567_base.cpp | 6 ++---- esphome/components/st7567_base/st7567_base.h | 6 ++---- esphome/components/st7567_i2c/st7567_i2c.cpp | 6 ++---- esphome/components/st7567_i2c/st7567_i2c.h | 6 ++---- esphome/components/st7567_spi/st7567_spi.cpp | 6 ++---- esphome/components/st7567_spi/st7567_spi.h | 6 ++---- esphome/components/st7735/st7735.cpp | 6 ++---- esphome/components/st7735/st7735.h | 6 ++---- esphome/components/st7789v/st7789v.cpp | 6 ++---- esphome/components/st7789v/st7789v.h | 6 ++---- esphome/components/st7920/st7920.cpp | 6 ++---- esphome/components/st7920/st7920.h | 6 ++---- esphome/components/statsd/statsd.cpp | 8 ++++---- esphome/components/statsd/statsd.h | 7 +++---- esphome/components/status_led/light/status_led_light.cpp | 6 ++---- esphome/components/status_led/light/status_led_light.h | 6 ++---- esphome/components/status_led/status_led.cpp | 6 ++---- esphome/components/status_led/status_led.h | 6 ++---- esphome/components/stepper/stepper.cpp | 6 ++---- esphome/components/stepper/stepper.h | 6 ++---- esphome/components/sts3x/sts3x.cpp | 6 ++---- esphome/components/sts3x/sts3x.h | 6 ++---- esphome/components/sun/sensor/sun_sensor.cpp | 6 ++---- esphome/components/sun/sensor/sun_sensor.h | 6 ++---- esphome/components/sun/sun.cpp | 6 ++---- esphome/components/sun/sun.h | 6 ++---- esphome/components/sun/text_sensor/sun_text_sensor.cpp | 6 ++---- esphome/components/sun/text_sensor/sun_text_sensor.h | 6 ++---- esphome/components/sun_gtil2/sun_gtil2.cpp | 6 ++---- esphome/components/sun_gtil2/sun_gtil2.h | 6 ++---- esphome/components/sx126x/automation.h | 6 ++---- .../sx126x/packet_transport/sx126x_transport.cpp | 6 ++---- .../components/sx126x/packet_transport/sx126x_transport.h | 6 ++---- esphome/components/sx126x/sx126x.cpp | 6 ++---- esphome/components/sx126x/sx126x.h | 6 ++---- esphome/components/sx126x/sx126x_reg.h | 6 ++---- esphome/components/sx127x/automation.h | 6 ++---- .../sx127x/packet_transport/sx127x_transport.cpp | 6 ++---- .../components/sx127x/packet_transport/sx127x_transport.h | 6 ++---- esphome/components/sx127x/sx127x.cpp | 6 ++---- esphome/components/sx127x/sx127x.h | 6 ++---- esphome/components/sx127x/sx127x_reg.h | 6 ++---- .../sx1509/binary_sensor/sx1509_binary_keypad_sensor.h | 6 ++---- esphome/components/sx1509/output/sx1509_float_output.cpp | 6 ++---- esphome/components/sx1509/output/sx1509_float_output.h | 6 ++---- esphome/components/sx1509/sx1509.cpp | 6 ++---- esphome/components/sx1509/sx1509.h | 6 ++---- esphome/components/sx1509/sx1509_gpio_pin.cpp | 6 ++---- esphome/components/sx1509/sx1509_gpio_pin.h | 6 ++---- esphome/components/sx1509/sx1509_registers.h | 6 ++---- 227 files changed, 459 insertions(+), 908 deletions(-) diff --git a/esphome/components/safe_mode/button/safe_mode_button.cpp b/esphome/components/safe_mode/button/safe_mode_button.cpp index bb5b64daf76..04203854fb5 100644 --- a/esphome/components/safe_mode/button/safe_mode_button.cpp +++ b/esphome/components/safe_mode/button/safe_mode_button.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace safe_mode { +namespace esphome::safe_mode { static const char *const TAG = "safe_mode.button"; @@ -23,5 +22,4 @@ void SafeModeButton::press_action() { void SafeModeButton::dump_config() { LOG_BUTTON("", "Safe Mode Button", this); } -} // namespace safe_mode -} // namespace esphome +} // namespace esphome::safe_mode diff --git a/esphome/components/safe_mode/button/safe_mode_button.h b/esphome/components/safe_mode/button/safe_mode_button.h index 0307a81febd..6012bb2aebd 100644 --- a/esphome/components/safe_mode/button/safe_mode_button.h +++ b/esphome/components/safe_mode/button/safe_mode_button.h @@ -4,8 +4,7 @@ #include "esphome/components/safe_mode/safe_mode.h" #include "esphome/core/component.h" -namespace esphome { -namespace safe_mode { +namespace esphome::safe_mode { class SafeModeButton final : public button::Button, public Component { public: @@ -17,5 +16,4 @@ class SafeModeButton final : public button::Button, public Component { void press_action() override; }; -} // namespace safe_mode -} // namespace esphome +} // namespace esphome::safe_mode diff --git a/esphome/components/safe_mode/switch/safe_mode_switch.cpp b/esphome/components/safe_mode/switch/safe_mode_switch.cpp index 1637da3059d..f513465db0d 100644 --- a/esphome/components/safe_mode/switch/safe_mode_switch.cpp +++ b/esphome/components/safe_mode/switch/safe_mode_switch.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace safe_mode { +namespace esphome::safe_mode { static const char *const TAG = "safe_mode.switch"; @@ -28,5 +27,4 @@ void SafeModeSwitch::write_state(bool state) { void SafeModeSwitch::dump_config() { LOG_SWITCH("", "Safe Mode Switch", this); } -} // namespace safe_mode -} // namespace esphome +} // namespace esphome::safe_mode diff --git a/esphome/components/safe_mode/switch/safe_mode_switch.h b/esphome/components/safe_mode/switch/safe_mode_switch.h index 24e660c8032..c73a2087d79 100644 --- a/esphome/components/safe_mode/switch/safe_mode_switch.h +++ b/esphome/components/safe_mode/switch/safe_mode_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "esphome/core/component.h" -namespace esphome { -namespace safe_mode { +namespace esphome::safe_mode { class SafeModeSwitch : public switch_::Switch, public Component { public: @@ -17,5 +16,4 @@ class SafeModeSwitch : public switch_::Switch, public Component { void write_state(bool state) override; }; -} // namespace safe_mode -} // namespace esphome +} // namespace esphome::safe_mode diff --git a/esphome/components/scd30/automation.h b/esphome/components/scd30/automation.h index 1f89e7c8159..1f047398933 100644 --- a/esphome/components/scd30/automation.h +++ b/esphome/components/scd30/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "scd30.h" -namespace esphome { -namespace scd30 { +namespace esphome::scd30 { template class ForceRecalibrationWithReference : public Action, public Parented { public: @@ -19,5 +18,4 @@ template class ForceRecalibrationWithReference : public Action #endif -namespace esphome { -namespace scd30 { +namespace esphome::scd30 { static const char *const TAG = "scd30"; @@ -230,5 +229,4 @@ uint16_t SCD30Component::get_forced_calibration_reference() { return forced_calibration_reference; } -} // namespace scd30 -} // namespace esphome +} // namespace esphome::scd30 diff --git a/esphome/components/scd30/scd30.h b/esphome/components/scd30/scd30.h index ed3f5e7e9aa..a5a5df1903a 100644 --- a/esphome/components/scd30/scd30.h +++ b/esphome/components/scd30/scd30.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace scd30 { +namespace esphome::scd30 { /// This class implements support for the Sensirion scd30 i2c GAS (VOC and CO2eq) sensors. class SCD30Component : public Component, public sensirion_common::SensirionI2CDevice { @@ -48,5 +47,4 @@ class SCD30Component : public Component, public sensirion_common::SensirionI2CDe sensor::Sensor *temperature_sensor_{nullptr}; }; -} // namespace scd30 -} // namespace esphome +} // namespace esphome::scd30 diff --git a/esphome/components/scd4x/automation.h b/esphome/components/scd4x/automation.h index 6ce14685770..e485289c95b 100644 --- a/esphome/components/scd4x/automation.h +++ b/esphome/components/scd4x/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "scd4x.h" -namespace esphome { -namespace scd4x { +namespace esphome::scd4x { template class PerformForcedCalibrationAction : public Action, public Parented { public: @@ -24,5 +23,4 @@ template class FactoryResetAction : public Action, public void play(const Ts &...x) override { this->parent_->factory_reset(); } }; -} // namespace scd4x -} // namespace esphome +} // namespace esphome::scd4x diff --git a/esphome/components/scd4x/scd4x.cpp b/esphome/components/scd4x/scd4x.cpp index 0c108fba9d6..d9a2439bb90 100644 --- a/esphome/components/scd4x/scd4x.cpp +++ b/esphome/components/scd4x/scd4x.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace scd4x { +namespace esphome::scd4x { static const char *const TAG = "scd4x"; @@ -324,5 +323,4 @@ bool SCD4XComponent::start_measurement_() { return false; } -} // namespace scd4x -} // namespace esphome +} // namespace esphome::scd4x diff --git a/esphome/components/scd4x/scd4x.h b/esphome/components/scd4x/scd4x.h index ab5d72aeec2..3e4827ef141 100644 --- a/esphome/components/scd4x/scd4x.h +++ b/esphome/components/scd4x/scd4x.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace scd4x { +namespace esphome::scd4x { enum ErrorCode : uint8_t { COMMUNICATION_FAILED, @@ -59,5 +58,4 @@ class SCD4XComponent : public PollingComponent, public sensirion_common::Sensiri MeasurementMode measurement_mode_{PERIODIC}; }; -} // namespace scd4x -} // namespace esphome +} // namespace esphome::scd4x diff --git a/esphome/components/script/script.cpp b/esphome/components/script/script.cpp index 81f652d26a0..61bca5bc281 100644 --- a/esphome/components/script/script.cpp +++ b/esphome/components/script/script.cpp @@ -1,8 +1,7 @@ #include "script.h" #include "esphome/core/log.h" -namespace esphome { -namespace script { +namespace esphome::script { static const char *const TAG = "script"; @@ -16,5 +15,4 @@ void ScriptLogger::esp_log_(int level, int line, const char *format, const char } #endif -} // namespace script -} // namespace esphome +} // namespace esphome::script diff --git a/esphome/components/script/script.h b/esphome/components/script/script.h index a0dffe26bf2..847fab02bd2 100644 --- a/esphome/components/script/script.h +++ b/esphome/components/script/script.h @@ -7,8 +7,8 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace script { + +namespace esphome::script { class ScriptLogger { protected: @@ -338,5 +338,4 @@ template class ScriptWaitAction : public Action, std::list> param_queue_; }; -} // namespace script -} // namespace esphome +} // namespace esphome::script diff --git a/esphome/components/sdm_meter/sdm_meter.cpp b/esphome/components/sdm_meter/sdm_meter.cpp index 12a3277269e..a4fe6e7d356 100644 --- a/esphome/components/sdm_meter/sdm_meter.cpp +++ b/esphome/components/sdm_meter/sdm_meter.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace sdm_meter { +namespace esphome::sdm_meter { static const char *const TAG = "sdm_meter"; @@ -110,5 +109,4 @@ void SDMMeter::dump_config() { LOG_SENSOR(" ", "Export Reactive Energy", this->export_reactive_energy_sensor_); } -} // namespace sdm_meter -} // namespace esphome +} // namespace esphome::sdm_meter diff --git a/esphome/components/sdm_meter/sdm_meter.h b/esphome/components/sdm_meter/sdm_meter.h index f8a3014a892..e729e29d6c0 100644 --- a/esphome/components/sdm_meter/sdm_meter.h +++ b/esphome/components/sdm_meter/sdm_meter.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace sdm_meter { +namespace esphome::sdm_meter { class SDMMeter : public PollingComponent, public modbus::ModbusDevice { public: @@ -79,5 +78,4 @@ class SDMMeter : public PollingComponent, public modbus::ModbusDevice { sensor::Sensor *export_reactive_energy_sensor_{nullptr}; }; -} // namespace sdm_meter -} // namespace esphome +} // namespace esphome::sdm_meter diff --git a/esphome/components/sdm_meter/sdm_meter_registers.h b/esphome/components/sdm_meter/sdm_meter_registers.h index dd981d6f003..b4b2855576c 100644 --- a/esphome/components/sdm_meter/sdm_meter_registers.h +++ b/esphome/components/sdm_meter/sdm_meter_registers.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace sdm_meter { +namespace esphome::sdm_meter { /* PHASE STATUS REGISTERS */ static const uint16_t SDM_PHASE_1_VOLTAGE = 0x0000; @@ -110,5 +109,4 @@ static const uint16_t SDM_CURRENT_RESETTABLE_EXPORT_ENERGY = 0x0186; static const uint16_t SDM_IMPORT_POWER = 0x0500; static const uint16_t SDM_EXPORT_POWER = 0x0502; -} // namespace sdm_meter -} // namespace esphome +} // namespace esphome::sdm_meter diff --git a/esphome/components/sdp3x/sdp3x.cpp b/esphome/components/sdp3x/sdp3x.cpp index 6f6cc1ebd8f..7fcd47a265e 100644 --- a/esphome/components/sdp3x/sdp3x.cpp +++ b/esphome/components/sdp3x/sdp3x.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace sdp3x { +namespace esphome::sdp3x { static const char *const TAG = "sdp3x.sensor"; static const uint16_t SDP3X_SOFT_RESET = 0x0006; @@ -114,5 +113,4 @@ void SDP3XComponent::read_pressure_() { this->status_clear_warning(); } -} // namespace sdp3x -} // namespace esphome +} // namespace esphome::sdp3x diff --git a/esphome/components/sdp3x/sdp3x.h b/esphome/components/sdp3x/sdp3x.h index afb58d47c8f..c4ef6a4a1e8 100644 --- a/esphome/components/sdp3x/sdp3x.h +++ b/esphome/components/sdp3x/sdp3x.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace sdp3x { +namespace esphome::sdp3x { enum MeasurementMode { MASS_FLOW_AVG, DP_AVG }; @@ -25,5 +24,4 @@ class SDP3XComponent : public PollingComponent, public sensirion_common::Sensiri MeasurementMode measurement_mode_; }; -} // namespace sdp3x -} // namespace esphome +} // namespace esphome::sdp3x diff --git a/esphome/components/sds011/sds011.cpp b/esphome/components/sds011/sds011.cpp index cdfd7544ad8..b1f89f18bfa 100644 --- a/esphome/components/sds011/sds011.cpp +++ b/esphome/components/sds011/sds011.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace sds011 { +namespace esphome::sds011 { static const char *const TAG = "sds011"; @@ -184,5 +183,4 @@ void SDS011Component::set_update_interval_min(uint8_t update_interval_min) { this->update_interval_min_ = update_interval_min; } -} // namespace sds011 -} // namespace esphome +} // namespace esphome::sds011 diff --git a/esphome/components/sds011/sds011.h b/esphome/components/sds011/sds011.h index d65299c6350..56d46d118f8 100644 --- a/esphome/components/sds011/sds011.h +++ b/esphome/components/sds011/sds011.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace sds011 { +namespace esphome::sds011 { class SDS011Component : public Component, public uart::UARTDevice { public: @@ -44,5 +43,4 @@ class SDS011Component : public Component, public uart::UARTDevice { bool rx_mode_only_; }; -} // namespace sds011 -} // namespace esphome +} // namespace esphome::sds011 diff --git a/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.cpp b/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.cpp index 0ae88892479..aec940dd22e 100644 --- a/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.cpp +++ b/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.cpp @@ -1,9 +1,7 @@ #include "custom_mode_end_button.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { void CustomSetEndButton::press_action() { this->parent_->set_custom_end_mode(); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.h b/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.h index a1701d8581b..bc98bb93b68 100644 --- a/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.h +++ b/esphome/components/seeed_mr24hpc1/button/custom_mode_end_button.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class CustomSetEndButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class CustomSetEndButton : public button::Button, public Parentedparent_->set_restart(); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/button/restart_button.h b/esphome/components/seeed_mr24hpc1/button/restart_button.h index 8a2ec2087ca..49a4f46138e 100644 --- a/esphome/components/seeed_mr24hpc1/button/restart_button.h +++ b/esphome/components/seeed_mr24hpc1/button/restart_button.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class RestartButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class RestartButton : public button::Button, public Parented void press_action() override; }; -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/custom_mode_number.cpp b/esphome/components/seeed_mr24hpc1/number/custom_mode_number.cpp index 0aebd8fb9fe..08a8076e227 100644 --- a/esphome/components/seeed_mr24hpc1/number/custom_mode_number.cpp +++ b/esphome/components/seeed_mr24hpc1/number/custom_mode_number.cpp @@ -1,12 +1,10 @@ #include "custom_mode_number.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { void CustomModeNumber::control(float value) { this->publish_state(value); this->parent_->set_custom_mode(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/custom_mode_number.h b/esphome/components/seeed_mr24hpc1/number/custom_mode_number.h index 40ff3f201ac..f51e592fc00 100644 --- a/esphome/components/seeed_mr24hpc1/number/custom_mode_number.h +++ b/esphome/components/seeed_mr24hpc1/number/custom_mode_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class CustomModeNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class CustomModeNumber : public number::Number, public Parentedparent_->set_custom_unman_time(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/custom_unman_time_number.h b/esphome/components/seeed_mr24hpc1/number/custom_unman_time_number.h index 6b871c4c134..281e727a365 100644 --- a/esphome/components/seeed_mr24hpc1/number/custom_unman_time_number.h +++ b/esphome/components/seeed_mr24hpc1/number/custom_unman_time_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class CustomUnmanTimeNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class CustomUnmanTimeNumber : public number::Number, public Parentedparent_->set_existence_threshold(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/existence_threshold_number.h b/esphome/components/seeed_mr24hpc1/number/existence_threshold_number.h index 656bad17deb..c811b2d6b69 100644 --- a/esphome/components/seeed_mr24hpc1/number/existence_threshold_number.h +++ b/esphome/components/seeed_mr24hpc1/number/existence_threshold_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class ExistenceThresholdNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class ExistenceThresholdNumber : public number::Number, public Parentedparent_->set_motion_threshold(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/motion_threshold_number.h b/esphome/components/seeed_mr24hpc1/number/motion_threshold_number.h index e8ae37b96f0..748119f1985 100644 --- a/esphome/components/seeed_mr24hpc1/number/motion_threshold_number.h +++ b/esphome/components/seeed_mr24hpc1/number/motion_threshold_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class MotionThresholdNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class MotionThresholdNumber : public number::Number, public Parentedparent_->set_motion_trigger_time(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/motion_trigger_time_number.h b/esphome/components/seeed_mr24hpc1/number/motion_trigger_time_number.h index 996356e2371..dd7947b2a5a 100644 --- a/esphome/components/seeed_mr24hpc1/number/motion_trigger_time_number.h +++ b/esphome/components/seeed_mr24hpc1/number/motion_trigger_time_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class MotionTriggerTimeNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class MotionTriggerTimeNumber : public number::Number, public Parentedparent_->set_motion_to_rest_time(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/motiontorest_time_number.h b/esphome/components/seeed_mr24hpc1/number/motiontorest_time_number.h index 559d23fdeb7..47493e79542 100644 --- a/esphome/components/seeed_mr24hpc1/number/motiontorest_time_number.h +++ b/esphome/components/seeed_mr24hpc1/number/motiontorest_time_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class MotionToRestTimeNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class MotionToRestTimeNumber : public number::Number, public Parentedparent_->set_sensitivity(value); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/number/sensitivity_number.h b/esphome/components/seeed_mr24hpc1/number/sensitivity_number.h index fee33521d04..c1d54351517 100644 --- a/esphome/components/seeed_mr24hpc1/number/sensitivity_number.h +++ b/esphome/components/seeed_mr24hpc1/number/sensitivity_number.h @@ -3,8 +3,7 @@ #include "esphome/components/number/number.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class SensitivityNumber : public number::Number, public Parented { public: @@ -14,5 +13,4 @@ class SensitivityNumber : public number::Number, public Parented -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { static const char *const TAG = "seeed_mr24hpc1"; @@ -1002,5 +1001,4 @@ void MR24HPC1Component::set_custom_unman_time(uint16_t value) { this->get_custom_unman_time(); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h index 8fc61ad37c7..b62504ba0eb 100644 --- a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h +++ b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1.h @@ -30,8 +30,7 @@ #include -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { enum FrameState { FRAME_IDLE, @@ -213,5 +212,4 @@ class MR24HPC1Component : public Component, void set_custom_unman_time(uint16_t value); }; -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1_constants.h b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1_constants.h index dafc6c03680..7ed7e1db940 100644 --- a/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1_constants.h +++ b/esphome/components/seeed_mr24hpc1/seeed_mr24hpc1_constants.h @@ -2,8 +2,7 @@ #include -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { static const uint8_t FRAME_BUF_MAX_SIZE = 128; static const uint8_t PRODUCT_BUF_MAX_SIZE = 32; @@ -169,5 +168,4 @@ static const uint8_t GET_KEEP_AWAY[] = { FRAME_TAIL1_VALUE, FRAME_TAIL2_VALUE, }; -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.cpp b/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.cpp index 81543055a48..af01152e487 100644 --- a/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.cpp +++ b/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.cpp @@ -1,12 +1,10 @@ #include "existence_boundary_select.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { void ExistenceBoundarySelect::control(size_t index) { this->publish_state(index); this->parent_->set_existence_boundary(index); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.h b/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.h index 933279dd13e..878d0525c90 100644 --- a/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.h +++ b/esphome/components/seeed_mr24hpc1/select/existence_boundary_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class ExistenceBoundarySelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class ExistenceBoundarySelect : public select::Select, public Parentedpublish_state(index); this->parent_->set_motion_boundary(index); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/select/motion_boundary_select.h b/esphome/components/seeed_mr24hpc1/select/motion_boundary_select.h index b0051ae6b15..eecdef2019f 100644 --- a/esphome/components/seeed_mr24hpc1/select/motion_boundary_select.h +++ b/esphome/components/seeed_mr24hpc1/select/motion_boundary_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class MotionBoundarySelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class MotionBoundarySelect : public select::Select, public Parentedpublish_state(index); this->parent_->set_scene_mode(index); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/select/scene_mode_select.h b/esphome/components/seeed_mr24hpc1/select/scene_mode_select.h index f478ea5b669..377c61b32f4 100644 --- a/esphome/components/seeed_mr24hpc1/select/scene_mode_select.h +++ b/esphome/components/seeed_mr24hpc1/select/scene_mode_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class SceneModeSelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class SceneModeSelect : public select::Select, public Parentedpublish_state(index); this->parent_->set_unman_time(index); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/select/unman_time_select.h b/esphome/components/seeed_mr24hpc1/select/unman_time_select.h index a64ff4b8406..e68ae5e54fd 100644 --- a/esphome/components/seeed_mr24hpc1/select/unman_time_select.h +++ b/esphome/components/seeed_mr24hpc1/select/unman_time_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class UnmanTimeSelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class UnmanTimeSelect : public select::Select, public Parentedpublish_state(state); this->parent_->set_underlying_open_function(state); } -} // namespace seeed_mr24hpc1 -} // namespace esphome +} // namespace esphome::seeed_mr24hpc1 diff --git a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h b/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h index 1baabb25ce7..3224640ce7b 100644 --- a/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h +++ b/esphome/components/seeed_mr24hpc1/switch/underlyFuc_switch.h @@ -3,8 +3,7 @@ #include "esphome/components/switch/switch.h" #include "../seeed_mr24hpc1.h" -namespace esphome { -namespace seeed_mr24hpc1 { +namespace esphome::seeed_mr24hpc1 { class UnderlyOpenFunctionSwitch : public switch_::Switch, public Parented { public: @@ -14,5 +13,4 @@ class UnderlyOpenFunctionSwitch : public switch_::Switch, public Parented #include -namespace esphome { -namespace seeed_mr60bha2 { +namespace esphome::seeed_mr60bha2 { static const char *const TAG = "seeed_mr60bha2"; @@ -219,5 +218,4 @@ void MR60BHA2Component::process_frame_(uint16_t frame_id, uint16_t frame_type, c } } -} // namespace seeed_mr60bha2 -} // namespace esphome +} // namespace esphome::seeed_mr60bha2 diff --git a/esphome/components/seeed_mr60bha2/seeed_mr60bha2.h b/esphome/components/seeed_mr60bha2/seeed_mr60bha2.h index d20c8e50cc0..008acc6a57d 100644 --- a/esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +++ b/esphome/components/seeed_mr60bha2/seeed_mr60bha2.h @@ -13,8 +13,7 @@ #include -namespace esphome { -namespace seeed_mr60bha2 { +namespace esphome::seeed_mr60bha2 { static const uint8_t FRAME_HEADER_BUFFER = 0x01; static const uint16_t BREATH_RATE_TYPE_BUFFER = 0x0A14; static const uint16_t PEOPLE_EXIST_TYPE_BUFFER = 0x0F09; @@ -46,5 +45,4 @@ class MR60BHA2Component : public Component, std::vector rx_message_; }; -} // namespace seeed_mr60bha2 -} // namespace esphome +} // namespace esphome::seeed_mr60bha2 diff --git a/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.cpp b/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.cpp index 88be6dfe7c6..c377128fe6f 100644 --- a/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.cpp +++ b/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.cpp @@ -1,9 +1,7 @@ #include "get_radar_parameters_button.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { void GetRadarParametersButton::press_action() { this->parent_->get_radar_parameters(); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.h b/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.h index 9d6d507383a..c1b96d5f083 100644 --- a/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.h +++ b/esphome/components/seeed_mr60fda2/button/get_radar_parameters_button.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../seeed_mr60fda2.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { class GetRadarParametersButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class GetRadarParametersButton : public button::Button, public Parentedparent_->factory_reset(); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/button/reset_radar_button.h b/esphome/components/seeed_mr60fda2/button/reset_radar_button.h index 66780fb8af8..174ef5425e5 100644 --- a/esphome/components/seeed_mr60fda2/button/reset_radar_button.h +++ b/esphome/components/seeed_mr60fda2/button/reset_radar_button.h @@ -3,8 +3,7 @@ #include "esphome/components/button/button.h" #include "../seeed_mr60fda2.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { class ResetRadarButton : public button::Button, public Parented { public: @@ -14,5 +13,4 @@ class ResetRadarButton : public button::Button, public Parented #include -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { static const char *const TAG = "seeed_mr60fda2"; @@ -393,5 +392,4 @@ void MR60FDA2Component::factory_reset() { this->get_radar_parameters(); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h index e1ffa4f0715..0e97447074f 100644 --- a/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h +++ b/esphome/components/seeed_mr60fda2/seeed_mr60fda2.h @@ -19,8 +19,7 @@ #include -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { static const uint8_t DATA_BUF_MAX_SIZE = 28; static const uint8_t FRAME_BUF_MAX_SIZE = 37; @@ -97,5 +96,4 @@ class MR60FDA2Component : public Component, void factory_reset(); }; -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/select/height_threshold_select.cpp b/esphome/components/seeed_mr60fda2/select/height_threshold_select.cpp index c963ccdadd4..09cb9c4c1c4 100644 --- a/esphome/components/seeed_mr60fda2/select/height_threshold_select.cpp +++ b/esphome/components/seeed_mr60fda2/select/height_threshold_select.cpp @@ -1,12 +1,10 @@ #include "height_threshold_select.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { void HeightThresholdSelect::control(size_t index) { this->publish_state(index); this->parent_->set_height_threshold(index); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/select/height_threshold_select.h b/esphome/components/seeed_mr60fda2/select/height_threshold_select.h index f5707c7a880..0e495766588 100644 --- a/esphome/components/seeed_mr60fda2/select/height_threshold_select.h +++ b/esphome/components/seeed_mr60fda2/select/height_threshold_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr60fda2.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { class HeightThresholdSelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class HeightThresholdSelect : public select::Select, public Parentedpublish_state(index); this->parent_->set_install_height(index); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/select/install_height_select.h b/esphome/components/seeed_mr60fda2/select/install_height_select.h index 470d96c50cd..c1e2a3eeb1e 100644 --- a/esphome/components/seeed_mr60fda2/select/install_height_select.h +++ b/esphome/components/seeed_mr60fda2/select/install_height_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr60fda2.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { class InstallHeightSelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class InstallHeightSelect : public select::Select, public Parentedpublish_state(index); this->parent_->set_sensitivity(index); } -} // namespace seeed_mr60fda2 -} // namespace esphome +} // namespace esphome::seeed_mr60fda2 diff --git a/esphome/components/seeed_mr60fda2/select/sensitivity_select.h b/esphome/components/seeed_mr60fda2/select/sensitivity_select.h index 82ed4c5d79b..f2e0307dc10 100644 --- a/esphome/components/seeed_mr60fda2/select/sensitivity_select.h +++ b/esphome/components/seeed_mr60fda2/select/sensitivity_select.h @@ -3,8 +3,7 @@ #include "esphome/components/select/select.h" #include "../seeed_mr60fda2.h" -namespace esphome { -namespace seeed_mr60fda2 { +namespace esphome::seeed_mr60fda2 { class SensitivitySelect : public select::Select, public Parented { public: @@ -14,5 +13,4 @@ class SensitivitySelect : public select::Select, public Parentedmaximum_demand_apparent_power_sensor_); } -} // namespace selec_meter -} // namespace esphome +} // namespace esphome::selec_meter diff --git a/esphome/components/selec_meter/selec_meter.h b/esphome/components/selec_meter/selec_meter.h index 730791c91b2..159acab124f 100644 --- a/esphome/components/selec_meter/selec_meter.h +++ b/esphome/components/selec_meter/selec_meter.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace selec_meter { +namespace esphome::selec_meter { #define SELEC_METER_SENSOR(name) \ protected: \ @@ -43,5 +42,4 @@ class SelecMeter : public PollingComponent, public modbus::ModbusDevice { void dump_config() override; }; -} // namespace selec_meter -} // namespace esphome +} // namespace esphome::selec_meter diff --git a/esphome/components/selec_meter/selec_meter_registers.h b/esphome/components/selec_meter/selec_meter_registers.h index dfaf65ff083..d299560aaba 100644 --- a/esphome/components/selec_meter/selec_meter_registers.h +++ b/esphome/components/selec_meter/selec_meter_registers.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace selec_meter { +namespace esphome::selec_meter { static const float TWO_DEC_UNIT = 0.01; static const float ONE_DEC_UNIT = 0.1; @@ -28,5 +27,4 @@ static const uint16_t SELEC_MAXIMUM_DEMAND_ACTIVE_POWER = 0x001C; static const uint16_t SELEC_MAXIMUM_DEMAND_REACTIVE_POWER = 0x001E; static const uint16_t SELEC_MAXIMUM_DEMAND_APPARENT_POWER = 0x0020; -} // namespace selec_meter -} // namespace esphome +} // namespace esphome::selec_meter diff --git a/esphome/components/sen0321/sen0321.cpp b/esphome/components/sen0321/sen0321.cpp index 6a5931272dc..e074934d0f0 100644 --- a/esphome/components/sen0321/sen0321.cpp +++ b/esphome/components/sen0321/sen0321.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace sen0321_sensor { +namespace esphome::sen0321_sensor { static const char *const TAG = "sen0321_sensor.sensor"; @@ -31,5 +30,4 @@ void Sen0321Sensor::read_data_() { this->publish_state(((uint16_t) (result[0] << 8) + result[1])); } -} // namespace sen0321_sensor -} // namespace esphome +} // namespace esphome::sen0321_sensor diff --git a/esphome/components/sen0321/sen0321.h b/esphome/components/sen0321/sen0321.h index 3bb3d5b0154..6d5aa20a610 100644 --- a/esphome/components/sen0321/sen0321.h +++ b/esphome/components/sen0321/sen0321.h @@ -7,8 +7,7 @@ // ref: // https://github.com/DFRobot/DFRobot_OzoneSensor -namespace esphome { -namespace sen0321_sensor { +namespace esphome::sen0321_sensor { // Sensor Mode // While passive is supposedly supported, it does not appear to work reliably. static const uint8_t SENSOR_MODE_REGISTER = 0x03; @@ -31,5 +30,4 @@ class Sen0321Sensor : public sensor::Sensor, public PollingComponent, public i2c void read_data_(); }; -} // namespace sen0321_sensor -} // namespace esphome +} // namespace esphome::sen0321_sensor diff --git a/esphome/components/sen21231/sen21231.cpp b/esphome/components/sen21231/sen21231.cpp index 8c9f3d71346..b42ba2fa1dc 100644 --- a/esphome/components/sen21231/sen21231.cpp +++ b/esphome/components/sen21231/sen21231.cpp @@ -1,8 +1,7 @@ #include "sen21231.h" #include "esphome/core/log.h" -namespace esphome { -namespace sen21231_sensor { +namespace esphome::sen21231_sensor { static const char *const TAG = "sen21231_sensor.sensor"; @@ -33,5 +32,4 @@ void Sen21231Sensor::read_data_() { } } -} // namespace sen21231_sensor -} // namespace esphome +} // namespace esphome::sen21231_sensor diff --git a/esphome/components/sen21231/sen21231.h b/esphome/components/sen21231/sen21231.h index b4d540df556..486a9473d2d 100644 --- a/esphome/components/sen21231/sen21231.h +++ b/esphome/components/sen21231/sen21231.h @@ -7,8 +7,7 @@ // ref: // https://github.com/usefulsensors/person_sensor_pico_c/blob/main/person_sensor.h -namespace esphome { -namespace sen21231_sensor { +namespace esphome::sen21231_sensor { // The I2C address of the person sensor board. static const uint8_t PERSON_SENSOR_I2C_ADDRESS = 0x62; static const uint8_t PERSON_SENSOR_REG_MODE = 0x01; @@ -73,5 +72,4 @@ class Sen21231Sensor : public sensor::Sensor, public PollingComponent, public i2 void read_data_(); }; -} // namespace sen21231_sensor -} // namespace esphome +} // namespace esphome::sen21231_sensor diff --git a/esphome/components/sen5x/automation.h b/esphome/components/sen5x/automation.h index 558ea46e47f..e6111f4a8fa 100644 --- a/esphome/components/sen5x/automation.h +++ b/esphome/components/sen5x/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "sen5x.h" -namespace esphome { -namespace sen5x { +namespace esphome::sen5x { template class StartFanAction : public Action { public: @@ -17,5 +16,4 @@ template class StartFanAction : public Action { SEN5XComponent *sen5x_; }; -} // namespace sen5x -} // namespace esphome +} // namespace esphome::sen5x diff --git a/esphome/components/sen5x/sen5x.cpp b/esphome/components/sen5x/sen5x.cpp index 09dda8bca46..588650e6307 100644 --- a/esphome/components/sen5x/sen5x.cpp +++ b/esphome/components/sen5x/sen5x.cpp @@ -5,8 +5,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace sen5x { +namespace esphome::sen5x { static const char *const TAG = "sen5x"; @@ -423,5 +422,4 @@ bool SEN5XComponent::start_fan_cleaning() { return true; } -} // namespace sen5x -} // namespace esphome +} // namespace esphome::sen5x diff --git a/esphome/components/sen5x/sen5x.h b/esphome/components/sen5x/sen5x.h index a9d4da86b89..ec8f9cc5447 100644 --- a/esphome/components/sen5x/sen5x.h +++ b/esphome/components/sen5x/sen5x.h @@ -6,8 +6,7 @@ #include "esphome/core/application.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace sen5x { +namespace esphome::sen5x { enum ERRORCODE : uint8_t { COMMUNICATION_FAILED, @@ -130,5 +129,4 @@ class SEN5XComponent : public PollingComponent, public sensirion_common::Sensiri ESPPreferenceObject pref_; }; -} // namespace sen5x -} // namespace esphome +} // namespace esphome::sen5x diff --git a/esphome/components/senseair/senseair.cpp b/esphome/components/senseair/senseair.cpp index 84520d407dd..8ed9fbb53b0 100644 --- a/esphome/components/senseair/senseair.cpp +++ b/esphome/components/senseair/senseair.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace senseair { +namespace esphome::senseair { static const char *const TAG = "senseair"; static const uint8_t SENSEAIR_REQUEST_LENGTH = 8; @@ -150,5 +149,4 @@ void SenseAirComponent::dump_config() { this->check_uart_settings(9600); } -} // namespace senseair -} // namespace esphome +} // namespace esphome::senseair diff --git a/esphome/components/senseair/senseair.h b/esphome/components/senseair/senseair.h index 9db849075d9..333c003f48d 100644 --- a/esphome/components/senseair/senseair.h +++ b/esphome/components/senseair/senseair.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace senseair { +namespace esphome::senseair { enum SenseAirStatus : uint8_t { FATAL_ERROR = 1 << 0, @@ -88,5 +87,4 @@ template class SenseAirABCGetPeriodAction : public Action SenseAirComponent *senseair_; }; -} // namespace senseair -} // namespace esphome +} // namespace esphome::senseair diff --git a/esphome/components/sensirion_common/i2c_sensirion.cpp b/esphome/components/sensirion_common/i2c_sensirion.cpp index 6e244faf596..f6ff4711d40 100644 --- a/esphome/components/sensirion_common/i2c_sensirion.cpp +++ b/esphome/components/sensirion_common/i2c_sensirion.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace sensirion_common { +namespace esphome::sensirion_common { static const char *const TAG = "sensirion_i2c"; // To avoid memory allocations for small writes a stack buffer is used @@ -79,5 +78,4 @@ bool SensirionI2CDevice::get_register_(uint16_t reg, CommandLen command_len, uin return result; } -} // namespace sensirion_common -} // namespace esphome +} // namespace esphome::sensirion_common diff --git a/esphome/components/sensirion_common/i2c_sensirion.h b/esphome/components/sensirion_common/i2c_sensirion.h index 3c2c14ccb81..558fbdbb129 100644 --- a/esphome/components/sensirion_common/i2c_sensirion.h +++ b/esphome/components/sensirion_common/i2c_sensirion.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace sensirion_common { +namespace esphome::sensirion_common { /** * Implementation of I2C functions for Sensirion sensors @@ -149,5 +148,4 @@ class SensirionI2CDevice : public i2c::I2CDevice { i2c::ErrorCode last_error_; }; -} // namespace sensirion_common -} // namespace esphome +} // namespace esphome::sensirion_common diff --git a/esphome/components/servo/servo.cpp b/esphome/components/servo/servo.cpp index b4511de2d0f..d2028ce9bdf 100644 --- a/esphome/components/servo/servo.cpp +++ b/esphome/components/servo/servo.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace servo { +namespace esphome::servo { static const char *const TAG = "servo"; @@ -106,5 +105,4 @@ void Servo::save_level_(float v) { this->rtc_.save(&v); } -} // namespace servo -} // namespace esphome +} // namespace esphome::servo diff --git a/esphome/components/servo/servo.h b/esphome/components/servo/servo.h index 3d15aefefec..31e93579471 100644 --- a/esphome/components/servo/servo.h +++ b/esphome/components/servo/servo.h @@ -6,8 +6,7 @@ #include "esphome/core/preferences.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace servo { +namespace esphome::servo { extern uint32_t global_servo_id; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) @@ -73,5 +72,4 @@ template class ServoDetachAction : public Action { Servo *servo_; }; -} // namespace servo -} // namespace esphome +} // namespace esphome::servo diff --git a/esphome/components/sfa30/sfa30.cpp b/esphome/components/sfa30/sfa30.cpp index bbe3bcd7d28..960806e98b0 100644 --- a/esphome/components/sfa30/sfa30.cpp +++ b/esphome/components/sfa30/sfa30.cpp @@ -1,8 +1,7 @@ #include "sfa30.h" #include "esphome/core/log.h" -namespace esphome { -namespace sfa30 { +namespace esphome::sfa30 { static const char *const TAG = "sfa30"; @@ -91,5 +90,4 @@ void SFA30Component::update() { }); } -} // namespace sfa30 -} // namespace esphome +} // namespace esphome::sfa30 diff --git a/esphome/components/sfa30/sfa30.h b/esphome/components/sfa30/sfa30.h index 2b744b8da43..d2f2520a576 100644 --- a/esphome/components/sfa30/sfa30.h +++ b/esphome/components/sfa30/sfa30.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace sfa30 { +namespace esphome::sfa30 { class SFA30Component : public PollingComponent, public sensirion_common::SensirionI2CDevice { enum ErrorCode { DEVICE_MARKING_READ_FAILED, MEASUREMENT_INIT_FAILED, UNKNOWN }; @@ -29,5 +28,4 @@ class SFA30Component : public PollingComponent, public sensirion_common::Sensiri sensor::Sensor *temperature_sensor_{nullptr}; }; -} // namespace sfa30 -} // namespace esphome +} // namespace esphome::sfa30 diff --git a/esphome/components/sgp30/sgp30.cpp b/esphome/components/sgp30/sgp30.cpp index 35e5b3dd42b..fd007c92cc8 100644 --- a/esphome/components/sgp30/sgp30.cpp +++ b/esphome/components/sgp30/sgp30.cpp @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace sgp30 { +namespace esphome::sgp30 { static const char *const TAG = "sgp30"; @@ -302,5 +301,4 @@ void SGP30Component::update() { }); } -} // namespace sgp30 -} // namespace esphome +} // namespace esphome::sgp30 diff --git a/esphome/components/sgp30/sgp30.h b/esphome/components/sgp30/sgp30.h index 4648a33e157..cb4aa1c1bb1 100644 --- a/esphome/components/sgp30/sgp30.h +++ b/esphome/components/sgp30/sgp30.h @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace sgp30 { +namespace esphome::sgp30 { struct SGP30Baselines { uint16_t eco2; @@ -67,5 +66,4 @@ class SGP30Component : public PollingComponent, public sensirion_common::Sensiri sensor::Sensor *temperature_sensor_{nullptr}; }; -} // namespace sgp30 -} // namespace esphome +} // namespace esphome::sgp30 diff --git a/esphome/components/sgp4x/sgp4x.cpp b/esphome/components/sgp4x/sgp4x.cpp index bbf1ffd4c09..94e6d69dcbd 100644 --- a/esphome/components/sgp4x/sgp4x.cpp +++ b/esphome/components/sgp4x/sgp4x.cpp @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace sgp4x { +namespace esphome::sgp4x { static const char *const TAG = "sgp4x"; @@ -290,5 +289,4 @@ void SGP4xComponent::dump_config() { LOG_SENSOR(" ", "NOx", this->nox_sensor_); } -} // namespace sgp4x -} // namespace esphome +} // namespace esphome::sgp4x diff --git a/esphome/components/sgp4x/sgp4x.h b/esphome/components/sgp4x/sgp4x.h index 6b8b598aff3..23bf6319a90 100644 --- a/esphome/components/sgp4x/sgp4x.h +++ b/esphome/components/sgp4x/sgp4x.h @@ -11,8 +11,7 @@ #include #include -namespace esphome { -namespace sgp4x { +namespace esphome::sgp4x { struct SGP4xBaselines { int32_t state0; @@ -134,5 +133,4 @@ class SGP4xComponent : public PollingComponent, public sensor::Sensor, public se uint32_t seconds_since_last_store_; SGP4xBaselines voc_baselines_storage_; }; -} // namespace sgp4x -} // namespace esphome +} // namespace esphome::sgp4x diff --git a/esphome/components/sht3xd/sht3xd.cpp b/esphome/components/sht3xd/sht3xd.cpp index 8050a2d5f97..eba6be65d58 100644 --- a/esphome/components/sht3xd/sht3xd.cpp +++ b/esphome/components/sht3xd/sht3xd.cpp @@ -1,8 +1,7 @@ #include "sht3xd.h" #include "esphome/core/log.h" -namespace esphome { -namespace sht3xd { +namespace esphome::sht3xd { static const char *const TAG = "sht3xd"; @@ -82,5 +81,4 @@ void SHT3XDComponent::update() { }); } -} // namespace sht3xd -} // namespace esphome +} // namespace esphome::sht3xd diff --git a/esphome/components/sht3xd/sht3xd.h b/esphome/components/sht3xd/sht3xd.h index 54514d6de73..6df5587507c 100644 --- a/esphome/components/sht3xd/sht3xd.h +++ b/esphome/components/sht3xd/sht3xd.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace sht3xd { +namespace esphome::sht3xd { /// This class implements support for the SHT3x-DIS family of temperature+humidity i2c sensors. class SHT3XDComponent : public PollingComponent, public sensirion_common::SensirionI2CDevice { @@ -25,5 +24,4 @@ class SHT3XDComponent : public PollingComponent, public sensirion_common::Sensir uint32_t serial_number_{0}; }; -} // namespace sht3xd -} // namespace esphome +} // namespace esphome::sht3xd diff --git a/esphome/components/sht4x/sht4x.cpp b/esphome/components/sht4x/sht4x.cpp index b1dbde22a4d..4a3df5a91f2 100644 --- a/esphome/components/sht4x/sht4x.cpp +++ b/esphome/components/sht4x/sht4x.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace sht4x { +namespace esphome::sht4x { static const char *const TAG = "sht4x"; @@ -127,5 +126,4 @@ void SHT4XComponent::update() { }); } -} // namespace sht4x -} // namespace esphome +} // namespace esphome::sht4x diff --git a/esphome/components/sht4x/sht4x.h b/esphome/components/sht4x/sht4x.h index 51f473fe3f2..d1fa9033df4 100644 --- a/esphome/components/sht4x/sht4x.h +++ b/esphome/components/sht4x/sht4x.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace sht4x { +namespace esphome::sht4x { enum SHT4XPRECISION { SHT4X_PRECISION_HIGH = 0, SHT4X_PRECISION_MED, SHT4X_PRECISION_LOW }; @@ -45,5 +44,4 @@ class SHT4XComponent : public PollingComponent, public sensirion_common::Sensiri sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace sht4x -} // namespace esphome +} // namespace esphome::sht4x diff --git a/esphome/components/shutdown/button/shutdown_button.cpp b/esphome/components/shutdown/button/shutdown_button.cpp index b40af7517b4..6394c6c14e6 100644 --- a/esphome/components/shutdown/button/shutdown_button.cpp +++ b/esphome/components/shutdown/button/shutdown_button.cpp @@ -10,8 +10,7 @@ #include #endif -namespace esphome { -namespace shutdown { +namespace esphome::shutdown { static const char *const TAG = "shutdown.button"; @@ -29,5 +28,4 @@ void ShutdownButton::press_action() { #endif } -} // namespace shutdown -} // namespace esphome +} // namespace esphome::shutdown diff --git a/esphome/components/shutdown/button/shutdown_button.h b/esphome/components/shutdown/button/shutdown_button.h index d0094c899d8..d4247ec0f98 100644 --- a/esphome/components/shutdown/button/shutdown_button.h +++ b/esphome/components/shutdown/button/shutdown_button.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/button/button.h" -namespace esphome { -namespace shutdown { +namespace esphome::shutdown { class ShutdownButton : public button::Button, public Component { public: @@ -14,5 +13,4 @@ class ShutdownButton : public button::Button, public Component { void press_action() override; }; -} // namespace shutdown -} // namespace esphome +} // namespace esphome::shutdown diff --git a/esphome/components/shutdown/switch/shutdown_switch.cpp b/esphome/components/shutdown/switch/shutdown_switch.cpp index b685ab14ab4..a44a572aa1c 100644 --- a/esphome/components/shutdown/switch/shutdown_switch.cpp +++ b/esphome/components/shutdown/switch/shutdown_switch.cpp @@ -10,8 +10,7 @@ #include #endif -namespace esphome { -namespace shutdown { +namespace esphome::shutdown { static const char *const TAG = "shutdown.switch"; @@ -34,5 +33,4 @@ void ShutdownSwitch::write_state(bool state) { } } -} // namespace shutdown -} // namespace esphome +} // namespace esphome::shutdown diff --git a/esphome/components/shutdown/switch/shutdown_switch.h b/esphome/components/shutdown/switch/shutdown_switch.h index 6aa64ff06b2..933345915ff 100644 --- a/esphome/components/shutdown/switch/shutdown_switch.h +++ b/esphome/components/shutdown/switch/shutdown_switch.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace shutdown { +namespace esphome::shutdown { class ShutdownSwitch : public switch_::Switch, public Component { public: @@ -14,5 +13,4 @@ class ShutdownSwitch : public switch_::Switch, public Component { void write_state(bool state) override; }; -} // namespace shutdown -} // namespace esphome +} // namespace esphome::shutdown diff --git a/esphome/components/sigma_delta_output/sigma_delta_output.cpp b/esphome/components/sigma_delta_output/sigma_delta_output.cpp index d386f8db1a5..6cc131c68ff 100644 --- a/esphome/components/sigma_delta_output/sigma_delta_output.cpp +++ b/esphome/components/sigma_delta_output/sigma_delta_output.cpp @@ -1,8 +1,7 @@ #include "sigma_delta_output.h" #include "esphome/core/log.h" -namespace esphome { -namespace sigma_delta_output { +namespace esphome::sigma_delta_output { static const char *const TAG = "output.sigma_delta"; @@ -53,5 +52,4 @@ void SigmaDeltaOutput::update() { } } -} // namespace sigma_delta_output -} // namespace esphome +} // namespace esphome::sigma_delta_output diff --git a/esphome/components/sigma_delta_output/sigma_delta_output.h b/esphome/components/sigma_delta_output/sigma_delta_output.h index 8fd1e1f761a..a5df3c6c7c2 100644 --- a/esphome/components/sigma_delta_output/sigma_delta_output.h +++ b/esphome/components/sigma_delta_output/sigma_delta_output.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace sigma_delta_output { +namespace esphome::sigma_delta_output { class SigmaDeltaOutput : public PollingComponent, public output::FloatOutput { public: @@ -43,5 +42,4 @@ class SigmaDeltaOutput : public PollingComponent, public output::FloatOutput { float state_{0.}; bool value_{false}; }; -} // namespace sigma_delta_output -} // namespace esphome +} // namespace esphome::sigma_delta_output diff --git a/esphome/components/sim800l/sim800l.cpp b/esphome/components/sim800l/sim800l.cpp index 001ec774546..b8e97b11211 100644 --- a/esphome/components/sim800l/sim800l.cpp +++ b/esphome/components/sim800l/sim800l.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace sim800l { +namespace esphome::sim800l { static const char *const TAG = "sim800l"; @@ -492,5 +491,4 @@ void Sim800LComponent::set_registered_(bool registered) { #endif } -} // namespace sim800l -} // namespace esphome +} // namespace esphome::sim800l diff --git a/esphome/components/sim800l/sim800l.h b/esphome/components/sim800l/sim800l.h index d0da1230398..0b3259ede00 100644 --- a/esphome/components/sim800l/sim800l.h +++ b/esphome/components/sim800l/sim800l.h @@ -13,8 +13,7 @@ #include "esphome/components/uart/uart.h" #include "esphome/core/automation.h" -namespace esphome { -namespace sim800l { +namespace esphome::sim800l { const uint16_t SIM800L_READ_BUFFER_LENGTH = 1024; @@ -184,5 +183,4 @@ template class Sim800LDisconnectAction : public Action { Sim800LComponent *parent_; }; -} // namespace sim800l -} // namespace esphome +} // namespace esphome::sim800l diff --git a/esphome/components/slow_pwm/slow_pwm_output.cpp b/esphome/components/slow_pwm/slow_pwm_output.cpp index 033729c407d..e695ab95403 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.cpp +++ b/esphome/components/slow_pwm/slow_pwm_output.cpp @@ -3,8 +3,7 @@ #include "esphome/core/gpio.h" #include "esphome/core/log.h" -namespace esphome { -namespace slow_pwm { +namespace esphome::slow_pwm { static const char *const TAG = "output.slow_pwm"; @@ -79,5 +78,4 @@ void SlowPWMOutput::write_state(float state) { this->restart_cycle(); } -} // namespace slow_pwm -} // namespace esphome +} // namespace esphome::slow_pwm diff --git a/esphome/components/slow_pwm/slow_pwm_output.h b/esphome/components/slow_pwm/slow_pwm_output.h index 3e5a3e2a400..d866435af1e 100644 --- a/esphome/components/slow_pwm/slow_pwm_output.h +++ b/esphome/components/slow_pwm/slow_pwm_output.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace slow_pwm { +namespace esphome::slow_pwm { class SlowPWMOutput : public output::FloatOutput, public Component { public: @@ -57,5 +56,4 @@ class SlowPWMOutput : public output::FloatOutput, public Component { bool restart_cycle_on_state_change_; }; -} // namespace slow_pwm -} // namespace esphome +} // namespace esphome::slow_pwm diff --git a/esphome/components/sm10bit_base/sm10bit_base.cpp b/esphome/components/sm10bit_base/sm10bit_base.cpp index d380f31c6fa..45de3c457d2 100644 --- a/esphome/components/sm10bit_base/sm10bit_base.cpp +++ b/esphome/components/sm10bit_base/sm10bit_base.cpp @@ -1,8 +1,7 @@ #include "sm10bit_base.h" #include "esphome/core/log.h" -namespace esphome { -namespace sm10bit_base { +namespace esphome::sm10bit_base { static const char *const TAG = "sm10bit_base"; @@ -127,5 +126,4 @@ void Sm10BitBase::write_buffer_(uint8_t *buffer, uint8_t size) { delayMicroseconds(SM10BIT_DELAY); } -} // namespace sm10bit_base -} // namespace esphome +} // namespace esphome::sm10bit_base diff --git a/esphome/components/sm10bit_base/sm10bit_base.h b/esphome/components/sm10bit_base/sm10bit_base.h index c8e92e352fe..b419b86dbfa 100644 --- a/esphome/components/sm10bit_base/sm10bit_base.h +++ b/esphome/components/sm10bit_base/sm10bit_base.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include -namespace esphome { -namespace sm10bit_base { +namespace esphome::sm10bit_base { class Sm10BitBase : public Component { public: @@ -59,5 +58,4 @@ class Sm10BitBase : public Component { bool update_{true}; }; -} // namespace sm10bit_base -} // namespace esphome +} // namespace esphome::sm10bit_base diff --git a/esphome/components/sm16716/sm16716.cpp b/esphome/components/sm16716/sm16716.cpp index b8e293929bd..59e9f1b7120 100644 --- a/esphome/components/sm16716/sm16716.cpp +++ b/esphome/components/sm16716/sm16716.cpp @@ -1,8 +1,7 @@ #include "sm16716.h" #include "esphome/core/log.h" -namespace esphome { -namespace sm16716 { +namespace esphome::sm16716 { static const char *const TAG = "sm16716"; @@ -49,5 +48,4 @@ void SM16716::loop() { this->update_ = false; } -} // namespace sm16716 -} // namespace esphome +} // namespace esphome::sm16716 diff --git a/esphome/components/sm16716/sm16716.h b/esphome/components/sm16716/sm16716.h index 73414c0003b..09deb2e8bf8 100644 --- a/esphome/components/sm16716/sm16716.h +++ b/esphome/components/sm16716/sm16716.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include -namespace esphome { -namespace sm16716 { +namespace esphome::sm16716 { class SM16716 : public Component { public: @@ -68,5 +67,4 @@ class SM16716 : public Component { bool update_{true}; }; -} // namespace sm16716 -} // namespace esphome +} // namespace esphome::sm16716 diff --git a/esphome/components/sm2135/sm2135.cpp b/esphome/components/sm2135/sm2135.cpp index c3d10e70c28..0086a63878b 100644 --- a/esphome/components/sm2135/sm2135.cpp +++ b/esphome/components/sm2135/sm2135.cpp @@ -3,8 +3,7 @@ // Tnx to the work of https://github.com/arendst (Tasmota) for making the initial version of the driver -namespace esphome { -namespace sm2135 { +namespace esphome::sm2135 { static const char *const TAG = "sm2135"; @@ -149,5 +148,4 @@ void SM2135::sm2135_set_high_(GPIOPin *pin) { pin->pin_mode(gpio::FLAG_PULLUP); } -} // namespace sm2135 -} // namespace esphome +} // namespace esphome::sm2135 diff --git a/esphome/components/sm2135/sm2135.h b/esphome/components/sm2135/sm2135.h index 6f207d093aa..040ec14b7fd 100644 --- a/esphome/components/sm2135/sm2135.h +++ b/esphome/components/sm2135/sm2135.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace sm2135 { +namespace esphome::sm2135 { enum SM2135Current : uint8_t { SM2135_CURRENT_10MA = 0x00, @@ -86,5 +85,4 @@ class SM2135 : public Component { bool update_{true}; }; -} // namespace sm2135 -} // namespace esphome +} // namespace esphome::sm2135 diff --git a/esphome/components/sm2235/sm2235.cpp b/esphome/components/sm2235/sm2235.cpp index 44768623182..e981bd0f71f 100644 --- a/esphome/components/sm2235/sm2235.cpp +++ b/esphome/components/sm2235/sm2235.cpp @@ -1,8 +1,7 @@ #include "sm2235.h" #include "esphome/core/log.h" -namespace esphome { -namespace sm2235 { +namespace esphome::sm2235 { static const char *const TAG = "sm2235"; @@ -24,5 +23,4 @@ void SM2235::dump_config() { LOG_PIN(" Clock Pin: ", this->clock_pin_); } -} // namespace sm2235 -} // namespace esphome +} // namespace esphome::sm2235 diff --git a/esphome/components/sm2235/sm2235.h b/esphome/components/sm2235/sm2235.h index 56d1782055a..cdb754e2980 100644 --- a/esphome/components/sm2235/sm2235.h +++ b/esphome/components/sm2235/sm2235.h @@ -4,8 +4,7 @@ #include "esphome/components/sm10bit_base/sm10bit_base.h" #include "esphome/core/hal.h" -namespace esphome { -namespace sm2235 { +namespace esphome::sm2235 { class SM2235 : public sm10bit_base::Sm10BitBase { public: @@ -15,5 +14,4 @@ class SM2235 : public sm10bit_base::Sm10BitBase { void dump_config() override; }; -} // namespace sm2235 -} // namespace esphome +} // namespace esphome::sm2235 diff --git a/esphome/components/sm2335/sm2335.cpp b/esphome/components/sm2335/sm2335.cpp index f860517021b..93f1096800f 100644 --- a/esphome/components/sm2335/sm2335.cpp +++ b/esphome/components/sm2335/sm2335.cpp @@ -1,8 +1,7 @@ #include "sm2335.h" #include "esphome/core/log.h" -namespace esphome { -namespace sm2335 { +namespace esphome::sm2335 { static const char *const TAG = "sm2335"; @@ -24,5 +23,4 @@ void SM2335::dump_config() { LOG_PIN(" Clock Pin: ", this->clock_pin_); } -} // namespace sm2335 -} // namespace esphome +} // namespace esphome::sm2335 diff --git a/esphome/components/sm2335/sm2335.h b/esphome/components/sm2335/sm2335.h index c8cf8251895..44e0e5b03ff 100644 --- a/esphome/components/sm2335/sm2335.h +++ b/esphome/components/sm2335/sm2335.h @@ -4,8 +4,7 @@ #include "esphome/components/sm10bit_base/sm10bit_base.h" #include "esphome/core/hal.h" -namespace esphome { -namespace sm2335 { +namespace esphome::sm2335 { class SM2335 : public sm10bit_base::Sm10BitBase { public: @@ -15,5 +14,4 @@ class SM2335 : public sm10bit_base::Sm10BitBase { void dump_config() override; }; -} // namespace sm2335 -} // namespace esphome +} // namespace esphome::sm2335 diff --git a/esphome/components/sm300d2/sm300d2.cpp b/esphome/components/sm300d2/sm300d2.cpp index 365271cec94..391cc0ac117 100644 --- a/esphome/components/sm300d2/sm300d2.cpp +++ b/esphome/components/sm300d2/sm300d2.cpp @@ -1,8 +1,7 @@ #include "sm300d2.h" #include "esphome/core/log.h" -namespace esphome { -namespace sm300d2 { +namespace esphome::sm300d2 { static const char *const TAG = "sm300d2"; static const uint8_t SM300D2_RESPONSE_LENGTH = 17; @@ -104,5 +103,4 @@ void SM300D2Sensor::dump_config() { this->check_uart_settings(9600); } -} // namespace sm300d2 -} // namespace esphome +} // namespace esphome::sm300d2 diff --git a/esphome/components/sm300d2/sm300d2.h b/esphome/components/sm300d2/sm300d2.h index 4e97b54988b..629e758e30d 100644 --- a/esphome/components/sm300d2/sm300d2.h +++ b/esphome/components/sm300d2/sm300d2.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace sm300d2 { +namespace esphome::sm300d2 { class SM300D2Sensor : public PollingComponent, public uart::UARTDevice { public: @@ -32,5 +31,4 @@ class SM300D2Sensor : public PollingComponent, public uart::UARTDevice { sensor::Sensor *humidity_sensor_{nullptr}; }; -} // namespace sm300d2 -} // namespace esphome +} // namespace esphome::sm300d2 diff --git a/esphome/components/sml/constants.h b/esphome/components/sml/constants.h index 0142fe98f75..b44fff7bdeb 100644 --- a/esphome/components/sml/constants.h +++ b/esphome/components/sml/constants.h @@ -3,8 +3,7 @@ #include #include -namespace esphome { -namespace sml { +namespace esphome::sml { enum SmlType : uint8_t { SML_OCTET = 0, @@ -24,5 +23,4 @@ const uint16_t END_MASK = 0x0157; // 0x1b 1b 1b 1b 1a constexpr std::array START_SEQ = {0x1b, 0x1b, 0x1b, 0x1b, 0x01, 0x01, 0x01, 0x01}; -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sensor/sml_sensor.cpp b/esphome/components/sml/sensor/sml_sensor.cpp index e9a384d2755..047a13e88d8 100644 --- a/esphome/components/sml/sensor/sml_sensor.cpp +++ b/esphome/components/sml/sensor/sml_sensor.cpp @@ -2,8 +2,7 @@ #include "sml_sensor.h" #include "../sml_parser.h" -namespace esphome { -namespace sml { +namespace esphome::sml { static const char *const TAG = "sml_sensor"; @@ -37,5 +36,4 @@ void SmlSensor::dump_config() { ESP_LOGCONFIG(TAG, " OBIS Code: %s", this->obis_code.c_str()); } -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sensor/sml_sensor.h b/esphome/components/sml/sensor/sml_sensor.h index eb7b108f94e..d2f8a7743f0 100644 --- a/esphome/components/sml/sensor/sml_sensor.h +++ b/esphome/components/sml/sensor/sml_sensor.h @@ -2,8 +2,7 @@ #include "esphome/components/sml/sml.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace sml { +namespace esphome::sml { class SmlSensor : public SmlListener, public sensor::Sensor, public Component { public: @@ -12,5 +11,4 @@ class SmlSensor : public SmlListener, public sensor::Sensor, public Component { void dump_config() override; }; -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sml.cpp b/esphome/components/sml/sml.cpp index c8d5fcc2694..bacfbcccef0 100644 --- a/esphome/components/sml/sml.cpp +++ b/esphome/components/sml/sml.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "sml_parser.h" -namespace esphome { -namespace sml { +namespace esphome::sml { static const char *const TAG = "sml"; @@ -140,5 +139,4 @@ uint8_t get_code(uint8_t byte) { } } -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sml.h b/esphome/components/sml/sml.h index 29a2f48bbec..60a80e3ad84 100644 --- a/esphome/components/sml/sml.h +++ b/esphome/components/sml/sml.h @@ -7,8 +7,7 @@ #include "esphome/components/uart/uart.h" #include "sml_parser.h" -namespace esphome { -namespace sml { +namespace esphome::sml { class SmlListener { public: @@ -44,5 +43,4 @@ class Sml : public Component, public uart::UARTDevice { bool check_sml_data(const bytes &buffer); uint8_t get_code(uint8_t byte); -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sml_parser.cpp b/esphome/components/sml/sml_parser.cpp index ed086e385d2..66e12ea64b5 100644 --- a/esphome/components/sml/sml_parser.cpp +++ b/esphome/components/sml/sml_parser.cpp @@ -2,8 +2,7 @@ #include "constants.h" #include "sml_parser.h" -namespace esphome { -namespace sml { +namespace esphome::sml { SmlFile::SmlFile(const BytesView &buffer) : buffer_(buffer) { // extract messages @@ -158,5 +157,4 @@ std::string ObisInfo::code_repr() const { return buf; } -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/sml_parser.h b/esphome/components/sml/sml_parser.h index bee0c8965bc..2fe404c96af 100644 --- a/esphome/components/sml/sml_parser.h +++ b/esphome/components/sml/sml_parser.h @@ -7,8 +7,7 @@ #include #include "constants.h" -namespace esphome { -namespace sml { +namespace esphome::sml { using bytes = std::vector; @@ -80,5 +79,4 @@ uint64_t bytes_to_uint(const BytesView &buffer); int64_t bytes_to_int(const BytesView &buffer); std::string bytes_to_string(const BytesView &buffer); -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/text_sensor/sml_text_sensor.cpp b/esphome/components/sml/text_sensor/sml_text_sensor.cpp index 17b93ecccf6..d0965e3dcaa 100644 --- a/esphome/components/sml/text_sensor/sml_text_sensor.cpp +++ b/esphome/components/sml/text_sensor/sml_text_sensor.cpp @@ -4,8 +4,7 @@ #include "../sml_parser.h" #include -namespace esphome { -namespace sml { +namespace esphome::sml { static const char *const TAG = "sml_text_sensor"; @@ -60,5 +59,4 @@ void SmlTextSensor::dump_config() { ESP_LOGCONFIG(TAG, " OBIS Code: %s", this->obis_code.c_str()); } -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/sml/text_sensor/sml_text_sensor.h b/esphome/components/sml/text_sensor/sml_text_sensor.h index 20d27c9f715..6194f223493 100644 --- a/esphome/components/sml/text_sensor/sml_text_sensor.h +++ b/esphome/components/sml/text_sensor/sml_text_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "../constants.h" -namespace esphome { -namespace sml { +namespace esphome::sml { class SmlTextSensor : public SmlListener, public text_sensor::TextSensor, public Component { public: @@ -17,5 +16,4 @@ class SmlTextSensor : public SmlListener, public text_sensor::TextSensor, public SmlType format_; }; -} // namespace sml -} // namespace esphome +} // namespace esphome::sml diff --git a/esphome/components/smt100/smt100.cpp b/esphome/components/smt100/smt100.cpp index 6eb6416447f..ed33fc54c53 100644 --- a/esphome/components/smt100/smt100.cpp +++ b/esphome/components/smt100/smt100.cpp @@ -1,8 +1,7 @@ #include "smt100.h" #include "esphome/core/log.h" -namespace esphome { -namespace smt100 { +namespace esphome::smt100 { static const char *const TAG = "smt100"; @@ -91,5 +90,4 @@ int SMT100Component::readline_(int readch, char *buffer, int len) { return -1; } -} // namespace smt100 -} // namespace esphome +} // namespace esphome::smt100 diff --git a/esphome/components/smt100/smt100.h b/esphome/components/smt100/smt100.h index cb01b1ed554..b68151eeb40 100644 --- a/esphome/components/smt100/smt100.h +++ b/esphome/components/smt100/smt100.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace smt100 { +namespace esphome::smt100 { class SMT100Component : public PollingComponent, public uart::UARTDevice { static const uint16_t MAX_LINE_LENGTH = 31; @@ -40,5 +39,4 @@ class SMT100Component : public PollingComponent, public uart::UARTDevice { uint32_t last_transmission_{0}; }; -} // namespace smt100 -} // namespace esphome +} // namespace esphome::smt100 diff --git a/esphome/components/sn74hc165/sn74hc165.cpp b/esphome/components/sn74hc165/sn74hc165.cpp index 63b3f98521a..fde789e90c7 100644 --- a/esphome/components/sn74hc165/sn74hc165.cpp +++ b/esphome/components/sn74hc165/sn74hc165.cpp @@ -1,8 +1,7 @@ #include "sn74hc165.h" #include "esphome/core/log.h" -namespace esphome { -namespace sn74hc165 { +namespace esphome::sn74hc165 { static const char *const TAG = "sn74hc165"; @@ -68,5 +67,4 @@ size_t SN74HC165GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via SN74HC165", this->pin_); } -} // namespace sn74hc165 -} // namespace esphome +} // namespace esphome::sn74hc165 diff --git a/esphome/components/sn74hc165/sn74hc165.h b/esphome/components/sn74hc165/sn74hc165.h index 5a3f3fe8ef0..596f2eb4f59 100644 --- a/esphome/components/sn74hc165/sn74hc165.h +++ b/esphome/components/sn74hc165/sn74hc165.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace sn74hc165 { +namespace esphome::sn74hc165 { class SN74HC165Component : public Component { public: @@ -60,5 +59,4 @@ class SN74HC165GPIOPin : public GPIOPin, public Parented { bool inverted_; }; -} // namespace sn74hc165 -} // namespace esphome +} // namespace esphome::sn74hc165 diff --git a/esphome/components/sn74hc595/sn74hc595.cpp b/esphome/components/sn74hc595/sn74hc595.cpp index 1bb8c7936db..710e51ad128 100644 --- a/esphome/components/sn74hc595/sn74hc595.cpp +++ b/esphome/components/sn74hc595/sn74hc595.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace sn74hc595 { +namespace esphome::sn74hc595 { static const char *const TAG = "sn74hc595"; @@ -97,5 +96,4 @@ size_t SN74HC595GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via SN74HC595", this->pin_); } -} // namespace sn74hc595 -} // namespace esphome +} // namespace esphome::sn74hc595 diff --git a/esphome/components/sn74hc595/sn74hc595.h b/esphome/components/sn74hc595/sn74hc595.h index 1cf70c86b50..23977e3d04c 100644 --- a/esphome/components/sn74hc595/sn74hc595.h +++ b/esphome/components/sn74hc595/sn74hc595.h @@ -11,8 +11,7 @@ #include -namespace esphome { -namespace sn74hc595 { +namespace esphome::sn74hc595 { class SN74HC595Component : public Component { public: @@ -93,5 +92,4 @@ class SN74HC595SPIComponent : public SN74HC595Component, #endif -} // namespace sn74hc595 -} // namespace esphome +} // namespace esphome::sn74hc595 diff --git a/esphome/components/sntp/sntp_component.cpp b/esphome/components/sntp/sntp_component.cpp index c4d78b6e0b1..f8d48b40981 100644 --- a/esphome/components/sntp/sntp_component.cpp +++ b/esphome/components/sntp/sntp_component.cpp @@ -9,8 +9,7 @@ #include "lwip/apps/sntp.h" #endif -namespace esphome { -namespace sntp { +namespace esphome::sntp { static const char *const TAG = "sntp"; @@ -102,5 +101,4 @@ void SNTPComponent::time_synced() { this->time_sync_callback_.call(); } -} // namespace sntp -} // namespace esphome +} // namespace esphome::sntp diff --git a/esphome/components/sntp/sntp_component.h b/esphome/components/sntp/sntp_component.h index 8f2e411c18b..ef737c1978c 100644 --- a/esphome/components/sntp/sntp_component.h +++ b/esphome/components/sntp/sntp_component.h @@ -4,8 +4,7 @@ #include "esphome/components/time/real_time_clock.h" #include -namespace esphome { -namespace sntp { +namespace esphome::sntp { // Server count is calculated at compile time by Python codegen // SNTP_SERVER_COUNT will always be defined @@ -42,5 +41,4 @@ class SNTPComponent : public time::RealTimeClock { #endif }; -} // namespace sntp -} // namespace esphome +} // namespace esphome::sntp diff --git a/esphome/components/sonoff_d1/sonoff_d1.cpp b/esphome/components/sonoff_d1/sonoff_d1.cpp index 03586b63984..3e5af2b51ff 100644 --- a/esphome/components/sonoff_d1/sonoff_d1.cpp +++ b/esphome/components/sonoff_d1/sonoff_d1.cpp @@ -44,8 +44,7 @@ #include "sonoff_d1.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace sonoff_d1 { +namespace esphome::sonoff_d1 { static const char *const TAG = "sonoff_d1"; @@ -321,5 +320,4 @@ void SonoffD1Output::loop() { } } -} // namespace sonoff_d1 -} // namespace esphome +} // namespace esphome::sonoff_d1 diff --git a/esphome/components/sonoff_d1/sonoff_d1.h b/esphome/components/sonoff_d1/sonoff_d1.h index 20bea23287b..a92877e6c8f 100644 --- a/esphome/components/sonoff_d1/sonoff_d1.h +++ b/esphome/components/sonoff_d1/sonoff_d1.h @@ -39,8 +39,7 @@ #include "esphome/components/light/light_state.h" #include "esphome/components/light/light_traits.h" -namespace esphome { -namespace sonoff_d1 { +namespace esphome::sonoff_d1 { class SonoffD1Output : public light::LightOutput, public uart::UARTDevice, public Component { public: @@ -80,5 +79,4 @@ class SonoffD1Output : public light::LightOutput, public uart::UARTDevice, publi void publish_state_(bool is_on, uint8_t brightness); }; -} // namespace sonoff_d1 -} // namespace esphome +} // namespace esphome::sonoff_d1 diff --git a/esphome/components/sound_level/sound_level.cpp b/esphome/components/sound_level/sound_level.cpp index 2719172409d..99533dbdd55 100644 --- a/esphome/components/sound_level/sound_level.cpp +++ b/esphome/components/sound_level/sound_level.cpp @@ -7,8 +7,7 @@ #include #include -namespace esphome { -namespace sound_level { +namespace esphome::sound_level { static const char *const TAG = "sound_level"; @@ -190,7 +189,6 @@ bool SoundLevelComponent::start_() { void SoundLevelComponent::stop_() { this->audio_buffer_.reset(); } -} // namespace sound_level -} // namespace esphome +} // namespace esphome::sound_level #endif diff --git a/esphome/components/sound_level/sound_level.h b/esphome/components/sound_level/sound_level.h index a1021eb1e82..0e46a203e86 100644 --- a/esphome/components/sound_level/sound_level.h +++ b/esphome/components/sound_level/sound_level.h @@ -10,8 +10,7 @@ #include "esphome/core/component.h" #include "esphome/core/ring_buffer.h" -namespace esphome { -namespace sound_level { +namespace esphome::sound_level { class SoundLevelComponent : public Component { public: @@ -69,6 +68,6 @@ template class StopAction : public Action, public Parente void play(const Ts &...x) override { this->parent_->stop(); } }; -} // namespace sound_level -} // namespace esphome +} // namespace esphome::sound_level + #endif diff --git a/esphome/components/speaker/automation.h b/esphome/components/speaker/automation.h index 391c9e4c627..9997b064d50 100644 --- a/esphome/components/speaker/automation.h +++ b/esphome/components/speaker/automation.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace speaker { +namespace esphome::speaker { template class PlayAction : public Action, public Parented { public: @@ -84,5 +83,4 @@ template class IsStoppedCondition : public Condition, pub bool check(const Ts &...x) override { return this->parent_->is_stopped(); } }; -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker diff --git a/esphome/components/speaker/media_player/audio_pipeline.cpp b/esphome/components/speaker/media_player/audio_pipeline.cpp index 0822d80254e..892d4f4112f 100644 --- a/esphome/components/speaker/media_player/audio_pipeline.cpp +++ b/esphome/components/speaker/media_player/audio_pipeline.cpp @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace speaker { +namespace esphome::speaker { static const uint32_t INITIAL_BUFFER_MS = 1000; // Start playback after buffering this duration of the file @@ -513,7 +512,6 @@ void AudioPipeline::decode_task(void *params) { } } -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker #endif diff --git a/esphome/components/speaker/media_player/audio_pipeline.h b/esphome/components/speaker/media_player/audio_pipeline.h index 2c785728359..ef7f75dd38c 100644 --- a/esphome/components/speaker/media_player/audio_pipeline.h +++ b/esphome/components/speaker/media_player/audio_pipeline.h @@ -15,8 +15,7 @@ #include #include -namespace esphome { -namespace speaker { +namespace esphome::speaker { // Internal sink/source buffers for reader and decoder static const size_t DEFAULT_TRANSFER_BUFFER_SIZE = 24 * 1024; @@ -147,7 +146,6 @@ class AudioPipeline { StaticTask decode_task_; }; -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker #endif diff --git a/esphome/components/speaker/media_player/automation.h b/esphome/components/speaker/media_player/automation.h index 6270da7bd4a..7843399866f 100644 --- a/esphome/components/speaker/media_player/automation.h +++ b/esphome/components/speaker/media_player/automation.h @@ -7,8 +7,7 @@ #include "esphome/components/audio/audio.h" #include "esphome/core/automation.h" -namespace esphome { -namespace speaker { +namespace esphome::speaker { template class PlayOnDeviceMediaAction : public Action, public Parented { TEMPLATABLE_VALUE(audio::AudioFile *, audio_file) @@ -20,7 +19,6 @@ template class PlayOnDeviceMediaAction : public Action, p } }; -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker #endif diff --git a/esphome/components/speaker/media_player/speaker_media_player.cpp b/esphome/components/speaker/media_player/speaker_media_player.cpp index afd93b3f45c..7d9cfecfdfa 100644 --- a/esphome/components/speaker/media_player/speaker_media_player.cpp +++ b/esphome/components/speaker/media_player/speaker_media_player.cpp @@ -9,8 +9,7 @@ #include "esphome/components/ota/ota_backend.h" #endif -namespace esphome { -namespace speaker { +namespace esphome::speaker { // Framework: // - Media player that can handle two streams: one for media and one for announcements @@ -622,7 +621,6 @@ void SpeakerMediaPlayer::set_volume_(float volume, bool publish) { this->defer([this, volume]() { this->volume_trigger_.trigger(volume); }); } -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker #endif diff --git a/esphome/components/speaker/media_player/speaker_media_player.h b/esphome/components/speaker/media_player/speaker_media_player.h index 3fa6f47b848..2d80377312e 100644 --- a/esphome/components/speaker/media_player/speaker_media_player.h +++ b/esphome/components/speaker/media_player/speaker_media_player.h @@ -21,8 +21,7 @@ #include #include -namespace esphome { -namespace speaker { +namespace esphome::speaker { struct MediaCallCommand { optional command; @@ -167,7 +166,6 @@ class SpeakerMediaPlayer : public Component, Trigger volume_trigger_; }; -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker #endif diff --git a/esphome/components/speaker/speaker.h b/esphome/components/speaker/speaker.h index 5b89d00c69f..c89b6c588c7 100644 --- a/esphome/components/speaker/speaker.h +++ b/esphome/components/speaker/speaker.h @@ -16,8 +16,7 @@ #include "esphome/components/audio_dac/audio_dac.h" #endif -namespace esphome { -namespace speaker { +namespace esphome::speaker { enum State : uint8_t { STATE_STOPPED = 0, @@ -123,5 +122,4 @@ class Speaker { CallbackManager audio_output_callback_{}; }; -} // namespace speaker -} // namespace esphome +} // namespace esphome::speaker diff --git a/esphome/components/speed/fan/speed_fan.cpp b/esphome/components/speed/fan/speed_fan.cpp index eaa8a55858d..af46ef52e1c 100644 --- a/esphome/components/speed/fan/speed_fan.cpp +++ b/esphome/components/speed/fan/speed_fan.cpp @@ -1,8 +1,7 @@ #include "speed_fan.h" #include "esphome/core/log.h" -namespace esphome { -namespace speed { +namespace esphome::speed { static const char *const TAG = "speed.fan"; @@ -47,5 +46,4 @@ void SpeedFan::write_state_() { this->direction_->set_state(this->direction == fan::FanDirection::REVERSE); } -} // namespace speed -} // namespace esphome +} // namespace esphome::speed diff --git a/esphome/components/speed/fan/speed_fan.h b/esphome/components/speed/fan/speed_fan.h index db96039a135..c618d6bc5f6 100644 --- a/esphome/components/speed/fan/speed_fan.h +++ b/esphome/components/speed/fan/speed_fan.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace speed { +namespace esphome::speed { class SpeedFan : public Component, public fan::Fan { public: @@ -33,5 +32,4 @@ class SpeedFan : public Component, public fan::Fan { fan::FanTraits traits_; }; -} // namespace speed -} // namespace esphome +} // namespace esphome::speed diff --git a/esphome/components/spi_device/spi_device.cpp b/esphome/components/spi_device/spi_device.cpp index 34f83027db4..bdf5978bc7d 100644 --- a/esphome/components/spi_device/spi_device.cpp +++ b/esphome/components/spi_device/spi_device.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace spi_device { +namespace esphome::spi_device { static const char *const TAG = "spi_device"; @@ -23,5 +22,4 @@ void SPIDeviceComponent::dump_config() { } } -} // namespace spi_device -} // namespace esphome +} // namespace esphome::spi_device diff --git a/esphome/components/spi_device/spi_device.h b/esphome/components/spi_device/spi_device.h index e3aa74aaf05..3a2523fbab0 100644 --- a/esphome/components/spi_device/spi_device.h +++ b/esphome/components/spi_device/spi_device.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace spi_device { +namespace esphome::spi_device { class SPIDeviceComponent : public Component, public spi::SPIDevicenum_leds_ = num_leds; @@ -65,5 +64,4 @@ light::ESPColorView SpiLedStrip::get_view_internal(int32_t index) const { return {this->buf_ + pos + 2, this->buf_ + pos + 1, this->buf_ + pos + 0, nullptr, this->effect_data_ + index, &this->correction_}; } -} // namespace spi_led_strip -} // namespace esphome +} // namespace esphome::spi_led_strip diff --git a/esphome/components/spi_led_strip/spi_led_strip.h b/esphome/components/spi_led_strip/spi_led_strip.h index 14c5627ac32..e2bcd5af639 100644 --- a/esphome/components/spi_led_strip/spi_led_strip.h +++ b/esphome/components/spi_led_strip/spi_led_strip.h @@ -5,8 +5,7 @@ #include "esphome/components/light/addressable_light.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace spi_led_strip { +namespace esphome::spi_led_strip { static const char *const TAG = "spi_led_strip"; class SpiLedStrip : public light::AddressableLight, @@ -36,5 +35,4 @@ class SpiLedStrip : public light::AddressableLight, uint16_t num_leds_; }; -} // namespace spi_led_strip -} // namespace esphome +} // namespace esphome::spi_led_strip diff --git a/esphome/components/sps30/automation.h b/esphome/components/sps30/automation.h index 5eafc1b6c2d..e58f857eb3a 100644 --- a/esphome/components/sps30/automation.h +++ b/esphome/components/sps30/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "sps30.h" -namespace esphome { -namespace sps30 { +namespace esphome::sps30 { template class StartFanAction : public Action, public Parented { public: @@ -22,5 +21,4 @@ template class StopMeasurementAction : public Action, pub void play(const Ts &...x) override { this->parent_->stop_measurement(); } }; -} // namespace sps30 -} // namespace esphome +} // namespace esphome::sps30 diff --git a/esphome/components/sps30/sps30.cpp b/esphome/components/sps30/sps30.cpp index e4fc4ffd31d..73fa4ef4633 100644 --- a/esphome/components/sps30/sps30.cpp +++ b/esphome/components/sps30/sps30.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace sps30 { +namespace esphome::sps30 { static const char *const TAG = "sps30"; @@ -291,5 +290,4 @@ bool SPS30Component::start_fan_cleaning() { return true; } -} // namespace sps30 -} // namespace esphome +} // namespace esphome::sps30 diff --git a/esphome/components/sps30/sps30.h b/esphome/components/sps30/sps30.h index 4e9b90ba7ec..ccb3e8ff413 100644 --- a/esphome/components/sps30/sps30.h +++ b/esphome/components/sps30/sps30.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/sensirion_common/i2c_sensirion.h" -namespace esphome { -namespace sps30 { +namespace esphome::sps30 { /// This class implements support for the Sensirion SPS30 i2c/UART Particulate Matter /// PM1.0, PM2.5, PM4, PM10 Air Quality sensors. @@ -67,5 +66,4 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri optional idle_interval_; }; -} // namespace sps30 -} // namespace esphome +} // namespace esphome::sps30 diff --git a/esphome/components/ssd1306_base/ssd1306_base.cpp b/esphome/components/ssd1306_base/ssd1306_base.cpp index 5bd83ec8a8e..5f1c6fca8f4 100644 --- a/esphome/components/ssd1306_base/ssd1306_base.cpp +++ b/esphome/components/ssd1306_base/ssd1306_base.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/progmem.h" -namespace esphome { -namespace ssd1306_base { +namespace esphome::ssd1306_base { static const char *const TAG = "ssd1306"; @@ -376,5 +375,4 @@ const LogString *SSD1306::model_str_() { return ModelStrings::get_log_str(static_cast(this->model_), ModelStrings::LAST_INDEX); } -} // namespace ssd1306_base -} // namespace esphome +} // namespace esphome::ssd1306_base diff --git a/esphome/components/ssd1306_base/ssd1306_base.h b/esphome/components/ssd1306_base/ssd1306_base.h index 3cc795a3236..7b4c9fe0bfc 100644 --- a/esphome/components/ssd1306_base/ssd1306_base.h +++ b/esphome/components/ssd1306_base/ssd1306_base.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/display/display_buffer.h" -namespace esphome { -namespace ssd1306_base { +namespace esphome::ssd1306_base { enum SSD1306Model { SSD1306_MODEL_128_32 = 0, @@ -88,5 +87,4 @@ class SSD1306 : public display::DisplayBuffer { bool invert_{false}; }; -} // namespace ssd1306_base -} // namespace esphome +} // namespace esphome::ssd1306_base diff --git a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp index e1f6e912430..8ff908fe7a6 100644 --- a/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp +++ b/esphome/components/ssd1306_i2c/ssd1306_i2c.cpp @@ -1,8 +1,7 @@ #include "ssd1306_i2c.h" #include "esphome/core/log.h" -namespace esphome { -namespace ssd1306_i2c { +namespace esphome::ssd1306_i2c { static const char *const TAG = "ssd1306_i2c"; @@ -76,5 +75,4 @@ void HOT I2CSSD1306::write_display_data() { } } -} // namespace ssd1306_i2c -} // namespace esphome +} // namespace esphome::ssd1306_i2c diff --git a/esphome/components/ssd1306_i2c/ssd1306_i2c.h b/esphome/components/ssd1306_i2c/ssd1306_i2c.h index e3f21fe74c9..0316da0e778 100644 --- a/esphome/components/ssd1306_i2c/ssd1306_i2c.h +++ b/esphome/components/ssd1306_i2c/ssd1306_i2c.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1306_base/ssd1306_base.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ssd1306_i2c { +namespace esphome::ssd1306_i2c { class I2CSSD1306 : public ssd1306_base::SSD1306, public i2c::I2CDevice { public: @@ -19,5 +18,4 @@ class I2CSSD1306 : public ssd1306_base::SSD1306, public i2c::I2CDevice { enum ErrorCode { NONE = 0, COMMUNICATION_FAILED } error_code_{NONE}; }; -} // namespace ssd1306_i2c -} // namespace esphome +} // namespace esphome::ssd1306_i2c diff --git a/esphome/components/ssd1306_spi/ssd1306_spi.cpp b/esphome/components/ssd1306_spi/ssd1306_spi.cpp index af9a17c8ab2..5c9369f1a20 100644 --- a/esphome/components/ssd1306_spi/ssd1306_spi.cpp +++ b/esphome/components/ssd1306_spi/ssd1306_spi.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace ssd1306_spi { +namespace esphome::ssd1306_spi { static const char *const TAG = "ssd1306_spi"; @@ -63,5 +62,4 @@ void HOT SPISSD1306::write_display_data() { } } -} // namespace ssd1306_spi -} // namespace esphome +} // namespace esphome::ssd1306_spi diff --git a/esphome/components/ssd1306_spi/ssd1306_spi.h b/esphome/components/ssd1306_spi/ssd1306_spi.h index c58ebc800a6..f8346033b32 100644 --- a/esphome/components/ssd1306_spi/ssd1306_spi.h +++ b/esphome/components/ssd1306_spi/ssd1306_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1306_base/ssd1306_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1306_spi { +namespace esphome::ssd1306_spi { class SPISSD1306 : public ssd1306_base::SSD1306, public spi::SPIDevicedisable(); } -} // namespace ssd1322_spi -} // namespace esphome +} // namespace esphome::ssd1322_spi diff --git a/esphome/components/ssd1322_spi/ssd1322_spi.h b/esphome/components/ssd1322_spi/ssd1322_spi.h index 316742706ef..31d17d0ef1a 100644 --- a/esphome/components/ssd1322_spi/ssd1322_spi.h +++ b/esphome/components/ssd1322_spi/ssd1322_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1322_base/ssd1322_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1322_spi { +namespace esphome::ssd1322_spi { class SPISSD1322 : public ssd1322_base::SSD1322, public spi::SPIDevicedisable(); } -} // namespace ssd1325_spi -} // namespace esphome +} // namespace esphome::ssd1325_spi diff --git a/esphome/components/ssd1325_spi/ssd1325_spi.h b/esphome/components/ssd1325_spi/ssd1325_spi.h index e4e7d55769f..32cbb28fd85 100644 --- a/esphome/components/ssd1325_spi/ssd1325_spi.h +++ b/esphome/components/ssd1325_spi/ssd1325_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1325_base/ssd1325_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1325_spi { +namespace esphome::ssd1325_spi { class SPISSD1325 : public ssd1325_base::SSD1325, public spi::SPIDevicedisable(); } -} // namespace ssd1327_spi -} // namespace esphome +} // namespace esphome::ssd1327_spi diff --git a/esphome/components/ssd1327_spi/ssd1327_spi.h b/esphome/components/ssd1327_spi/ssd1327_spi.h index 6f7abea96f5..fd1ed0357f3 100644 --- a/esphome/components/ssd1327_spi/ssd1327_spi.h +++ b/esphome/components/ssd1327_spi/ssd1327_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1327_base/ssd1327_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1327_spi { +namespace esphome::ssd1327_spi { class SPISSD1327 : public ssd1327_base::SSD1327, public spi::SPIDevicedisable(); } -} // namespace ssd1331_spi -} // namespace esphome +} // namespace esphome::ssd1331_spi diff --git a/esphome/components/ssd1331_spi/ssd1331_spi.h b/esphome/components/ssd1331_spi/ssd1331_spi.h index 93b2e228b11..acdc004b26a 100644 --- a/esphome/components/ssd1331_spi/ssd1331_spi.h +++ b/esphome/components/ssd1331_spi/ssd1331_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1331_base/ssd1331_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1331_spi { +namespace esphome::ssd1331_spi { class SPISSD1331 : public ssd1331_base::SSD1331, public spi::SPIDevicedisable(); } -} // namespace ssd1351_spi -} // namespace esphome +} // namespace esphome::ssd1351_spi diff --git a/esphome/components/ssd1351_spi/ssd1351_spi.h b/esphome/components/ssd1351_spi/ssd1351_spi.h index b8f3310f5c9..5ce41c1f9ed 100644 --- a/esphome/components/ssd1351_spi/ssd1351_spi.h +++ b/esphome/components/ssd1351_spi/ssd1351_spi.h @@ -4,8 +4,7 @@ #include "esphome/components/ssd1351_base/ssd1351_base.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace ssd1351_spi { +namespace esphome::ssd1351_spi { class SPISSD1351 : public ssd1351_base::SSD1351, public spi::SPIDevicewrite_array(byte, 4); } -} // namespace st7735 -} // namespace esphome +} // namespace esphome::st7735 diff --git a/esphome/components/st7735/st7735.h b/esphome/components/st7735/st7735.h index e81be520ed9..7fa0ad73357 100644 --- a/esphome/components/st7735/st7735.h +++ b/esphome/components/st7735/st7735.h @@ -4,8 +4,7 @@ #include "esphome/components/spi/spi.h" #include "esphome/components/display/display_buffer.h" -namespace esphome { -namespace st7735 { +namespace esphome::st7735 { static const uint8_t ST7735_TFTWIDTH_128 = 128; // for 1.44 and mini^M static const uint8_t ST7735_TFTWIDTH_80 = 80; // for mini^M @@ -85,5 +84,4 @@ class ST7735 : public display::DisplayBuffer, GPIOPin *dc_pin_{nullptr}; }; -} // namespace st7735 -} // namespace esphome +} // namespace esphome::st7735 diff --git a/esphome/components/st7789v/st7789v.cpp b/esphome/components/st7789v/st7789v.cpp index dc03fb04cae..b3a60af8c33 100644 --- a/esphome/components/st7789v/st7789v.cpp +++ b/esphome/components/st7789v/st7789v.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace st7789v { +namespace esphome::st7789v { static const char *const TAG = "st7789v"; #ifdef USE_ESP32 @@ -317,5 +316,4 @@ void HOT ST7789V::draw_absolute_pixel_internal(int x, int y, Color color) { } } -} // namespace st7789v -} // namespace esphome +} // namespace esphome::st7789v diff --git a/esphome/components/st7789v/st7789v.h b/esphome/components/st7789v/st7789v.h index 29ea3159791..3f9942b1173 100644 --- a/esphome/components/st7789v/st7789v.h +++ b/esphome/components/st7789v/st7789v.h @@ -7,8 +7,7 @@ #include "esphome/components/power_supply/power_supply.h" #endif -namespace esphome { -namespace st7789v { +namespace esphome::st7789v { static const uint8_t ST7789_NOP = 0x00; // No Operation static const uint8_t ST7789_SWRESET = 0x01; // Software Reset @@ -168,5 +167,4 @@ class ST7789V : public display::DisplayBuffer, const char *model_str_; }; -} // namespace st7789v -} // namespace esphome +} // namespace esphome::st7789v diff --git a/esphome/components/st7920/st7920.cpp b/esphome/components/st7920/st7920.cpp index a840f981523..429ed9e57be 100644 --- a/esphome/components/st7920/st7920.cpp +++ b/esphome/components/st7920/st7920.cpp @@ -3,8 +3,7 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" -namespace esphome { -namespace st7920 { +namespace esphome::st7920 { static const char *const TAG = "st7920"; @@ -154,5 +153,4 @@ void ST7920::display_init_() { this->write_display_data(); } -} // namespace st7920 -} // namespace esphome +} // namespace esphome::st7920 diff --git a/esphome/components/st7920/st7920.h b/esphome/components/st7920/st7920.h index c48fe8cc1c3..71fe7aa89c0 100644 --- a/esphome/components/st7920/st7920.h +++ b/esphome/components/st7920/st7920.h @@ -4,8 +4,7 @@ #include "esphome/components/display/display_buffer.h" #include "esphome/components/spi/spi.h" -namespace esphome { -namespace st7920 { +namespace esphome::st7920 { class ST7920; @@ -47,5 +46,4 @@ class ST7920 : public display::DisplayBuffer, st7920_writer_t writer_local_{}; }; -} // namespace st7920 -} // namespace esphome +} // namespace esphome::st7920 diff --git a/esphome/components/statsd/statsd.cpp b/esphome/components/statsd/statsd.cpp index 7d773bc56eb..7086e462a75 100644 --- a/esphome/components/statsd/statsd.cpp +++ b/esphome/components/statsd/statsd.cpp @@ -3,8 +3,8 @@ #include "statsd.h" #ifdef USE_NETWORK -namespace esphome { -namespace statsd { + +namespace esphome::statsd { // send UDP packet if we reach 1Kb packed size // this is needed since statsD does not support fragmented UDP packets @@ -165,6 +165,6 @@ void StatsdComponent::send_(std::string *out) { #endif } -} // namespace statsd -} // namespace esphome +} // namespace esphome::statsd + #endif diff --git a/esphome/components/statsd/statsd.h b/esphome/components/statsd/statsd.h index eab77a7a6e0..349bffe6fbd 100644 --- a/esphome/components/statsd/statsd.h +++ b/esphome/components/statsd/statsd.h @@ -25,8 +25,7 @@ #include "IPAddress.h" #endif -namespace esphome { -namespace statsd { +namespace esphome::statsd { class StatsdComponent : public PollingComponent { public: @@ -82,6 +81,6 @@ class StatsdComponent : public PollingComponent { void send_(std::string *out); }; -} // namespace statsd -} // namespace esphome +} // namespace esphome::statsd + #endif diff --git a/esphome/components/status_led/light/status_led_light.cpp b/esphome/components/status_led/light/status_led_light.cpp index ec7bf2dae16..341d3bfce53 100644 --- a/esphome/components/status_led/light/status_led_light.cpp +++ b/esphome/components/status_led/light/status_led_light.cpp @@ -3,8 +3,7 @@ #include "esphome/core/application.h" #include -namespace esphome { -namespace status_led { +namespace esphome::status_led { static const char *const TAG = "status_led"; @@ -71,5 +70,4 @@ void StatusLEDLightOutput::output_state_(bool state) { this->output_->set_state(state); } -} // namespace status_led -} // namespace esphome +} // namespace esphome::status_led diff --git a/esphome/components/status_led/light/status_led_light.h b/esphome/components/status_led/light/status_led_light.h index 3a745e0017a..0483669d0ab 100644 --- a/esphome/components/status_led/light/status_led_light.h +++ b/esphome/components/status_led/light/status_led_light.h @@ -5,8 +5,7 @@ #include "esphome/components/light/light_output.h" #include "esphome/components/output/binary_output.h" -namespace esphome { -namespace status_led { +namespace esphome::status_led { class StatusLEDLightOutput : public light::LightOutput, public Component { public: @@ -39,5 +38,4 @@ class StatusLEDLightOutput : public light::LightOutput, public Component { void output_state_(bool state); }; -} // namespace status_led -} // namespace esphome +} // namespace esphome::status_led diff --git a/esphome/components/status_led/status_led.cpp b/esphome/components/status_led/status_led.cpp index 48762a73334..ae37b3fae78 100644 --- a/esphome/components/status_led/status_led.cpp +++ b/esphome/components/status_led/status_led.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace status_led { +namespace esphome::status_led { static const char *const TAG = "status_led"; @@ -40,5 +39,4 @@ void StatusLED::loop() { } float StatusLED::get_setup_priority() const { return setup_priority::HARDWARE; } -} // namespace status_led -} // namespace esphome +} // namespace esphome::status_led diff --git a/esphome/components/status_led/status_led.h b/esphome/components/status_led/status_led.h index a4b5db93d7e..bda144d2cdd 100644 --- a/esphome/components/status_led/status_led.h +++ b/esphome/components/status_led/status_led.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace status_led { +namespace esphome::status_led { class StatusLED : public Component { public: @@ -21,5 +20,4 @@ class StatusLED : public Component { extern StatusLED *global_status_led; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace status_led -} // namespace esphome +} // namespace esphome::status_led diff --git a/esphome/components/stepper/stepper.cpp b/esphome/components/stepper/stepper.cpp index 79260242047..54df83782ec 100644 --- a/esphome/components/stepper/stepper.cpp +++ b/esphome/components/stepper/stepper.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace stepper { +namespace esphome::stepper { static const char *const TAG = "stepper"; @@ -47,5 +46,4 @@ int32_t Stepper::should_step_() { return 0; } -} // namespace stepper -} // namespace esphome +} // namespace esphome::stepper diff --git a/esphome/components/stepper/stepper.h b/esphome/components/stepper/stepper.h index 2bad672494f..9fbd0d92e6e 100644 --- a/esphome/components/stepper/stepper.h +++ b/esphome/components/stepper/stepper.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/automation.h" -namespace esphome { -namespace stepper { +namespace esphome::stepper { #define LOG_STEPPER(this) \ ESP_LOGCONFIG(TAG, \ @@ -108,5 +107,4 @@ template class SetDecelerationAction : public Action { Stepper *parent_; }; -} // namespace stepper -} // namespace esphome +} // namespace esphome::stepper diff --git a/esphome/components/sts3x/sts3x.cpp b/esphome/components/sts3x/sts3x.cpp index 8713b0b6b89..ff2a7748bf0 100644 --- a/esphome/components/sts3x/sts3x.cpp +++ b/esphome/components/sts3x/sts3x.cpp @@ -1,8 +1,7 @@ #include "sts3x.h" #include "esphome/core/log.h" -namespace esphome { -namespace sts3x { +namespace esphome::sts3x { static const char *const TAG = "sts3x"; @@ -66,5 +65,4 @@ void STS3XComponent::update() { }); } -} // namespace sts3x -} // namespace esphome +} // namespace esphome::sts3x diff --git a/esphome/components/sts3x/sts3x.h b/esphome/components/sts3x/sts3x.h index 6c1dd2b2442..038fa0dd802 100644 --- a/esphome/components/sts3x/sts3x.h +++ b/esphome/components/sts3x/sts3x.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace sts3x { +namespace esphome::sts3x { /// This class implements support for the ST3x-DIS family of temperature i2c sensors. class STS3XComponent : public sensor::Sensor, public PollingComponent, public sensirion_common::SensirionI2CDevice { @@ -17,5 +16,4 @@ class STS3XComponent : public sensor::Sensor, public PollingComponent, public se void update() override; }; -} // namespace sts3x -} // namespace esphome +} // namespace esphome::sts3x diff --git a/esphome/components/sun/sensor/sun_sensor.cpp b/esphome/components/sun/sensor/sun_sensor.cpp index 6c90722c29a..d788e19ea41 100644 --- a/esphome/components/sun/sensor/sun_sensor.cpp +++ b/esphome/components/sun/sensor/sun_sensor.cpp @@ -1,12 +1,10 @@ #include "sun_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace sun { +namespace esphome::sun { static const char *const TAG = "sun.sensor"; void SunSensor::dump_config() { LOG_SENSOR("", "Sun Sensor", this); } -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun/sensor/sun_sensor.h b/esphome/components/sun/sensor/sun_sensor.h index 2bd33375eff..148e5297d94 100644 --- a/esphome/components/sun/sensor/sun_sensor.h +++ b/esphome/components/sun/sensor/sun_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/sun/sun.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace sun { +namespace esphome::sun { enum SensorType { SUN_SENSOR_ELEVATION, @@ -37,5 +36,4 @@ class SunSensor : public sensor::Sensor, public PollingComponent { SensorType type_; }; -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun/sun.cpp b/esphome/components/sun/sun.cpp index d55a14f192e..d03ff07981e 100644 --- a/esphome/components/sun/sun.cpp +++ b/esphome/components/sun/sun.cpp @@ -12,8 +12,7 @@ like exact nutation are not included. But in some testing the accuracy appears t for random spots around the globe. */ -namespace esphome { -namespace sun { +namespace esphome::sun { using namespace esphome::sun::internal; @@ -322,5 +321,4 @@ optional Sun::sunset(ESPTime date, double elevation) { return this->cal double Sun::elevation() { return this->calc_coords_().elevation; } double Sun::azimuth() { return this->calc_coords_().azimuth; } -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun/sun.h b/esphome/components/sun/sun.h index 67a0306a37b..2999c93c715 100644 --- a/esphome/components/sun/sun.h +++ b/esphome/components/sun/sun.h @@ -7,8 +7,7 @@ #include "esphome/components/time/real_time_clock.h" -namespace esphome { -namespace sun { +namespace esphome::sun { namespace internal { @@ -129,5 +128,4 @@ template class SunCondition : public Condition, public Pa bool above_; }; -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun/text_sensor/sun_text_sensor.cpp b/esphome/components/sun/text_sensor/sun_text_sensor.cpp index c047b87fdd1..21aa4b86e0f 100644 --- a/esphome/components/sun/text_sensor/sun_text_sensor.cpp +++ b/esphome/components/sun/text_sensor/sun_text_sensor.cpp @@ -1,12 +1,10 @@ #include "sun_text_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace sun { +namespace esphome::sun { static const char *const TAG = "sun.text_sensor"; void SunTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Sun Text Sensor", this); } -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun/text_sensor/sun_text_sensor.h b/esphome/components/sun/text_sensor/sun_text_sensor.h index c3b60ffd65e..65b0e358d0b 100644 --- a/esphome/components/sun/text_sensor/sun_text_sensor.h +++ b/esphome/components/sun/text_sensor/sun_text_sensor.h @@ -6,8 +6,7 @@ #include "esphome/components/sun/sun.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace sun { +namespace esphome::sun { class SunTextSensor : public text_sensor::TextSensor, public PollingComponent { public: @@ -44,5 +43,4 @@ class SunTextSensor : public text_sensor::TextSensor, public PollingComponent { bool sunrise_; }; -} // namespace sun -} // namespace esphome +} // namespace esphome::sun diff --git a/esphome/components/sun_gtil2/sun_gtil2.cpp b/esphome/components/sun_gtil2/sun_gtil2.cpp index d416d9a636b..78e398d0868 100644 --- a/esphome/components/sun_gtil2/sun_gtil2.cpp +++ b/esphome/components/sun_gtil2/sun_gtil2.cpp @@ -1,8 +1,7 @@ #include "sun_gtil2.h" #include "esphome/core/log.h" -namespace esphome { -namespace sun_gtil2 { +namespace esphome::sun_gtil2 { static const char *const TAG = "sun_gtil2"; @@ -131,5 +130,4 @@ void SunGTIL2::dump_config() { #endif } -} // namespace sun_gtil2 -} // namespace esphome +} // namespace esphome::sun_gtil2 diff --git a/esphome/components/sun_gtil2/sun_gtil2.h b/esphome/components/sun_gtil2/sun_gtil2.h index 3e28527cf7a..e774fefcf8c 100644 --- a/esphome/components/sun_gtil2/sun_gtil2.h +++ b/esphome/components/sun_gtil2/sun_gtil2.h @@ -13,8 +13,7 @@ #endif #include "esphome/components/uart/uart.h" -namespace esphome { -namespace sun_gtil2 { +namespace esphome::sun_gtil2 { class SunGTIL2 : public Component, public uart::UARTDevice { public: @@ -58,5 +57,4 @@ class SunGTIL2 : public Component, public uart::UARTDevice { std::vector rx_message_; }; -} // namespace sun_gtil2 -} // namespace esphome +} // namespace esphome::sun_gtil2 diff --git a/esphome/components/sx126x/automation.h b/esphome/components/sx126x/automation.h index ed5986e0974..2721cbfbbfa 100644 --- a/esphome/components/sx126x/automation.h +++ b/esphome/components/sx126x/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/sx126x/sx126x.h" -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { template class RunImageCalAction : public Action, public Parented { public: @@ -65,5 +64,4 @@ template class SetModeStandbyAction : public Action, publ void play(const Ts &...x) override { this->parent_->set_mode_standby(STDBY_XOSC); } }; -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx126x/packet_transport/sx126x_transport.cpp b/esphome/components/sx126x/packet_transport/sx126x_transport.cpp index 59d80bd2974..5e992cc731b 100644 --- a/esphome/components/sx126x/packet_transport/sx126x_transport.cpp +++ b/esphome/components/sx126x/packet_transport/sx126x_transport.cpp @@ -2,8 +2,7 @@ #include "esphome/core/application.h" #include "sx126x_transport.h" -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { static const char *const TAG = "sx126x_transport"; @@ -16,5 +15,4 @@ void SX126xTransport::send_packet(const std::vector &buf) const { this- void SX126xTransport::on_packet(const std::vector &packet, float rssi, float snr) { this->process_(packet); } -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx126x/packet_transport/sx126x_transport.h b/esphome/components/sx126x/packet_transport/sx126x_transport.h index 640c6a76f91..7590e35c28d 100644 --- a/esphome/components/sx126x/packet_transport/sx126x_transport.h +++ b/esphome/components/sx126x/packet_transport/sx126x_transport.h @@ -5,8 +5,7 @@ #include "esphome/components/packet_transport/packet_transport.h" #include -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { class SX126xTransport : public packet_transport::PacketTransport, public Parented, public SX126xListener { public: @@ -20,5 +19,4 @@ class SX126xTransport : public packet_transport::PacketTransport, public Parente size_t get_max_packet_size() override { return this->parent_->get_max_packet_size(); } }; -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx126x/sx126x.cpp b/esphome/components/sx126x/sx126x.cpp index 02f7d972a99..6e6857fadbb 100644 --- a/esphome/components/sx126x/sx126x.cpp +++ b/esphome/components/sx126x/sx126x.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { static const char *const TAG = "sx126x"; static const uint16_t RAMP[8] = {10, 20, 40, 80, 200, 800, 1700, 3400}; @@ -547,5 +546,4 @@ void SX126x::dump_config() { } } -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx126x/sx126x.h b/esphome/components/sx126x/sx126x.h index 87bbf18c793..8298beb36e0 100644 --- a/esphome/components/sx126x/sx126x.h +++ b/esphome/components/sx126x/sx126x.h @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { enum SX126xBw : uint8_t { // FSK @@ -146,5 +145,4 @@ class SX126x : public Component, bool rf_switch_{false}; }; -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx126x/sx126x_reg.h b/esphome/components/sx126x/sx126x_reg.h index 143f4a05da2..c70817364fc 100644 --- a/esphome/components/sx126x/sx126x_reg.h +++ b/esphome/components/sx126x/sx126x_reg.h @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" -namespace esphome { -namespace sx126x { +namespace esphome::sx126x { static const uint32_t XTAL_FREQ = 32000000; @@ -161,5 +160,4 @@ enum SX126xRampTime : uint8_t { PA_RAMP_3400 = 0x07, }; -} // namespace sx126x -} // namespace esphome +} // namespace esphome::sx126x diff --git a/esphome/components/sx127x/automation.h b/esphome/components/sx127x/automation.h index fb0367fcca0..7a2eb7ee8d9 100644 --- a/esphome/components/sx127x/automation.h +++ b/esphome/components/sx127x/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/sx127x/sx127x.h" -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { template class RunImageCalAction : public Action, public Parented { public: @@ -64,5 +63,4 @@ template class SetModeStandbyAction : public Action, publ void play(const Ts &...x) override { this->parent_->set_mode_standby(); } }; -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx127x/packet_transport/sx127x_transport.cpp b/esphome/components/sx127x/packet_transport/sx127x_transport.cpp index 893726e816e..52d5631791c 100644 --- a/esphome/components/sx127x/packet_transport/sx127x_transport.cpp +++ b/esphome/components/sx127x/packet_transport/sx127x_transport.cpp @@ -2,8 +2,7 @@ #include "esphome/core/application.h" #include "sx127x_transport.h" -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { static const char *const TAG = "sx127x_transport"; @@ -16,5 +15,4 @@ void SX127xTransport::send_packet(const std::vector &buf) const { this- void SX127xTransport::on_packet(const std::vector &packet, float rssi, float snr) { this->process_(packet); } -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx127x/packet_transport/sx127x_transport.h b/esphome/components/sx127x/packet_transport/sx127x_transport.h index 62083729714..5dcfe02c339 100644 --- a/esphome/components/sx127x/packet_transport/sx127x_transport.h +++ b/esphome/components/sx127x/packet_transport/sx127x_transport.h @@ -5,8 +5,7 @@ #include "esphome/components/packet_transport/packet_transport.h" #include -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { class SX127xTransport : public packet_transport::PacketTransport, public Parented, public SX127xListener { public: @@ -20,5 +19,4 @@ class SX127xTransport : public packet_transport::PacketTransport, public Parente size_t get_max_packet_size() override { return this->parent_->get_max_packet_size(); } }; -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx127x/sx127x.cpp b/esphome/components/sx127x/sx127x.cpp index 2b13efb38da..0596e91ccc0 100644 --- a/esphome/components/sx127x/sx127x.cpp +++ b/esphome/components/sx127x/sx127x.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/log.h" -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { static const char *const TAG = "sx127x"; static const uint32_t FXOSC = 32000000u; @@ -507,5 +506,4 @@ void SX127x::dump_config() { } } -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx127x/sx127x.h b/esphome/components/sx127x/sx127x.h index 76f942fddac..376c987ed15 100644 --- a/esphome/components/sx127x/sx127x.h +++ b/esphome/components/sx127x/sx127x.h @@ -7,8 +7,7 @@ #include "esphome/core/hal.h" #include -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { enum SX127xBw : uint8_t { SX127X_BW_2_6, @@ -126,5 +125,4 @@ class SX127x : public Component, bool rx_start_{false}; }; -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx127x/sx127x_reg.h b/esphome/components/sx127x/sx127x_reg.h index d5e9c50957e..295af738cc1 100644 --- a/esphome/components/sx127x/sx127x_reg.h +++ b/esphome/components/sx127x/sx127x_reg.h @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" -namespace esphome { -namespace sx127x { +namespace esphome::sx127x { enum SX127xReg : uint8_t { // Common registers @@ -291,5 +290,4 @@ enum SX127xModemCfg3 : uint8_t { MODEM_AGC_AUTO_ON = 0x04, }; -} // namespace sx127x -} // namespace esphome +} // namespace esphome::sx127x diff --git a/esphome/components/sx1509/binary_sensor/sx1509_binary_keypad_sensor.h b/esphome/components/sx1509/binary_sensor/sx1509_binary_keypad_sensor.h index 2eef19782c0..bcd89015307 100644 --- a/esphome/components/sx1509/binary_sensor/sx1509_binary_keypad_sensor.h +++ b/esphome/components/sx1509/binary_sensor/sx1509_binary_keypad_sensor.h @@ -3,8 +3,7 @@ #include "esphome/components/sx1509/sx1509.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { class SX1509BinarySensor : public sx1509::SX1509Processor, public binary_sensor::BinarySensor { public: @@ -15,5 +14,4 @@ class SX1509BinarySensor : public sx1509::SX1509Processor, public binary_sensor: uint16_t key_{0}; }; -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/output/sx1509_float_output.cpp b/esphome/components/sx1509/output/sx1509_float_output.cpp index 4a24d78478d..528de1fde5a 100644 --- a/esphome/components/sx1509/output/sx1509_float_output.cpp +++ b/esphome/components/sx1509/output/sx1509_float_output.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { static const char *const TAG = "sx1509_float_channel"; @@ -29,5 +28,4 @@ void SX1509FloatOutputChannel::dump_config() { LOG_FLOAT_OUTPUT(this); } -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/output/sx1509_float_output.h b/esphome/components/sx1509/output/sx1509_float_output.h index 39e51839ea4..ee53cef637a 100644 --- a/esphome/components/sx1509/output/sx1509_float_output.h +++ b/esphome/components/sx1509/output/sx1509_float_output.h @@ -3,8 +3,7 @@ #include "esphome/components/sx1509/sx1509.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { class SX1509Component; @@ -23,5 +22,4 @@ class SX1509FloatOutputChannel : public output::FloatOutput, public Component { uint8_t pin_; }; -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/sx1509.cpp b/esphome/components/sx1509/sx1509.cpp index 1cdae76eaf4..2397049000d 100644 --- a/esphome/components/sx1509/sx1509.cpp +++ b/esphome/components/sx1509/sx1509.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { static const char *const TAG = "sx1509"; @@ -313,5 +312,4 @@ void SX1509Component::set_debounce_keypad_(uint8_t time, uint8_t num_rows, uint8 set_debounce_pin_(i + 8); } -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/sx1509.h b/esphome/components/sx1509/sx1509.h index f98fc0a44f3..f645ede7549 100644 --- a/esphome/components/sx1509/sx1509.h +++ b/esphome/components/sx1509/sx1509.h @@ -10,8 +10,7 @@ #include -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { // These are used for clock config: const uint8_t INTERNAL_CLOCK_2MHZ = 2; @@ -97,5 +96,4 @@ class SX1509Component : public Component, void clock_(uint8_t osc_source = 2, uint8_t osc_pin_function = 1, uint8_t osc_freq_out = 0, uint8_t osc_divider = 0); }; -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/sx1509_gpio_pin.cpp b/esphome/components/sx1509/sx1509_gpio_pin.cpp index a7e5d0514d9..28ef1c5830f 100644 --- a/esphome/components/sx1509/sx1509_gpio_pin.cpp +++ b/esphome/components/sx1509/sx1509_gpio_pin.cpp @@ -3,8 +3,7 @@ #include "sx1509.h" #include "sx1509_gpio_pin.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { static const char *const TAG = "sx1509_gpio_pin"; @@ -16,5 +15,4 @@ size_t SX1509GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via sx1509", this->pin_); } -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/sx1509_gpio_pin.h b/esphome/components/sx1509/sx1509_gpio_pin.h index 5903af9d12a..9dcad37b272 100644 --- a/esphome/components/sx1509/sx1509_gpio_pin.h +++ b/esphome/components/sx1509/sx1509_gpio_pin.h @@ -2,8 +2,7 @@ #include "esphome/core/gpio.h" -namespace esphome { -namespace sx1509 { +namespace esphome::sx1509 { class SX1509Component; @@ -29,5 +28,4 @@ class SX1509GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 diff --git a/esphome/components/sx1509/sx1509_registers.h b/esphome/components/sx1509/sx1509_registers.h index 9712cacf9b2..8349a8b8292 100644 --- a/esphome/components/sx1509/sx1509_registers.h +++ b/esphome/components/sx1509/sx1509_registers.h @@ -7,7 +7,6 @@ https://github.com/sparkfun/SparkFun_SX1509_Arduino_Library */ #pragma once -namespace esphome { /** Here you'll find the Arduino code used to interface with the SX1509 I2C 16 I/O expander. There are functions to take advantage of everything the @@ -25,7 +24,7 @@ local, and you've found our code helpful, please buy us a round! Distributed as-is; no warranty is given. */ -namespace sx1509 { +namespace esphome::sx1509 { const uint8_t REG_INPUT_DISABLE_B = 0x00; // RegInputDisableB Input buffer disable register _ I/O[15_8] (Bank B) 0000 0000 @@ -106,5 +105,4 @@ const uint8_t REG_RESET = 0x7D; // RegReset Software reset register 0000 00 const uint8_t REG_TEST_1 = 0x7E; // RegTest1 Test register 0000 0000 const uint8_t REG_TEST_2 = 0x7F; // RegTest2 Test register 0000 0000 -} // namespace sx1509 -} // namespace esphome +} // namespace esphome::sx1509 From 6ffcb821cae98cc4b419d6fe5efd84ad52f8eb86 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 21:13:38 -0400 Subject: [PATCH 08/52] [clang-tidy] Concatenate nested namespaces (6/7: components t-z) (#16305) --- esphome/components/t6615/t6615.cpp | 6 ++---- esphome/components/t6615/t6615.h | 6 ++---- esphome/components/tc74/tc74.cpp | 6 ++---- esphome/components/tc74/tc74.h | 6 ++---- esphome/components/tca9548a/tca9548a.cpp | 6 ++---- esphome/components/tca9548a/tca9548a.h | 6 ++---- esphome/components/tca9555/tca9555.cpp | 6 ++---- esphome/components/tca9555/tca9555.h | 6 ++---- esphome/components/tcl112/tcl112.cpp | 6 ++---- esphome/components/tcl112/tcl112.h | 6 ++---- esphome/components/tcs34725/tcs34725.cpp | 6 ++---- esphome/components/tcs34725/tcs34725.h | 6 ++---- esphome/components/tee501/tee501.cpp | 6 ++---- esphome/components/tee501/tee501.h | 6 ++---- esphome/components/teleinfo/sensor/teleinfo_sensor.cpp | 7 +++---- esphome/components/teleinfo/sensor/teleinfo_sensor.h | 6 ++---- esphome/components/teleinfo/teleinfo.cpp | 6 ++---- esphome/components/teleinfo/teleinfo.h | 6 ++---- .../teleinfo/text_sensor/teleinfo_text_sensor.cpp | 7 +++---- .../components/teleinfo/text_sensor/teleinfo_text_sensor.h | 7 +++---- esphome/components/tem3200/tem3200.cpp | 6 ++---- esphome/components/tem3200/tem3200.h | 6 ++---- esphome/components/time_based/cover/time_based_cover.cpp | 6 ++---- esphome/components/time_based/cover/time_based_cover.h | 6 ++---- esphome/components/tlc59208f/tlc59208f_output.cpp | 6 ++---- esphome/components/tlc59208f/tlc59208f_output.h | 6 ++---- esphome/components/tlc5947/output/tlc5947_output.cpp | 6 ++---- esphome/components/tlc5947/output/tlc5947_output.h | 6 ++---- esphome/components/tlc5947/tlc5947.cpp | 6 ++---- esphome/components/tlc5947/tlc5947.h | 6 ++---- esphome/components/tlc5971/output/tlc5971_output.cpp | 6 ++---- esphome/components/tlc5971/output/tlc5971_output.h | 6 ++---- esphome/components/tlc5971/tlc5971.cpp | 6 ++---- esphome/components/tlc5971/tlc5971.h | 6 ++---- esphome/components/tm1621/tm1621.cpp | 6 ++---- esphome/components/tm1621/tm1621.h | 6 ++---- esphome/components/tm1637/tm1637.cpp | 6 ++---- esphome/components/tm1637/tm1637.h | 6 ++---- esphome/components/tm1638/binary_sensor/tm1638_key.cpp | 6 ++---- esphome/components/tm1638/binary_sensor/tm1638_key.h | 6 ++---- esphome/components/tm1638/output/tm1638_output_led.cpp | 6 ++---- esphome/components/tm1638/output/tm1638_output_led.h | 6 ++---- esphome/components/tm1638/sevenseg.h | 6 ++---- esphome/components/tm1638/switch/tm1638_switch_led.cpp | 6 ++---- esphome/components/tm1638/switch/tm1638_switch_led.h | 6 ++---- esphome/components/tm1638/tm1638.cpp | 6 ++---- esphome/components/tm1638/tm1638.h | 6 ++---- esphome/components/tm1651/tm1651.cpp | 6 ++---- esphome/components/tm1651/tm1651.h | 6 ++---- esphome/components/tmp102/tmp102.cpp | 6 ++---- esphome/components/tmp102/tmp102.h | 6 ++---- esphome/components/tmp1075/tmp1075.cpp | 6 ++---- esphome/components/tmp1075/tmp1075.h | 6 ++---- esphome/components/tof10120/tof10120_sensor.cpp | 6 ++---- esphome/components/tof10120/tof10120_sensor.h | 6 ++---- esphome/components/tormatic/tormatic_cover.cpp | 6 ++---- esphome/components/tormatic/tormatic_cover.h | 6 ++---- esphome/components/tormatic/tormatic_protocol.h | 6 ++---- esphome/components/toshiba/toshiba.cpp | 6 ++---- esphome/components/toshiba/toshiba.h | 6 ++---- .../binary_sensor/touchscreen_binary_sensor.cpp | 6 ++---- .../touchscreen/binary_sensor/touchscreen_binary_sensor.h | 6 ++---- esphome/components/touchscreen/touchscreen.cpp | 6 ++---- esphome/components/touchscreen/touchscreen.h | 6 ++---- esphome/components/tsl2561/tsl2561.cpp | 6 ++---- esphome/components/tsl2561/tsl2561.h | 6 ++---- esphome/components/tsl2591/tsl2591.cpp | 6 ++---- esphome/components/tsl2591/tsl2591.h | 6 ++---- .../components/tt21100/binary_sensor/tt21100_button.cpp | 6 ++---- esphome/components/tt21100/binary_sensor/tt21100_button.h | 6 ++---- esphome/components/tt21100/touchscreen/tt21100.cpp | 6 ++---- esphome/components/tt21100/touchscreen/tt21100.h | 6 ++---- esphome/components/ttp229_bsf/ttp229_bsf.cpp | 6 ++---- esphome/components/ttp229_bsf/ttp229_bsf.h | 6 ++---- esphome/components/ttp229_lsf/ttp229_lsf.cpp | 6 ++---- esphome/components/ttp229_lsf/ttp229_lsf.h | 6 ++---- esphome/components/tuya/automation.cpp | 6 ++---- esphome/components/tuya/automation.h | 6 ++---- .../components/tuya/binary_sensor/tuya_binary_sensor.cpp | 6 ++---- esphome/components/tuya/binary_sensor/tuya_binary_sensor.h | 6 ++---- esphome/components/tuya/climate/tuya_climate.cpp | 6 ++---- esphome/components/tuya/climate/tuya_climate.h | 6 ++---- esphome/components/tuya/cover/tuya_cover.cpp | 6 ++---- esphome/components/tuya/cover/tuya_cover.h | 6 ++---- esphome/components/tuya/fan/tuya_fan.cpp | 6 ++---- esphome/components/tuya/fan/tuya_fan.h | 6 ++---- esphome/components/tuya/light/tuya_light.cpp | 6 ++---- esphome/components/tuya/light/tuya_light.h | 6 ++---- esphome/components/tuya/number/tuya_number.cpp | 6 ++---- esphome/components/tuya/number/tuya_number.h | 6 ++---- esphome/components/tuya/select/tuya_select.cpp | 6 ++---- esphome/components/tuya/select/tuya_select.h | 6 ++---- esphome/components/tuya/sensor/tuya_sensor.cpp | 6 ++---- esphome/components/tuya/sensor/tuya_sensor.h | 6 ++---- esphome/components/tuya/switch/tuya_switch.cpp | 6 ++---- esphome/components/tuya/switch/tuya_switch.h | 6 ++---- esphome/components/tuya/text_sensor/tuya_text_sensor.cpp | 6 ++---- esphome/components/tuya/text_sensor/tuya_text_sensor.h | 6 ++---- esphome/components/tuya/tuya.cpp | 6 ++---- esphome/components/tuya/tuya.h | 6 ++---- esphome/components/tx20/tx20.cpp | 6 ++---- esphome/components/tx20/tx20.h | 6 ++---- esphome/components/udp/automation.h | 7 +++---- esphome/components/udp/packet_transport/udp_transport.cpp | 6 ++---- esphome/components/udp/packet_transport/udp_transport.h | 7 +++---- esphome/components/ufire_ec/ufire_ec.cpp | 6 ++---- esphome/components/ufire_ec/ufire_ec.h | 6 ++---- esphome/components/ufire_ise/ufire_ise.cpp | 6 ++---- esphome/components/ufire_ise/ufire_ise.h | 6 ++---- esphome/components/update/automation.h | 6 ++---- esphome/components/update/update_entity.cpp | 6 ++---- esphome/components/update/update_entity.h | 6 ++---- .../uponor_smatrix/climate/uponor_smatrix_climate.cpp | 6 ++---- .../uponor_smatrix/climate/uponor_smatrix_climate.h | 6 ++---- .../uponor_smatrix/sensor/uponor_smatrix_sensor.cpp | 6 ++---- .../uponor_smatrix/sensor/uponor_smatrix_sensor.h | 6 ++---- esphome/components/uponor_smatrix/uponor_smatrix.cpp | 6 ++---- esphome/components/uponor_smatrix/uponor_smatrix.h | 6 ++---- esphome/components/valve/automation.h | 6 ++---- esphome/components/valve/valve.cpp | 6 ++---- esphome/components/valve/valve.h | 6 ++---- esphome/components/valve/valve_traits.h | 6 ++---- .../components/vbus/binary_sensor/vbus_binary_sensor.cpp | 6 ++---- esphome/components/vbus/binary_sensor/vbus_binary_sensor.h | 6 ++---- esphome/components/vbus/sensor/vbus_sensor.cpp | 6 ++---- esphome/components/vbus/sensor/vbus_sensor.h | 6 ++---- esphome/components/vbus/vbus.cpp | 6 ++---- esphome/components/vbus/vbus.h | 6 ++---- esphome/components/veml3235/veml3235.cpp | 6 ++---- esphome/components/veml3235/veml3235.h | 6 ++---- esphome/components/veml7700/veml7700.cpp | 6 ++---- esphome/components/veml7700/veml7700.h | 6 ++---- esphome/components/vl53l0x/vl53l0x_sensor.cpp | 6 ++---- esphome/components/vl53l0x/vl53l0x_sensor.h | 6 ++---- esphome/components/voice_assistant/voice_assistant.cpp | 6 ++---- esphome/components/voice_assistant/voice_assistant.h | 6 ++---- esphome/components/voltage_sampler/voltage_sampler.h | 6 ++---- esphome/components/wake_on_lan/wake_on_lan.cpp | 7 +++---- esphome/components/wake_on_lan/wake_on_lan.h | 7 +++---- esphome/components/watchdog/watchdog.cpp | 6 ++---- esphome/components/watchdog/watchdog.h | 6 ++---- esphome/components/waveshare_epaper/waveshare_213v3.cpp | 6 ++---- esphome/components/waveshare_epaper/waveshare_epaper.cpp | 6 ++---- esphome/components/waveshare_epaper/waveshare_epaper.h | 6 ++---- esphome/components/weikai/weikai.cpp | 6 ++---- esphome/components/weikai/weikai.h | 6 ++---- esphome/components/weikai/wk_reg_def.h | 6 ++---- esphome/components/weikai_i2c/weikai_i2c.cpp | 6 ++---- esphome/components/weikai_i2c/weikai_i2c.h | 6 ++---- esphome/components/weikai_spi/weikai_spi.cpp | 6 ++---- esphome/components/weikai_spi/weikai_spi.h | 6 ++---- esphome/components/whirlpool/whirlpool.cpp | 6 ++---- esphome/components/whirlpool/whirlpool.h | 6 ++---- esphome/components/whynter/whynter.cpp | 6 ++---- esphome/components/whynter/whynter.h | 6 ++---- esphome/components/wiegand/wiegand.cpp | 6 ++---- esphome/components/wiegand/wiegand.h | 6 ++---- esphome/components/wk2132_i2c/wk2132_i2c.cpp | 4 +--- esphome/components/wl_134/wl_134.cpp | 6 ++---- esphome/components/wl_134/wl_134.h | 6 ++---- esphome/components/wled/wled_light_effect.cpp | 6 ++---- esphome/components/wled/wled_light_effect.h | 6 ++---- esphome/components/wts01/wts01.cpp | 6 ++---- esphome/components/wts01/wts01.h | 6 ++---- esphome/components/x9c/x9c.cpp | 6 ++---- esphome/components/x9c/x9c.h | 6 ++---- esphome/components/xgzp68xx/xgzp68xx.cpp | 6 ++---- esphome/components/xgzp68xx/xgzp68xx.h | 6 ++---- esphome/components/xiaomi_ble/xiaomi_ble.cpp | 6 ++---- esphome/components/xiaomi_ble/xiaomi_ble.h | 6 ++---- esphome/components/xiaomi_cgd1/xiaomi_cgd1.cpp | 6 ++---- esphome/components/xiaomi_cgd1/xiaomi_cgd1.h | 6 ++---- esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.cpp | 6 ++---- esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.h | 6 ++---- esphome/components/xiaomi_cgg1/xiaomi_cgg1.cpp | 6 ++---- esphome/components/xiaomi_cgg1/xiaomi_cgg1.h | 6 ++---- esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.cpp | 6 ++---- esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.h | 6 ++---- esphome/components/xiaomi_gcls002/xiaomi_gcls002.cpp | 6 ++---- esphome/components/xiaomi_gcls002/xiaomi_gcls002.h | 6 ++---- esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.cpp | 6 ++---- esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.h | 6 ++---- esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.cpp | 6 ++---- esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.h | 6 ++---- esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.cpp | 6 ++---- esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.h | 6 ++---- esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.cpp | 6 ++---- esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.h | 6 ++---- esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.cpp | 6 ++---- esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.h | 6 ++---- esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.cpp | 6 ++---- esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.h | 6 ++---- esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp | 6 ++---- esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.h | 6 ++---- esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp | 6 ++---- esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h | 6 ++---- esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp | 6 ++---- esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h | 6 ++---- esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp | 6 ++---- esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h | 6 ++---- esphome/components/xiaomi_miscale/xiaomi_miscale.cpp | 6 ++---- esphome/components/xiaomi_miscale/xiaomi_miscale.h | 6 ++---- esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.cpp | 6 ++---- esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.h | 6 ++---- esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.cpp | 6 ++---- esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.h | 6 ++---- esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.cpp | 6 ++---- esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.h | 6 ++---- esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.cpp | 6 ++---- esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.h | 6 ++---- .../components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.cpp | 6 ++---- esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.h | 6 ++---- esphome/components/xl9535/xl9535.cpp | 6 ++---- esphome/components/xl9535/xl9535.h | 6 ++---- esphome/components/xpt2046/touchscreen/xpt2046.cpp | 6 ++---- esphome/components/xpt2046/touchscreen/xpt2046.h | 6 ++---- esphome/components/xxtea/xxtea.cpp | 6 ++---- esphome/components/xxtea/xxtea.h | 6 ++---- esphome/components/yashima/yashima.cpp | 6 ++---- esphome/components/yashima/yashima.h | 6 ++---- esphome/components/zhlt01/zhlt01.cpp | 6 ++---- esphome/components/zhlt01/zhlt01.h | 6 ++---- esphome/components/zio_ultrasonic/zio_ultrasonic.cpp | 6 ++---- esphome/components/zio_ultrasonic/zio_ultrasonic.h | 6 ++---- esphome/components/zyaura/zyaura.cpp | 6 ++---- esphome/components/zyaura/zyaura.h | 6 ++---- 226 files changed, 458 insertions(+), 903 deletions(-) diff --git a/esphome/components/t6615/t6615.cpp b/esphome/components/t6615/t6615.cpp index 75f9ed108e4..1a98e48c144 100644 --- a/esphome/components/t6615/t6615.cpp +++ b/esphome/components/t6615/t6615.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace t6615 { +namespace esphome::t6615 { static const char *const TAG = "t6615"; @@ -92,5 +91,4 @@ void T6615Component::dump_config() { this->check_uart_settings(19200); } -} // namespace t6615 -} // namespace esphome +} // namespace esphome::t6615 diff --git a/esphome/components/t6615/t6615.h b/esphome/components/t6615/t6615.h index 69c406a5bad..0c2088f7b04 100644 --- a/esphome/components/t6615/t6615.h +++ b/esphome/components/t6615/t6615.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace t6615 { +namespace esphome::t6615 { enum class T6615Command : uint8_t { NONE = 0, @@ -38,5 +37,4 @@ class T6615Component : public PollingComponent, public uart::UARTDevice { sensor::Sensor *co2_sensor_{nullptr}; }; -} // namespace t6615 -} // namespace esphome +} // namespace esphome::t6615 diff --git a/esphome/components/tc74/tc74.cpp b/esphome/components/tc74/tc74.cpp index cb58e583dca..bc522d1b745 100644 --- a/esphome/components/tc74/tc74.cpp +++ b/esphome/components/tc74/tc74.cpp @@ -3,8 +3,7 @@ #include "tc74.h" #include "esphome/core/log.h" -namespace esphome { -namespace tc74 { +namespace esphome::tc74 { static const char *const TAG = "tc74"; @@ -62,5 +61,4 @@ void TC74Component::read_temperature_() { this->status_clear_warning(); } -} // namespace tc74 -} // namespace esphome +} // namespace esphome::tc74 diff --git a/esphome/components/tc74/tc74.h b/esphome/components/tc74/tc74.h index f3ce225ff41..4a53f39bc18 100644 --- a/esphome/components/tc74/tc74.h +++ b/esphome/components/tc74/tc74.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tc74 { +namespace esphome::tc74 { class TC74Component : public PollingComponent, public i2c::I2CDevice, public sensor::Sensor { public: @@ -22,5 +21,4 @@ class TC74Component : public PollingComponent, public i2c::I2CDevice, public sen bool data_ready_ = false; }; -} // namespace tc74 -} // namespace esphome +} // namespace esphome::tc74 diff --git a/esphome/components/tca9548a/tca9548a.cpp b/esphome/components/tca9548a/tca9548a.cpp index 1de3c491087..3fc91a3bbb9 100644 --- a/esphome/components/tca9548a/tca9548a.cpp +++ b/esphome/components/tca9548a/tca9548a.cpp @@ -1,8 +1,7 @@ #include "tca9548a.h" #include "esphome/core/log.h" -namespace esphome { -namespace tca9548a { +namespace esphome::tca9548a { static const char *const TAG = "tca9548a"; @@ -44,5 +43,4 @@ void TCA9548AComponent::disable_all_channels() { } } -} // namespace tca9548a -} // namespace esphome +} // namespace esphome::tca9548a diff --git a/esphome/components/tca9548a/tca9548a.h b/esphome/components/tca9548a/tca9548a.h index 0fb9ada99ad..f0417ac7f70 100644 --- a/esphome/components/tca9548a/tca9548a.h +++ b/esphome/components/tca9548a/tca9548a.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tca9548a { +namespace esphome::tca9548a { static const uint8_t TCA9548A_DISABLE_CHANNELS_COMMAND = 0x00; @@ -35,5 +34,4 @@ class TCA9548AComponent : public Component, public i2c::I2CDevice { protected: friend class TCA9548AChannel; }; -} // namespace tca9548a -} // namespace esphome +} // namespace esphome::tca9548a diff --git a/esphome/components/tca9555/tca9555.cpp b/esphome/components/tca9555/tca9555.cpp index 2fefe08c0d7..b210c082dda 100644 --- a/esphome/components/tca9555/tca9555.cpp +++ b/esphome/components/tca9555/tca9555.cpp @@ -10,8 +10,7 @@ static const uint8_t TCA9555_POLARITY_REGISTER_1 = 0x05; static const uint8_t TCA9555_CONFIGURATION_PORT_0 = 0x06; static const uint8_t TCA9555_CONFIGURATION_PORT_1 = 0x07; -namespace esphome { -namespace tca9555 { +namespace esphome::tca9555 { static const char *const TAG = "tca9555"; @@ -162,5 +161,4 @@ size_t TCA9555GPIOPin::dump_summary(char *buffer, size_t len) const { return buf_append_printf(buffer, len, 0, "%u via TCA9555", this->pin_); } -} // namespace tca9555 -} // namespace esphome +} // namespace esphome::tca9555 diff --git a/esphome/components/tca9555/tca9555.h b/esphome/components/tca9555/tca9555.h index d4d070013c7..7d37edad73b 100644 --- a/esphome/components/tca9555/tca9555.h +++ b/esphome/components/tca9555/tca9555.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace tca9555 { +namespace esphome::tca9555 { class TCA9555Component : public Component, public i2c::I2CDevice, @@ -67,5 +66,4 @@ class TCA9555GPIOPin : public GPIOPin, public Parented { gpio::Flags flags_; }; -} // namespace tca9555 -} // namespace esphome +} // namespace esphome::tca9555 diff --git a/esphome/components/tcl112/tcl112.cpp b/esphome/components/tcl112/tcl112.cpp index afeee3d7396..cd819e5b16b 100644 --- a/esphome/components/tcl112/tcl112.cpp +++ b/esphome/components/tcl112/tcl112.cpp @@ -1,8 +1,7 @@ #include "tcl112.h" #include "esphome/core/log.h" -namespace esphome { -namespace tcl112 { +namespace esphome::tcl112 { static const char *const TAG = "tcl112.climate"; @@ -240,5 +239,4 @@ bool Tcl112Climate::on_receive(remote_base::RemoteReceiveData data) { return true; } -} // namespace tcl112 -} // namespace esphome +} // namespace esphome::tcl112 diff --git a/esphome/components/tcl112/tcl112.h b/esphome/components/tcl112/tcl112.h index e982755d402..0aef2decc82 100644 --- a/esphome/components/tcl112/tcl112.h +++ b/esphome/components/tcl112/tcl112.h @@ -2,8 +2,7 @@ #include "esphome/components/climate_ir/climate_ir.h" -namespace esphome { -namespace tcl112 { +namespace esphome::tcl112 { // Temperature const float TCL112_TEMP_MAX = 31.0; @@ -24,5 +23,4 @@ class Tcl112Climate : public climate_ir::ClimateIR { bool on_receive(remote_base::RemoteReceiveData data) override; }; -} // namespace tcl112 -} // namespace esphome +} // namespace esphome::tcl112 diff --git a/esphome/components/tcs34725/tcs34725.cpp b/esphome/components/tcs34725/tcs34725.cpp index 1098d8de5fe..40c65e9f84b 100644 --- a/esphome/components/tcs34725/tcs34725.cpp +++ b/esphome/components/tcs34725/tcs34725.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace tcs34725 { +namespace esphome::tcs34725 { static const char *const TAG = "tcs34725"; @@ -348,5 +347,4 @@ void TCS34725Component::set_glass_attenuation_factor(float ga) { this->glass_attenuation_ = ga; } -} // namespace tcs34725 -} // namespace esphome +} // namespace esphome::tcs34725 diff --git a/esphome/components/tcs34725/tcs34725.h b/esphome/components/tcs34725/tcs34725.h index 85bb383e4b7..15e4fae52ff 100644 --- a/esphome/components/tcs34725/tcs34725.h +++ b/esphome/components/tcs34725/tcs34725.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tcs34725 { +namespace esphome::tcs34725 { enum TCS34725IntegrationTime { TCS34725_INTEGRATION_TIME_2_4MS = 0xFF, @@ -85,5 +84,4 @@ class TCS34725Component : public PollingComponent, public i2c::I2CDevice { uint8_t gain_reg_{TCS34725_GAIN_1X}; }; -} // namespace tcs34725 -} // namespace esphome +} // namespace esphome::tcs34725 diff --git a/esphome/components/tee501/tee501.cpp b/esphome/components/tee501/tee501.cpp index 00a62247f90..c198ff10813 100644 --- a/esphome/components/tee501/tee501.cpp +++ b/esphome/components/tee501/tee501.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tee501 { +namespace esphome::tee501 { static const char *const TAG = "tee501"; @@ -66,5 +65,4 @@ void TEE501Component::update() { }); } -} // namespace tee501 -} // namespace esphome +} // namespace esphome::tee501 diff --git a/esphome/components/tee501/tee501.h b/esphome/components/tee501/tee501.h index 62a6f1c9440..4a082913188 100644 --- a/esphome/components/tee501/tee501.h +++ b/esphome/components/tee501/tee501.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace tee501 { +namespace esphome::tee501 { /// This class implements support for the tee501 of temperature i2c sensors. class TEE501Component : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { @@ -18,5 +17,4 @@ class TEE501Component : public sensor::Sensor, public PollingComponent, public i enum ErrorCode { NONE = 0, COMMUNICATION_FAILED, CRC_CHECK_FAILED } error_code_{NONE}; }; -} // namespace tee501 -} // namespace esphome +} // namespace esphome::tee501 diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp index ad9c6dae004..3878a3967b2 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.cpp @@ -1,7 +1,7 @@ #include "esphome/core/log.h" #include "teleinfo_sensor.h" -namespace esphome { -namespace teleinfo { + +namespace esphome::teleinfo { static const char *const TAG = "teleinfo_sensor"; TeleInfoSensor::TeleInfoSensor(const char *tag) { this->tag = std::string(tag); } @@ -10,5 +10,4 @@ void TeleInfoSensor::publish_val(const std::string &val) { publish_state(newval); } void TeleInfoSensor::dump_config() { LOG_SENSOR(" ", "Teleinfo Sensor", this); } -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/teleinfo/sensor/teleinfo_sensor.h b/esphome/components/teleinfo/sensor/teleinfo_sensor.h index 56781166abb..37736c4e737 100644 --- a/esphome/components/teleinfo/sensor/teleinfo_sensor.h +++ b/esphome/components/teleinfo/sensor/teleinfo_sensor.h @@ -2,8 +2,7 @@ #include "esphome/components/teleinfo/teleinfo.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace teleinfo { +namespace esphome::teleinfo { class TeleInfoSensor : public TeleInfoListener, public sensor::Sensor, public Component { public: @@ -12,5 +11,4 @@ class TeleInfoSensor : public TeleInfoListener, public sensor::Sensor, public Co void dump_config() override; }; -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/teleinfo/teleinfo.cpp b/esphome/components/teleinfo/teleinfo.cpp index 4d617ae4e61..cd2ddbbb381 100644 --- a/esphome/components/teleinfo/teleinfo.cpp +++ b/esphome/components/teleinfo/teleinfo.cpp @@ -1,8 +1,7 @@ #include "teleinfo.h" #include "esphome/core/log.h" -namespace esphome { -namespace teleinfo { +namespace esphome::teleinfo { static const char *const TAG = "teleinfo"; @@ -205,5 +204,4 @@ TeleInfo::TeleInfo(bool historical_mode) { } void TeleInfo::register_teleinfo_listener(TeleInfoListener *listener) { teleinfo_listeners_.push_back(listener); } -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/teleinfo/teleinfo.h b/esphome/components/teleinfo/teleinfo.h index 0c6217853e7..eeab3b5103a 100644 --- a/esphome/components/teleinfo/teleinfo.h +++ b/esphome/components/teleinfo/teleinfo.h @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace teleinfo { +namespace esphome::teleinfo { /* * 198 bytes should be enough to contain a full session in historical mode with * three phases. But go with 1024 just to be sure. @@ -50,5 +49,4 @@ class TeleInfo : public PollingComponent, public uart::UARTDevice { bool check_crc_(const char *grp, const char *grp_end); void publish_value_(const std::string &tag, const std::string &val); }; -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp index 87cf0dea178..7c638d8545b 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.cpp @@ -1,11 +1,10 @@ #include "esphome/core/log.h" #include "teleinfo_text_sensor.h" -namespace esphome { -namespace teleinfo { + +namespace esphome::teleinfo { static const char *const TAG = "teleinfo_text_sensor"; TeleInfoTextSensor::TeleInfoTextSensor(const char *tag) { this->tag = std::string(tag); } void TeleInfoTextSensor::publish_val(const std::string &val) { publish_state(val); } void TeleInfoTextSensor::dump_config() { LOG_TEXT_SENSOR(" ", "Teleinfo Text Sensor", this); } -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h index 5a7dc9d1a73..f4c04a03a03 100644 --- a/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h +++ b/esphome/components/teleinfo/text_sensor/teleinfo_text_sensor.h @@ -1,13 +1,12 @@ #pragma once #include "esphome/components/teleinfo/teleinfo.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace teleinfo { + +namespace esphome::teleinfo { class TeleInfoTextSensor : public TeleInfoListener, public text_sensor::TextSensor, public Component { public: TeleInfoTextSensor(const char *tag); void publish_val(const std::string &val) override; void dump_config() override; }; -} // namespace teleinfo -} // namespace esphome +} // namespace esphome::teleinfo diff --git a/esphome/components/tem3200/tem3200.cpp b/esphome/components/tem3200/tem3200.cpp index 9c305f8f6f0..72cf31e0a67 100644 --- a/esphome/components/tem3200/tem3200.cpp +++ b/esphome/components/tem3200/tem3200.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tem3200 { +namespace esphome::tem3200 { static const char *const TAG = "tem3200"; @@ -142,5 +141,4 @@ void TEM3200Component::update() { this->status_clear_warning(); } -} // namespace tem3200 -} // namespace esphome +} // namespace esphome::tem3200 diff --git a/esphome/components/tem3200/tem3200.h b/esphome/components/tem3200/tem3200.h index 37589b2a066..5c73a25fbb4 100644 --- a/esphome/components/tem3200/tem3200.h +++ b/esphome/components/tem3200/tem3200.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tem3200 { +namespace esphome::tem3200 { /// This class implements support for the tem3200 pressure and temperature i2c sensors. class TEM3200Component : public PollingComponent, public i2c::I2CDevice { @@ -25,5 +24,4 @@ class TEM3200Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *raw_pressure_sensor_{nullptr}; }; -} // namespace tem3200 -} // namespace esphome +} // namespace esphome::tem3200 diff --git a/esphome/components/time_based/cover/time_based_cover.cpp b/esphome/components/time_based/cover/time_based_cover.cpp index c83829ff592..613b190cf3c 100644 --- a/esphome/components/time_based/cover/time_based_cover.cpp +++ b/esphome/components/time_based/cover/time_based_cover.cpp @@ -3,8 +3,7 @@ #include "esphome/core/hal.h" #include "esphome/core/application.h" -namespace esphome { -namespace time_based { +namespace esphome::time_based { static const char *const TAG = "time_based.cover"; @@ -183,5 +182,4 @@ void TimeBasedCover::recompute_position_() { this->last_recompute_time_ = now; } -} // namespace time_based -} // namespace esphome +} // namespace esphome::time_based diff --git a/esphome/components/time_based/cover/time_based_cover.h b/esphome/components/time_based/cover/time_based_cover.h index 0adc5cb370d..ce0b105cebe 100644 --- a/esphome/components/time_based/cover/time_based_cover.h +++ b/esphome/components/time_based/cover/time_based_cover.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace time_based { +namespace esphome::time_based { class TimeBasedCover : public cover::Cover, public Component { public: @@ -50,5 +49,4 @@ class TimeBasedCover : public cover::Cover, public Component { cover::CoverOperation last_operation_{cover::COVER_OPERATION_OPENING}; }; -} // namespace time_based -} // namespace esphome +} // namespace esphome::time_based diff --git a/esphome/components/tlc59208f/tlc59208f_output.cpp b/esphome/components/tlc59208f/tlc59208f_output.cpp index d35585fe5f3..def337befc0 100644 --- a/esphome/components/tlc59208f/tlc59208f_output.cpp +++ b/esphome/components/tlc59208f/tlc59208f_output.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tlc59208f { +namespace esphome::tlc59208f { static const char *const TAG = "tlc59208f"; @@ -143,5 +142,4 @@ void TLC59208FChannel::write_state(float state) { this->parent_->set_channel_value_(this->channel_, duty); } -} // namespace tlc59208f -} // namespace esphome +} // namespace esphome::tlc59208f diff --git a/esphome/components/tlc59208f/tlc59208f_output.h b/esphome/components/tlc59208f/tlc59208f_output.h index 34663cd3644..46f88de01f4 100644 --- a/esphome/components/tlc59208f/tlc59208f_output.h +++ b/esphome/components/tlc59208f/tlc59208f_output.h @@ -5,8 +5,7 @@ #include "esphome/components/output/float_output.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tlc59208f { +namespace esphome::tlc59208f { // 0*: Group dimming, 1: Group blinking inline constexpr uint8_t TLC59208F_MODE2_DMBLNK = (1 << 5); @@ -65,5 +64,4 @@ class TLC59208FOutput : public Component, public i2c::I2CDevice { bool update_{true}; }; -} // namespace tlc59208f -} // namespace esphome +} // namespace esphome::tlc59208f diff --git a/esphome/components/tlc5947/output/tlc5947_output.cpp b/esphome/components/tlc5947/output/tlc5947_output.cpp index 9630fb8c1e8..b1badbac993 100644 --- a/esphome/components/tlc5947/output/tlc5947_output.cpp +++ b/esphome/components/tlc5947/output/tlc5947_output.cpp @@ -1,12 +1,10 @@ #include "tlc5947_output.h" -namespace esphome { -namespace tlc5947 { +namespace esphome::tlc5947 { void TLC5947Channel::write_state(float state) { auto amount = static_cast(state * 0xfff); this->parent_->set_channel_value(this->channel_, amount); } -} // namespace tlc5947 -} // namespace esphome +} // namespace esphome::tlc5947 diff --git a/esphome/components/tlc5947/output/tlc5947_output.h b/esphome/components/tlc5947/output/tlc5947_output.h index 0faec96acbf..16a96b51401 100644 --- a/esphome/components/tlc5947/output/tlc5947_output.h +++ b/esphome/components/tlc5947/output/tlc5947_output.h @@ -6,8 +6,7 @@ #include "../tlc5947.h" -namespace esphome { -namespace tlc5947 { +namespace esphome::tlc5947 { class TLC5947Channel : public output::FloatOutput, public Parented { public: @@ -18,5 +17,4 @@ class TLC5947Channel : public output::FloatOutput, public Parented { uint16_t channel_; }; -} // namespace tlc5947 -} // namespace esphome +} // namespace esphome::tlc5947 diff --git a/esphome/components/tlc5947/tlc5947.cpp b/esphome/components/tlc5947/tlc5947.cpp index 0a278bbaf61..f886118a088 100644 --- a/esphome/components/tlc5947/tlc5947.cpp +++ b/esphome/components/tlc5947/tlc5947.cpp @@ -1,8 +1,7 @@ #include "tlc5947.h" #include "esphome/core/log.h" -namespace esphome { -namespace tlc5947 { +namespace esphome::tlc5947 { static const char *const TAG = "tlc5947"; @@ -69,5 +68,4 @@ void TLC5947::set_channel_value(uint16_t channel, uint16_t value) { this->pwm_amounts_[channel] = value; } -} // namespace tlc5947 -} // namespace esphome +} // namespace esphome::tlc5947 diff --git a/esphome/components/tlc5947/tlc5947.h b/esphome/components/tlc5947/tlc5947.h index 95d76408c9c..18acffa25f4 100644 --- a/esphome/components/tlc5947/tlc5947.h +++ b/esphome/components/tlc5947/tlc5947.h @@ -7,8 +7,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace tlc5947 { +namespace esphome::tlc5947 { class TLC5947 : public Component { public: @@ -42,5 +41,4 @@ class TLC5947 : public Component { bool update_{true}; }; -} // namespace tlc5947 -} // namespace esphome +} // namespace esphome::tlc5947 diff --git a/esphome/components/tlc5971/output/tlc5971_output.cpp b/esphome/components/tlc5971/output/tlc5971_output.cpp index b4378890721..5c9183def65 100644 --- a/esphome/components/tlc5971/output/tlc5971_output.cpp +++ b/esphome/components/tlc5971/output/tlc5971_output.cpp @@ -1,12 +1,10 @@ #include "tlc5971_output.h" -namespace esphome { -namespace tlc5971 { +namespace esphome::tlc5971 { void TLC5971Channel::write_state(float state) { auto amount = static_cast(state * 0xffff); this->parent_->set_channel_value(this->channel_, amount); } -} // namespace tlc5971 -} // namespace esphome +} // namespace esphome::tlc5971 diff --git a/esphome/components/tlc5971/output/tlc5971_output.h b/esphome/components/tlc5971/output/tlc5971_output.h index ca3099e7b28..2a24a19b6c4 100644 --- a/esphome/components/tlc5971/output/tlc5971_output.h +++ b/esphome/components/tlc5971/output/tlc5971_output.h @@ -6,8 +6,7 @@ #include "../tlc5971.h" -namespace esphome { -namespace tlc5971 { +namespace esphome::tlc5971 { class TLC5971Channel : public output::FloatOutput, public Parented { public: @@ -18,5 +17,4 @@ class TLC5971Channel : public output::FloatOutput, public Parented { uint16_t channel_; }; -} // namespace tlc5971 -} // namespace esphome +} // namespace esphome::tlc5971 diff --git a/esphome/components/tlc5971/tlc5971.cpp b/esphome/components/tlc5971/tlc5971.cpp index 8128dd90462..5818eace679 100644 --- a/esphome/components/tlc5971/tlc5971.cpp +++ b/esphome/components/tlc5971/tlc5971.cpp @@ -1,8 +1,7 @@ #include "tlc5971.h" #include "esphome/core/log.h" -namespace esphome { -namespace tlc5971 { +namespace esphome::tlc5971 { static const char *const TAG = "tlc5971"; @@ -90,5 +89,4 @@ void TLC5971::set_channel_value(uint16_t channel, uint16_t value) { this->pwm_amounts_[channel] = value; } -} // namespace tlc5971 -} // namespace esphome +} // namespace esphome::tlc5971 diff --git a/esphome/components/tlc5971/tlc5971.h b/esphome/components/tlc5971/tlc5971.h index 6b0daf10d16..080249c89c2 100644 --- a/esphome/components/tlc5971/tlc5971.h +++ b/esphome/components/tlc5971/tlc5971.h @@ -7,8 +7,7 @@ #include "esphome/components/output/float_output.h" #include -namespace esphome { -namespace tlc5971 { +namespace esphome::tlc5971 { class TLC5971 : public Component { public: @@ -39,5 +38,4 @@ class TLC5971 : public Component { std::vector pwm_amounts_; bool update_{true}; }; -} // namespace tlc5971 -} // namespace esphome +} // namespace esphome::tlc5971 diff --git a/esphome/components/tm1621/tm1621.cpp b/esphome/components/tm1621/tm1621.cpp index c82d3064601..68d16e38116 100644 --- a/esphome/components/tm1621/tm1621.cpp +++ b/esphome/components/tm1621/tm1621.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1621 { +namespace esphome::tm1621 { static const char *const TAG = "tm1621"; @@ -277,5 +276,4 @@ int TM1621Display::get_command_code_(char *destination, size_t destination_size, } return result; } -} // namespace tm1621 -} // namespace esphome +} // namespace esphome::tm1621 diff --git a/esphome/components/tm1621/tm1621.h b/esphome/components/tm1621/tm1621.h index fe923417a60..7708ee6c988 100644 --- a/esphome/components/tm1621/tm1621.h +++ b/esphome/components/tm1621/tm1621.h @@ -5,8 +5,7 @@ #include "esphome/core/hal.h" #include "esphome/components/display/display.h" -namespace esphome { -namespace tm1621 { +namespace esphome::tm1621 { class TM1621Display; @@ -71,5 +70,4 @@ class TM1621Display : public PollingComponent { bool kwh_; }; -} // namespace tm1621 -} // namespace esphome +} // namespace esphome::tm1621 diff --git a/esphome/components/tm1637/tm1637.cpp b/esphome/components/tm1637/tm1637.cpp index 4814d5b1c49..a1604fa60e8 100644 --- a/esphome/components/tm1637/tm1637.cpp +++ b/esphome/components/tm1637/tm1637.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1637 { +namespace esphome::tm1637 { static const char *const TAG = "display.tm1637"; const uint8_t TM1637_CMD_DATA = 0x40; //!< Display data command @@ -391,5 +390,4 @@ uint8_t TM1637Display::strftime(uint8_t pos, const char *format, ESPTime time) { } uint8_t TM1637Display::strftime(const char *format, ESPTime time) { return this->strftime(0, format, time); } -} // namespace tm1637 -} // namespace esphome +} // namespace esphome::tm1637 diff --git a/esphome/components/tm1637/tm1637.h b/esphome/components/tm1637/tm1637.h index 1738d37107a..1ad56ae75a3 100644 --- a/esphome/components/tm1637/tm1637.h +++ b/esphome/components/tm1637/tm1637.h @@ -12,8 +12,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #endif -namespace esphome { -namespace tm1637 { +namespace esphome::tm1637 { class TM1637Display; #ifdef USE_BINARY_SENSOR @@ -105,5 +104,4 @@ class TM1637Key : public binary_sensor::BinarySensor { }; #endif -} // namespace tm1637 -} // namespace esphome +} // namespace esphome::tm1637 diff --git a/esphome/components/tm1638/binary_sensor/tm1638_key.cpp b/esphome/components/tm1638/binary_sensor/tm1638_key.cpp index c143bafaea0..9eecf97a9bd 100644 --- a/esphome/components/tm1638/binary_sensor/tm1638_key.cpp +++ b/esphome/components/tm1638/binary_sensor/tm1638_key.cpp @@ -1,7 +1,6 @@ #include "tm1638_key.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { void TM1638Key::keys_update(uint8_t keys) { bool pressed = keys & (1 << key_code_); @@ -9,5 +8,4 @@ void TM1638Key::keys_update(uint8_t keys) { this->publish_state(pressed); } -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/binary_sensor/tm1638_key.h b/esphome/components/tm1638/binary_sensor/tm1638_key.h index 0ea385f434d..fba1e43bde0 100644 --- a/esphome/components/tm1638/binary_sensor/tm1638_key.h +++ b/esphome/components/tm1638/binary_sensor/tm1638_key.h @@ -3,8 +3,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #include "../tm1638.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { class TM1638Key : public binary_sensor::BinarySensor, public KeyListener { public: @@ -15,5 +14,4 @@ class TM1638Key : public binary_sensor::BinarySensor, public KeyListener { uint8_t key_code_{0}; }; -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/output/tm1638_output_led.cpp b/esphome/components/tm1638/output/tm1638_output_led.cpp index ea1c84e64bf..e32826fa930 100644 --- a/esphome/components/tm1638/output/tm1638_output_led.cpp +++ b/esphome/components/tm1638/output/tm1638_output_led.cpp @@ -1,8 +1,7 @@ #include "tm1638_output_led.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { static const char *const TAG = "tm1638.led"; @@ -13,5 +12,4 @@ void TM1638OutputLed::dump_config() { ESP_LOGCONFIG(TAG, " LED: %d", led_); } -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/output/tm1638_output_led.h b/esphome/components/tm1638/output/tm1638_output_led.h index 6aa1015aae7..b1c1090447b 100644 --- a/esphome/components/tm1638/output/tm1638_output_led.h +++ b/esphome/components/tm1638/output/tm1638_output_led.h @@ -4,8 +4,7 @@ #include "esphome/components/output/binary_output.h" #include "../tm1638.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { class TM1638OutputLed : public output::BinaryOutput, public Component { public: @@ -21,5 +20,4 @@ class TM1638OutputLed : public output::BinaryOutput, public Component { int led_; }; -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/sevenseg.h b/esphome/components/tm1638/sevenseg.h index a4c16c7422c..61098b5a5b1 100644 --- a/esphome/components/tm1638/sevenseg.h +++ b/esphome/components/tm1638/sevenseg.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { namespace TM1638Translation { constexpr unsigned char SEVEN_SEG[] PROGMEM = { @@ -103,5 +102,4 @@ constexpr unsigned char SEVEN_SEG[] PROGMEM = { }; }; // namespace TM1638Translation -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/switch/tm1638_switch_led.cpp b/esphome/components/tm1638/switch/tm1638_switch_led.cpp index 60c9e8b4a96..743d0af5075 100644 --- a/esphome/components/tm1638/switch/tm1638_switch_led.cpp +++ b/esphome/components/tm1638/switch/tm1638_switch_led.cpp @@ -1,8 +1,7 @@ #include "tm1638_switch_led.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { static const char *const TAG = "tm1638.led"; @@ -16,5 +15,4 @@ void TM1638SwitchLed::dump_config() { ESP_LOGCONFIG(TAG, " LED: %d", led_); } -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/switch/tm1638_switch_led.h b/esphome/components/tm1638/switch/tm1638_switch_led.h index 10516e0079a..c7154eefb38 100644 --- a/esphome/components/tm1638/switch/tm1638_switch_led.h +++ b/esphome/components/tm1638/switch/tm1638_switch_led.h @@ -4,8 +4,7 @@ #include "esphome/components/switch/switch.h" #include "../tm1638.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { class TM1638SwitchLed : public switch_::Switch, public Component { public: @@ -19,5 +18,4 @@ class TM1638SwitchLed : public switch_::Switch, public Component { TM1638Component *tm1638_; int led_; }; -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/tm1638.cpp b/esphome/components/tm1638/tm1638.cpp index c67ff1adbc2..1f0692479c2 100644 --- a/esphome/components/tm1638/tm1638.cpp +++ b/esphome/components/tm1638/tm1638.cpp @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { static const char *const TAG = "display.tm1638"; static const uint8_t TM1638_REGISTER_FIXEDADDRESS = 0x44; @@ -282,5 +281,4 @@ void TM1638Component::shift_out_(uint8_t val) { } } -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1638/tm1638.h b/esphome/components/tm1638/tm1638.h index 27898aa3dcc..24d49f4a9f5 100644 --- a/esphome/components/tm1638/tm1638.h +++ b/esphome/components/tm1638/tm1638.h @@ -9,8 +9,7 @@ #include -namespace esphome { -namespace tm1638 { +namespace esphome::tm1638 { class KeyListener { public: @@ -75,5 +74,4 @@ class TM1638Component : public PollingComponent { std::vector listeners_{}; }; -} // namespace tm1638 -} // namespace esphome +} // namespace esphome::tm1638 diff --git a/esphome/components/tm1651/tm1651.cpp b/esphome/components/tm1651/tm1651.cpp index 15ada0f8ff3..282b0dcf76b 100644 --- a/esphome/components/tm1651/tm1651.cpp +++ b/esphome/components/tm1651/tm1651.cpp @@ -51,8 +51,7 @@ #include "tm1651.h" #include "esphome/core/log.h" -namespace esphome { -namespace tm1651 { +namespace esphome::tm1651 { static const char *const TAG = "tm1651.display"; @@ -256,5 +255,4 @@ void TM1651Display::delineate_transmission_(bool dio_state) { delayMicroseconds(QUARTER_CLOCK_CYCLE); } -} // namespace tm1651 -} // namespace esphome +} // namespace esphome::tm1651 diff --git a/esphome/components/tm1651/tm1651.h b/esphome/components/tm1651/tm1651.h index 83e74c5f330..f1abbcc7922 100644 --- a/esphome/components/tm1651/tm1651.h +++ b/esphome/components/tm1651/tm1651.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace tm1651 { +namespace esphome::tm1651 { enum TM1651Brightness : uint8_t { TM1651_DARKEST = 1, @@ -97,5 +96,4 @@ template class TurnOffAction : public Action, public Pare void play(const Ts &...x) override { this->parent_->turn_off(); } }; -} // namespace tm1651 -} // namespace esphome +} // namespace esphome::tm1651 diff --git a/esphome/components/tmp102/tmp102.cpp b/esphome/components/tmp102/tmp102.cpp index 99f6753ddcc..cb2462858b6 100644 --- a/esphome/components/tmp102/tmp102.cpp +++ b/esphome/components/tmp102/tmp102.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace tmp102 { +namespace esphome::tmp102 { static const char *const TAG = "tmp102"; @@ -46,5 +45,4 @@ void TMP102Component::update() { }); } -} // namespace tmp102 -} // namespace esphome +} // namespace esphome::tmp102 diff --git a/esphome/components/tmp102/tmp102.h b/esphome/components/tmp102/tmp102.h index fe860a38191..aedfefd0528 100644 --- a/esphome/components/tmp102/tmp102.h +++ b/esphome/components/tmp102/tmp102.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tmp102 { +namespace esphome::tmp102 { class TMP102Component : public PollingComponent, public i2c::I2CDevice, public sensor::Sensor { public: @@ -13,5 +12,4 @@ class TMP102Component : public PollingComponent, public i2c::I2CDevice, public s void update() override; }; -} // namespace tmp102 -} // namespace esphome +} // namespace esphome::tmp102 diff --git a/esphome/components/tmp1075/tmp1075.cpp b/esphome/components/tmp1075/tmp1075.cpp index 3c7ed019706..681603d1136 100644 --- a/esphome/components/tmp1075/tmp1075.cpp +++ b/esphome/components/tmp1075/tmp1075.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tmp1075.h" -namespace esphome { -namespace tmp1075 { +namespace esphome::tmp1075 { static const char *const TAG = "tmp1075"; @@ -127,5 +126,4 @@ static float regvalue2temp(const uint16_t regvalue) { return (signed_value >> 4) * 0.0625f; } -} // namespace tmp1075 -} // namespace esphome +} // namespace esphome::tmp1075 diff --git a/esphome/components/tmp1075/tmp1075.h b/esphome/components/tmp1075/tmp1075.h index b5fd60c08e2..4dc9449597a 100644 --- a/esphome/components/tmp1075/tmp1075.h +++ b/esphome/components/tmp1075/tmp1075.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace tmp1075 { +namespace esphome::tmp1075 { struct TMP1075Config { union { @@ -85,5 +84,4 @@ class TMP1075Sensor : public PollingComponent, public sensor::Sensor, public i2c void log_config_(); }; -} // namespace tmp1075 -} // namespace esphome +} // namespace esphome::tmp1075 diff --git a/esphome/components/tof10120/tof10120_sensor.cpp b/esphome/components/tof10120/tof10120_sensor.cpp index e27c7bbd649..290bc76a521 100644 --- a/esphome/components/tof10120/tof10120_sensor.cpp +++ b/esphome/components/tof10120/tof10120_sensor.cpp @@ -5,8 +5,7 @@ // Very basic support for TOF10120 distance sensor -namespace esphome { -namespace tof10120 { +namespace esphome::tof10120 { static const char *const TAG = "tof10120"; static const uint8_t TOF10120_READ_DISTANCE_CMD[] = {0x00}; @@ -56,5 +55,4 @@ void TOF10120Sensor::update() { this->status_clear_warning(); } -} // namespace tof10120 -} // namespace esphome +} // namespace esphome::tof10120 diff --git a/esphome/components/tof10120/tof10120_sensor.h b/esphome/components/tof10120/tof10120_sensor.h index d0cca19d4c6..8bf92b50a06 100644 --- a/esphome/components/tof10120/tof10120_sensor.h +++ b/esphome/components/tof10120/tof10120_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tof10120 { +namespace esphome::tof10120 { class TOF10120Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice { public: @@ -14,5 +13,4 @@ class TOF10120Sensor : public sensor::Sensor, public PollingComponent, public i2 void dump_config() override; void update() override; }; -} // namespace tof10120 -} // namespace esphome +} // namespace esphome::tof10120 diff --git a/esphome/components/tormatic/tormatic_cover.cpp b/esphome/components/tormatic/tormatic_cover.cpp index cca7b2bba02..7004c4f8365 100644 --- a/esphome/components/tormatic/tormatic_cover.cpp +++ b/esphome/components/tormatic/tormatic_cover.cpp @@ -5,8 +5,7 @@ using namespace std; -namespace esphome { -namespace tormatic { +namespace esphome::tormatic { static const char *const TAG = "tormatic.cover"; @@ -390,5 +389,4 @@ void Tormatic::drain_rx_(uint16_t n) { } } -} // namespace tormatic -} // namespace esphome +} // namespace esphome::tormatic diff --git a/esphome/components/tormatic/tormatic_cover.h b/esphome/components/tormatic/tormatic_cover.h index 34483ed6a35..2a83213ffec 100644 --- a/esphome/components/tormatic/tormatic_cover.h +++ b/esphome/components/tormatic/tormatic_cover.h @@ -5,8 +5,7 @@ #include "tormatic_protocol.h" -namespace esphome { -namespace tormatic { +namespace esphome::tormatic { using namespace esphome::cover; @@ -56,5 +55,4 @@ class Tormatic : public cover::Cover, public uart::UARTDevice, public PollingCom optional target_position_{}; }; -} // namespace tormatic -} // namespace esphome +} // namespace esphome::tormatic diff --git a/esphome/components/tormatic/tormatic_protocol.h b/esphome/components/tormatic/tormatic_protocol.h index 269b63ff783..476aa668d71 100644 --- a/esphome/components/tormatic/tormatic_protocol.h +++ b/esphome/components/tormatic/tormatic_protocol.h @@ -46,8 +46,7 @@ * for this purpose. */ -namespace esphome { -namespace tormatic { +namespace esphome::tormatic { using namespace esphome::cover; @@ -225,5 +224,4 @@ struct CommandRequestReply { void byteswap() { this->type = convert_big_endian(this->type); } } __attribute__((packed)); -} // namespace tormatic -} // namespace esphome +} // namespace esphome::tormatic diff --git a/esphome/components/toshiba/toshiba.cpp b/esphome/components/toshiba/toshiba.cpp index a23b4c7cc3e..1b37c6897da 100644 --- a/esphome/components/toshiba/toshiba.cpp +++ b/esphome/components/toshiba/toshiba.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace toshiba { +namespace esphome::toshiba { struct RacPt1411hwruFanSpeed { uint8_t code1; @@ -1372,5 +1371,4 @@ bool ToshibaClimate::decode_(remote_base::RemoteReceiveData *data, uint8_t *mess return true; } -} // namespace toshiba -} // namespace esphome +} // namespace esphome::toshiba diff --git a/esphome/components/toshiba/toshiba.h b/esphome/components/toshiba/toshiba.h index ee1dec5cc9f..4525d6bffef 100644 --- a/esphome/components/toshiba/toshiba.h +++ b/esphome/components/toshiba/toshiba.h @@ -3,8 +3,7 @@ #include "esphome/components/climate_ir/climate_ir.h" #include "esphome/components/remote_base/toshiba_ac_protocol.h" -namespace esphome { -namespace toshiba { +namespace esphome::toshiba { // Simple enum to represent models. enum Model { @@ -82,5 +81,4 @@ class ToshibaClimate : public climate_ir::ClimateIR { Model model_; }; -} // namespace toshiba -} // namespace esphome +} // namespace esphome::toshiba diff --git a/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.cpp b/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.cpp index 0662cebf872..25a7ffacf21 100644 --- a/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.cpp +++ b/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.cpp @@ -1,7 +1,6 @@ #include "touchscreen_binary_sensor.h" -namespace esphome { -namespace touchscreen { +namespace esphome::touchscreen { void TouchscreenBinarySensor::setup() { this->parent_->register_listener(this); @@ -30,5 +29,4 @@ void TouchscreenBinarySensor::touch(TouchPoint tp) { void TouchscreenBinarySensor::release() { this->publish_state(false); } -} // namespace touchscreen -} // namespace esphome +} // namespace esphome::touchscreen diff --git a/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.h b/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.h index 79055e6c953..2f86bc97498 100644 --- a/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.h +++ b/esphome/components/touchscreen/binary_sensor/touchscreen_binary_sensor.h @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace touchscreen { +namespace esphome::touchscreen { class TouchscreenBinarySensor : public binary_sensor::BinarySensor, public Component, @@ -44,5 +43,4 @@ class TouchscreenBinarySensor : public binary_sensor::BinarySensor, std::vector pages_{}; }; -} // namespace touchscreen -} // namespace esphome +} // namespace esphome::touchscreen diff --git a/esphome/components/touchscreen/touchscreen.cpp b/esphome/components/touchscreen/touchscreen.cpp index dcf32097524..5687213eb53 100644 --- a/esphome/components/touchscreen/touchscreen.cpp +++ b/esphome/components/touchscreen/touchscreen.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace touchscreen { +namespace esphome::touchscreen { static const char *const TAG = "touchscreen"; @@ -162,5 +161,4 @@ int16_t Touchscreen::normalize_(int16_t val, int16_t min_val, int16_t max_val, b return ret; } -} // namespace touchscreen -} // namespace esphome +} // namespace esphome::touchscreen diff --git a/esphome/components/touchscreen/touchscreen.h b/esphome/components/touchscreen/touchscreen.h index 7451c207ec3..f1f53986038 100644 --- a/esphome/components/touchscreen/touchscreen.h +++ b/esphome/components/touchscreen/touchscreen.h @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace touchscreen { +namespace esphome::touchscreen { static const uint8_t STATE_RELEASED = 0x00; static const uint8_t STATE_PRESSED = 0x01; @@ -120,5 +119,4 @@ class Touchscreen : public PollingComponent { bool skip_update_{false}; }; -} // namespace touchscreen -} // namespace esphome +} // namespace esphome::touchscreen diff --git a/esphome/components/tsl2561/tsl2561.cpp b/esphome/components/tsl2561/tsl2561.cpp index bccff1fb26a..963114b230c 100644 --- a/esphome/components/tsl2561/tsl2561.cpp +++ b/esphome/components/tsl2561/tsl2561.cpp @@ -1,8 +1,7 @@ #include "tsl2561.h" #include "esphome/core/log.h" -namespace esphome { -namespace tsl2561 { +namespace esphome::tsl2561 { static const char *const TAG = "tsl2561"; @@ -165,5 +164,4 @@ bool TSL2561Sensor::tsl2561_read_byte(uint8_t a_register, uint8_t *value) { return this->read_byte(a_register | TSL2561_COMMAND_BIT, value); } -} // namespace tsl2561 -} // namespace esphome +} // namespace esphome::tsl2561 diff --git a/esphome/components/tsl2561/tsl2561.h b/esphome/components/tsl2561/tsl2561.h index a8f0aef90f9..0fbb59c648d 100644 --- a/esphome/components/tsl2561/tsl2561.h +++ b/esphome/components/tsl2561/tsl2561.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace tsl2561 { +namespace esphome::tsl2561 { /** Enum listing all conversion/integration time settings for the TSL2561 * @@ -82,5 +81,4 @@ class TSL2561Sensor : public sensor::Sensor, public PollingComponent, public i2c bool package_cs_{false}; }; -} // namespace tsl2561 -} // namespace esphome +} // namespace esphome::tsl2561 diff --git a/esphome/components/tsl2591/tsl2591.cpp b/esphome/components/tsl2591/tsl2591.cpp index 4ce673a91a1..fb34dd833d9 100644 --- a/esphome/components/tsl2591/tsl2591.cpp +++ b/esphome/components/tsl2591/tsl2591.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace tsl2591 { +namespace esphome::tsl2591 { static const char *const TAG = "tsl2591.sensor"; @@ -475,5 +474,4 @@ float TSL2591Component::get_actual_gain() { } } -} // namespace tsl2591 -} // namespace esphome +} // namespace esphome::tsl2591 diff --git a/esphome/components/tsl2591/tsl2591.h b/esphome/components/tsl2591/tsl2591.h index 84c92b6ba98..4b63c8ec40a 100644 --- a/esphome/components/tsl2591/tsl2591.h +++ b/esphome/components/tsl2591/tsl2591.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace tsl2591 { +namespace esphome::tsl2591 { /** Enum listing all conversion/integration time settings for the TSL2591. * @@ -270,5 +269,4 @@ class TSL2591Component : public PollingComponent, public i2c::I2CDevice { void interval_function_for_update_(); }; -} // namespace tsl2591 -} // namespace esphome +} // namespace esphome::tsl2591 diff --git a/esphome/components/tt21100/binary_sensor/tt21100_button.cpp b/esphome/components/tt21100/binary_sensor/tt21100_button.cpp index 2d5ac22a830..ccf6e53d665 100644 --- a/esphome/components/tt21100/binary_sensor/tt21100_button.cpp +++ b/esphome/components/tt21100/binary_sensor/tt21100_button.cpp @@ -1,8 +1,7 @@ #include "tt21100_button.h" #include "esphome/core/log.h" -namespace esphome { -namespace tt21100 { +namespace esphome::tt21100 { static const char *const TAG = "tt21100.binary_sensor"; @@ -23,5 +22,4 @@ void TT21100Button::update_button(uint8_t index, uint16_t state) { this->publish_state(state > 0); } -} // namespace tt21100 -} // namespace esphome +} // namespace esphome::tt21100 diff --git a/esphome/components/tt21100/binary_sensor/tt21100_button.h b/esphome/components/tt21100/binary_sensor/tt21100_button.h index 90b55bb75a0..a1f59464479 100644 --- a/esphome/components/tt21100/binary_sensor/tt21100_button.h +++ b/esphome/components/tt21100/binary_sensor/tt21100_button.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace tt21100 { +namespace esphome::tt21100 { class TT21100Button : public binary_sensor::BinarySensor, public Component, @@ -24,5 +23,4 @@ class TT21100Button : public binary_sensor::BinarySensor, uint8_t index_; }; -} // namespace tt21100 -} // namespace esphome +} // namespace esphome::tt21100 diff --git a/esphome/components/tt21100/touchscreen/tt21100.cpp b/esphome/components/tt21100/touchscreen/tt21100.cpp index b4735fe6d70..018094df737 100644 --- a/esphome/components/tt21100/touchscreen/tt21100.cpp +++ b/esphome/components/tt21100/touchscreen/tt21100.cpp @@ -1,8 +1,7 @@ #include "tt21100.h" #include "esphome/core/log.h" -namespace esphome { -namespace tt21100 { +namespace esphome::tt21100 { static const char *const TAG = "tt21100"; @@ -139,5 +138,4 @@ void TT21100Touchscreen::dump_config() { LOG_PIN(" Reset Pin: ", this->reset_pin_); } -} // namespace tt21100 -} // namespace esphome +} // namespace esphome::tt21100 diff --git a/esphome/components/tt21100/touchscreen/tt21100.h b/esphome/components/tt21100/touchscreen/tt21100.h index 5d1b2efe3cf..3c6030c9c1b 100644 --- a/esphome/components/tt21100/touchscreen/tt21100.h +++ b/esphome/components/tt21100/touchscreen/tt21100.h @@ -7,8 +7,7 @@ #include -namespace esphome { -namespace tt21100 { +namespace esphome::tt21100 { using namespace touchscreen; @@ -39,5 +38,4 @@ class TT21100Touchscreen : public Touchscreen, public i2c::I2CDevice { std::vector button_listeners_; }; -} // namespace tt21100 -} // namespace esphome +} // namespace esphome::tt21100 diff --git a/esphome/components/ttp229_bsf/ttp229_bsf.cpp b/esphome/components/ttp229_bsf/ttp229_bsf.cpp index 8d1ed45bb01..1c7fa3531f0 100644 --- a/esphome/components/ttp229_bsf/ttp229_bsf.cpp +++ b/esphome/components/ttp229_bsf/ttp229_bsf.cpp @@ -1,8 +1,7 @@ #include "ttp229_bsf.h" #include "esphome/core/log.h" -namespace esphome { -namespace ttp229_bsf { +namespace esphome::ttp229_bsf { static const char *const TAG = "ttp229_bsf"; @@ -18,5 +17,4 @@ void TTP229BSFComponent::dump_config() { LOG_PIN(" SDO pin: ", this->sdo_pin_); } -} // namespace ttp229_bsf -} // namespace esphome +} // namespace esphome::ttp229_bsf diff --git a/esphome/components/ttp229_bsf/ttp229_bsf.h b/esphome/components/ttp229_bsf/ttp229_bsf.h index fea4356b55b..07f0c638c2d 100644 --- a/esphome/components/ttp229_bsf/ttp229_bsf.h +++ b/esphome/components/ttp229_bsf/ttp229_bsf.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace ttp229_bsf { +namespace esphome::ttp229_bsf { class TTP229BSFChannel : public binary_sensor::BinarySensor { public: @@ -51,5 +50,4 @@ class TTP229BSFComponent : public Component { std::vector channels_{}; }; -} // namespace ttp229_bsf -} // namespace esphome +} // namespace esphome::ttp229_bsf diff --git a/esphome/components/ttp229_lsf/ttp229_lsf.cpp b/esphome/components/ttp229_lsf/ttp229_lsf.cpp index 7bdb57ebec9..eaef33d7935 100644 --- a/esphome/components/ttp229_lsf/ttp229_lsf.cpp +++ b/esphome/components/ttp229_lsf/ttp229_lsf.cpp @@ -1,8 +1,7 @@ #include "ttp229_lsf.h" #include "esphome/core/log.h" -namespace esphome { -namespace ttp229_lsf { +namespace esphome::ttp229_lsf { static const char *const TAG = "ttp229_lsf"; @@ -40,5 +39,4 @@ void TTP229LSFComponent::loop() { } } -} // namespace ttp229_lsf -} // namespace esphome +} // namespace esphome::ttp229_lsf diff --git a/esphome/components/ttp229_lsf/ttp229_lsf.h b/esphome/components/ttp229_lsf/ttp229_lsf.h index 7cc4bfca89a..09e7745d256 100644 --- a/esphome/components/ttp229_lsf/ttp229_lsf.h +++ b/esphome/components/ttp229_lsf/ttp229_lsf.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace ttp229_lsf { +namespace esphome::ttp229_lsf { class TTP229Channel : public binary_sensor::BinarySensor { public: @@ -33,5 +32,4 @@ class TTP229LSFComponent : public Component, public i2c::I2CDevice { } error_code_{NONE}; }; -} // namespace ttp229_lsf -} // namespace esphome +} // namespace esphome::ttp229_lsf diff --git a/esphome/components/tuya/automation.cpp b/esphome/components/tuya/automation.cpp index a8cfd098f10..5c84f36b832 100644 --- a/esphome/components/tuya/automation.cpp +++ b/esphome/components/tuya/automation.cpp @@ -4,8 +4,7 @@ static const char *const TAG = "tuya.automation"; -namespace esphome { -namespace tuya { +namespace esphome::tuya { void check_expected_datapoint(const TuyaDatapoint &dp, TuyaDatapointType expected) { if (dp.type != expected) { @@ -63,5 +62,4 @@ TuyaBitmaskDatapointUpdateTrigger::TuyaBitmaskDatapointUpdateTrigger(Tuya *paren }); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/automation.h b/esphome/components/tuya/automation.h index 8d91cfdfbf5..f5c806b0135 100644 --- a/esphome/components/tuya/automation.h +++ b/esphome/components/tuya/automation.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaDatapointUpdateTrigger : public Trigger { public: @@ -51,5 +50,4 @@ class TuyaBitmaskDatapointUpdateTrigger : public Trigger { explicit TuyaBitmaskDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id); }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp index a63e9c8318e..f93bd31b9d9 100644 --- a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp +++ b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_binary_sensor.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.binary_sensor"; @@ -20,5 +19,4 @@ void TuyaBinarySensor::dump_config() { this->sensor_id_); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.h b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.h index 1eeeb404776..f92652d087b 100644 --- a/esphome/components/tuya/binary_sensor/tuya_binary_sensor.h +++ b/esphome/components/tuya/binary_sensor/tuya_binary_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaBinarySensor : public binary_sensor::BinarySensor, public Component { public: @@ -20,5 +19,4 @@ class TuyaBinarySensor : public binary_sensor::BinarySensor, public Component { uint8_t sensor_id_{0}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/climate/tuya_climate.cpp b/esphome/components/tuya/climate/tuya_climate.cpp index 6602ccd8c9a..7dbf33878a4 100644 --- a/esphome/components/tuya/climate/tuya_climate.cpp +++ b/esphome/components/tuya/climate/tuya_climate.cpp @@ -1,8 +1,7 @@ #include "tuya_climate.h" #include "esphome/core/log.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.climate"; @@ -533,5 +532,4 @@ void TuyaClimate::switch_to_action_(climate::ClimateAction action) { this->action = action; } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/climate/tuya_climate.h b/esphome/components/tuya/climate/tuya_climate.h index 09f3fd30c39..b9fb45257aa 100644 --- a/esphome/components/tuya/climate/tuya_climate.h +++ b/esphome/components/tuya/climate/tuya_climate.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/climate/climate.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaClimate : public climate::Climate, public Component { public: @@ -125,5 +124,4 @@ class TuyaClimate : public climate::Climate, public Component { bool reports_fahrenheit_{false}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/cover/tuya_cover.cpp b/esphome/components/tuya/cover/tuya_cover.cpp index 125afec0483..dd268388d00 100644 --- a/esphome/components/tuya/cover/tuya_cover.cpp +++ b/esphome/components/tuya/cover/tuya_cover.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_cover.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { const uint8_t COMMAND_OPEN = 0x00; const uint8_t COMMAND_CLOSE = 0x02; @@ -140,5 +139,4 @@ cover::CoverTraits TuyaCover::get_traits() { return traits; } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/cover/tuya_cover.h b/esphome/components/tuya/cover/tuya_cover.h index bb5a00bc598..ab639756832 100644 --- a/esphome/components/tuya/cover/tuya_cover.h +++ b/esphome/components/tuya/cover/tuya_cover.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/cover/cover.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { enum TuyaCoverRestoreMode { COVER_NO_RESTORE, @@ -46,5 +45,4 @@ class TuyaCover : public cover::Cover, public Component { bool invert_position_report_; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/fan/tuya_fan.cpp b/esphome/components/tuya/fan/tuya_fan.cpp index a387606b776..0b5fc19038c 100644 --- a/esphome/components/tuya/fan/tuya_fan.cpp +++ b/esphome/components/tuya/fan/tuya_fan.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_fan.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.fan"; @@ -127,5 +126,4 @@ void TuyaFan::control(const fan::FanCall &call) { } } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/fan/tuya_fan.h b/esphome/components/tuya/fan/tuya_fan.h index 527efa8246d..bfb6bdeca03 100644 --- a/esphome/components/tuya/fan/tuya_fan.h +++ b/esphome/components/tuya/fan/tuya_fan.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/fan/fan.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaFan : public Component, public fan::Fan { public: @@ -32,5 +31,4 @@ class TuyaFan : public Component, public fan::Fan { TuyaDatapointType oscillation_type_{}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/light/tuya_light.cpp b/esphome/components/tuya/light/tuya_light.cpp index 620bb88d0b7..9f3f3c13cce 100644 --- a/esphome/components/tuya/light/tuya_light.cpp +++ b/esphome/components/tuya/light/tuya_light.cpp @@ -2,8 +2,7 @@ #include "tuya_light.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.light"; @@ -228,5 +227,4 @@ void TuyaLight::write_state(light::LightState *state) { } } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/light/tuya_light.h b/esphome/components/tuya/light/tuya_light.h index ded94f390af..d990eea72ad 100644 --- a/esphome/components/tuya/light/tuya_light.h +++ b/esphome/components/tuya/light/tuya_light.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/light/light_output.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { enum TuyaColorType { RGB, HSV, RGBHSV }; @@ -65,5 +64,4 @@ class TuyaLight : public Component, public light::LightOutput { light::LightState *state_{nullptr}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/number/tuya_number.cpp b/esphome/components/tuya/number/tuya_number.cpp index fd22e642c64..bfedbb93194 100644 --- a/esphome/components/tuya/number/tuya_number.cpp +++ b/esphome/components/tuya/number/tuya_number.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_number.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.number"; @@ -91,5 +90,4 @@ void TuyaNumber::dump_config() { ESP_LOGCONFIG(TAG, " Restore Value: %s", YESNO(this->restore_value_)); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/number/tuya_number.h b/esphome/components/tuya/number/tuya_number.h index 53137d6f66c..51c53a4442e 100644 --- a/esphome/components/tuya/number/tuya_number.h +++ b/esphome/components/tuya/number/tuya_number.h @@ -6,8 +6,7 @@ #include "esphome/core/optional.h" #include "esphome/core/preferences.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaNumber : public number::Number, public Component { public: @@ -34,5 +33,4 @@ class TuyaNumber : public number::Number, public Component { ESPPreferenceObject pref_; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/select/tuya_select.cpp b/esphome/components/tuya/select/tuya_select.cpp index 9d46e4c8ca0..f0fc47f5040 100644 --- a/esphome/components/tuya/select/tuya_select.cpp +++ b/esphome/components/tuya/select/tuya_select.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_select.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.select"; @@ -47,5 +46,4 @@ void TuyaSelect::dump_config() { } } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/select/tuya_select.h b/esphome/components/tuya/select/tuya_select.h index 24505c99104..f8d2d89ea89 100644 --- a/esphome/components/tuya/select/tuya_select.h +++ b/esphome/components/tuya/select/tuya_select.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaSelect : public select::Select, public Component { public: @@ -32,5 +31,4 @@ class TuyaSelect : public select::Select, public Component { bool is_int_ = false; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/sensor/tuya_sensor.cpp b/esphome/components/tuya/sensor/tuya_sensor.cpp index 673471a6cec..c9489847864 100644 --- a/esphome/components/tuya/sensor/tuya_sensor.cpp +++ b/esphome/components/tuya/sensor/tuya_sensor.cpp @@ -2,8 +2,7 @@ #include "tuya_sensor.h" #include -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.sensor"; @@ -30,5 +29,4 @@ void TuyaSensor::dump_config() { ESP_LOGCONFIG(TAG, " Sensor has datapoint ID %u", this->sensor_id_); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/sensor/tuya_sensor.h b/esphome/components/tuya/sensor/tuya_sensor.h index 8fd7cd17702..b700fc8bd74 100644 --- a/esphome/components/tuya/sensor/tuya_sensor.h +++ b/esphome/components/tuya/sensor/tuya_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaSensor : public sensor::Sensor, public Component { public: @@ -20,5 +19,4 @@ class TuyaSensor : public sensor::Sensor, public Component { uint8_t sensor_id_{0}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/switch/tuya_switch.cpp b/esphome/components/tuya/switch/tuya_switch.cpp index cbd794b0013..8d4d183d5b6 100644 --- a/esphome/components/tuya/switch/tuya_switch.cpp +++ b/esphome/components/tuya/switch/tuya_switch.cpp @@ -1,8 +1,7 @@ #include "esphome/core/log.h" #include "tuya_switch.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.switch"; @@ -24,5 +23,4 @@ void TuyaSwitch::dump_config() { ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", this->switch_id_); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/switch/tuya_switch.h b/esphome/components/tuya/switch/tuya_switch.h index 89e6264e5c3..7e0109c34c9 100644 --- a/esphome/components/tuya/switch/tuya_switch.h +++ b/esphome/components/tuya/switch/tuya_switch.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/switch/switch.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaSwitch : public switch_::Switch, public Component { public: @@ -22,5 +21,4 @@ class TuyaSwitch : public switch_::Switch, public Component { uint8_t switch_id_{0}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/text_sensor/tuya_text_sensor.cpp b/esphome/components/tuya/text_sensor/tuya_text_sensor.cpp index b15fb6f85a7..ebb35cead7f 100644 --- a/esphome/components/tuya/text_sensor/tuya_text_sensor.cpp +++ b/esphome/components/tuya/text_sensor/tuya_text_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/entity_base.h" #include "esphome/core/log.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya.text_sensor"; @@ -43,5 +42,4 @@ void TuyaTextSensor::dump_config() { this->sensor_id_); } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/text_sensor/tuya_text_sensor.h b/esphome/components/tuya/text_sensor/tuya_text_sensor.h index 502ae5e8c73..c9ac64deb8e 100644 --- a/esphome/components/tuya/text_sensor/tuya_text_sensor.h +++ b/esphome/components/tuya/text_sensor/tuya_text_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/tuya/tuya.h" #include "esphome/components/text_sensor/text_sensor.h" -namespace esphome { -namespace tuya { +namespace esphome::tuya { class TuyaTextSensor : public text_sensor::TextSensor, public Component { public: @@ -20,5 +19,4 @@ class TuyaTextSensor : public text_sensor::TextSensor, public Component { uint8_t sensor_id_{0}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index a1acbf2f56c..d682adffe38 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -13,8 +13,7 @@ #include "esphome/components/captive_portal/captive_portal.h" #endif -namespace esphome { -namespace tuya { +namespace esphome::tuya { static const char *const TAG = "tuya"; static const int COMMAND_DELAY = 10; @@ -760,5 +759,4 @@ void Tuya::register_listener(uint8_t datapoint_id, const std::functioninit_state_; } -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tuya/tuya.h b/esphome/components/tuya/tuya.h index 7e6b50f0847..8ba8ac85a05 100644 --- a/esphome/components/tuya/tuya.h +++ b/esphome/components/tuya/tuya.h @@ -13,8 +13,7 @@ #include "esphome/core/time.h" #endif -namespace esphome { -namespace tuya { +namespace esphome::tuya { enum class TuyaDatapointType : uint8_t { RAW = 0x00, // variable length @@ -162,5 +161,4 @@ class Tuya : public Component, public uart::UARTDevice { CallbackManager initialized_callback_{}; }; -} // namespace tuya -} // namespace esphome +} // namespace esphome::tuya diff --git a/esphome/components/tx20/tx20.cpp b/esphome/components/tx20/tx20.cpp index 3e0234fac04..353cb31513a 100644 --- a/esphome/components/tx20/tx20.cpp +++ b/esphome/components/tx20/tx20.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace tx20 { +namespace esphome::tx20 { static const char *const TAG = "tx20"; static const uint8_t MAX_BUFFER_SIZE = 41; @@ -206,5 +205,4 @@ void IRAM_ATTR Tx20ComponentStore::reset() { start_time = 0; } -} // namespace tx20 -} // namespace esphome +} // namespace esphome::tx20 diff --git a/esphome/components/tx20/tx20.h b/esphome/components/tx20/tx20.h index d1673f99f2b..7ca29eaf3bc 100644 --- a/esphome/components/tx20/tx20.h +++ b/esphome/components/tx20/tx20.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace tx20 { +namespace esphome::tx20 { /// Store data in a class that doesn't use multiple-inheritance (vtables in flash) struct Tx20ComponentStore { @@ -47,5 +46,4 @@ class Tx20Component : public Component { Tx20ComponentStore store_; }; -} // namespace tx20 -} // namespace esphome +} // namespace esphome::tx20 diff --git a/esphome/components/udp/automation.h b/esphome/components/udp/automation.h index b66c2a9892a..c37b82921e4 100644 --- a/esphome/components/udp/automation.h +++ b/esphome/components/udp/automation.h @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace udp { +namespace esphome::udp { template class UDPWriteAction : public Action, public Parented { public: @@ -40,6 +39,6 @@ template class UDPWriteAction : public Action, public Par } data_; }; -} // namespace udp -} // namespace esphome +} // namespace esphome::udp + #endif diff --git a/esphome/components/udp/packet_transport/udp_transport.cpp b/esphome/components/udp/packet_transport/udp_transport.cpp index b5e73af7779..40ce46d74e9 100644 --- a/esphome/components/udp/packet_transport/udp_transport.cpp +++ b/esphome/components/udp/packet_transport/udp_transport.cpp @@ -3,8 +3,7 @@ #include "esphome/components/network/util.h" #include "udp_transport.h" -namespace esphome { -namespace udp { +namespace esphome::udp { static const char *const TAG = "udp_transport"; @@ -17,5 +16,4 @@ void UDPTransport::setup() { } void UDPTransport::send_packet(const std::vector &buf) const { this->parent_->send_packet(buf); } -} // namespace udp -} // namespace esphome +} // namespace esphome::udp diff --git a/esphome/components/udp/packet_transport/udp_transport.h b/esphome/components/udp/packet_transport/udp_transport.h index 8d01ae0909f..8621ddca482 100644 --- a/esphome/components/udp/packet_transport/udp_transport.h +++ b/esphome/components/udp/packet_transport/udp_transport.h @@ -6,8 +6,7 @@ #include "esphome/components/packet_transport/packet_transport.h" #include -namespace esphome { -namespace udp { +namespace esphome::udp { class UDPTransport : public packet_transport::PacketTransport, public Parented { public: @@ -21,6 +20,6 @@ class UDPTransport : public packet_transport::PacketTransport, public Parented -namespace esphome { -namespace ufire_ec { +namespace esphome::ufire_ec { static const char *const TAG = "ufire_ec"; @@ -122,5 +121,4 @@ void UFireECComponent::dump_config() { LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_); } -} // namespace ufire_ec -} // namespace esphome +} // namespace esphome::ufire_ec diff --git a/esphome/components/ufire_ec/ufire_ec.h b/esphome/components/ufire_ec/ufire_ec.h index 8a648b5038b..fce62586322 100644 --- a/esphome/components/ufire_ec/ufire_ec.h +++ b/esphome/components/ufire_ec/ufire_ec.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ufire_ec { +namespace esphome::ufire_ec { static const uint8_t CONFIG_TEMP_COMPENSATION = 0x02; @@ -83,5 +82,4 @@ template class UFireECResetAction : public Action { UFireECComponent *parent_; }; -} // namespace ufire_ec -} // namespace esphome +} // namespace esphome::ufire_ec diff --git a/esphome/components/ufire_ise/ufire_ise.cpp b/esphome/components/ufire_ise/ufire_ise.cpp index e967fc53c37..bd2dc2836ed 100644 --- a/esphome/components/ufire_ise/ufire_ise.cpp +++ b/esphome/components/ufire_ise/ufire_ise.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace ufire_ise { +namespace esphome::ufire_ise { static const char *const TAG = "ufire_ise"; @@ -147,5 +146,4 @@ void UFireISEComponent::dump_config() { LOG_SENSOR(" ", "Temperature Sensor external", this->temperature_sensor_external_); } -} // namespace ufire_ise -} // namespace esphome +} // namespace esphome::ufire_ise diff --git a/esphome/components/ufire_ise/ufire_ise.h b/esphome/components/ufire_ise/ufire_ise.h index fe9a6dfb9c8..bff8eeff9de 100644 --- a/esphome/components/ufire_ise/ufire_ise.h +++ b/esphome/components/ufire_ise/ufire_ise.h @@ -6,8 +6,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace ufire_ise { +namespace esphome::ufire_ise { static const float PROBE_MV_TO_PH = 59.2; static const float PROBE_TMP_CORRECTION = 0.03; @@ -91,5 +90,4 @@ template class UFireISEResetAction : public Action { UFireISEComponent *parent_; }; -} // namespace ufire_ise -} // namespace esphome +} // namespace esphome::ufire_ise diff --git a/esphome/components/update/automation.h b/esphome/components/update/automation.h index af24c838b14..821151f67ce 100644 --- a/esphome/components/update/automation.h +++ b/esphome/components/update/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" -namespace esphome { -namespace update { +namespace esphome::update { template class PerformAction : public Action, public Parented { TEMPLATABLE_VALUE(bool, force) @@ -24,5 +23,4 @@ template class IsAvailableCondition : public Condition, p bool check(const Ts &...x) override { return this->parent_->state == UPDATE_STATE_AVAILABLE; } }; -} // namespace update -} // namespace esphome +} // namespace esphome::update diff --git a/esphome/components/update/update_entity.cpp b/esphome/components/update/update_entity.cpp index 1a5a55577f9..b0d4c01cc96 100644 --- a/esphome/components/update/update_entity.cpp +++ b/esphome/components/update/update_entity.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/progmem.h" -namespace esphome { -namespace update { +namespace esphome::update { static const char *const TAG = "update"; @@ -49,5 +48,4 @@ void UpdateEntity::publish_state() { #endif } -} // namespace update -} // namespace esphome +} // namespace esphome::update diff --git a/esphome/components/update/update_entity.h b/esphome/components/update/update_entity.h index f7d0032f217..f925d338ff7 100644 --- a/esphome/components/update/update_entity.h +++ b/esphome/components/update/update_entity.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/entity_base.h" -namespace esphome { -namespace update { +namespace esphome::update { struct UpdateInfo { std::string latest_version; @@ -58,5 +57,4 @@ class UpdateEntity : public EntityBase { std::unique_ptr> update_available_trigger_{nullptr}; }; -} // namespace update -} // namespace esphome +} // namespace esphome::update diff --git a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp index 512a2581229..0400888511d 100644 --- a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp +++ b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { static const char *const TAG = "uponor_smatrix.climate"; @@ -100,5 +99,4 @@ void UponorSmatrixClimate::on_device_data(const UponorSmatrixData *data, size_t this->last_data_ = millis(); } -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.h b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.h index b8458045c61..4cc5a4a3bcf 100644 --- a/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.h +++ b/esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.h @@ -4,8 +4,7 @@ #include "esphome/components/uponor_smatrix/uponor_smatrix.h" #include "esphome/core/component.h" -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { class UponorSmatrixClimate : public climate::Climate, public Component, public UponorSmatrixDevice { public: @@ -24,5 +23,4 @@ class UponorSmatrixClimate : public climate::Climate, public Component, public U uint16_t target_temperature_raw_; }; -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp index 5f690a6879a..97e9c275700 100644 --- a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +++ b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { static const char *const TAG = "uponor_smatrix.sensor"; @@ -42,5 +41,4 @@ void UponorSmatrixSensor::on_device_data(const UponorSmatrixData *data, size_t d } } -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h index 97d0d21838f..346fe1e3d66 100644 --- a/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +++ b/esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h @@ -4,8 +4,7 @@ #include "esphome/components/uponor_smatrix/uponor_smatrix.h" #include "esphome/core/component.h" -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { class UponorSmatrixSensor : public sensor::Sensor, public Component, public UponorSmatrixDevice { SUB_SENSOR(temperature) @@ -20,5 +19,4 @@ class UponorSmatrixSensor : public sensor::Sensor, public Component, public Upon void on_device_data(const UponorSmatrixData *data, size_t data_len) override; }; -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/uponor_smatrix/uponor_smatrix.cpp b/esphome/components/uponor_smatrix/uponor_smatrix.cpp index 1fd53955a0e..3f1feaa9273 100644 --- a/esphome/components/uponor_smatrix/uponor_smatrix.cpp +++ b/esphome/components/uponor_smatrix/uponor_smatrix.cpp @@ -5,8 +5,7 @@ #include -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { static const char *const TAG = "uponor_smatrix"; @@ -221,5 +220,4 @@ bool UponorSmatrixComponent::do_send_time_() { } #endif -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/uponor_smatrix/uponor_smatrix.h b/esphome/components/uponor_smatrix/uponor_smatrix.h index bd20e9b6a0a..e9e772feaba 100644 --- a/esphome/components/uponor_smatrix/uponor_smatrix.h +++ b/esphome/components/uponor_smatrix/uponor_smatrix.h @@ -15,8 +15,7 @@ #include #include -namespace esphome { -namespace uponor_smatrix { +namespace esphome::uponor_smatrix { /// Date/Time Part 1 (year, month, day of week) static const uint8_t UPONOR_ID_DATETIME1 = 0x08; @@ -123,5 +122,4 @@ inline uint16_t celsius_to_raw(float celsius) { : static_cast(lroundf(celsius_to_fahrenheit(celsius) * 10.0f)); } -} // namespace uponor_smatrix -} // namespace esphome +} // namespace esphome::uponor_smatrix diff --git a/esphome/components/valve/automation.h b/esphome/components/valve/automation.h index 27c0e329f08..08c9f4e0110 100644 --- a/esphome/components/valve/automation.h +++ b/esphome/components/valve/automation.h @@ -4,8 +4,7 @@ #include "esphome/core/component.h" #include "valve.h" -namespace esphome { -namespace valve { +namespace esphome::valve { template class OpenAction : public Action { public: @@ -121,5 +120,4 @@ class ValveClosedTrigger : public Trigger<> { Valve *valve_; }; -} // namespace valve -} // namespace esphome +} // namespace esphome::valve diff --git a/esphome/components/valve/valve.cpp b/esphome/components/valve/valve.cpp index 9e1ef9da508..8fccd1e6d69 100644 --- a/esphome/components/valve/valve.cpp +++ b/esphome/components/valve/valve.cpp @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace valve { +namespace esphome::valve { static const char *const TAG = "valve"; @@ -176,5 +175,4 @@ void ValveRestoreState::apply(Valve *valve) { valve->publish_state(); } -} // namespace valve -} // namespace esphome +} // namespace esphome::valve diff --git a/esphome/components/valve/valve.h b/esphome/components/valve/valve.h index b4141f5ff59..c6cdf07096a 100644 --- a/esphome/components/valve/valve.h +++ b/esphome/components/valve/valve.h @@ -7,8 +7,7 @@ #include "esphome/core/preferences.h" #include "valve_traits.h" -namespace esphome { -namespace valve { +namespace esphome::valve { const extern float VALVE_OPEN; const extern float VALVE_CLOSED; @@ -147,5 +146,4 @@ class Valve : public EntityBase { ESPPreferenceObject rtc_; }; -} // namespace valve -} // namespace esphome +} // namespace esphome::valve diff --git a/esphome/components/valve/valve_traits.h b/esphome/components/valve/valve_traits.h index 7e9aab2f26f..81b845a5f20 100644 --- a/esphome/components/valve/valve_traits.h +++ b/esphome/components/valve/valve_traits.h @@ -1,7 +1,6 @@ #pragma once -namespace esphome { -namespace valve { +namespace esphome::valve { class ValveTraits { public: @@ -23,5 +22,4 @@ class ValveTraits { bool supports_stop_{false}; }; -} // namespace valve -} // namespace esphome +} // namespace esphome::valve diff --git a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp index e598b1de6b7..ddb6b530686 100644 --- a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp +++ b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace vbus { +namespace esphome::vbus { static const char *const TAG = "vbus.binary_sensor"; @@ -199,5 +198,4 @@ void VBusCustomSubBSensor::parse_message(std::vector &message) { this->publish_state(this->message_parser_(message)); } -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.h b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.h index 04c9a7b8264..8d372f45d63 100644 --- a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.h +++ b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.h @@ -3,8 +3,7 @@ #include "../vbus.h" #include "esphome/components/binary_sensor/binary_sensor.h" -namespace esphome { -namespace vbus { +namespace esphome::vbus { class DeltaSolBSPlusBSensor : public VBusListener, public Component { public: @@ -166,5 +165,4 @@ class VBusCustomSubBSensor : public binary_sensor::BinarySensor, public Componen message_parser_t message_parser_; }; -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/vbus/sensor/vbus_sensor.cpp b/esphome/components/vbus/sensor/vbus_sensor.cpp index 407a81c83b1..773e1435e29 100644 --- a/esphome/components/vbus/sensor/vbus_sensor.cpp +++ b/esphome/components/vbus/sensor/vbus_sensor.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace vbus { +namespace esphome::vbus { static const char *const TAG = "vbus.sensor"; @@ -337,5 +336,4 @@ void VBusCustomSubSensor::parse_message(std::vector &message) { this->publish_state(this->message_parser_(message)); } -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/vbus/sensor/vbus_sensor.h b/esphome/components/vbus/sensor/vbus_sensor.h index ea248b1db24..34f2c442242 100644 --- a/esphome/components/vbus/sensor/vbus_sensor.h +++ b/esphome/components/vbus/sensor/vbus_sensor.h @@ -3,8 +3,7 @@ #include "../vbus.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace vbus { +namespace esphome::vbus { class DeltaSolBSPlusSensor : public VBusListener, public Component { public: @@ -243,5 +242,4 @@ class VBusCustomSubSensor : public sensor::Sensor, public Component { message_parser_t message_parser_; }; -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/vbus/vbus.cpp b/esphome/components/vbus/vbus.cpp index 195d6ed5680..81714a2049c 100644 --- a/esphome/components/vbus/vbus.cpp +++ b/esphome/components/vbus/vbus.cpp @@ -4,8 +4,7 @@ #include #include -namespace esphome { -namespace vbus { +namespace esphome::vbus { static const char *const TAG = "vbus"; @@ -131,5 +130,4 @@ void VBusListener::on_message(uint16_t command, uint16_t source, uint16_t dest, this->handle_message(message); } -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/vbus/vbus.h b/esphome/components/vbus/vbus.h index 0a253f1bdbd..ff523178ef6 100644 --- a/esphome/components/vbus/vbus.h +++ b/esphome/components/vbus/vbus.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace vbus { +namespace esphome::vbus { using message_parser_t = std::function &)>; @@ -47,5 +46,4 @@ class VBus : public uart::UARTDevice, public Component { std::vector listeners_{}; }; -} // namespace vbus -} // namespace esphome +} // namespace esphome::vbus diff --git a/esphome/components/veml3235/veml3235.cpp b/esphome/components/veml3235/veml3235.cpp index 1e02e3e802e..fd6cf1e2ede 100644 --- a/esphome/components/veml3235/veml3235.cpp +++ b/esphome/components/veml3235/veml3235.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace veml3235 { +namespace esphome::veml3235 { static const char *const TAG = "veml3235.sensor"; @@ -225,5 +224,4 @@ void VEML3235Sensor::dump_config() { digital_gain, gain, integration_time); } -} // namespace veml3235 -} // namespace esphome +} // namespace esphome::veml3235 diff --git a/esphome/components/veml3235/veml3235.h b/esphome/components/veml3235/veml3235.h index b57e1571f1a..df88bc6ff57 100644 --- a/esphome/components/veml3235/veml3235.h +++ b/esphome/components/veml3235/veml3235.h @@ -5,8 +5,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace veml3235 { +namespace esphome::veml3235 { // Register IDs/locations // @@ -104,5 +103,4 @@ class VEML3235Sensor : public sensor::Sensor, public PollingComponent, public i2 VEML3235ComponentIntegrationTime integration_time_{VEML3235_INTEGRATION_TIME_50MS}; }; -} // namespace veml3235 -} // namespace esphome +} // namespace esphome::veml3235 diff --git a/esphome/components/veml7700/veml7700.cpp b/esphome/components/veml7700/veml7700.cpp index 1ed484119bd..80e6f872abb 100644 --- a/esphome/components/veml7700/veml7700.cpp +++ b/esphome/components/veml7700/veml7700.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace veml7700 { +namespace esphome::veml7700 { static const char *const TAG = "veml7700"; static const size_t VEML_REG_SIZE = 2; @@ -434,5 +433,4 @@ void VEML7700Component::publish_data_part_3_(Readings &data) { this->actual_integration_time_sensor_->publish_state(get_itime_ms(data.actual_time)); } } -} // namespace veml7700 -} // namespace esphome +} // namespace esphome::veml7700 diff --git a/esphome/components/veml7700/veml7700.h b/esphome/components/veml7700/veml7700.h index 4b5edf733dc..a036bdf0029 100644 --- a/esphome/components/veml7700/veml7700.h +++ b/esphome/components/veml7700/veml7700.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/core/component.h" -namespace esphome { -namespace veml7700 { +namespace esphome::veml7700 { using esphome::i2c::ErrorCode; @@ -196,5 +195,4 @@ class VEML7700Component : public PollingComponent, public i2c::I2CDevice { sensor::Sensor *actual_integration_time_sensor_{nullptr}; // Actual integration time for the measurement }; -} // namespace veml7700 -} // namespace esphome +} // namespace esphome::veml7700 diff --git a/esphome/components/vl53l0x/vl53l0x_sensor.cpp b/esphome/components/vl53l0x/vl53l0x_sensor.cpp index 58b5a426754..df7929f676b 100644 --- a/esphome/components/vl53l0x/vl53l0x_sensor.cpp +++ b/esphome/components/vl53l0x/vl53l0x_sensor.cpp @@ -12,8 +12,7 @@ * in the vl53l0x integration directory. */ -namespace esphome { -namespace vl53l0x { +namespace esphome::vl53l0x { static const char *const TAG = "vl53l0x"; @@ -535,5 +534,4 @@ bool VL53L0XSensor::perform_single_ref_calibration_(uint8_t vhv_init_byte) { return true; } -} // namespace vl53l0x -} // namespace esphome +} // namespace esphome::vl53l0x diff --git a/esphome/components/vl53l0x/vl53l0x_sensor.h b/esphome/components/vl53l0x/vl53l0x_sensor.h index f533005b5b3..7c916f4fdeb 100644 --- a/esphome/components/vl53l0x/vl53l0x_sensor.h +++ b/esphome/components/vl53l0x/vl53l0x_sensor.h @@ -7,8 +7,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace vl53l0x { +namespace esphome::vl53l0x { struct SequenceStepEnables { bool tcc, msrc, dss, pre_range, final_range; @@ -70,5 +69,4 @@ class VL53L0XSensor : public sensor::Sensor, public PollingComponent, public i2c static bool enable_pin_setup_complete; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) }; -} // namespace vl53l0x -} // namespace esphome +} // namespace esphome::vl53l0x diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index ddce606b2c4..f2244a8ff43 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -9,8 +9,7 @@ #include #include -namespace esphome { -namespace voice_assistant { +namespace esphome::voice_assistant { static const char *const TAG = "voice_assistant"; @@ -1007,7 +1006,6 @@ const Configuration &VoiceAssistant::get_configuration() { VoiceAssistant *global_voice_assistant = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace voice_assistant -} // namespace esphome +} // namespace esphome::voice_assistant #endif // USE_VOICE_ASSISTANT diff --git a/esphome/components/voice_assistant/voice_assistant.h b/esphome/components/voice_assistant/voice_assistant.h index b1b5f20bff2..eb23dcb5e0d 100644 --- a/esphome/components/voice_assistant/voice_assistant.h +++ b/esphome/components/voice_assistant/voice_assistant.h @@ -26,8 +26,7 @@ #include #include -namespace esphome { -namespace voice_assistant { +namespace esphome::voice_assistant { // Version 1: Initial version // Version 2: Adds raw speaker support @@ -367,7 +366,6 @@ template class ConnectedCondition : public Condition, pub extern VoiceAssistant *global_voice_assistant; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) -} // namespace voice_assistant -} // namespace esphome +} // namespace esphome::voice_assistant #endif // USE_VOICE_ASSISTANT diff --git a/esphome/components/voltage_sampler/voltage_sampler.h b/esphome/components/voltage_sampler/voltage_sampler.h index d2e74d33bc5..c1b6ffb11e9 100644 --- a/esphome/components/voltage_sampler/voltage_sampler.h +++ b/esphome/components/voltage_sampler/voltage_sampler.h @@ -2,8 +2,7 @@ #include "esphome/core/component.h" -namespace esphome { -namespace voltage_sampler { +namespace esphome::voltage_sampler { /// Abstract interface for components to request voltage (usually ADC readings) class VoltageSampler { @@ -12,5 +11,4 @@ class VoltageSampler { virtual float sample() = 0; }; -} // namespace voltage_sampler -} // namespace esphome +} // namespace esphome::voltage_sampler diff --git a/esphome/components/wake_on_lan/wake_on_lan.cpp b/esphome/components/wake_on_lan/wake_on_lan.cpp index 8c5bdac54b2..fee6377965e 100644 --- a/esphome/components/wake_on_lan/wake_on_lan.cpp +++ b/esphome/components/wake_on_lan/wake_on_lan.cpp @@ -4,8 +4,7 @@ #include "esphome/components/network/ip_address.h" #include "esphome/components/network/util.h" -namespace esphome { -namespace wake_on_lan { +namespace esphome::wake_on_lan { static const char *const TAG = "wake_on_lan.button"; static const uint8_t PREFIX[6] = {255, 255, 255, 255, 255, 255}; @@ -84,6 +83,6 @@ void WakeOnLanButton::setup() { #endif } -} // namespace wake_on_lan -} // namespace esphome +} // namespace esphome::wake_on_lan + #endif diff --git a/esphome/components/wake_on_lan/wake_on_lan.h b/esphome/components/wake_on_lan/wake_on_lan.h index f516c4d669c..48f8d00a662 100644 --- a/esphome/components/wake_on_lan/wake_on_lan.h +++ b/esphome/components/wake_on_lan/wake_on_lan.h @@ -9,8 +9,7 @@ #include "WiFiUdp.h" #endif -namespace esphome { -namespace wake_on_lan { +namespace esphome::wake_on_lan { class WakeOnLanButton : public button::Button, public Component { public: @@ -31,6 +30,6 @@ class WakeOnLanButton : public button::Button, public Component { uint8_t macaddr_[6]; }; -} // namespace wake_on_lan -} // namespace esphome +} // namespace esphome::wake_on_lan + #endif diff --git a/esphome/components/watchdog/watchdog.cpp b/esphome/components/watchdog/watchdog.cpp index edf113b0b4a..b05d7d4f6d9 100644 --- a/esphome/components/watchdog/watchdog.cpp +++ b/esphome/components/watchdog/watchdog.cpp @@ -14,8 +14,7 @@ #include "pico/stdlib.h" #endif -namespace esphome { -namespace watchdog { +namespace esphome::watchdog { static const char *const TAG = "http_request.watchdog"; @@ -75,5 +74,4 @@ uint32_t WatchdogManager::get_timeout_() { return timeout_ms; } -} // namespace watchdog -} // namespace esphome +} // namespace esphome::watchdog diff --git a/esphome/components/watchdog/watchdog.h b/esphome/components/watchdog/watchdog.h index 899ec3fde01..795c057672f 100644 --- a/esphome/components/watchdog/watchdog.h +++ b/esphome/components/watchdog/watchdog.h @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace watchdog { +namespace esphome::watchdog { class WatchdogManager { public: @@ -20,5 +19,4 @@ class WatchdogManager { uint32_t timeout_ms_{0}; }; -} // namespace watchdog -} // namespace esphome +} // namespace esphome::watchdog diff --git a/esphome/components/waveshare_epaper/waveshare_213v3.cpp b/esphome/components/waveshare_epaper/waveshare_213v3.cpp index b55f3c8d26d..cc9c34cb42f 100644 --- a/esphome/components/waveshare_epaper/waveshare_213v3.cpp +++ b/esphome/components/waveshare_epaper/waveshare_213v3.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" -namespace esphome { -namespace waveshare_epaper { +namespace esphome::waveshare_epaper { static const char *const TAG = "waveshare_2.13v3"; @@ -188,5 +187,4 @@ void WaveshareEPaper2P13InV3::set_full_update_every(uint32_t full_update_every) this->full_update_every_ = full_update_every; } -} // namespace waveshare_epaper -} // namespace esphome +} // namespace esphome::waveshare_epaper diff --git a/esphome/components/waveshare_epaper/waveshare_epaper.cpp b/esphome/components/waveshare_epaper/waveshare_epaper.cpp index 4db9438206a..14ff5ed53cc 100644 --- a/esphome/components/waveshare_epaper/waveshare_epaper.cpp +++ b/esphome/components/waveshare_epaper/waveshare_epaper.cpp @@ -5,8 +5,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace waveshare_epaper { +namespace esphome::waveshare_epaper { static const char *const TAG = "waveshare_epaper"; @@ -4770,5 +4769,4 @@ void WaveshareEPaper13P3InK::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace waveshare_epaper -} // namespace esphome +} // namespace esphome::waveshare_epaper diff --git a/esphome/components/waveshare_epaper/waveshare_epaper.h b/esphome/components/waveshare_epaper/waveshare_epaper.h index 74bb1535196..fa3737238e6 100644 --- a/esphome/components/waveshare_epaper/waveshare_epaper.h +++ b/esphome/components/waveshare_epaper/waveshare_epaper.h @@ -4,8 +4,7 @@ #include "esphome/components/spi/spi.h" #include "esphome/components/display/display_buffer.h" -namespace esphome { -namespace waveshare_epaper { +namespace esphome::waveshare_epaper { class WaveshareEPaperBase : public display::DisplayBuffer, public spi::SPIDevice -namespace esphome { -namespace whynter { +namespace esphome::whynter { // Temperature const uint8_t TEMP_MIN_C = 16; // Celsius @@ -49,5 +48,4 @@ class Whynter : public climate_ir::ClimateIR { climate::ClimateMode mode_before_{climate::CLIMATE_MODE_OFF}; }; -} // namespace whynter -} // namespace esphome +} // namespace esphome::whynter diff --git a/esphome/components/wiegand/wiegand.cpp b/esphome/components/wiegand/wiegand.cpp index f3f578794a6..e5c29f8b115 100644 --- a/esphome/components/wiegand/wiegand.cpp +++ b/esphome/components/wiegand/wiegand.cpp @@ -3,8 +3,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace wiegand { +namespace esphome::wiegand { static const char *const TAG = "wiegand"; static const char *const KEYS = "0123456789*#"; @@ -127,5 +126,4 @@ void Wiegand::dump_config() { LOG_PIN(" D1 pin: ", this->d1_pin_); } -} // namespace wiegand -} // namespace esphome +} // namespace esphome::wiegand diff --git a/esphome/components/wiegand/wiegand.h b/esphome/components/wiegand/wiegand.h index 994631a3a35..33d81ba086b 100644 --- a/esphome/components/wiegand/wiegand.h +++ b/esphome/components/wiegand/wiegand.h @@ -5,8 +5,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace wiegand { +namespace esphome::wiegand { class Wiegand; @@ -50,5 +49,4 @@ class Wiegand : public key_provider::KeyProvider, public Component { std::vector key_triggers_; }; -} // namespace wiegand -} // namespace esphome +} // namespace esphome::wiegand diff --git a/esphome/components/wk2132_i2c/wk2132_i2c.cpp b/esphome/components/wk2132_i2c/wk2132_i2c.cpp index aaefae6f970..d60e8a834f9 100644 --- a/esphome/components/wk2132_i2c/wk2132_i2c.cpp +++ b/esphome/components/wk2132_i2c/wk2132_i2c.cpp @@ -1,4 +1,2 @@ /* compiling with esp-idf framework requires a .cpp file for some reason ? */ -namespace esphome { -namespace wk2132_i2c {} -} // namespace esphome +namespace esphome::wk2132_i2c {} // namespace esphome::wk2132_i2c diff --git a/esphome/components/wl_134/wl_134.cpp b/esphome/components/wl_134/wl_134.cpp index a902adfddd0..f3eb17965d0 100644 --- a/esphome/components/wl_134/wl_134.cpp +++ b/esphome/components/wl_134/wl_134.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace wl_134 { +namespace esphome::wl_134 { static const char *const TAG = "wl_134.sensor"; static const uint8_t ASCII_CR = 0x0D; @@ -114,5 +113,4 @@ void Wl134Component::dump_config() { // As specified in the sensor's data sheet this->check_uart_settings(9600, 1, esphome::uart::UART_CONFIG_PARITY_NONE, 8); } -} // namespace wl_134 -} // namespace esphome +} // namespace esphome::wl_134 diff --git a/esphome/components/wl_134/wl_134.h b/esphome/components/wl_134/wl_134.h index c0a90de17dd..973e5a1e7c3 100644 --- a/esphome/components/wl_134/wl_134.h +++ b/esphome/components/wl_134/wl_134.h @@ -6,8 +6,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace wl_134 { +namespace esphome::wl_134 { class Wl134Component : public text_sensor::TextSensor, public Component, public uart::UARTDevice { public: @@ -59,5 +58,4 @@ class Wl134Component : public text_sensor::TextSensor, public Component, public uint64_t hex_lsb_ascii_to_uint64_(const uint8_t *text, uint8_t text_size); }; -} // namespace wl_134 -} // namespace esphome +} // namespace esphome::wl_134 diff --git a/esphome/components/wled/wled_light_effect.cpp b/esphome/components/wled/wled_light_effect.cpp index db2708d6d02..e0724aa94a3 100644 --- a/esphome/components/wled/wled_light_effect.cpp +++ b/esphome/components/wled/wled_light_effect.cpp @@ -17,8 +17,7 @@ #include #endif -namespace esphome { -namespace wled { +namespace esphome::wled { // Description of protocols: // https://github.com/Aircoookie/WLED/wiki/UDP-Realtime-Control @@ -284,7 +283,6 @@ bool WLEDLightEffect::parse_dnrgb_frame_(light::AddressableLight &it, const uint return true; } -} // namespace wled -} // namespace esphome +} // namespace esphome::wled #endif // USE_ARDUINO diff --git a/esphome/components/wled/wled_light_effect.h b/esphome/components/wled/wled_light_effect.h index 3f3b7106119..bed897f5a61 100644 --- a/esphome/components/wled/wled_light_effect.h +++ b/esphome/components/wled/wled_light_effect.h @@ -10,8 +10,7 @@ class UDP; -namespace esphome { -namespace wled { +namespace esphome::wled { class WLEDLightEffect : public light::AddressableLightEffect { public: @@ -42,7 +41,6 @@ class WLEDLightEffect : public light::AddressableLightEffect { bool blank_on_start_{true}; }; -} // namespace wled -} // namespace esphome +} // namespace esphome::wled #endif // USE_ARDUINO diff --git a/esphome/components/wts01/wts01.cpp b/esphome/components/wts01/wts01.cpp index a7948c805a1..cc7ee980790 100644 --- a/esphome/components/wts01/wts01.cpp +++ b/esphome/components/wts01/wts01.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace wts01 { +namespace esphome::wts01 { constexpr uint8_t HEADER_1 = 0x55; constexpr uint8_t HEADER_2 = 0x01; @@ -90,5 +89,4 @@ void WTS01Sensor::process_packet_() { this->publish_state(temperature); } -} // namespace wts01 -} // namespace esphome +} // namespace esphome::wts01 diff --git a/esphome/components/wts01/wts01.h b/esphome/components/wts01/wts01.h index aae90c2c771..17d4dc57a2f 100644 --- a/esphome/components/wts01/wts01.h +++ b/esphome/components/wts01/wts01.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/uart/uart.h" -namespace esphome { -namespace wts01 { +namespace esphome::wts01 { constexpr uint8_t PACKET_SIZE = 9; @@ -22,5 +21,4 @@ class WTS01Sensor : public sensor::Sensor, public uart::UARTDevice, public Compo void process_packet_(); }; -} // namespace wts01 -} // namespace esphome +} // namespace esphome::wts01 diff --git a/esphome/components/x9c/x9c.cpp b/esphome/components/x9c/x9c.cpp index 773e52d6e13..52ce328b3c6 100644 --- a/esphome/components/x9c/x9c.cpp +++ b/esphome/components/x9c/x9c.cpp @@ -1,8 +1,7 @@ #include "x9c.h" #include "esphome/core/log.h" -namespace esphome { -namespace x9c { +namespace esphome::x9c { static const char *const TAG = "x9c.output"; @@ -73,5 +72,4 @@ void X9cOutput::dump_config() { LOG_FLOAT_OUTPUT(this); } -} // namespace x9c -} // namespace esphome +} // namespace esphome::x9c diff --git a/esphome/components/x9c/x9c.h b/esphome/components/x9c/x9c.h index 7dcd79bb7ce..112f0405d7d 100644 --- a/esphome/components/x9c/x9c.h +++ b/esphome/components/x9c/x9c.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace x9c { +namespace esphome::x9c { class X9cOutput : public output::FloatOutput, public Component { public: @@ -30,5 +29,4 @@ class X9cOutput : public output::FloatOutput, public Component { int step_delay_{0}; }; -} // namespace x9c -} // namespace esphome +} // namespace esphome::x9c diff --git a/esphome/components/xgzp68xx/xgzp68xx.cpp b/esphome/components/xgzp68xx/xgzp68xx.cpp index 5e816469acf..0eefd594d09 100644 --- a/esphome/components/xgzp68xx/xgzp68xx.cpp +++ b/esphome/components/xgzp68xx/xgzp68xx.cpp @@ -6,8 +6,7 @@ #include -namespace esphome { -namespace xgzp68xx { +namespace esphome::xgzp68xx { static const char *const TAG = "xgzp68xx.sensor"; @@ -118,5 +117,4 @@ void XGZP68XXComponent::dump_config() { LOG_UPDATE_INTERVAL(this); } -} // namespace xgzp68xx -} // namespace esphome +} // namespace esphome::xgzp68xx diff --git a/esphome/components/xgzp68xx/xgzp68xx.h b/esphome/components/xgzp68xx/xgzp68xx.h index ce9cfd6b781..1bab9b091aa 100644 --- a/esphome/components/xgzp68xx/xgzp68xx.h +++ b/esphome/components/xgzp68xx/xgzp68xx.h @@ -4,8 +4,7 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace xgzp68xx { +namespace esphome::xgzp68xx { /// Enum listing all oversampling options for the XGZP68XX. enum XGZP68XXOversampling : uint8_t { @@ -43,5 +42,4 @@ class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public XGZP68XXOversampling last_pressure_oversampling_{XGZP68XX_OVERSAMPLING_UNKNOWN}; }; -} // namespace xgzp68xx -} // namespace esphome +} // namespace esphome::xgzp68xx diff --git a/esphome/components/xiaomi_ble/xiaomi_ble.cpp b/esphome/components/xiaomi_ble/xiaomi_ble.cpp index 2c1611d0c7d..0961df2bd63 100644 --- a/esphome/components/xiaomi_ble/xiaomi_ble.cpp +++ b/esphome/components/xiaomi_ble/xiaomi_ble.cpp @@ -12,8 +12,7 @@ #include "mbedtls/ccm.h" #endif -namespace esphome { -namespace xiaomi_ble { +namespace esphome::xiaomi_ble { static const char *const TAG = "xiaomi_ble"; @@ -460,7 +459,6 @@ bool XiaomiListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return false; // with true it's not showing device scans } -} // namespace xiaomi_ble -} // namespace esphome +} // namespace esphome::xiaomi_ble #endif diff --git a/esphome/components/xiaomi_ble/xiaomi_ble.h b/esphome/components/xiaomi_ble/xiaomi_ble.h index 42609a998b2..a4ecca0c66e 100644 --- a/esphome/components/xiaomi_ble/xiaomi_ble.h +++ b/esphome/components/xiaomi_ble/xiaomi_ble.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_ble { +namespace esphome::xiaomi_ble { struct XiaomiParseResult { enum { @@ -78,7 +77,6 @@ class XiaomiListener : public esp32_ble_tracker::ESPBTDeviceListener { bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override; }; -} // namespace xiaomi_ble -} // namespace esphome +} // namespace esphome::xiaomi_ble #endif diff --git a/esphome/components/xiaomi_cgd1/xiaomi_cgd1.cpp b/esphome/components/xiaomi_cgd1/xiaomi_cgd1.cpp index 82a04f0d6e6..948e02be463 100644 --- a/esphome/components/xiaomi_cgd1/xiaomi_cgd1.cpp +++ b/esphome/components/xiaomi_cgd1/xiaomi_cgd1.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgd1 { +namespace esphome::xiaomi_cgd1 { static const char *const TAG = "xiaomi_cgd1"; @@ -65,7 +64,6 @@ bool XiaomiCGD1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiCGD1::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_cgd1 -} // namespace esphome +} // namespace esphome::xiaomi_cgd1 #endif diff --git a/esphome/components/xiaomi_cgd1/xiaomi_cgd1.h b/esphome/components/xiaomi_cgd1/xiaomi_cgd1.h index 4a34eea32ad..1c510c7eb4b 100644 --- a/esphome/components/xiaomi_cgd1/xiaomi_cgd1.h +++ b/esphome/components/xiaomi_cgd1/xiaomi_cgd1.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgd1 { +namespace esphome::xiaomi_cgd1 { class XiaomiCGD1 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -29,7 +28,6 @@ class XiaomiCGD1 : public Component, public esp32_ble_tracker::ESPBTDeviceListen sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_cgd1 -} // namespace esphome +} // namespace esphome::xiaomi_cgd1 #endif diff --git a/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.cpp b/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.cpp index 39ece3e0916..ff9036db14e 100644 --- a/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.cpp +++ b/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgdk2 { +namespace esphome::xiaomi_cgdk2 { static const char *const TAG = "xiaomi_cgdk2"; @@ -65,7 +64,6 @@ bool XiaomiCGDK2::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiCGDK2::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_cgdk2 -} // namespace esphome +} // namespace esphome::xiaomi_cgdk2 #endif diff --git a/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.h b/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.h index ed917e2bbd8..02d098c31b0 100644 --- a/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.h +++ b/esphome/components/xiaomi_cgdk2/xiaomi_cgdk2.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgdk2 { +namespace esphome::xiaomi_cgdk2 { class XiaomiCGDK2 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -29,7 +28,6 @@ class XiaomiCGDK2 : public Component, public esp32_ble_tracker::ESPBTDeviceListe sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_cgdk2 -} // namespace esphome +} // namespace esphome::xiaomi_cgdk2 #endif diff --git a/esphome/components/xiaomi_cgg1/xiaomi_cgg1.cpp b/esphome/components/xiaomi_cgg1/xiaomi_cgg1.cpp index 448592db16f..ef4ef46424d 100644 --- a/esphome/components/xiaomi_cgg1/xiaomi_cgg1.cpp +++ b/esphome/components/xiaomi_cgg1/xiaomi_cgg1.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgg1 { +namespace esphome::xiaomi_cgg1 { static const char *const TAG = "xiaomi_cgg1"; @@ -65,7 +64,6 @@ bool XiaomiCGG1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiCGG1::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_cgg1 -} // namespace esphome +} // namespace esphome::xiaomi_cgg1 #endif diff --git a/esphome/components/xiaomi_cgg1/xiaomi_cgg1.h b/esphome/components/xiaomi_cgg1/xiaomi_cgg1.h index c560bddd695..d49e3a08d1e 100644 --- a/esphome/components/xiaomi_cgg1/xiaomi_cgg1.h +++ b/esphome/components/xiaomi_cgg1/xiaomi_cgg1.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgg1 { +namespace esphome::xiaomi_cgg1 { class XiaomiCGG1 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -30,7 +29,6 @@ class XiaomiCGG1 : public Component, public esp32_ble_tracker::ESPBTDeviceListen sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_cgg1 -} // namespace esphome +} // namespace esphome::xiaomi_cgg1 #endif diff --git a/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.cpp b/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.cpp index 8813f6479b7..3203f358b99 100644 --- a/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.cpp +++ b/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgpr1 { +namespace esphome::xiaomi_cgpr1 { static const char *const TAG = "xiaomi_cgpr1"; @@ -62,7 +61,6 @@ bool XiaomiCGPR1::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiCGPR1::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_cgpr1 -} // namespace esphome +} // namespace esphome::xiaomi_cgpr1 #endif diff --git a/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.h b/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.h index 82bbbfa58d9..28a7a3ae2d6 100644 --- a/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.h +++ b/esphome/components/xiaomi_cgpr1/xiaomi_cgpr1.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_cgpr1 { +namespace esphome::xiaomi_cgpr1 { class XiaomiCGPR1 : public Component, public binary_sensor::BinarySensorInitiallyOff, @@ -33,7 +32,6 @@ class XiaomiCGPR1 : public Component, sensor::Sensor *illuminance_{nullptr}; }; -} // namespace xiaomi_cgpr1 -} // namespace esphome +} // namespace esphome::xiaomi_cgpr1 #endif diff --git a/esphome/components/xiaomi_gcls002/xiaomi_gcls002.cpp b/esphome/components/xiaomi_gcls002/xiaomi_gcls002.cpp index 159b6df80bc..11ea98045b5 100644 --- a/esphome/components/xiaomi_gcls002/xiaomi_gcls002.cpp +++ b/esphome/components/xiaomi_gcls002/xiaomi_gcls002.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_gcls002 { +namespace esphome::xiaomi_gcls002 { static const char *const TAG = "xiaomi_gcls002"; @@ -58,7 +57,6 @@ bool XiaomiGCLS002::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { return success; } -} // namespace xiaomi_gcls002 -} // namespace esphome +} // namespace esphome::xiaomi_gcls002 #endif diff --git a/esphome/components/xiaomi_gcls002/xiaomi_gcls002.h b/esphome/components/xiaomi_gcls002/xiaomi_gcls002.h index 83c8f15ace7..e14077adb0f 100644 --- a/esphome/components/xiaomi_gcls002/xiaomi_gcls002.h +++ b/esphome/components/xiaomi_gcls002/xiaomi_gcls002.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_gcls002 { +namespace esphome::xiaomi_gcls002 { class XiaomiGCLS002 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -30,7 +29,6 @@ class XiaomiGCLS002 : public Component, public esp32_ble_tracker::ESPBTDeviceLis sensor::Sensor *illuminance_{nullptr}; }; -} // namespace xiaomi_gcls002 -} // namespace esphome +} // namespace esphome::xiaomi_gcls002 #endif diff --git a/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.cpp b/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.cpp index e10754d8329..1d872c68c11 100644 --- a/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.cpp +++ b/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccjcy01 { +namespace esphome::xiaomi_hhccjcy01 { static const char *const TAG = "xiaomi_hhccjcy01"; @@ -61,7 +60,6 @@ bool XiaomiHHCCJCY01::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return success; } -} // namespace xiaomi_hhccjcy01 -} // namespace esphome +} // namespace esphome::xiaomi_hhccjcy01 #endif diff --git a/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.h b/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.h index 96ea9217fbb..8bc63990655 100644 --- a/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.h +++ b/esphome/components/xiaomi_hhccjcy01/xiaomi_hhccjcy01.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccjcy01 { +namespace esphome::xiaomi_hhccjcy01 { class XiaomiHHCCJCY01 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -32,7 +31,6 @@ class XiaomiHHCCJCY01 : public Component, public esp32_ble_tracker::ESPBTDeviceL sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_hhccjcy01 -} // namespace esphome +} // namespace esphome::xiaomi_hhccjcy01 #endif diff --git a/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.cpp b/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.cpp index 028d797ac1e..c6ebd5ff744 100644 --- a/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.cpp +++ b/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccjcy10 { +namespace esphome::xiaomi_hhccjcy10 { static const char *const TAG = "xiaomi_hhccjcy10"; @@ -63,7 +62,6 @@ bool XiaomiHHCCJCY10::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return success; } -} // namespace xiaomi_hhccjcy10 -} // namespace esphome +} // namespace esphome::xiaomi_hhccjcy10 #endif diff --git a/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.h b/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.h index bd4ad75c1d5..812e3a7d8f4 100644 --- a/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.h +++ b/esphome/components/xiaomi_hhccjcy10/xiaomi_hhccjcy10.h @@ -6,8 +6,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccjcy10 { +namespace esphome::xiaomi_hhccjcy10 { class XiaomiHHCCJCY10 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -31,7 +30,6 @@ class XiaomiHHCCJCY10 : public Component, public esp32_ble_tracker::ESPBTDeviceL sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_hhccjcy10 -} // namespace esphome +} // namespace esphome::xiaomi_hhccjcy10 #endif diff --git a/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.cpp b/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.cpp index 2d2447db271..bbca9faaa6a 100644 --- a/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.cpp +++ b/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccpot002 { +namespace esphome::xiaomi_hhccpot002 { static const char *const TAG = "xiaomi_hhccpot002"; @@ -52,7 +51,6 @@ bool XiaomiHHCCPOT002::parse_device(const esp32_ble_tracker::ESPBTDevice &device return success; } -} // namespace xiaomi_hhccpot002 -} // namespace esphome +} // namespace esphome::xiaomi_hhccpot002 #endif diff --git a/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.h b/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.h index 0ec34b1871d..2bdd6102be0 100644 --- a/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.h +++ b/esphome/components/xiaomi_hhccpot002/xiaomi_hhccpot002.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_hhccpot002 { +namespace esphome::xiaomi_hhccpot002 { class XiaomiHHCCPOT002 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -26,7 +25,6 @@ class XiaomiHHCCPOT002 : public Component, public esp32_ble_tracker::ESPBTDevice sensor::Sensor *conductivity_{nullptr}; }; -} // namespace xiaomi_hhccpot002 -} // namespace esphome +} // namespace esphome::xiaomi_hhccpot002 #endif diff --git a/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.cpp b/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.cpp index 8216a92e54d..c0f4de3d06b 100644 --- a/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.cpp +++ b/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_jqjcy01ym { +namespace esphome::xiaomi_jqjcy01ym { static const char *const TAG = "xiaomi_jqjcy01ym"; @@ -58,7 +57,6 @@ bool XiaomiJQJCY01YM::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return success; } -} // namespace xiaomi_jqjcy01ym -} // namespace esphome +} // namespace esphome::xiaomi_jqjcy01ym #endif diff --git a/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.h b/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.h index e9c44800f29..aaf34f899fe 100644 --- a/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.h +++ b/esphome/components/xiaomi_jqjcy01ym/xiaomi_jqjcy01ym.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_jqjcy01ym { +namespace esphome::xiaomi_jqjcy01ym { class XiaomiJQJCY01YM : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -30,7 +29,6 @@ class XiaomiJQJCY01YM : public Component, public esp32_ble_tracker::ESPBTDeviceL sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_jqjcy01ym -} // namespace esphome +} // namespace esphome::xiaomi_jqjcy01ym #endif diff --git a/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.cpp b/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.cpp index e140835d039..75909738c87 100644 --- a/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.cpp +++ b/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd02 { +namespace esphome::xiaomi_lywsd02 { static const char *const TAG = "xiaomi_lywsd02"; @@ -55,7 +54,6 @@ bool XiaomiLYWSD02::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { return success; } -} // namespace xiaomi_lywsd02 -} // namespace esphome +} // namespace esphome::xiaomi_lywsd02 #endif diff --git a/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.h b/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.h index 772b389a927..e45596f966d 100644 --- a/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.h +++ b/esphome/components/xiaomi_lywsd02/xiaomi_lywsd02.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd02 { +namespace esphome::xiaomi_lywsd02 { class XiaomiLYWSD02 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -28,7 +27,6 @@ class XiaomiLYWSD02 : public Component, public esp32_ble_tracker::ESPBTDeviceLis sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_lywsd02 -} // namespace esphome +} // namespace esphome::xiaomi_lywsd02 #endif diff --git a/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.cpp b/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.cpp index 2dd60d4ecbc..79610ee2662 100644 --- a/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.cpp +++ b/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd02mmc { +namespace esphome::xiaomi_lywsd02mmc { static const char *const TAG = "xiaomi_lywsd02mmc"; @@ -65,7 +64,6 @@ bool XiaomiLYWSD02MMC::parse_device(const esp32_ble_tracker::ESPBTDevice &device void XiaomiLYWSD02MMC::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_lywsd02mmc -} // namespace esphome +} // namespace esphome::xiaomi_lywsd02mmc #endif diff --git a/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.h b/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.h index 968604fee69..23efcbf8fc4 100644 --- a/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.h +++ b/esphome/components/xiaomi_lywsd02mmc/xiaomi_lywsd02mmc.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd02mmc { +namespace esphome::xiaomi_lywsd02mmc { class XiaomiLYWSD02MMC : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -30,7 +29,6 @@ class XiaomiLYWSD02MMC : public Component, public esp32_ble_tracker::ESPBTDevice sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_lywsd02mmc -} // namespace esphome +} // namespace esphome::xiaomi_lywsd02mmc #endif diff --git a/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp b/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp index b11bbdc40cd..a0a92601563 100644 --- a/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp +++ b/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd03mmc { +namespace esphome::xiaomi_lywsd03mmc { static const char *const TAG = "xiaomi_lywsd03mmc"; @@ -69,7 +68,6 @@ bool XiaomiLYWSD03MMC::parse_device(const esp32_ble_tracker::ESPBTDevice &device void XiaomiLYWSD03MMC::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_lywsd03mmc -} // namespace esphome +} // namespace esphome::xiaomi_lywsd03mmc #endif diff --git a/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.h b/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.h index d890e5ed120..03462b850fd 100644 --- a/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.h +++ b/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsd03mmc { +namespace esphome::xiaomi_lywsd03mmc { class XiaomiLYWSD03MMC : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -29,7 +28,6 @@ class XiaomiLYWSD03MMC : public Component, public esp32_ble_tracker::ESPBTDevice sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_lywsd03mmc -} // namespace esphome +} // namespace esphome::xiaomi_lywsd03mmc #endif diff --git a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp index 65991ffa0e9..56efaaef513 100644 --- a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp +++ b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsdcgq { +namespace esphome::xiaomi_lywsdcgq { static const char *const TAG = "xiaomi_lywsdcgq"; @@ -55,7 +54,6 @@ bool XiaomiLYWSDCGQ::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return success; } -} // namespace xiaomi_lywsdcgq -} // namespace esphome +} // namespace esphome::xiaomi_lywsdcgq #endif diff --git a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h index cf90db937f5..e169afc6519 100644 --- a/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h +++ b/esphome/components/xiaomi_lywsdcgq/xiaomi_lywsdcgq.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_lywsdcgq { +namespace esphome::xiaomi_lywsdcgq { class XiaomiLYWSDCGQ : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -28,7 +27,6 @@ class XiaomiLYWSDCGQ : public Component, public esp32_ble_tracker::ESPBTDeviceLi sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_lywsdcgq -} // namespace esphome +} // namespace esphome::xiaomi_lywsdcgq #endif diff --git a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp index 1097b9c1e81..74626ed0a51 100644 --- a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp +++ b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mhoc303 { +namespace esphome::xiaomi_mhoc303 { static const char *const TAG = "xiaomi_mhoc303"; @@ -55,7 +54,6 @@ bool XiaomiMHOC303::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { return success; } -} // namespace xiaomi_mhoc303 -} // namespace esphome +} // namespace esphome::xiaomi_mhoc303 #endif diff --git a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h index c3b8e7d68f5..daacd6be867 100644 --- a/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h +++ b/esphome/components/xiaomi_mhoc303/xiaomi_mhoc303.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mhoc303 { +namespace esphome::xiaomi_mhoc303 { class XiaomiMHOC303 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -28,7 +27,6 @@ class XiaomiMHOC303 : public Component, public esp32_ble_tracker::ESPBTDeviceLis sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_mhoc303 -} // namespace esphome +} // namespace esphome::xiaomi_mhoc303 #endif diff --git a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp index 10cd15ddbdd..1cf0de14d36 100644 --- a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp +++ b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mhoc401 { +namespace esphome::xiaomi_mhoc401 { static const char *const TAG = "xiaomi_mhoc401"; @@ -69,7 +68,6 @@ bool XiaomiMHOC401::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { void XiaomiMHOC401::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_mhoc401 -} // namespace esphome +} // namespace esphome::xiaomi_mhoc401 #endif diff --git a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h index 13547e45d9f..225c9ff1898 100644 --- a/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h +++ b/esphome/components/xiaomi_mhoc401/xiaomi_mhoc401.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mhoc401 { +namespace esphome::xiaomi_mhoc401 { class XiaomiMHOC401 : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -29,7 +28,6 @@ class XiaomiMHOC401 : public Component, public esp32_ble_tracker::ESPBTDeviceLis sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_mhoc401 -} // namespace esphome +} // namespace esphome::xiaomi_mhoc401 #endif diff --git a/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp b/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp index e4f77fb9153..2b1492129c2 100644 --- a/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp +++ b/esphome/components/xiaomi_miscale/xiaomi_miscale.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_miscale { +namespace esphome::xiaomi_miscale { static const char *const TAG = "xiaomi_miscale"; @@ -167,7 +166,6 @@ bool XiaomiMiscale::report_results_(const optional &result, const c return true; } -} // namespace xiaomi_miscale -} // namespace esphome +} // namespace esphome::xiaomi_miscale #endif diff --git a/esphome/components/xiaomi_miscale/xiaomi_miscale.h b/esphome/components/xiaomi_miscale/xiaomi_miscale.h index 3d793e07ac5..c75a22c9fb8 100644 --- a/esphome/components/xiaomi_miscale/xiaomi_miscale.h +++ b/esphome/components/xiaomi_miscale/xiaomi_miscale.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_miscale { +namespace esphome::xiaomi_miscale { struct ParseResult { int version; @@ -40,7 +39,6 @@ class XiaomiMiscale : public Component, public esp32_ble_tracker::ESPBTDeviceLis bool report_results_(const optional &result, const char *address); }; -} // namespace xiaomi_miscale -} // namespace esphome +} // namespace esphome::xiaomi_miscale #endif diff --git a/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.cpp b/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.cpp index ec03c851cd4..a7b2554aad9 100644 --- a/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.cpp +++ b/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mjyd02yla { +namespace esphome::xiaomi_mjyd02yla { static const char *const TAG = "xiaomi_mjyd02yla"; @@ -65,7 +64,6 @@ bool XiaomiMJYD02YLA::parse_device(const esp32_ble_tracker::ESPBTDevice &device) void XiaomiMJYD02YLA::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_mjyd02yla -} // namespace esphome +} // namespace esphome::xiaomi_mjyd02yla #endif diff --git a/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.h b/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.h index bf9dcaf8446..ee4ed525209 100644 --- a/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.h +++ b/esphome/components/xiaomi_mjyd02yla/xiaomi_mjyd02yla.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mjyd02yla { +namespace esphome::xiaomi_mjyd02yla { class XiaomiMJYD02YLA : public Component, public binary_sensor::BinarySensorInitiallyOff, @@ -35,7 +34,6 @@ class XiaomiMJYD02YLA : public Component, binary_sensor::BinarySensor *is_light_{nullptr}; }; -} // namespace xiaomi_mjyd02yla -} // namespace esphome +} // namespace esphome::xiaomi_mjyd02yla #endif diff --git a/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.cpp b/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.cpp index a3f9325946c..259e0159c50 100644 --- a/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.cpp +++ b/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mue4094rt { +namespace esphome::xiaomi_mue4094rt { static const char *const TAG = "xiaomi_mue4094rt"; @@ -51,7 +50,6 @@ bool XiaomiMUE4094RT::parse_device(const esp32_ble_tracker::ESPBTDevice &device) return success; } -} // namespace xiaomi_mue4094rt -} // namespace esphome +} // namespace esphome::xiaomi_mue4094rt #endif diff --git a/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.h b/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.h index f1da0705d02..a6d8abc5bf6 100644 --- a/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.h +++ b/esphome/components/xiaomi_mue4094rt/xiaomi_mue4094rt.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_mue4094rt { +namespace esphome::xiaomi_mue4094rt { class XiaomiMUE4094RT : public Component, public binary_sensor::BinarySensorInitiallyOff, @@ -26,7 +25,6 @@ class XiaomiMUE4094RT : public Component, uint16_t timeout_; }; -} // namespace xiaomi_mue4094rt -} // namespace esphome +} // namespace esphome::xiaomi_mue4094rt #endif diff --git a/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.cpp b/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.cpp index 0f27f09c871..b42a5a37006 100644 --- a/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.cpp +++ b/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_rtcgq02lm { +namespace esphome::xiaomi_rtcgq02lm { static const char *const TAG = "xiaomi_rtcgq02lm"; @@ -79,7 +78,6 @@ bool XiaomiRTCGQ02LM::parse_device(const esp32_ble_tracker::ESPBTDevice &device) void XiaomiRTCGQ02LM::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_rtcgq02lm -} // namespace esphome +} // namespace esphome::xiaomi_rtcgq02lm #endif diff --git a/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.h b/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.h index 87dfc0b62bc..cc6a334a20d 100644 --- a/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.h +++ b/esphome/components/xiaomi_rtcgq02lm/xiaomi_rtcgq02lm.h @@ -13,8 +13,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_rtcgq02lm { +namespace esphome::xiaomi_rtcgq02lm { class XiaomiRTCGQ02LM : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -54,7 +53,6 @@ class XiaomiRTCGQ02LM : public Component, public esp32_ble_tracker::ESPBTDeviceL #endif }; -} // namespace xiaomi_rtcgq02lm -} // namespace esphome +} // namespace esphome::xiaomi_rtcgq02lm #endif diff --git a/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.cpp b/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.cpp index b0e02e2372e..1bf861a6afd 100644 --- a/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.cpp +++ b/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.cpp @@ -3,8 +3,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_wx08zm { +namespace esphome::xiaomi_wx08zm { static const char *const TAG = "xiaomi_wx08zm"; @@ -56,7 +55,6 @@ bool XiaomiWX08ZM::parse_device(const esp32_ble_tracker::ESPBTDevice &device) { return success; } -} // namespace xiaomi_wx08zm -} // namespace esphome +} // namespace esphome::xiaomi_wx08zm #endif diff --git a/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.h b/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.h index 081705fd505..0b0cb8db0bc 100644 --- a/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.h +++ b/esphome/components/xiaomi_wx08zm/xiaomi_wx08zm.h @@ -8,8 +8,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_wx08zm { +namespace esphome::xiaomi_wx08zm { class XiaomiWX08ZM : public Component, public binary_sensor::BinarySensorInitiallyOff, @@ -29,7 +28,6 @@ class XiaomiWX08ZM : public Component, sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_wx08zm -} // namespace esphome +} // namespace esphome::xiaomi_wx08zm #endif diff --git a/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.cpp b/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.cpp index 50cf5f2d767..a4303b055ab 100644 --- a/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.cpp +++ b/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.cpp @@ -4,8 +4,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_xmwsdj04mmc { +namespace esphome::xiaomi_xmwsdj04mmc { static const char *const TAG = "xiaomi_xmwsdj04mmc"; @@ -69,7 +68,6 @@ bool XiaomiXMWSDJ04MMC::parse_device(const esp32_ble_tracker::ESPBTDevice &devic void XiaomiXMWSDJ04MMC::set_bindkey(const char *bindkey) { parse_hex(bindkey, this->bindkey_, sizeof(this->bindkey_)); } -} // namespace xiaomi_xmwsdj04mmc -} // namespace esphome +} // namespace esphome::xiaomi_xmwsdj04mmc #endif diff --git a/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.h b/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.h index 22cac630595..9bab943ab94 100644 --- a/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.h +++ b/esphome/components/xiaomi_xmwsdj04mmc/xiaomi_xmwsdj04mmc.h @@ -7,8 +7,7 @@ #ifdef USE_ESP32 -namespace esphome { -namespace xiaomi_xmwsdj04mmc { +namespace esphome::xiaomi_xmwsdj04mmc { class XiaomiXMWSDJ04MMC : public Component, public esp32_ble_tracker::ESPBTDeviceListener { public: @@ -30,7 +29,6 @@ class XiaomiXMWSDJ04MMC : public Component, public esp32_ble_tracker::ESPBTDevic sensor::Sensor *battery_level_{nullptr}; }; -} // namespace xiaomi_xmwsdj04mmc -} // namespace esphome +} // namespace esphome::xiaomi_xmwsdj04mmc #endif diff --git a/esphome/components/xl9535/xl9535.cpp b/esphome/components/xl9535/xl9535.cpp index cfcbeeeb8d7..d189d9b5c71 100644 --- a/esphome/components/xl9535/xl9535.cpp +++ b/esphome/components/xl9535/xl9535.cpp @@ -1,8 +1,7 @@ #include "xl9535.h" #include "esphome/core/log.h" -namespace esphome { -namespace xl9535 { +namespace esphome::xl9535 { static const char *const TAG = "xl9535"; @@ -118,5 +117,4 @@ void XL9535GPIOPin::pin_mode(gpio::Flags flags) { this->parent_->pin_mode(this-> bool XL9535GPIOPin::digital_read() { return this->parent_->digital_read(this->pin_) != this->inverted_; } void XL9535GPIOPin::digital_write(bool value) { this->parent_->digital_write(this->pin_, value != this->inverted_); } -} // namespace xl9535 -} // namespace esphome +} // namespace esphome::xl9535 diff --git a/esphome/components/xl9535/xl9535.h b/esphome/components/xl9535/xl9535.h index be0e2fbd820..253ce762734 100644 --- a/esphome/components/xl9535/xl9535.h +++ b/esphome/components/xl9535/xl9535.h @@ -4,8 +4,7 @@ #include "esphome/components/i2c/i2c.h" #include "esphome/core/hal.h" -namespace esphome { -namespace xl9535 { +namespace esphome::xl9535 { enum { XL9535_INPUT_PORT_0_REGISTER = 0x00, @@ -52,5 +51,4 @@ class XL9535GPIOPin : public GPIOPin { gpio::Flags flags_; }; -} // namespace xl9535 -} // namespace esphome +} // namespace esphome::xl9535 diff --git a/esphome/components/xpt2046/touchscreen/xpt2046.cpp b/esphome/components/xpt2046/touchscreen/xpt2046.cpp index 84d3daf8239..d08a54529d8 100644 --- a/esphome/components/xpt2046/touchscreen/xpt2046.cpp +++ b/esphome/components/xpt2046/touchscreen/xpt2046.cpp @@ -4,8 +4,7 @@ #include -namespace esphome { -namespace xpt2046 { +namespace esphome::xpt2046 { static const char *const TAG = "xpt2046"; @@ -107,5 +106,4 @@ int16_t XPT2046Component::read_adc_(uint8_t ctrl) { // NOLINT return ((data[0] << 8) | data[1]) >> 3; } -} // namespace xpt2046 -} // namespace esphome +} // namespace esphome::xpt2046 diff --git a/esphome/components/xpt2046/touchscreen/xpt2046.h b/esphome/components/xpt2046/touchscreen/xpt2046.h index f691ae2c7b3..f619e06fb77 100644 --- a/esphome/components/xpt2046/touchscreen/xpt2046.h +++ b/esphome/components/xpt2046/touchscreen/xpt2046.h @@ -7,8 +7,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace xpt2046 { +namespace esphome::xpt2046 { using namespace touchscreen; @@ -37,5 +36,4 @@ class XPT2046Component : public Touchscreen, InternalGPIOPin *irq_pin_{nullptr}; }; -} // namespace xpt2046 -} // namespace esphome +} // namespace esphome::xpt2046 diff --git a/esphome/components/xxtea/xxtea.cpp b/esphome/components/xxtea/xxtea.cpp index ba17530b243..ded7abc2216 100644 --- a/esphome/components/xxtea/xxtea.cpp +++ b/esphome/components/xxtea/xxtea.cpp @@ -1,7 +1,6 @@ #include "xxtea.h" -namespace esphome { -namespace xxtea { +namespace esphome::xxtea { static const uint32_t DELTA = 0x9e3779b9; #define MX ((((z >> 5) ^ (y << 2)) + ((y >> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[(p ^ e) & 7] ^ z))) @@ -46,5 +45,4 @@ void decrypt(uint32_t *v, size_t n, const uint32_t *k) { } } -} // namespace xxtea -} // namespace esphome +} // namespace esphome::xxtea diff --git a/esphome/components/xxtea/xxtea.h b/esphome/components/xxtea/xxtea.h index 86afbd1d46b..8019fb07fc2 100644 --- a/esphome/components/xxtea/xxtea.h +++ b/esphome/components/xxtea/xxtea.h @@ -3,8 +3,7 @@ #include #include -namespace esphome { -namespace xxtea { +namespace esphome::xxtea { /** * Encrypt a block of data in-place using XXTEA algorithm with 256-bit key @@ -22,5 +21,4 @@ void encrypt(uint32_t *v, size_t n, const uint32_t *k); */ void decrypt(uint32_t *v, size_t n, const uint32_t *k); -} // namespace xxtea -} // namespace esphome +} // namespace esphome::xxtea diff --git a/esphome/components/yashima/yashima.cpp b/esphome/components/yashima/yashima.cpp index 4a64e6c41c6..ba0a3a64040 100644 --- a/esphome/components/yashima/yashima.cpp +++ b/esphome/components/yashima/yashima.cpp @@ -1,8 +1,7 @@ #include "yashima.h" #include "esphome/core/log.h" -namespace esphome { -namespace yashima { +namespace esphome::yashima { static const char *const TAG = "yashima.climate"; @@ -197,5 +196,4 @@ void YashimaClimate::transmit_state_() { transmit.perform(); } -} // namespace yashima -} // namespace esphome +} // namespace esphome::yashima diff --git a/esphome/components/yashima/yashima.h b/esphome/components/yashima/yashima.h index 466816bd5f7..336b28f5c52 100644 --- a/esphome/components/yashima/yashima.h +++ b/esphome/components/yashima/yashima.h @@ -7,8 +7,7 @@ #include "esphome/components/remote_transmitter/remote_transmitter.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace yashima { +namespace esphome::yashima { class YashimaClimate : public climate::Climate, public Component { public: @@ -36,5 +35,4 @@ class YashimaClimate : public climate::Climate, public Component { sensor::Sensor *sensor_{nullptr}; }; -} // namespace yashima -} // namespace esphome +} // namespace esphome::yashima diff --git a/esphome/components/zhlt01/zhlt01.cpp b/esphome/components/zhlt01/zhlt01.cpp index e5ab5915e4b..2585ac1b572 100644 --- a/esphome/components/zhlt01/zhlt01.cpp +++ b/esphome/components/zhlt01/zhlt01.cpp @@ -1,8 +1,7 @@ #include "zhlt01.h" #include "esphome/core/log.h" -namespace esphome { -namespace zhlt01 { +namespace esphome::zhlt01 { static const char *const TAG = "zhlt01.climate"; @@ -234,5 +233,4 @@ bool ZHLT01Climate::on_receive(remote_base::RemoteReceiveData data) { return true; } -} // namespace zhlt01 -} // namespace esphome +} // namespace esphome::zhlt01 diff --git a/esphome/components/zhlt01/zhlt01.h b/esphome/components/zhlt01/zhlt01.h index 4413be2835c..61fc2cc16a1 100644 --- a/esphome/components/zhlt01/zhlt01.h +++ b/esphome/components/zhlt01/zhlt01.h @@ -82,8 +82,7 @@ * ***********************************************************************************/ -namespace esphome { -namespace zhlt01 { +namespace esphome::zhlt01 { /******************************************************************************** * TIMINGS @@ -163,5 +162,4 @@ class ZHLT01Climate : public climate_ir::ClimateIR { bool on_receive(remote_base::RemoteReceiveData data) override; }; -} // namespace zhlt01 -} // namespace esphome +} // namespace esphome::zhlt01 diff --git a/esphome/components/zio_ultrasonic/zio_ultrasonic.cpp b/esphome/components/zio_ultrasonic/zio_ultrasonic.cpp index 565bbe9b4f6..1fa995b3dcd 100644 --- a/esphome/components/zio_ultrasonic/zio_ultrasonic.cpp +++ b/esphome/components/zio_ultrasonic/zio_ultrasonic.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" -namespace esphome { -namespace zio_ultrasonic { +namespace esphome::zio_ultrasonic { static const char *const TAG = "zio_ultrasonic"; @@ -27,5 +26,4 @@ void ZioUltrasonicComponent::update() { } } -} // namespace zio_ultrasonic -} // namespace esphome +} // namespace esphome::zio_ultrasonic diff --git a/esphome/components/zio_ultrasonic/zio_ultrasonic.h b/esphome/components/zio_ultrasonic/zio_ultrasonic.h index 23057b2ab01..d4d2ac974fe 100644 --- a/esphome/components/zio_ultrasonic/zio_ultrasonic.h +++ b/esphome/components/zio_ultrasonic/zio_ultrasonic.h @@ -6,8 +6,7 @@ static const char *const TAG = "Zio Ultrasonic"; -namespace esphome { -namespace zio_ultrasonic { +namespace esphome::zio_ultrasonic { class ZioUltrasonicComponent : public i2c::I2CDevice, public PollingComponent, public sensor::Sensor { public: @@ -16,5 +15,4 @@ class ZioUltrasonicComponent : public i2c::I2CDevice, public PollingComponent, p void update() override; }; -} // namespace zio_ultrasonic -} // namespace esphome +} // namespace esphome::zio_ultrasonic diff --git a/esphome/components/zyaura/zyaura.cpp b/esphome/components/zyaura/zyaura.cpp index 621439aa0c2..0b834de90a4 100644 --- a/esphome/components/zyaura/zyaura.cpp +++ b/esphome/components/zyaura/zyaura.cpp @@ -1,8 +1,7 @@ #include "zyaura.h" #include "esphome/core/log.h" -namespace esphome { -namespace zyaura { +namespace esphome::zyaura { static const char *const TAG = "zyaura"; @@ -121,5 +120,4 @@ void ZyAuraSensor::update() { } } -} // namespace zyaura -} // namespace esphome +} // namespace esphome::zyaura diff --git a/esphome/components/zyaura/zyaura.h b/esphome/components/zyaura/zyaura.h index 3070aa90c5a..7c7954dec25 100644 --- a/esphome/components/zyaura/zyaura.h +++ b/esphome/components/zyaura/zyaura.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -namespace esphome { -namespace zyaura { +namespace esphome::zyaura { static const uint8_t ZA_MAX_MS = 2; static const uint8_t ZA_MSG_LEN = 5; @@ -81,5 +80,4 @@ class ZyAuraSensor : public PollingComponent { bool publish_state_(ZaDataType data_type, sensor::Sensor *sensor, uint16_t *data_value); }; -} // namespace zyaura -} // namespace esphome +} // namespace esphome::zyaura From e152c6155b1d76fe7b5e84dd42b7f2144834c139 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 8 May 2026 14:00:50 +1200 Subject: [PATCH 09/52] [ci] Skip needs-docs for new components without CONFIG_SCHEMA (#16303) --- .github/scripts/auto-label-pr/detectors.js | 105 +++++++++++++++------ .github/scripts/auto-label-pr/index.js | 17 +++- 2 files changed, 86 insertions(+), 36 deletions(-) diff --git a/.github/scripts/auto-label-pr/detectors.js b/.github/scripts/auto-label-pr/detectors.js index 25c0ba49afc..410c1a53c07 100644 --- a/.github/scripts/auto-label-pr/detectors.js +++ b/.github/scripts/auto-label-pr/detectors.js @@ -1,4 +1,3 @@ -const fs = require('fs'); const { DOCS_PR_PATTERNS } = require('./constants'); const { COMPONENT_REGEX, @@ -9,6 +8,31 @@ const { } = require('../detect-tags'); const { loadCodeowners, getEffectiveOwners } = require('../codeowners'); +// Top-level `CONFIG_SCHEMA = ...` (assignment) or `CONFIG_SCHEMA: ConfigType = ...` (annotation). +// Ruff/Black enforce exactly one space around `=` and no space before `:`, +// so we can match strictly: `CONFIG_SCHEMA ` or `CONFIG_SCHEMA:`. +const CONFIG_SCHEMA_REGEX = /^CONFIG_SCHEMA[ :]/m; + +// Fetch a file's contents from the PR head SHA via the GitHub API. +// The auto-label workflow runs on `pull_request_target`, which checks out the +// base branch — files added by the PR don't exist in the workspace, so we have +// to fetch them from the head SHA. Returns null if the file can't be fetched. +async function fetchPrFileContent(github, context, path) { + try { + const { owner, repo } = context.repo; + const { data } = await github.rest.repos.getContent({ + owner, + repo, + path, + ref: context.payload.pull_request.head.sha, + }); + return Buffer.from(data.content, 'base64').toString('utf8'); + } catch (error) { + console.log(`Failed to fetch ${path} from PR head:`, error.message); + return null; + } +} + // Strategy: Merge branch detection async function detectMergeBranch(context) { const labels = new Set(); @@ -45,52 +69,64 @@ async function detectComponentPlatforms(changedFiles, apiData) { } // Strategy: New component detection -async function detectNewComponents(prFiles) { +async function detectNewComponents(github, context, prFiles) { const labels = new Set(); + let hasYamlLoadable = false; const addedFiles = prFiles.filter(file => file.status === 'added').map(file => file.filename); for (const file of addedFiles) { const componentMatch = file.match(/^esphome\/components\/([^\/]+)\/__init__\.py$/); - if (componentMatch) { - try { - const content = fs.readFileSync(file, 'utf8'); - if (content.includes('IS_TARGET_PLATFORM = True')) { - labels.add('new-target-platform'); - } - } catch (error) { - console.log(`Failed to read content of ${file}:`, error.message); - } - labels.add('new-component'); + if (!componentMatch) continue; + + labels.add('new-component'); + const content = await fetchPrFileContent(github, context, file); + if (content === null) { + // Safe default: assume YAML-loadable so needs-docs behaviour is unchanged on fetch failure + hasYamlLoadable = true; + continue; + } + if (content.includes('IS_TARGET_PLATFORM = True')) { + labels.add('new-target-platform'); + } + if (CONFIG_SCHEMA_REGEX.test(content)) { + hasYamlLoadable = true; } } - return labels; + return { labels, hasYamlLoadable }; } // Strategy: New platform detection -async function detectNewPlatforms(prFiles, apiData) { +async function detectNewPlatforms(github, context, prFiles, apiData) { const labels = new Set(); + let hasYamlLoadable = false; const addedFiles = prFiles.filter(file => file.status === 'added').map(file => file.filename); - for (const file of addedFiles) { - const platformFileMatch = file.match(/^esphome\/components\/([^\/]+)\/([^\/]+)\.py$/); - if (platformFileMatch) { - const [, component, platform] = platformFileMatch; - if (apiData.platformComponents.includes(platform)) { - labels.add('new-platform'); - } - } + const platformPathPatterns = [ + /^esphome\/components\/([^\/]+)\/([^\/]+)\.py$/, + /^esphome\/components\/([^\/]+)\/([^\/]+)\/__init__\.py$/, + ]; - const platformDirMatch = file.match(/^esphome\/components\/([^\/]+)\/([^\/]+)\/__init__\.py$/); - if (platformDirMatch) { - const [, component, platform] = platformDirMatch; - if (apiData.platformComponents.includes(platform)) { - labels.add('new-platform'); + for (const file of addedFiles) { + for (const re of platformPathPatterns) { + const match = file.match(re); + if (!match) continue; + const platform = match[2]; + if (!apiData.platformComponents.includes(platform)) break; + + labels.add('new-platform'); + const content = await fetchPrFileContent(github, context, file); + if (content === null) { + // Safe default: assume YAML-loadable so needs-docs behaviour is unchanged on fetch failure + hasYamlLoadable = true; + } else if (CONFIG_SCHEMA_REGEX.test(content)) { + hasYamlLoadable = true; } + break; } } - return labels; + return { labels, hasYamlLoadable }; } // Strategy: Core files detection @@ -300,7 +336,7 @@ function detectMaintainerAccess(context) { } // Strategy: Requirements detection -async function detectRequirements(allLabels, prFiles, context) { +async function detectRequirements(allLabels, prFiles, context, hasYamlLoadable) { const labels = new Set(); // Check for missing tests @@ -308,8 +344,15 @@ async function detectRequirements(allLabels, prFiles, context) { labels.add('needs-tests'); } - // Check for missing docs - if (allLabels.has('new-component') || allLabels.has('new-platform') || allLabels.has('new-feature')) { + // Check for missing docs. + // `new-feature` (PR-body checkbox) always counts. `new-component` / `new-platform` + // only count when at least one newly added file defines a top-level CONFIG_SCHEMA, + // i.e. the new component/platform is actually loadable from YAML. + const docsEligible = + allLabels.has('new-feature') || + ((allLabels.has('new-component') || allLabels.has('new-platform')) && hasYamlLoadable); + + if (docsEligible) { const prBody = context.payload.pull_request.body || ''; const hasDocsLink = DOCS_PR_PATTERNS.some(pattern => pattern.test(prBody)); diff --git a/.github/scripts/auto-label-pr/index.js b/.github/scripts/auto-label-pr/index.js index 021e91a9ee1..9769cd80601 100644 --- a/.github/scripts/auto-label-pr/index.js +++ b/.github/scripts/auto-label-pr/index.js @@ -106,8 +106,8 @@ module.exports = async ({ github, context }) => { const [ branchLabels, componentLabels, - newComponentLabels, - newPlatformLabels, + newComponentResult, + newPlatformResult, coreLabels, sizeLabels, dashboardLabels, @@ -120,8 +120,8 @@ module.exports = async ({ github, context }) => { ] = await Promise.all([ detectMergeBranch(context), detectComponentPlatforms(changedFiles, apiData), - detectNewComponents(prFiles), - detectNewPlatforms(prFiles, apiData), + detectNewComponents(github, context, prFiles), + detectNewPlatforms(github, context, prFiles, apiData), detectCoreChanges(changedFiles), detectPRSize(prFiles, totalAdditions, totalDeletions, totalChanges, isMegaPR, SMALL_PR_THRESHOLD, MEDIUM_PR_THRESHOLD, TOO_BIG_THRESHOLD), detectDashboardChanges(changedFiles), @@ -133,6 +133,13 @@ module.exports = async ({ github, context }) => { detectMaintainerAccess(context) ]); + // Extract new-component / new-platform results + const newComponentLabels = newComponentResult.labels; + const newPlatformLabels = newPlatformResult.labels; + // Eligible for needs-docs only if any newly added component or platform file + // defines a top-level CONFIG_SCHEMA (i.e. is actually loadable from YAML). + const hasYamlLoadable = newComponentResult.hasYamlLoadable || newPlatformResult.hasYamlLoadable; + // Extract deprecated component info const deprecatedLabels = deprecatedResult.labels; const deprecatedInfo = deprecatedResult.deprecatedInfo; @@ -154,7 +161,7 @@ module.exports = async ({ github, context }) => { ]); // Detect requirements based on all other labels - const requirementLabels = await detectRequirements(allLabels, prFiles, context); + const requirementLabels = await detectRequirements(allLabels, prFiles, context, hasYamlLoadable); for (const label of requirementLabels) { allLabels.add(label); } From 08b17c9da1fcdb5d58d3133b144481969ca7bf54 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Thu, 7 May 2026 22:01:37 -0400 Subject: [PATCH 10/52] [core] Move core ring buffer to helper component (#16298) --- CODEOWNERS | 1 + esphome/components/audio/__init__.py | 1 + esphome/components/audio/audio_decoder.cpp | 4 +- esphome/components/audio/audio_decoder.h | 6 +- esphome/components/audio/audio_reader.cpp | 2 +- esphome/components/audio/audio_reader.h | 6 +- esphome/components/audio/audio_resampler.cpp | 4 +- esphome/components/audio/audio_resampler.h | 6 +- .../components/audio/audio_transfer_buffer.h | 10 +- .../i2s_audio/speaker/i2s_audio_speaker.cpp | 4 +- .../i2s_audio/speaker/i2s_audio_speaker.h | 4 +- .../speaker/i2s_audio_speaker_standard.cpp | 2 +- .../components/micro_wake_word/__init__.py | 1 + .../micro_wake_word/micro_wake_word.cpp | 4 +- .../micro_wake_word/micro_wake_word.h | 4 +- .../mixer/speaker/mixer_speaker.cpp | 6 +- .../components/mixer/speaker/mixer_speaker.h | 3 +- .../resampler/speaker/resampler_speaker.cpp | 8 +- .../resampler/speaker/resampler_speaker.h | 3 +- esphome/components/ring_buffer/__init__.py | 7 + .../ring_buffer}/ring_buffer.cpp | 6 +- esphome/components/ring_buffer/ring_buffer.h | 126 ++++++++++++++++++ .../components/sound_level/sound_level.cpp | 6 +- esphome/components/sound_level/sound_level.h | 4 +- .../speaker/media_player/audio_pipeline.cpp | 6 +- .../speaker/media_player/audio_pipeline.h | 4 +- .../components/voice_assistant/__init__.py | 2 +- .../voice_assistant/voice_assistant.cpp | 4 +- .../voice_assistant/voice_assistant.h | 4 +- esphome/core/config.py | 4 - esphome/core/ring_buffer.h | 126 ++---------------- esphome/writer.py | 10 +- 32 files changed, 214 insertions(+), 174 deletions(-) create mode 100644 esphome/components/ring_buffer/__init__.py rename esphome/{core => components/ring_buffer}/ring_buffer.cpp (97%) create mode 100644 esphome/components/ring_buffer/ring_buffer.h diff --git a/CODEOWNERS b/CODEOWNERS index 471def542bb..f8cdfdc6c68 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -416,6 +416,7 @@ esphome/components/resampler/speaker/* @kahrendt esphome/components/restart/* @esphome/core esphome/components/rf_bridge/* @jesserockz esphome/components/rgbct/* @jesserockz +esphome/components/ring_buffer/* @kahrendt esphome/components/rp2040/* @jesserockz esphome/components/rp2040_ble/* @bdraco esphome/components/rp2040_pio_led_strip/* @Papa-DMan diff --git a/esphome/components/audio/__init__.py b/esphome/components/audio/__init__.py index 67ef2e7d1ae..44371e87ab2 100644 --- a/esphome/components/audio/__init__.py +++ b/esphome/components/audio/__init__.py @@ -16,6 +16,7 @@ from esphome.const import ( from esphome.core import CORE import esphome.final_validate as fv +AUTO_LOAD = ["ring_buffer"] CODEOWNERS = ["@kahrendt"] DOMAIN = "audio" audio_ns = cg.esphome_ns.namespace("audio") diff --git a/esphome/components/audio/audio_decoder.cpp b/esphome/components/audio/audio_decoder.cpp index 3e6fad1101e..d4ff59fc363 100644 --- a/esphome/components/audio/audio_decoder.cpp +++ b/esphome/components/audio/audio_decoder.cpp @@ -19,7 +19,7 @@ AudioDecoder::AudioDecoder(size_t input_buffer_size, size_t output_buffer_size) this->output_transfer_buffer_ = AudioSinkTransferBuffer::create(output_buffer_size); } -esp_err_t AudioDecoder::add_source(std::weak_ptr &input_ring_buffer) { +esp_err_t AudioDecoder::add_source(std::weak_ptr &input_ring_buffer) { auto source = AudioSourceTransferBuffer::create(this->input_buffer_size_); if (source == nullptr) { return ESP_ERR_NO_MEM; @@ -36,7 +36,7 @@ esp_err_t AudioDecoder::add_source(const uint8_t *data_pointer, size_t length) { return ESP_OK; } -esp_err_t AudioDecoder::add_sink(std::weak_ptr &output_ring_buffer) { +esp_err_t AudioDecoder::add_sink(std::weak_ptr &output_ring_buffer) { if (this->output_transfer_buffer_ != nullptr) { this->output_transfer_buffer_->set_sink(output_ring_buffer); return ESP_OK; diff --git a/esphome/components/audio/audio_decoder.h b/esphome/components/audio/audio_decoder.h index 7ea7a824f96..c34ebbc613b 100644 --- a/esphome/components/audio/audio_decoder.h +++ b/esphome/components/audio/audio_decoder.h @@ -5,9 +5,9 @@ #include "audio.h" #include "audio_transfer_buffer.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/core/defines.h" #include "esphome/core/helpers.h" -#include "esphome/core/ring_buffer.h" #ifdef USE_SPEAKER #include "esphome/components/speaker/speaker.h" @@ -70,12 +70,12 @@ class AudioDecoder { /// @brief Adds a source ring buffer for raw file data. Takes ownership of the ring buffer in a shared_ptr. /// @param input_ring_buffer weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership /// @return ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated - esp_err_t add_source(std::weak_ptr &input_ring_buffer); + esp_err_t add_source(std::weak_ptr &input_ring_buffer); /// @brief Adds a sink ring buffer for decoded audio. Takes ownership of the ring buffer in a shared_ptr. /// @param output_ring_buffer weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership /// @return ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated - esp_err_t add_sink(std::weak_ptr &output_ring_buffer); + esp_err_t add_sink(std::weak_ptr &output_ring_buffer); #ifdef USE_SPEAKER /// @brief Adds a sink speaker for decoded audio. diff --git a/esphome/components/audio/audio_reader.cpp b/esphome/components/audio/audio_reader.cpp index 500f20533cd..4678ed548c7 100644 --- a/esphome/components/audio/audio_reader.cpp +++ b/esphome/components/audio/audio_reader.cpp @@ -54,7 +54,7 @@ enum HttpStatus { AudioReader::~AudioReader() { this->cleanup_connection_(); } -esp_err_t AudioReader::add_sink(const std::weak_ptr &output_ring_buffer) { +esp_err_t AudioReader::add_sink(const std::weak_ptr &output_ring_buffer) { if (current_audio_file_ != nullptr) { // A transfer buffer isn't ncessary for a local file this->file_ring_buffer_ = output_ring_buffer.lock(); diff --git a/esphome/components/audio/audio_reader.h b/esphome/components/audio/audio_reader.h index 61f187d151d..b1f76172b01 100644 --- a/esphome/components/audio/audio_reader.h +++ b/esphome/components/audio/audio_reader.h @@ -5,7 +5,7 @@ #include "audio.h" #include "audio_transfer_buffer.h" -#include "esphome/core/ring_buffer.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esp_err.h" @@ -35,7 +35,7 @@ class AudioReader { /// @brief Adds a sink ring buffer for audio data. Takes ownership of the ring buffer in a shared_ptr /// @param output_ring_buffer weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership /// @return ESP_OK if successful, ESP_ERR_INVALID_STATE otherwise - esp_err_t add_sink(const std::weak_ptr &output_ring_buffer); + esp_err_t add_sink(const std::weak_ptr &output_ring_buffer); /// @brief Starts reading an audio file from an http source. The transfer buffer is allocated here. /// @param uri Web url to the http file. @@ -60,7 +60,7 @@ class AudioReader { AudioReaderState file_read_(); AudioReaderState http_read_(); - std::shared_ptr file_ring_buffer_; + std::shared_ptr file_ring_buffer_; std::unique_ptr output_transfer_buffer_; void cleanup_connection_(); diff --git a/esphome/components/audio/audio_resampler.cpp b/esphome/components/audio/audio_resampler.cpp index ac1039971e6..c04cc881f5b 100644 --- a/esphome/components/audio/audio_resampler.cpp +++ b/esphome/components/audio/audio_resampler.cpp @@ -16,7 +16,7 @@ AudioResampler::AudioResampler(size_t input_buffer_size, size_t output_buffer_si this->output_transfer_buffer_ = AudioSinkTransferBuffer::create(output_buffer_size); } -esp_err_t AudioResampler::add_source(std::weak_ptr &input_ring_buffer) { +esp_err_t AudioResampler::add_source(std::weak_ptr &input_ring_buffer) { if (this->input_transfer_buffer_ != nullptr) { this->input_transfer_buffer_->set_source(input_ring_buffer); return ESP_OK; @@ -24,7 +24,7 @@ esp_err_t AudioResampler::add_source(std::weak_ptr &input_ring_buffe return ESP_ERR_NO_MEM; } -esp_err_t AudioResampler::add_sink(std::weak_ptr &output_ring_buffer) { +esp_err_t AudioResampler::add_sink(std::weak_ptr &output_ring_buffer) { if (this->output_transfer_buffer_ != nullptr) { this->output_transfer_buffer_->set_sink(output_ring_buffer); return ESP_OK; diff --git a/esphome/components/audio/audio_resampler.h b/esphome/components/audio/audio_resampler.h index e7503d1de07..575ad13692c 100644 --- a/esphome/components/audio/audio_resampler.h +++ b/esphome/components/audio/audio_resampler.h @@ -5,9 +5,9 @@ #include "audio.h" #include "audio_transfer_buffer.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/core/defines.h" #include "esphome/core/helpers.h" -#include "esphome/core/ring_buffer.h" #ifdef USE_SPEAKER #include "esphome/components/speaker/speaker.h" @@ -40,12 +40,12 @@ class AudioResampler { /// @brief Adds a source ring buffer for audio data. Takes ownership of the ring buffer in a shared_ptr. /// @param input_ring_buffer weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership /// @return ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated - esp_err_t add_source(std::weak_ptr &input_ring_buffer); + esp_err_t add_source(std::weak_ptr &input_ring_buffer); /// @brief Adds a sink ring buffer for resampled audio. Takes ownership of the ring buffer in a shared_ptr. /// @param output_ring_buffer weak_ptr of a shared_ptr of the sink ring buffer to transfer ownership /// @return ESP_OK if successsful, ESP_ERR_NO_MEM if the transfer buffer wasn't allocated - esp_err_t add_sink(std::weak_ptr &output_ring_buffer); + esp_err_t add_sink(std::weak_ptr &output_ring_buffer); #ifdef USE_SPEAKER /// @brief Adds a sink speaker for decoded audio. diff --git a/esphome/components/audio/audio_transfer_buffer.h b/esphome/components/audio/audio_transfer_buffer.h index 7aa830fafa1..68151bf4e21 100644 --- a/esphome/components/audio/audio_transfer_buffer.h +++ b/esphome/components/audio/audio_transfer_buffer.h @@ -1,8 +1,8 @@ #pragma once #ifdef USE_ESP32 +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/core/defines.h" -#include "esphome/core/ring_buffer.h" #ifdef USE_SPEAKER #include "esphome/components/speaker/speaker.h" @@ -76,7 +76,7 @@ class AudioTransferBuffer { void deallocate_buffer_(); // A possible source or sink for the transfer buffer - std::shared_ptr ring_buffer_; + std::shared_ptr ring_buffer_; uint8_t *buffer_{nullptr}; uint8_t *data_start_{nullptr}; @@ -105,7 +105,7 @@ class AudioSinkTransferBuffer : public AudioTransferBuffer { /// @brief Adds a ring buffer as the transfer buffer's sink. /// @param ring_buffer weak_ptr to the allocated ring buffer - void set_sink(const std::weak_ptr &ring_buffer) { this->ring_buffer_ = ring_buffer.lock(); } + void set_sink(const std::weak_ptr &ring_buffer) { this->ring_buffer_ = ring_buffer.lock(); } #ifdef USE_SPEAKER /// @brief Adds a speaker as the transfer buffer's sink. @@ -179,7 +179,9 @@ class AudioSourceTransferBuffer : public AudioTransferBuffer, public AudioReadab /// @brief Adds a ring buffer as the transfer buffer's source. /// @param ring_buffer weak_ptr to the allocated ring buffer - void set_source(const std::weak_ptr &ring_buffer) { this->ring_buffer_ = ring_buffer.lock(); }; + void set_source(const std::weak_ptr &ring_buffer) { + this->ring_buffer_ = ring_buffer.lock(); + }; // AudioReadableBuffer interface const uint8_t *data() const override { return this->data_start_; } diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index 58d17ea6c43..a71b7db3baf 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -195,7 +195,7 @@ size_t I2SAudioSpeakerBase::play(const uint8_t *data, size_t length, TickType_t size_t bytes_written = 0; if (this->state_ == speaker::STATE_RUNNING) { - std::shared_ptr temp_ring_buffer = this->audio_ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->audio_ring_buffer_.lock(); if (temp_ring_buffer != nullptr) { // The weak_ptr locks successfully only while the speaker task owns the ring buffer, so it is safe to write bytes_written = temp_ring_buffer->write_without_replacement((void *) data, length, ticks_to_wait); @@ -207,7 +207,7 @@ size_t I2SAudioSpeakerBase::play(const uint8_t *data, size_t length, TickType_t bool I2SAudioSpeakerBase::has_buffered_data() const { if (this->audio_ring_buffer_.use_count() > 0) { - std::shared_ptr temp_ring_buffer = this->audio_ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->audio_ring_buffer_.lock(); return temp_ring_buffer->available() > 0; } return false; diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h index d9a228ef2c6..c598ca1bf87 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h @@ -9,12 +9,12 @@ #include #include "esphome/components/audio/audio.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/speaker/speaker.h" #include "esphome/core/component.h" #include "esphome/core/gpio.h" #include "esphome/core/helpers.h" -#include "esphome/core/ring_buffer.h" namespace esphome::i2s_audio { @@ -143,7 +143,7 @@ class I2SAudioSpeakerBase : public I2SAudioOut, public speaker::Speaker, public QueueHandle_t i2s_event_queue_{nullptr}; - std::weak_ptr audio_ring_buffer_; + std::weak_ptr audio_ring_buffer_; uint32_t buffer_duration_ms_; diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker_standard.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker_standard.cpp index edb316e3a25..51f2b225e20 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker_standard.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker_standard.cpp @@ -54,7 +54,7 @@ void I2SAudioSpeaker::run_speaker_task() { audio::AudioSourceTransferBuffer::create(bytes_to_fill_single_dma_buffer); if (transfer_buffer != nullptr) { - std::shared_ptr temp_ring_buffer = RingBuffer::create(ring_buffer_size); + std::shared_ptr temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size); if (temp_ring_buffer.use_count() == 1) { transfer_buffer->set_source(temp_ring_buffer); this->audio_ring_buffer_ = temp_ring_buffer; diff --git a/esphome/components/micro_wake_word/__init__.py b/esphome/components/micro_wake_word/__init__.py index 22d2098de0d..38926fce997 100644 --- a/esphome/components/micro_wake_word/__init__.py +++ b/esphome/components/micro_wake_word/__init__.py @@ -30,6 +30,7 @@ from esphome.core import CORE, HexInt _LOGGER = logging.getLogger(__name__) +AUTO_LOAD = ["ring_buffer"] CODEOWNERS = ["@kahrendt", "@jesserockz"] DEPENDENCIES = ["microphone"] diff --git a/esphome/components/micro_wake_word/micro_wake_word.cpp b/esphome/components/micro_wake_word/micro_wake_word.cpp index 1568fc6373b..c031a9f269d 100644 --- a/esphome/components/micro_wake_word/micro_wake_word.cpp +++ b/esphome/components/micro_wake_word/micro_wake_word.cpp @@ -106,7 +106,7 @@ void MicroWakeWord::setup() { if (this->state_ == State::STOPPED) { return; } - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (this->ring_buffer_.use_count() > 1) { size_t bytes_free = temp_ring_buffer->free(); @@ -156,7 +156,7 @@ void MicroWakeWord::inference_task(void *params) { if (!(xEventGroupGetBits(this_mww->event_group_) & ERROR_BITS)) { // Allocate ring buffer - std::shared_ptr temp_ring_buffer = RingBuffer::create( + std::shared_ptr temp_ring_buffer = ring_buffer::RingBuffer::create( this_mww->microphone_source_->get_audio_stream_info().ms_to_bytes(RING_BUFFER_DURATION_MS)); if (temp_ring_buffer.use_count() == 0) { xEventGroupSetBits(this_mww->event_group_, EventGroupBits::ERROR_MEMORY); diff --git a/esphome/components/micro_wake_word/micro_wake_word.h b/esphome/components/micro_wake_word/micro_wake_word.h index 79a1226fba6..5c0c056ac04 100644 --- a/esphome/components/micro_wake_word/micro_wake_word.h +++ b/esphome/components/micro_wake_word/micro_wake_word.h @@ -6,11 +6,11 @@ #include "streaming_model.h" #include "esphome/components/microphone/microphone_source.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/core/automation.h" #include "esphome/core/component.h" #include "esphome/core/defines.h" -#include "esphome/core/ring_buffer.h" #ifdef USE_OTA_STATE_LISTENER #include "esphome/components/ota/ota_backend.h" @@ -80,7 +80,7 @@ class MicroWakeWord : public Component Trigger wake_word_detected_trigger_; State state_{State::STOPPED}; - std::weak_ptr ring_buffer_; + std::weak_ptr ring_buffer_; std::vector wake_word_models_; #ifdef USE_MICRO_WAKE_WORD_VAD diff --git a/esphome/components/mixer/speaker/mixer_speaker.cpp b/esphome/components/mixer/speaker/mixer_speaker.cpp index 0d16bce330b..8dea4560c24 100644 --- a/esphome/components/mixer/speaker/mixer_speaker.cpp +++ b/esphome/components/mixer/speaker/mixer_speaker.cpp @@ -226,7 +226,7 @@ size_t SourceSpeaker::play(const uint8_t *data, size_t length, TickType_t ticks_ this->start(); } size_t bytes_written = 0; - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (temp_ring_buffer.use_count() > 0) { // Only write to the ring buffer if the reference is valid bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait); @@ -263,9 +263,9 @@ esp_err_t SourceSpeaker::start_() { return ESP_ERR_NO_MEM; } - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (!temp_ring_buffer) { - temp_ring_buffer = RingBuffer::create(ring_buffer_size); + temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size); this->ring_buffer_ = temp_ring_buffer; } diff --git a/esphome/components/mixer/speaker/mixer_speaker.h b/esphome/components/mixer/speaker/mixer_speaker.h index 29876ea262f..f392e83081a 100644 --- a/esphome/components/mixer/speaker/mixer_speaker.h +++ b/esphome/components/mixer/speaker/mixer_speaker.h @@ -4,6 +4,7 @@ #include "esphome/components/audio/audio.h" #include "esphome/components/audio/audio_transfer_buffer.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/speaker/speaker.h" #include "esphome/core/component.h" @@ -106,7 +107,7 @@ class SourceSpeaker : public speaker::Speaker, public Component { MixerSpeaker *parent_; std::shared_ptr transfer_buffer_; - std::weak_ptr ring_buffer_; + std::weak_ptr ring_buffer_; uint32_t buffer_duration_ms_; uint32_t last_seen_data_ms_{0}; diff --git a/esphome/components/resampler/speaker/resampler_speaker.cpp b/esphome/components/resampler/speaker/resampler_speaker.cpp index 9f69a7b50b0..ecbd445a806 100644 --- a/esphome/components/resampler/speaker/resampler_speaker.cpp +++ b/esphome/components/resampler/speaker/resampler_speaker.cpp @@ -226,7 +226,7 @@ size_t ResamplerSpeaker::play(const uint8_t *data, size_t length, TickType_t tic if ((this->output_speaker_->is_running()) && (!this->requires_resampling_())) { bytes_written = this->output_speaker_->play(data, length, ticks_to_wait); } else { - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (temp_ring_buffer) { // Only write to the ring buffer if the reference is valid bytes_written = temp_ring_buffer->write_without_replacement(data, length, ticks_to_wait); @@ -286,7 +286,7 @@ void ResamplerSpeaker::finish() { this->send_command_(ResamplingEventGroupBits:: bool ResamplerSpeaker::has_buffered_data() const { bool has_ring_buffer_data = false; if (this->requires_resampling_()) { - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (temp_ring_buffer) { has_ring_buffer_data = (temp_ring_buffer->available() > 0); } @@ -323,8 +323,8 @@ void ResamplerSpeaker::resample_task(void *params) { this_resampler->taps_, this_resampler->filters_); if (err == ESP_OK) { - std::shared_ptr temp_ring_buffer = - RingBuffer::create(this_resampler->audio_stream_info_.ms_to_bytes(this_resampler->buffer_duration_ms_)); + std::shared_ptr temp_ring_buffer = ring_buffer::RingBuffer::create( + this_resampler->audio_stream_info_.ms_to_bytes(this_resampler->buffer_duration_ms_)); if (!temp_ring_buffer) { err = ESP_ERR_NO_MEM; diff --git a/esphome/components/resampler/speaker/resampler_speaker.h b/esphome/components/resampler/speaker/resampler_speaker.h index 36f39fda97f..4a091e298a6 100644 --- a/esphome/components/resampler/speaker/resampler_speaker.h +++ b/esphome/components/resampler/speaker/resampler_speaker.h @@ -4,6 +4,7 @@ #include "esphome/components/audio/audio.h" #include "esphome/components/audio/audio_transfer_buffer.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/speaker/speaker.h" #include "esphome/core/component.h" @@ -75,7 +76,7 @@ class ResamplerSpeaker : public Component, public speaker::Speaker { EventGroupHandle_t event_group_{nullptr}; - std::weak_ptr ring_buffer_; + std::weak_ptr ring_buffer_; speaker::Speaker *output_speaker_{nullptr}; diff --git a/esphome/components/ring_buffer/__init__.py b/esphome/components/ring_buffer/__init__.py new file mode 100644 index 00000000000..b53476dcacb --- /dev/null +++ b/esphome/components/ring_buffer/__init__.py @@ -0,0 +1,7 @@ +import esphome.codegen as cg + +CODEOWNERS = ["@kahrendt"] +DEPENDENCIES = ["esp32"] + +ring_buffer_ns = cg.esphome_ns.namespace("ring_buffer") +RingBuffer = ring_buffer_ns.class_("RingBuffer") diff --git a/esphome/core/ring_buffer.cpp b/esphome/components/ring_buffer/ring_buffer.cpp similarity index 97% rename from esphome/core/ring_buffer.cpp rename to esphome/components/ring_buffer/ring_buffer.cpp index 486cf67f25d..9604290cf03 100644 --- a/esphome/core/ring_buffer.cpp +++ b/esphome/components/ring_buffer/ring_buffer.cpp @@ -5,7 +5,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { +namespace esphome::ring_buffer { static const char *const TAG = "ring_buffer"; @@ -135,6 +135,6 @@ bool RingBuffer::discard_bytes_(size_t discard_bytes) { return (bytes_read == discard_bytes); } -} // namespace esphome +} // namespace esphome::ring_buffer -#endif +#endif // USE_ESP32 diff --git a/esphome/components/ring_buffer/ring_buffer.h b/esphome/components/ring_buffer/ring_buffer.h new file mode 100644 index 00000000000..62094899d78 --- /dev/null +++ b/esphome/components/ring_buffer/ring_buffer.h @@ -0,0 +1,126 @@ +#pragma once + +#ifdef USE_ESP32 + +#include +#include + +#include +#include + +namespace esphome::ring_buffer { + +class RingBuffer { + public: + ~RingBuffer(); + + /** + * @brief Reads from the ring buffer, waiting up to a specified number of ticks if necessary. + * + * Available bytes are read into the provided data pointer. If not enough bytes are available, + * the function will wait up to `ticks_to_wait` FreeRTOS ticks before reading what is available. + * + * @param data Pointer to copy read data into + * @param len Number of bytes to read + * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) + * @return Number of bytes read + */ + size_t read(void *data, size_t len, TickType_t ticks_to_wait = 0); + + /** + * @brief Acquires a pointer into the ring buffer's internal storage without copying. + * + * The returned pointer is valid until receive_release() is called. Only one item + * may be checked out at a time. + * + * @param[out] length Set to the number of bytes actually acquired (may be less than max_length at wrap boundary) + * @param max_length Maximum number of bytes to acquire + * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) + * @return Pointer into the ring buffer's internal storage, or nullptr if no data is available + */ + void *receive_acquire(size_t &length, size_t max_length, TickType_t ticks_to_wait = 0); + + /** + * @brief Releases a previously acquired ring buffer item. + * + * Must be called exactly once for each successful receive_acquire(). + * + * @param item Pointer returned by receive_acquire() + */ + void receive_release(void *item); + + /** + * @brief Writes to the ring buffer, overwriting oldest data if necessary. + * + * The provided data is written to the ring buffer. If not enough space is available, + * the function will overwrite the oldest data in the ring buffer. + * + * @param data Pointer to data for writing + * @param len Number of bytes to write + * @return Number of bytes written + */ + size_t write(const void *data, size_t len); + + /** + * @brief Writes to the ring buffer without overwriting oldest data. + * + * The provided data is written to the ring buffer. If not enough space is available, + * the function will wait up to `ticks_to_wait` FreeRTOS ticks before writing as much as possible. + * + * @param data Pointer to data for writing + * @param len Number of bytes to write + * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) + * @return Number of bytes written + */ + size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait = 0, + bool write_partial = true); + + /** + * @brief Returns the number of available bytes in the ring buffer. + * + * This function provides the number of bytes that can be read from the ring buffer + * without blocking the calling FreeRTOS task. + * + * @return Number of available bytes + */ + size_t available() const; + + /** + * @brief Returns the number of free bytes in the ring buffer. + * + * This function provides the number of bytes that can be written to the ring buffer + * without overwriting data or blocking the calling FreeRTOS task. + * + * @return Number of free bytes + */ + size_t free() const; + + /** + * @brief Resets the ring buffer, discarding all stored data. + * + * @return pdPASS if successful, pdFAIL otherwise + */ + BaseType_t reset(); + + enum class MemoryPreference { + EXTERNAL_FIRST, // External RAM preferred, fall back to internal (default) + INTERNAL_FIRST, // Internal RAM preferred, fall back to external + }; + + static std::unique_ptr create(size_t len, MemoryPreference preference = MemoryPreference::EXTERNAL_FIRST); + + protected: + /// @brief Discards data from the ring buffer. + /// @param discard_bytes amount of bytes to discard + /// @return True if all bytes were successfully discarded, false otherwise + bool discard_bytes_(size_t discard_bytes); + + RingbufHandle_t handle_{nullptr}; + StaticRingbuffer_t structure_; + uint8_t *storage_{nullptr}; + size_t size_{0}; +}; + +} // namespace esphome::ring_buffer + +#endif // USE_ESP32 diff --git a/esphome/components/sound_level/sound_level.cpp b/esphome/components/sound_level/sound_level.cpp index 99533dbdd55..fb8bfd30856 100644 --- a/esphome/components/sound_level/sound_level.cpp +++ b/esphome/components/sound_level/sound_level.cpp @@ -29,7 +29,7 @@ void SoundLevelComponent::dump_config() { void SoundLevelComponent::setup() { this->microphone_source_->add_data_callback([this](const std::vector &data) { - std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this->ring_buffer_.lock(); if (this->ring_buffer_.use_count() == 2) { // ``audio_buffer_`` and ``temp_ring_buffer`` share ownership of a ring buffer, so its safe/useful to write temp_ring_buffer->write((void *) data.data(), data.size()); @@ -172,8 +172,8 @@ bool SoundLevelComponent::start_() { // Allocates a new ring buffer, adds it as a source for the transfer buffer, and points ring_buffer_ to it this->ring_buffer_.reset(); // Reset pointer to any previous ring buffer allocation - std::shared_ptr temp_ring_buffer = - RingBuffer::create(this->microphone_source_->get_audio_stream_info().ms_to_bytes(RING_BUFFER_DURATION_MS)); + std::shared_ptr temp_ring_buffer = ring_buffer::RingBuffer::create( + this->microphone_source_->get_audio_stream_info().ms_to_bytes(RING_BUFFER_DURATION_MS)); if (temp_ring_buffer.use_count() == 0) { this->status_momentary_error("ring_buffer", 15000); this->stop_(); diff --git a/esphome/components/sound_level/sound_level.h b/esphome/components/sound_level/sound_level.h index 0e46a203e86..4f0081a5104 100644 --- a/esphome/components/sound_level/sound_level.h +++ b/esphome/components/sound_level/sound_level.h @@ -4,11 +4,11 @@ #include "esphome/components/audio/audio_transfer_buffer.h" #include "esphome/components/microphone/microphone_source.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/sensor/sensor.h" #include "esphome/core/automation.h" #include "esphome/core/component.h" -#include "esphome/core/ring_buffer.h" namespace esphome::sound_level { @@ -49,7 +49,7 @@ class SoundLevelComponent : public Component { sensor::Sensor *rms_sensor_{nullptr}; std::unique_ptr audio_buffer_; - std::weak_ptr ring_buffer_; + std::weak_ptr ring_buffer_; int32_t squared_peak_{0}; uint64_t squared_samples_sum_{0}; diff --git a/esphome/components/speaker/media_player/audio_pipeline.cpp b/esphome/components/speaker/media_player/audio_pipeline.cpp index 892d4f4112f..010f0c50b33 100644 --- a/esphome/components/speaker/media_player/audio_pipeline.cpp +++ b/esphome/components/speaker/media_player/audio_pipeline.cpp @@ -315,10 +315,10 @@ void AudioPipeline::read_task(void *params) { if (err == ESP_OK) { size_t file_ring_buffer_size = this_pipeline->buffer_size_; - std::shared_ptr temp_ring_buffer; + std::shared_ptr temp_ring_buffer; if (!this_pipeline->raw_file_ring_buffer_.use_count()) { - temp_ring_buffer = RingBuffer::create(file_ring_buffer_size); + temp_ring_buffer = ring_buffer::RingBuffer::create(file_ring_buffer_size); this_pipeline->raw_file_ring_buffer_ = temp_ring_buffer; } @@ -502,7 +502,7 @@ void AudioPipeline::decode_task(void *params) { if (!started_playback && has_stream_info) { // Verify enough data is available before starting playback - std::shared_ptr temp_ring_buffer = this_pipeline->raw_file_ring_buffer_.lock(); + std::shared_ptr temp_ring_buffer = this_pipeline->raw_file_ring_buffer_.lock(); if (temp_ring_buffer != nullptr && temp_ring_buffer->available() >= initial_bytes_to_buffer) { started_playback = true; } diff --git a/esphome/components/speaker/media_player/audio_pipeline.h b/esphome/components/speaker/media_player/audio_pipeline.h index ef7f75dd38c..89f4707ab3c 100644 --- a/esphome/components/speaker/media_player/audio_pipeline.h +++ b/esphome/components/speaker/media_player/audio_pipeline.h @@ -5,9 +5,9 @@ #include "esphome/components/audio/audio.h" #include "esphome/components/audio/audio_reader.h" #include "esphome/components/audio/audio_decoder.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/speaker/speaker.h" -#include "esphome/core/ring_buffer.h" #include "esphome/core/static_task.h" #include "esp_err.h" @@ -129,7 +129,7 @@ class AudioPipeline { size_t buffer_size_; // Ring buffer between reader and decoder size_t transfer_buffer_size_; // Internal source/sink buffers for the audio reader and decoder - std::weak_ptr raw_file_ring_buffer_; + std::weak_ptr raw_file_ring_buffer_; // Handles basic control/state of the three tasks EventGroupHandle_t event_group_{nullptr}; diff --git a/esphome/components/voice_assistant/__init__.py b/esphome/components/voice_assistant/__init__.py index d970df2a44b..9387797ba2e 100644 --- a/esphome/components/voice_assistant/__init__.py +++ b/esphome/components/voice_assistant/__init__.py @@ -15,7 +15,7 @@ from esphome.const import ( CONF_SPEAKER, ) -AUTO_LOAD = ["socket"] +AUTO_LOAD = ["ring_buffer", "socket"] DEPENDENCIES = ["api", "microphone"] CODEOWNERS = ["@jesserockz", "@kahrendt"] diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index f2244a8ff43..bff0026b242 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -30,7 +30,7 @@ VoiceAssistant::VoiceAssistant() { global_voice_assistant = this; } void VoiceAssistant::setup() { this->mic_source_->add_data_callback([this](const std::vector &data) { - std::shared_ptr temp_ring_buffer = this->ring_buffer_; + std::shared_ptr temp_ring_buffer = this->ring_buffer_; if (this->ring_buffer_.use_count() > 1) { temp_ring_buffer->write((void *) data.data(), data.size()); } @@ -116,7 +116,7 @@ bool VoiceAssistant::allocate_buffers_() { #endif if (this->ring_buffer_.use_count() == 0) { - this->ring_buffer_ = RingBuffer::create(RING_BUFFER_SIZE); + this->ring_buffer_ = ring_buffer::RingBuffer::create(RING_BUFFER_SIZE); if (this->ring_buffer_.use_count() == 0) { ESP_LOGE(TAG, "Could not allocate ring buffer"); return false; diff --git a/esphome/components/voice_assistant/voice_assistant.h b/esphome/components/voice_assistant/voice_assistant.h index eb23dcb5e0d..faef09d8bd0 100644 --- a/esphome/components/voice_assistant/voice_assistant.h +++ b/esphome/components/voice_assistant/voice_assistant.h @@ -7,9 +7,9 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" #include "esphome/core/helpers.h" -#include "esphome/core/ring_buffer.h" #include "esphome/components/api/api_connection.h" +#include "esphome/components/ring_buffer/ring_buffer.h" #include "esphome/components/api/api_pb2.h" #include "esphome/components/microphone/microphone_source.h" #ifdef USE_MEDIA_PLAYER @@ -300,7 +300,7 @@ class VoiceAssistant : public Component { std::string wake_word_{""}; - std::shared_ptr ring_buffer_; + std::shared_ptr ring_buffer_; bool use_wake_word_; uint8_t noise_suppression_level_; diff --git a/esphome/core/config.py b/esphome/core/config.py index fe55c0fe25d..5a98b947819 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -759,10 +759,6 @@ async def to_code(config: ConfigType) -> None: # Platform-specific source files for core FILTER_SOURCE_FILES = filter_source_files_from_platform( { - "ring_buffer.cpp": { - PlatformFramework.ESP32_ARDUINO, - PlatformFramework.ESP32_IDF, - }, "static_task.cpp": { PlatformFramework.ESP32_ARDUINO, PlatformFramework.ESP32_IDF, diff --git a/esphome/core/ring_buffer.h b/esphome/core/ring_buffer.h index 8ac3ff38111..fbb089e9066 100644 --- a/esphome/core/ring_buffer.h +++ b/esphome/core/ring_buffer.h @@ -2,124 +2,20 @@ #ifdef USE_ESP32 -#include -#include - -#include -#include +// Deprecated: include "esphome/components/ring_buffer/ring_buffer.h" and use +// esphome::ring_buffer::RingBuffer. This shim will be removed in 2026.11.0. +#if __has_include("esphome/components/ring_buffer/ring_buffer.h") +#include "esphome/components/ring_buffer/ring_buffer.h" +#else +#error \ + "esphome/components/ring_buffer/ring_buffer.h not found. Add 'ring_buffer' to your component's AUTO_LOAD list to use esphome::ring_buffer::RingBuffer." +#endif +#include "esphome/core/helpers.h" // for ESPDEPRECATED namespace esphome { -class RingBuffer { - public: - ~RingBuffer(); - - /** - * @brief Reads from the ring buffer, waiting up to a specified number of ticks if necessary. - * - * Available bytes are read into the provided data pointer. If not enough bytes are available, - * the function will wait up to `ticks_to_wait` FreeRTOS ticks before reading what is available. - * - * @param data Pointer to copy read data into - * @param len Number of bytes to read - * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) - * @return Number of bytes read - */ - size_t read(void *data, size_t len, TickType_t ticks_to_wait = 0); - - /** - * @brief Acquires a pointer into the ring buffer's internal storage without copying. - * - * The returned pointer is valid until receive_release() is called. Only one item - * may be checked out at a time. - * - * @param[out] length Set to the number of bytes actually acquired (may be less than max_length at wrap boundary) - * @param max_length Maximum number of bytes to acquire - * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) - * @return Pointer into the ring buffer's internal storage, or nullptr if no data is available - */ - void *receive_acquire(size_t &length, size_t max_length, TickType_t ticks_to_wait = 0); - - /** - * @brief Releases a previously acquired ring buffer item. - * - * Must be called exactly once for each successful receive_acquire(). - * - * @param item Pointer returned by receive_acquire() - */ - void receive_release(void *item); - - /** - * @brief Writes to the ring buffer, overwriting oldest data if necessary. - * - * The provided data is written to the ring buffer. If not enough space is available, - * the function will overwrite the oldest data in the ring buffer. - * - * @param data Pointer to data for writing - * @param len Number of bytes to write - * @return Number of bytes written - */ - size_t write(const void *data, size_t len); - - /** - * @brief Writes to the ring buffer without overwriting oldest data. - * - * The provided data is written to the ring buffer. If not enough space is available, - * the function will wait up to `ticks_to_wait` FreeRTOS ticks before writing as much as possible. - * - * @param data Pointer to data for writing - * @param len Number of bytes to write - * @param ticks_to_wait Maximum number of FreeRTOS ticks to wait (default: 0) - * @return Number of bytes written - */ - size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait = 0, - bool write_partial = true); - - /** - * @brief Returns the number of available bytes in the ring buffer. - * - * This function provides the number of bytes that can be read from the ring buffer - * without blocking the calling FreeRTOS task. - * - * @return Number of available bytes - */ - size_t available() const; - - /** - * @brief Returns the number of free bytes in the ring buffer. - * - * This function provides the number of bytes that can be written to the ring buffer - * without overwriting data or blocking the calling FreeRTOS task. - * - * @return Number of free bytes - */ - size_t free() const; - - /** - * @brief Resets the ring buffer, discarding all stored data. - * - * @return pdPASS if successful, pdFAIL otherwise - */ - BaseType_t reset(); - - enum class MemoryPreference { - EXTERNAL_FIRST, // External RAM preferred, fall back to internal (default) - INTERNAL_FIRST, // Internal RAM preferred, fall back to external - }; - - static std::unique_ptr create(size_t len, MemoryPreference preference = MemoryPreference::EXTERNAL_FIRST); - - protected: - /// @brief Discards data from the ring buffer. - /// @param discard_bytes amount of bytes to discard - /// @return True if all bytes were successfully discarded, false otherwise - bool discard_bytes_(size_t discard_bytes); - - RingbufHandle_t handle_{nullptr}; - StaticRingbuffer_t structure_; - uint8_t *storage_{nullptr}; - size_t size_{0}; -}; +using RingBuffer ESPDEPRECATED("Use esphome::ring_buffer::RingBuffer instead. Removed in 2026.11.0.", + "2026.5.0") = ring_buffer::RingBuffer; } // namespace esphome diff --git a/esphome/writer.py b/esphome/writer.py index 816c57a0bc1..2fa43fa5eb1 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -199,7 +199,15 @@ def copy_src_tree(): # Build #include list for esphome.h # X-macro files are included multiple times with different macro definitions # and must not be included bare in esphome.h - esphome_h_exclude = {Path(ENTITY_TYPES_H_TARGET)} + # Deprecated headers that re-export from a relocated component must not be + # auto-included, since their #include of the new path only resolves when the + # new component is loaded by a consumer. + esphome_h_exclude = { + Path(ENTITY_TYPES_H_TARGET), + Path( + "esphome/core/ring_buffer.h" + ), # moved to components/ring_buffer/, removed in 2026.11.0 + } include_l = [] for target, _ in source_files_l: if target.suffix in HEADER_FILE_EXTENSIONS and target not in esphome_h_exclude: From 696a65473329a0f92df5c636e6af28bd2813b2a2 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Thu, 7 May 2026 23:05:17 -0400 Subject: [PATCH 11/52] [clang-tidy] Concatenate nested namespaces (7/7: tests, platform-gated, enable check) (#16307) --- .clang-tidy | 1 - .clang-tidy.hash | 2 +- esphome/components/adc/adc_sensor_esp8266.cpp | 6 ++---- esphome/components/adc/adc_sensor_libretiny.cpp | 6 ++---- esphome/components/adc/adc_sensor_rp2040.cpp | 6 ++---- esphome/components/adc/adc_sensor_zephyr.cpp | 6 ++---- .../components/beken_spi_led_strip/led_strip.cpp | 6 ++---- esphome/components/beken_spi_led_strip/led_strip.h | 6 ++---- .../bme68x_bsec2_i2c/bme68x_bsec2_i2c.cpp | 6 ++---- .../components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.h | 6 ++---- esphome/components/debug/debug_esp8266.cpp | 6 ++---- esphome/components/debug/debug_host.cpp | 6 ++---- esphome/components/debug/debug_libretiny.cpp | 6 ++---- esphome/components/debug/debug_rp2040.cpp | 6 ++---- .../components/deep_sleep/deep_sleep_esp8266.cpp | 6 ++---- esphome/components/esp8266_pwm/esp8266_pwm.cpp | 6 ++---- esphome/components/esp8266_pwm/esp8266_pwm.h | 6 ++---- esphome/components/esp_ldo/esp_ldo.cpp | 6 ++---- esphome/components/esp_ldo/esp_ldo.h | 6 ++---- esphome/components/host/gpio.h | 6 ++---- esphome/components/libretiny_pwm/libretiny_pwm.cpp | 6 ++---- esphome/components/libretiny_pwm/libretiny_pwm.h | 6 ++---- esphome/components/light/light_traits.h | 13 ++----------- esphome/components/lightwaverf/LwRx.cpp | 6 ++---- esphome/components/lightwaverf/LwTx.cpp | 6 ++---- esphome/components/lightwaverf/lightwaverf.cpp | 6 ++---- esphome/components/lightwaverf/lightwaverf.h | 6 ++---- esphome/components/midea/ir_transmitter.h | 6 ++---- esphome/components/mipi_dsi/mipi_dsi.cpp | 6 ++---- esphome/components/mipi_dsi/mipi_dsi.h | 6 ++---- esphome/components/mipi_rgb/mipi_rgb.cpp | 6 ++---- esphome/components/mipi_rgb/mipi_rgb.h | 6 ++---- esphome/components/neopixelbus/neopixelbus_light.h | 6 ++---- esphome/components/qspi_dbi/qspi_dbi.cpp | 6 ++---- esphome/components/qspi_dbi/qspi_dbi.h | 6 ++---- esphome/components/rp2040/core.h | 4 +--- esphome/components/rp2040/gpio.h | 6 ++---- .../components/rp2040_pio_led_strip/led_strip.cpp | 6 ++---- esphome/components/rp2040_pio_led_strip/led_strip.h | 6 ++---- esphome/components/rp2040_pwm/rp2040_pwm.cpp | 6 ++---- esphome/components/rp2040_pwm/rp2040_pwm.h | 6 ++---- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp | 6 ++---- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h | 6 ++---- esphome/components/sdl/sdl_esphome.cpp | 6 ++---- esphome/components/sdl/sdl_esphome.h | 6 ++---- .../components/sdl/touchscreen/sdl_touchscreen.h | 6 ++---- esphome/components/shelly_dimmer/dev_table.h | 6 ++---- esphome/components/shelly_dimmer/shelly_dimmer.cpp | 6 ++---- esphome/components/shelly_dimmer/shelly_dimmer.h | 6 ++---- esphome/components/shelly_dimmer/stm32flash.cpp | 12 ++---------- esphome/components/shelly_dimmer/stm32flash.h | 6 ++---- esphome/components/st7701s/st7701s.cpp | 6 ++---- esphome/components/st7701s/st7701s.h | 6 ++---- .../crc8_test_component/crc8_test_component.cpp | 6 ++---- .../crc8_test_component/crc8_test_component.h | 6 ++---- .../custom_api_device_component.cpp | 6 ++---- .../custom_api_device_component.h | 6 ++---- .../defer_stress_component.cpp | 6 ++---- .../defer_stress_component/defer_stress_component.h | 6 ++---- .../loop_test_component/loop_test_component.cpp | 6 ++---- .../loop_test_component/loop_test_component.h | 6 ++---- .../loop_test_component/loop_test_isr_component.cpp | 6 ++---- .../loop_test_component/loop_test_isr_component.h | 6 ++---- .../scheduler_bulk_cleanup_component.cpp | 6 ++---- .../scheduler_bulk_cleanup_component.h | 6 ++---- .../heap_scheduler_stress_component.cpp | 6 ++---- .../heap_scheduler_stress_component.h | 6 ++---- .../rapid_cancellation_component.cpp | 6 ++---- .../rapid_cancellation_component.h | 6 ++---- .../recursive_timeout_component.cpp | 6 ++---- .../recursive_timeout_component.h | 6 ++---- .../simultaneous_callbacks_component.cpp | 6 ++---- .../simultaneous_callbacks_component.h | 6 ++---- .../string_lifetime_component.cpp | 6 ++---- .../string_lifetime_component.h | 6 ++---- .../string_name_stress_component.cpp | 6 ++---- .../string_name_stress_component.h | 6 ++---- 77 files changed, 150 insertions(+), 314 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 4e128a19455..9aeeb1fc26c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -96,7 +96,6 @@ Checks: >- -modernize-avoid-variadic-functions, -modernize-avoid-c-arrays, -modernize-avoid-c-style-cast, - -modernize-concat-nested-namespaces, -modernize-macro-to-enum, -modernize-return-braced-init-list, -modernize-type-traits, diff --git a/.clang-tidy.hash b/.clang-tidy.hash index 582e0c1eaa2..2f973e34d9f 100644 --- a/.clang-tidy.hash +++ b/.clang-tidy.hash @@ -1 +1 @@ -0c7f309d70eca8e3efd510092ddb23c530f3934c49371717efa124b788d761f8 +c1e4375738304baabf7e915e5f7ca50fb22ec9b4a2d8312827a32a659f3fa40c diff --git a/esphome/components/adc/adc_sensor_esp8266.cpp b/esphome/components/adc/adc_sensor_esp8266.cpp index be14b252d43..e4f2f82f085 100644 --- a/esphome/components/adc/adc_sensor_esp8266.cpp +++ b/esphome/components/adc/adc_sensor_esp8266.cpp @@ -11,8 +11,7 @@ ADC_MODE(ADC_VCC) #include #endif // USE_ADC_SENSOR_VCC -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.esp8266"; @@ -55,7 +54,6 @@ float ADCSensor::sample() { return aggr.aggregate() / 1024.0f; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc #endif // USE_ESP8266 diff --git a/esphome/components/adc/adc_sensor_libretiny.cpp b/esphome/components/adc/adc_sensor_libretiny.cpp index 0b1393c2e70..d9b9f50be1f 100644 --- a/esphome/components/adc/adc_sensor_libretiny.cpp +++ b/esphome/components/adc/adc_sensor_libretiny.cpp @@ -3,8 +3,7 @@ #include "adc_sensor.h" #include "esphome/core/log.h" -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.libretiny"; @@ -48,7 +47,6 @@ float ADCSensor::sample() { return aggr.aggregate() / 1000.0f; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc #endif // USE_LIBRETINY diff --git a/esphome/components/adc/adc_sensor_rp2040.cpp b/esphome/components/adc/adc_sensor_rp2040.cpp index a79707e2347..8d41edb8145 100644 --- a/esphome/components/adc/adc_sensor_rp2040.cpp +++ b/esphome/components/adc/adc_sensor_rp2040.cpp @@ -15,8 +15,7 @@ #define PICO_VSYS_PIN 29 // NOLINT(cppcoreguidelines-macro-usage) #endif -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.rp2040"; @@ -98,7 +97,6 @@ float ADCSensor::sample() { return aggr.aggregate() * 3.3f / 4096.0f * coeff; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc #endif // USE_RP2040 diff --git a/esphome/components/adc/adc_sensor_zephyr.cpp b/esphome/components/adc/adc_sensor_zephyr.cpp index 2fb9d4b0e50..c3632b00e20 100644 --- a/esphome/components/adc/adc_sensor_zephyr.cpp +++ b/esphome/components/adc/adc_sensor_zephyr.cpp @@ -5,8 +5,7 @@ #include "hal/nrf_saadc.h" -namespace esphome { -namespace adc { +namespace esphome::adc { static const char *const TAG = "adc.zephyr"; @@ -202,6 +201,5 @@ float ADCSensor::sample() { return val_mv / 1000.0f; } -} // namespace adc -} // namespace esphome +} // namespace esphome::adc #endif diff --git a/esphome/components/beken_spi_led_strip/led_strip.cpp b/esphome/components/beken_spi_led_strip/led_strip.cpp index f425f3ca5c4..4e22489844b 100644 --- a/esphome/components/beken_spi_led_strip/led_strip.cpp +++ b/esphome/components/beken_spi_led_strip/led_strip.cpp @@ -33,8 +33,7 @@ static const uint32_t CTRL_NSSMD_3 = 1 << 17; static const uint32_t SPI_TX_FINISH_EN = 1 << 2; static const uint32_t SPI_RX_FINISH_EN = 1 << 3; -namespace esphome { -namespace beken_spi_led_strip { +namespace esphome::beken_spi_led_strip { static const char *const TAG = "beken_spi_led_strip"; @@ -382,7 +381,6 @@ void BekenSPILEDStripLightOutput::dump_config() { float BekenSPILEDStripLightOutput::get_setup_priority() const { return setup_priority::HARDWARE; } -} // namespace beken_spi_led_strip -} // namespace esphome +} // namespace esphome::beken_spi_led_strip #endif // USE_BK72XX diff --git a/esphome/components/beken_spi_led_strip/led_strip.h b/esphome/components/beken_spi_led_strip/led_strip.h index 705f9102a99..4ed640a3bc4 100644 --- a/esphome/components/beken_spi_led_strip/led_strip.h +++ b/esphome/components/beken_spi_led_strip/led_strip.h @@ -8,8 +8,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace beken_spi_led_strip { +namespace esphome::beken_spi_led_strip { enum RGBOrder : uint8_t { ORDER_RGB, @@ -79,7 +78,6 @@ class BekenSPILEDStripLightOutput : public light::AddressableLight { optional max_refresh_rate_{}; }; -} // namespace beken_spi_led_strip -} // namespace esphome +} // namespace esphome::beken_spi_led_strip #endif // USE_BK72XX diff --git a/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.cpp b/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.cpp index 2d74ba6b122..2a2c5e2bcc8 100644 --- a/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.cpp +++ b/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.cpp @@ -9,8 +9,7 @@ #include -namespace esphome { -namespace bme68x_bsec2_i2c { +namespace esphome::bme68x_bsec2_i2c { static const char *const TAG = "bme68x_bsec2_i2c.sensor"; @@ -53,6 +52,5 @@ void BME68xBSEC2I2CComponent::delay_us(uint32_t period, void *intfPtr) { delayMicroseconds(period); } -} // namespace bme68x_bsec2_i2c -} // namespace esphome +} // namespace esphome::bme68x_bsec2_i2c #endif diff --git a/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.h b/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.h index a21a123f7b9..6d20b613903 100644 --- a/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.h +++ b/esphome/components/bme68x_bsec2_i2c/bme68x_bsec2_i2c.h @@ -9,8 +9,7 @@ #include "esphome/components/bme68x_bsec2/bme68x_bsec2.h" #include "esphome/components/i2c/i2c.h" -namespace esphome { -namespace bme68x_bsec2_i2c { +namespace esphome::bme68x_bsec2_i2c { class BME68xBSEC2I2CComponent : public bme68x_bsec2::BME68xBSEC2Component, public i2c::I2CDevice { void setup() override; @@ -23,6 +22,5 @@ class BME68xBSEC2I2CComponent : public bme68x_bsec2::BME68xBSEC2Component, publi static void delay_us(uint32_t period, void *intfPtr); }; -} // namespace bme68x_bsec2_i2c -} // namespace esphome +} // namespace esphome::bme68x_bsec2_i2c #endif diff --git a/esphome/components/debug/debug_esp8266.cpp b/esphome/components/debug/debug_esp8266.cpp index 0519ab72fe9..272123dfc0e 100644 --- a/esphome/components/debug/debug_esp8266.cpp +++ b/esphome/components/debug/debug_esp8266.cpp @@ -15,8 +15,7 @@ extern uint32_t core_version; extern const char *core_release; } -namespace esphome { -namespace debug { +namespace esphome::debug { static const char *const TAG = "debug"; @@ -170,6 +169,5 @@ void DebugComponent::update_platform_() { #endif } -} // namespace debug -} // namespace esphome +} // namespace esphome::debug #endif diff --git a/esphome/components/debug/debug_host.cpp b/esphome/components/debug/debug_host.cpp index 0dfab86e4c4..298a7e44e70 100644 --- a/esphome/components/debug/debug_host.cpp +++ b/esphome/components/debug/debug_host.cpp @@ -2,8 +2,7 @@ #ifdef USE_HOST #include -namespace esphome { -namespace debug { +namespace esphome::debug { const char *DebugComponent::get_reset_reason_(std::span buffer) { return ""; } @@ -15,6 +14,5 @@ size_t DebugComponent::get_device_info_(std::span void DebugComponent::update_platform_() {} -} // namespace debug -} // namespace esphome +} // namespace esphome::debug #endif diff --git a/esphome/components/debug/debug_libretiny.cpp b/esphome/components/debug/debug_libretiny.cpp index 6f36debb95a..1cc04dcbd8e 100644 --- a/esphome/components/debug/debug_libretiny.cpp +++ b/esphome/components/debug/debug_libretiny.cpp @@ -2,8 +2,7 @@ #ifdef USE_LIBRETINY #include "esphome/core/log.h" -namespace esphome { -namespace debug { +namespace esphome::debug { static const char *const TAG = "debug"; @@ -62,6 +61,5 @@ void DebugComponent::update_platform_() { #endif } -} // namespace debug -} // namespace esphome +} // namespace esphome::debug #endif diff --git a/esphome/components/debug/debug_rp2040.cpp b/esphome/components/debug/debug_rp2040.cpp index 73f08492c86..adc23dbf51f 100644 --- a/esphome/components/debug/debug_rp2040.cpp +++ b/esphome/components/debug/debug_rp2040.cpp @@ -12,8 +12,7 @@ #ifdef USE_RP2040_CRASH_HANDLER #include "esphome/components/rp2040/crash_handler.h" #endif -namespace esphome { -namespace debug { +namespace esphome::debug { static const char *const TAG = "debug"; @@ -84,6 +83,5 @@ size_t DebugComponent::get_device_info_(std::span void DebugComponent::update_platform_() {} -} // namespace debug -} // namespace esphome +} // namespace esphome::debug #endif diff --git a/esphome/components/deep_sleep/deep_sleep_esp8266.cpp b/esphome/components/deep_sleep/deep_sleep_esp8266.cpp index 42c153c2f38..9239a7fb311 100644 --- a/esphome/components/deep_sleep/deep_sleep_esp8266.cpp +++ b/esphome/components/deep_sleep/deep_sleep_esp8266.cpp @@ -3,8 +3,7 @@ #include -namespace esphome { -namespace deep_sleep { +namespace esphome::deep_sleep { static const char *const TAG = "deep_sleep"; @@ -20,6 +19,5 @@ void DeepSleepComponent::deep_sleep_() { bool DeepSleepComponent::should_teardown_() { return true; } -} // namespace deep_sleep -} // namespace esphome +} // namespace esphome::deep_sleep #endif diff --git a/esphome/components/esp8266_pwm/esp8266_pwm.cpp b/esphome/components/esp8266_pwm/esp8266_pwm.cpp index cc6bfbc8a88..b5b3d5073aa 100644 --- a/esphome/components/esp8266_pwm/esp8266_pwm.cpp +++ b/esphome/components/esp8266_pwm/esp8266_pwm.cpp @@ -8,8 +8,7 @@ #include -namespace esphome { -namespace esp8266_pwm { +namespace esphome::esp8266_pwm { static const char *const TAG = "esp8266_pwm"; @@ -53,7 +52,6 @@ void HOT ESP8266PWM::write_state(float state) { } } -} // namespace esp8266_pwm -} // namespace esphome +} // namespace esphome::esp8266_pwm #endif diff --git a/esphome/components/esp8266_pwm/esp8266_pwm.h b/esphome/components/esp8266_pwm/esp8266_pwm.h index 4b021fc4622..51c4ea16028 100644 --- a/esphome/components/esp8266_pwm/esp8266_pwm.h +++ b/esphome/components/esp8266_pwm/esp8266_pwm.h @@ -7,8 +7,7 @@ #include "esphome/core/automation.h" #include "esphome/components/output/float_output.h" -namespace esphome { -namespace esp8266_pwm { +namespace esphome::esp8266_pwm { class ESP8266PWM : public output::FloatOutput, public Component { public: @@ -48,7 +47,6 @@ template class SetFrequencyAction : public Action { ESP8266PWM *parent_; }; -} // namespace esp8266_pwm -} // namespace esphome +} // namespace esphome::esp8266_pwm #endif diff --git a/esphome/components/esp_ldo/esp_ldo.cpp b/esphome/components/esp_ldo/esp_ldo.cpp index f8ebec19035..b3c9a59865d 100644 --- a/esphome/components/esp_ldo/esp_ldo.cpp +++ b/esphome/components/esp_ldo/esp_ldo.cpp @@ -3,8 +3,7 @@ #include "esphome/core/log.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace esp_ldo { +namespace esphome::esp_ldo { static const char *const TAG = "esp_ldo"; void EspLdo::setup() { @@ -41,7 +40,6 @@ void EspLdo::adjust_voltage(float voltage) { } } -} // namespace esp_ldo -} // namespace esphome +} // namespace esphome::esp_ldo #endif // USE_ESP32_VARIANT_ESP32P4 diff --git a/esphome/components/esp_ldo/esp_ldo.h b/esphome/components/esp_ldo/esp_ldo.h index 1a20f1d08ad..bb1579e83dd 100644 --- a/esphome/components/esp_ldo/esp_ldo.h +++ b/esphome/components/esp_ldo/esp_ldo.h @@ -4,8 +4,7 @@ #include "esphome/core/automation.h" #include "esp_ldo_regulator.h" -namespace esphome { -namespace esp_ldo { +namespace esphome::esp_ldo { class EspLdo : public Component { public: @@ -40,7 +39,6 @@ template class AdjustAction : public Action { EspLdo *ldo_; }; -} // namespace esp_ldo -} // namespace esphome +} // namespace esphome::esp_ldo #endif // USE_ESP32_VARIANT_ESP32P4 diff --git a/esphome/components/host/gpio.h b/esphome/components/host/gpio.h index ea6b13f436e..6f2bccf1021 100644 --- a/esphome/components/host/gpio.h +++ b/esphome/components/host/gpio.h @@ -4,8 +4,7 @@ #include "esphome/core/hal.h" -namespace esphome { -namespace host { +namespace esphome::host { class HostGPIOPin : public InternalGPIOPin { public: @@ -32,7 +31,6 @@ class HostGPIOPin : public InternalGPIOPin { gpio::Flags flags_{}; }; -} // namespace host -} // namespace esphome +} // namespace esphome::host #endif // USE_HOST diff --git a/esphome/components/libretiny_pwm/libretiny_pwm.cpp b/esphome/components/libretiny_pwm/libretiny_pwm.cpp index 4e4a16d761f..eea593a39da 100644 --- a/esphome/components/libretiny_pwm/libretiny_pwm.cpp +++ b/esphome/components/libretiny_pwm/libretiny_pwm.cpp @@ -3,8 +3,7 @@ #ifdef USE_LIBRETINY -namespace esphome { -namespace libretiny_pwm { +namespace esphome::libretiny_pwm { static const char *const TAG = "libretiny.pwm"; @@ -49,7 +48,6 @@ void LibreTinyPWM::update_frequency(float frequency) { this->write_state(this->duty_); } -} // namespace libretiny_pwm -} // namespace esphome +} // namespace esphome::libretiny_pwm #endif diff --git a/esphome/components/libretiny_pwm/libretiny_pwm.h b/esphome/components/libretiny_pwm/libretiny_pwm.h index f9117090548..f7737be386b 100644 --- a/esphome/components/libretiny_pwm/libretiny_pwm.h +++ b/esphome/components/libretiny_pwm/libretiny_pwm.h @@ -7,8 +7,7 @@ #ifdef USE_LIBRETINY -namespace esphome { -namespace libretiny_pwm { +namespace esphome::libretiny_pwm { class LibreTinyPWM : public output::FloatOutput, public Component { public: @@ -49,7 +48,6 @@ template class SetFrequencyAction : public Action { LibreTinyPWM *parent_; }; -} // namespace libretiny_pwm -} // namespace esphome +} // namespace esphome::libretiny_pwm #endif diff --git a/esphome/components/light/light_traits.h b/esphome/components/light/light_traits.h index c3bb27a9647..a2a6b0a916b 100644 --- a/esphome/components/light/light_traits.h +++ b/esphome/components/light/light_traits.h @@ -3,15 +3,7 @@ #include "color_mode.h" #include "esphome/core/helpers.h" -namespace esphome { - -#ifdef USE_API -namespace api { -class APIConnection; -} // namespace api -#endif - -namespace light { +namespace esphome::light { /// This class is used to represent the capabilities of a light. class LightTraits { @@ -43,5 +35,4 @@ class LightTraits { ColorModeMask supported_color_modes_{}; }; -} // namespace light -} // namespace esphome +} // namespace esphome::light diff --git a/esphome/components/lightwaverf/LwRx.cpp b/esphome/components/lightwaverf/LwRx.cpp index 97104578508..dfb8edfaf7a 100644 --- a/esphome/components/lightwaverf/LwRx.cpp +++ b/esphome/components/lightwaverf/LwRx.cpp @@ -10,8 +10,7 @@ #include #include "esphome/core/helpers.h" -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { /** Pin change interrupt routine that identifies 1 and 0 LightwaveRF bits @@ -430,6 +429,5 @@ void LwRx::rx_remove_pair_(uint8_t *buf) { } } -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf #endif diff --git a/esphome/components/lightwaverf/LwTx.cpp b/esphome/components/lightwaverf/LwTx.cpp index 8852935bfd8..339980d6ee6 100644 --- a/esphome/components/lightwaverf/LwTx.cpp +++ b/esphome/components/lightwaverf/LwTx.cpp @@ -11,8 +11,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { static const uint8_t TX_NIBBLE[] = {0xF6, 0xEE, 0xED, 0xEB, 0xDE, 0xDD, 0xDB, 0xBE, 0xBD, 0xBB, 0xB7, 0x7E, 0x7D, 0x7B, 0x77, 0x6F}; @@ -208,6 +207,5 @@ void LwTx::lw_timer_stop() { } } -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf #endif diff --git a/esphome/components/lightwaverf/lightwaverf.cpp b/esphome/components/lightwaverf/lightwaverf.cpp index 2c6a1ecf5b5..b8b6a9697ea 100644 --- a/esphome/components/lightwaverf/lightwaverf.cpp +++ b/esphome/components/lightwaverf/lightwaverf.cpp @@ -5,8 +5,7 @@ #include "lightwaverf.h" -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { static const char *const TAG = "lightwaverf.sensor"; @@ -62,7 +61,6 @@ void LightWaveRF::dump_config() { LOG_PIN(" Pin RX: ", this->pin_rx_); LOG_UPDATE_INTERVAL(this); } -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf #endif diff --git a/esphome/components/lightwaverf/lightwaverf.h b/esphome/components/lightwaverf/lightwaverf.h index 6210e6b5d47..224da6315f4 100644 --- a/esphome/components/lightwaverf/lightwaverf.h +++ b/esphome/components/lightwaverf/lightwaverf.h @@ -11,8 +11,7 @@ #include "LwRx.h" #include "LwTx.h" -namespace esphome { -namespace lightwaverf { +namespace esphome::lightwaverf { #ifdef USE_ESP8266 @@ -61,6 +60,5 @@ template class SendRawAction : public Action { }; #endif -} // namespace lightwaverf -} // namespace esphome +} // namespace esphome::lightwaverf #endif diff --git a/esphome/components/midea/ir_transmitter.h b/esphome/components/midea/ir_transmitter.h index a16aed2e722..f11682230d3 100644 --- a/esphome/components/midea/ir_transmitter.h +++ b/esphome/components/midea/ir_transmitter.h @@ -4,8 +4,7 @@ #ifdef USE_REMOTE_TRANSMITTER #include "esphome/components/remote_base/midea_protocol.h" -namespace esphome { -namespace midea { +namespace esphome::midea { using remote_base::RemoteTransmitterBase; using IrData = remote_base::MideaData; @@ -84,8 +83,7 @@ class IrTransmitter { RemoteTransmitterBase *transmitter_{nullptr}; }; -} // namespace midea -} // namespace esphome +} // namespace esphome::midea #endif #endif // USE_ARDUINO diff --git a/esphome/components/mipi_dsi/mipi_dsi.cpp b/esphome/components/mipi_dsi/mipi_dsi.cpp index fc59aeffe89..9bd2dded2c8 100644 --- a/esphome/components/mipi_dsi/mipi_dsi.cpp +++ b/esphome/components/mipi_dsi/mipi_dsi.cpp @@ -3,8 +3,7 @@ #include "mipi_dsi.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace mipi_dsi { +namespace esphome::mipi_dsi { // Maximum bytes to log for init commands (truncated if larger) static constexpr size_t MIPI_DSI_MAX_CMD_LOG_BYTES = 64; @@ -411,6 +410,5 @@ void MIPI_DSI::dump_config() { YESNO(this->invert_colors_), this->pclk_frequency_); LOG_PIN(" Reset Pin ", this->reset_pin_); } -} // namespace mipi_dsi -} // namespace esphome +} // namespace esphome::mipi_dsi #endif // USE_ESP32_VARIANT_ESP32P4 diff --git a/esphome/components/mipi_dsi/mipi_dsi.h b/esphome/components/mipi_dsi/mipi_dsi.h index c27c9ccc6ef..82827d813e8 100644 --- a/esphome/components/mipi_dsi/mipi_dsi.h +++ b/esphome/components/mipi_dsi/mipi_dsi.h @@ -16,8 +16,7 @@ #include "esp_lcd_mipi_dsi.h" -namespace esphome { -namespace mipi_dsi { +namespace esphome::mipi_dsi { constexpr static const char *const TAG = "display.mipi_dsi"; const uint8_t SW_RESET_CMD = 0x01; @@ -113,6 +112,5 @@ class MIPI_DSI : public display::Display { uint16_t y_high_{0}; }; -} // namespace mipi_dsi -} // namespace esphome +} // namespace esphome::mipi_dsi #endif diff --git a/esphome/components/mipi_rgb/mipi_rgb.cpp b/esphome/components/mipi_rgb/mipi_rgb.cpp index 6f5e2f2490c..b07460fdba9 100644 --- a/esphome/components/mipi_rgb/mipi_rgb.cpp +++ b/esphome/components/mipi_rgb/mipi_rgb.cpp @@ -8,8 +8,7 @@ #include #include -namespace esphome { -namespace mipi_rgb { +namespace esphome::mipi_rgb { static const uint8_t DELAY_FLAG = 0xFF; @@ -400,6 +399,5 @@ void MipiRgb::dump_config() { this->dump_pins_(3, 8, "Red", 0); } -} // namespace mipi_rgb -} // namespace esphome +} // namespace esphome::mipi_rgb #endif // defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32P4) diff --git a/esphome/components/mipi_rgb/mipi_rgb.h b/esphome/components/mipi_rgb/mipi_rgb.h index accc251a184..4d1d8360998 100644 --- a/esphome/components/mipi_rgb/mipi_rgb.h +++ b/esphome/components/mipi_rgb/mipi_rgb.h @@ -8,8 +8,7 @@ #include "esphome/components/spi/spi.h" #endif -namespace esphome { -namespace mipi_rgb { +namespace esphome::mipi_rgb { constexpr static const char *const TAG = "display.mipi_rgb"; const uint8_t SW_RESET_CMD = 0x01; @@ -120,6 +119,5 @@ class MipiRgbSpi : public MipiRgb, }; #endif -} // namespace mipi_rgb -} // namespace esphome +} // namespace esphome::mipi_rgb #endif diff --git a/esphome/components/neopixelbus/neopixelbus_light.h b/esphome/components/neopixelbus/neopixelbus_light.h index c27244b94dd..1cbe889acf9 100644 --- a/esphome/components/neopixelbus/neopixelbus_light.h +++ b/esphome/components/neopixelbus/neopixelbus_light.h @@ -11,8 +11,7 @@ #include "NeoPixelBus.h" -namespace esphome { -namespace neopixelbus { +namespace esphome::neopixelbus { enum class ESPNeoPixelOrder { GBWR = 0b11000110, @@ -140,7 +139,6 @@ class NeoPixelRGBWLightOutput : public NeoPixelBusLightOutputBasereset_pin_); } -} // namespace qspi_dbi -} // namespace esphome +} // namespace esphome::qspi_dbi #endif diff --git a/esphome/components/qspi_dbi/qspi_dbi.h b/esphome/components/qspi_dbi/qspi_dbi.h index 3eee9bec47b..fa77cc5f762 100644 --- a/esphome/components/qspi_dbi/qspi_dbi.h +++ b/esphome/components/qspi_dbi/qspi_dbi.h @@ -11,8 +11,7 @@ #include "esp_lcd_panel_rgb.h" -namespace esphome { -namespace qspi_dbi { +namespace esphome::qspi_dbi { constexpr static const char *const TAG = "display.qspi_dbi"; static const uint8_t SW_RESET_CMD = 0x01; @@ -168,6 +167,5 @@ class QspiDbi : public display::DisplayBuffer, esp_lcd_panel_handle_t handle_{}; }; -} // namespace qspi_dbi -} // namespace esphome +} // namespace esphome::qspi_dbi #endif diff --git a/esphome/components/rp2040/core.h b/esphome/components/rp2040/core.h index 92fc4f824e6..db8937a8a36 100644 --- a/esphome/components/rp2040/core.h +++ b/esphome/components/rp2040/core.h @@ -7,8 +7,6 @@ extern "C" unsigned long ulMainGetRunTimeCounterValue(); -namespace esphome { -namespace rp2040 {} // namespace rp2040 -} // namespace esphome +namespace esphome::rp2040 {} // namespace esphome::rp2040 #endif // USE_RP2040 diff --git a/esphome/components/rp2040/gpio.h b/esphome/components/rp2040/gpio.h index a98e1dab140..da97cff9b1e 100644 --- a/esphome/components/rp2040/gpio.h +++ b/esphome/components/rp2040/gpio.h @@ -5,8 +5,7 @@ #include #include "esphome/core/hal.h" -namespace esphome { -namespace rp2040 { +namespace esphome::rp2040 { class RP2040GPIOPin : public InternalGPIOPin { public: @@ -33,7 +32,6 @@ class RP2040GPIOPin : public InternalGPIOPin { gpio::Flags flags_{}; }; -} // namespace rp2040 -} // namespace esphome +} // namespace esphome::rp2040 #endif // USE_RP2040 diff --git a/esphome/components/rp2040_pio_led_strip/led_strip.cpp b/esphome/components/rp2040_pio_led_strip/led_strip.cpp index fdb49fb3efe..8afba6ba1d4 100644 --- a/esphome/components/rp2040_pio_led_strip/led_strip.cpp +++ b/esphome/components/rp2040_pio_led_strip/led_strip.cpp @@ -12,8 +12,7 @@ #include #include -namespace esphome { -namespace rp2040_pio_led_strip { +namespace esphome::rp2040_pio_led_strip { static const char *TAG = "rp2040_pio_led_strip"; @@ -210,7 +209,6 @@ void RP2040PIOLEDStripLightOutput::dump_config() { float RP2040PIOLEDStripLightOutput::get_setup_priority() const { return setup_priority::HARDWARE; } -} // namespace rp2040_pio_led_strip -} // namespace esphome +} // namespace esphome::rp2040_pio_led_strip #endif diff --git a/esphome/components/rp2040_pio_led_strip/led_strip.h b/esphome/components/rp2040_pio_led_strip/led_strip.h index 7b626489743..ebc3bbbaa54 100644 --- a/esphome/components/rp2040_pio_led_strip/led_strip.h +++ b/esphome/components/rp2040_pio_led_strip/led_strip.h @@ -16,8 +16,7 @@ #include #include -namespace esphome { -namespace rp2040_pio_led_strip { +namespace esphome::rp2040_pio_led_strip { enum RGBOrder : uint8_t { ORDER_RGB, @@ -127,7 +126,6 @@ class RP2040PIOLEDStripLightOutput : public light::AddressableLight { inline static struct semaphore dma_write_complete_sem_[12]; }; -} // namespace rp2040_pio_led_strip -} // namespace esphome +} // namespace esphome::rp2040_pio_led_strip #endif // USE_RP2040 diff --git a/esphome/components/rp2040_pwm/rp2040_pwm.cpp b/esphome/components/rp2040_pwm/rp2040_pwm.cpp index 90a507b14f7..c9b9e6739d1 100644 --- a/esphome/components/rp2040_pwm/rp2040_pwm.cpp +++ b/esphome/components/rp2040_pwm/rp2040_pwm.cpp @@ -11,8 +11,7 @@ #include #include -namespace esphome { -namespace rp2040_pwm { +namespace esphome::rp2040_pwm { static const char *const TAG = "rp2040_pwm"; @@ -60,7 +59,6 @@ void HOT RP2040PWM::write_state(float state) { pwm_set_gpio_level(this->pin_->get_pin(), state * this->wrap_); } -} // namespace rp2040_pwm -} // namespace esphome +} // namespace esphome::rp2040_pwm #endif diff --git a/esphome/components/rp2040_pwm/rp2040_pwm.h b/esphome/components/rp2040_pwm/rp2040_pwm.h index b82765b1c01..58d3955a31e 100644 --- a/esphome/components/rp2040_pwm/rp2040_pwm.h +++ b/esphome/components/rp2040_pwm/rp2040_pwm.h @@ -7,8 +7,7 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" -namespace esphome { -namespace rp2040_pwm { +namespace esphome::rp2040_pwm { class RP2040PWM : public output::FloatOutput, public Component { public: @@ -53,7 +52,6 @@ template class SetFrequencyAction : public Action { RP2040PWM *parent_; }; -} // namespace rp2040_pwm -} // namespace esphome +} // namespace esphome::rp2040_pwm #endif // USE_RP2040 diff --git a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp index d29f6a0bcb9..00530c3f96e 100644 --- a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +++ b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace rpi_dpi_rgb { +namespace esphome::rpi_dpi_rgb { void RpiDpiRgb::setup() { this->reset_display_(); @@ -160,7 +159,6 @@ void RpiDpiRgb::reset_display_() const { } } -} // namespace rpi_dpi_rgb -} // namespace esphome +} // namespace esphome::rpi_dpi_rgb #endif // USE_ESP32_VARIANT_ESP32S3 diff --git a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h index 7525040cd1f..8b1457926c1 100644 --- a/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h +++ b/esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h @@ -14,8 +14,7 @@ #include "esp_lcd_panel_rgb.h" -namespace esphome { -namespace rpi_dpi_rgb { +namespace esphome::rpi_dpi_rgb { constexpr static const char *const TAG = "rpi_dpi_rgb"; @@ -92,6 +91,5 @@ class RpiDpiRgb : public display::Display { esp_lcd_panel_handle_t handle_{}; }; -} // namespace rpi_dpi_rgb -} // namespace esphome +} // namespace esphome::rpi_dpi_rgb #endif // USE_ESP32_VARIANT_ESP32S3 diff --git a/esphome/components/sdl/sdl_esphome.cpp b/esphome/components/sdl/sdl_esphome.cpp index 74ca2ce39a5..c99b5081b3d 100644 --- a/esphome/components/sdl/sdl_esphome.cpp +++ b/esphome/components/sdl/sdl_esphome.cpp @@ -2,8 +2,7 @@ #include "sdl_esphome.h" #include "esphome/components/display/display_color_utils.h" -namespace esphome { -namespace sdl { +namespace esphome::sdl { int Sdl::get_width() { switch (this->rotation_) { @@ -162,6 +161,5 @@ void Sdl::loop() { } } -} // namespace sdl -} // namespace esphome +} // namespace esphome::sdl #endif diff --git a/esphome/components/sdl/sdl_esphome.h b/esphome/components/sdl/sdl_esphome.h index ce34cb817e0..3f54b705606 100644 --- a/esphome/components/sdl/sdl_esphome.h +++ b/esphome/components/sdl/sdl_esphome.h @@ -9,8 +9,7 @@ #include "SDL.h" #include -namespace esphome { -namespace sdl { +namespace esphome::sdl { constexpr static const char *const TAG = "sdl"; @@ -66,7 +65,6 @@ class Sdl : public display::Display { uint16_t y_high_{0}; std::map> key_callbacks_{}; }; -} // namespace sdl -} // namespace esphome +} // namespace esphome::sdl #endif diff --git a/esphome/components/sdl/touchscreen/sdl_touchscreen.h b/esphome/components/sdl/touchscreen/sdl_touchscreen.h index a1f0fb15e32..cf2fd650889 100644 --- a/esphome/components/sdl/touchscreen/sdl_touchscreen.h +++ b/esphome/components/sdl/touchscreen/sdl_touchscreen.h @@ -4,8 +4,7 @@ #include "../sdl_esphome.h" #include "esphome/components/touchscreen/touchscreen.h" -namespace esphome { -namespace sdl { +namespace esphome::sdl { class SdlTouchscreen : public touchscreen::Touchscreen, public Parented { public: @@ -21,6 +20,5 @@ class SdlTouchscreen : public touchscreen::Touchscreen, public Parented { } }; -} // namespace sdl -} // namespace esphome +} // namespace esphome::sdl #endif diff --git a/esphome/components/shelly_dimmer/dev_table.h b/esphome/components/shelly_dimmer/dev_table.h index e73cd1271cb..32b4810d7a2 100644 --- a/esphome/components/shelly_dimmer/dev_table.h +++ b/esphome/components/shelly_dimmer/dev_table.h @@ -23,8 +23,7 @@ #ifdef USE_SHD_FIRMWARE_DATA #include "stm32flash.h" -namespace esphome { -namespace shelly_dimmer { +namespace esphome::shelly_dimmer { constexpr uint32_t SZ_128 = 0x00000080; constexpr uint32_t SZ_256 = 0x00000100; @@ -153,7 +152,6 @@ constexpr stm32_dev_t DEVICES[] = { {0x0, "", 0x0, 0x0, 0x0, 0x0, 0x0, nullptr, 0x0, 0x0, 0x0, 0x0, 0x0}, }; -} // namespace shelly_dimmer -} // namespace esphome +} // namespace esphome::shelly_dimmer #endif // USE_SHD_FIRMWARE_DATA diff --git a/esphome/components/shelly_dimmer/shelly_dimmer.cpp b/esphome/components/shelly_dimmer/shelly_dimmer.cpp index 230fb963b13..b0f43f0ffca 100644 --- a/esphome/components/shelly_dimmer/shelly_dimmer.cpp +++ b/esphome/components/shelly_dimmer/shelly_dimmer.cpp @@ -56,8 +56,7 @@ template constexpr size_t size(const T (&/*unused*/)[N]) n } // Anonymous namespace -namespace esphome { -namespace shelly_dimmer { +namespace esphome::shelly_dimmer { /// Computes a crappy checksum as defined by the Shelly Dimmer protocol. uint16_t shelly_dimmer_checksum(const uint8_t *buf, int len) { @@ -522,7 +521,6 @@ void ShellyDimmer::reset_dfu_boot_() { this->reset_(true); } -} // namespace shelly_dimmer -} // namespace esphome +} // namespace esphome::shelly_dimmer #endif // USE_ESP8266 diff --git a/esphome/components/shelly_dimmer/shelly_dimmer.h b/esphome/components/shelly_dimmer/shelly_dimmer.h index fd75caa797d..c6d0e20afe8 100644 --- a/esphome/components/shelly_dimmer/shelly_dimmer.h +++ b/esphome/components/shelly_dimmer/shelly_dimmer.h @@ -10,8 +10,7 @@ #include -namespace esphome { -namespace shelly_dimmer { +namespace esphome::shelly_dimmer { class ShellyDimmer : public PollingComponent, public light::LightOutput, public uart::UARTDevice { private: @@ -117,7 +116,6 @@ class ShellyDimmer : public PollingComponent, public light::LightOutput, public void reset_dfu_boot_(); }; -} // namespace shelly_dimmer -} // namespace esphome +} // namespace esphome::shelly_dimmer #endif // USE_ESP8266 diff --git a/esphome/components/shelly_dimmer/stm32flash.cpp b/esphome/components/shelly_dimmer/stm32flash.cpp index a1a933bcab1..c758b0a3123 100644 --- a/esphome/components/shelly_dimmer/stm32flash.cpp +++ b/esphome/components/shelly_dimmer/stm32flash.cpp @@ -112,8 +112,7 @@ constexpr char TAG[] = "stm32flash"; } // Anonymous namespace -namespace esphome { -namespace shelly_dimmer { +namespace esphome::shelly_dimmer { namespace { @@ -487,12 +486,6 @@ template stm32_unique_ptr make_stm32_with_deletor(T ptr) { } // Anonymous namespace -} // namespace shelly_dimmer -} // namespace esphome - -namespace esphome { -namespace shelly_dimmer { - /* find newer command by higher code */ #define newer(prev, a) (((prev) == STM32_CMD_ERR) ? (a) : (((prev) > (a)) ? (prev) : (a))) @@ -1059,7 +1052,6 @@ stm32_err_t stm32_crc_wrapper(const stm32_unique_ptr &stm, uint32_t address, uin return STM32_ERR_OK; } -} // namespace shelly_dimmer -} // namespace esphome +} // namespace esphome::shelly_dimmer #endif // USE_SHD_FIRMWARE_DATA diff --git a/esphome/components/shelly_dimmer/stm32flash.h b/esphome/components/shelly_dimmer/stm32flash.h index d973b352221..9a81f07373e 100644 --- a/esphome/components/shelly_dimmer/stm32flash.h +++ b/esphome/components/shelly_dimmer/stm32flash.h @@ -26,8 +26,7 @@ #include #include "esphome/components/uart/uart.h" -namespace esphome { -namespace shelly_dimmer { +namespace esphome::shelly_dimmer { /* flags */ constexpr auto STREAM_OPT_BYTE = (1 << 0); /* byte (not frame) oriented */ @@ -125,7 +124,6 @@ stm32_err_t stm32_crc_memory(const stm32_unique_ptr &stm, uint32_t address, uint stm32_err_t stm32_crc_wrapper(const stm32_unique_ptr &stm, uint32_t address, uint32_t length, uint32_t *crc); uint32_t stm32_sw_crc(uint32_t crc, uint8_t *buf, unsigned int len); -} // namespace shelly_dimmer -} // namespace esphome +} // namespace esphome::shelly_dimmer #endif // USE_SHD_FIRMWARE_DATA diff --git a/esphome/components/st7701s/st7701s.cpp b/esphome/components/st7701s/st7701s.cpp index 701b6dd79ea..dac8ac9dbcd 100644 --- a/esphome/components/st7701s/st7701s.cpp +++ b/esphome/components/st7701s/st7701s.cpp @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include -namespace esphome { -namespace st7701s { +namespace esphome::st7701s { void ST7701S::setup() { this->spi_setup(); @@ -195,6 +194,5 @@ void ST7701S::dump_config() { ESP_LOGCONFIG(TAG, " SPI Data rate: %dMHz", (unsigned) (this->data_rate_ / 1000000)); } -} // namespace st7701s -} // namespace esphome +} // namespace esphome::st7701s #endif // USE_ESP32_VARIANT_ESP32S3 diff --git a/esphome/components/st7701s/st7701s.h b/esphome/components/st7701s/st7701s.h index a1e3c2e54a0..de5e4c13d49 100644 --- a/esphome/components/st7701s/st7701s.h +++ b/esphome/components/st7701s/st7701s.h @@ -12,8 +12,7 @@ #include "esp_lcd_panel_rgb.h" -namespace esphome { -namespace st7701s { +namespace esphome::st7701s { constexpr static const char *const TAG = "display.st7701s"; const uint8_t SW_RESET_CMD = 0x01; @@ -113,6 +112,5 @@ class ST7701S : public display::Display, esp_lcd_panel_handle_t handle_{}; }; -} // namespace st7701s -} // namespace esphome +} // namespace esphome::st7701s #endif diff --git a/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.cpp b/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.cpp index 6c46af19fdf..0c0201508af 100644 --- a/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.cpp +++ b/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.cpp @@ -2,8 +2,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace crc8_test_component { +namespace esphome::crc8_test_component { static const char *const TAG = "crc8_test"; @@ -166,5 +165,4 @@ void CRC8TestComponent::log_test_result(const char *test_name, bool passed) { } } -} // namespace crc8_test_component -} // namespace esphome +} // namespace esphome::crc8_test_component diff --git a/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.h b/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.h index 3b8847259c3..5d21ab134e0 100644 --- a/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.h +++ b/tests/integration/fixtures/external_components/crc8_test_component/crc8_test_component.h @@ -4,8 +4,7 @@ #include "esphome/core/helpers.h" #include "esphome/core/log.h" -namespace esphome { -namespace crc8_test_component { +namespace esphome::crc8_test_component { class CRC8TestComponent : public Component { public: @@ -25,5 +24,4 @@ class CRC8TestComponent : public Component { uint8_t poly = 0x8C, bool msb_first = false); }; -} // namespace crc8_test_component -} // namespace esphome +} // namespace esphome::crc8_test_component diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp index c86ab992425..b66372d8ba6 100644 --- a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #ifdef USE_API -namespace esphome { -namespace custom_api_device_component { +namespace esphome::custom_api_device_component { static const char *const TAG = "custom_api"; @@ -58,6 +57,5 @@ void CustomAPIDeviceComponent::on_ha_state_changed(std::string entity_id, std::s ESP_LOGI(TAG, "This subscription uses std::string API for backward compatibility"); } -} // namespace custom_api_device_component -} // namespace esphome +} // namespace esphome::custom_api_device_component #endif // USE_API diff --git a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h index 4d519d3ed1f..e75b3401223 100644 --- a/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h +++ b/tests/integration/fixtures/external_components/custom_api_device_component/custom_api_device_component.h @@ -6,8 +6,7 @@ #include "esphome/components/api/custom_api_device.h" #ifdef USE_API -namespace esphome { -namespace custom_api_device_component { +namespace esphome::custom_api_device_component { using namespace api; @@ -28,6 +27,5 @@ class CustomAPIDeviceComponent : public Component, public CustomAPIDevice { void on_ha_state_changed(std::string entity_id, std::string state); }; -} // namespace custom_api_device_component -} // namespace esphome +} // namespace esphome::custom_api_device_component #endif // USE_API diff --git a/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.cpp b/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.cpp index 21ca45947ec..5c3bbeea84d 100644 --- a/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.cpp +++ b/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.cpp @@ -5,8 +5,7 @@ #include #include -namespace esphome { -namespace defer_stress_component { +namespace esphome::defer_stress_component { static const char *const TAG = "defer_stress"; @@ -71,5 +70,4 @@ void DeferStressComponent::run_multi_thread_test() { ESP_LOGI(TAG, "All threads finished in %lldms. Created %d defer requests", thread_time, this->total_defers_.load()); } -} // namespace defer_stress_component -} // namespace esphome +} // namespace esphome::defer_stress_component diff --git a/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.h b/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.h index 59b75657260..2aac0aeddce 100644 --- a/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.h +++ b/tests/integration/fixtures/external_components/defer_stress_component/defer_stress_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace defer_stress_component { +namespace esphome::defer_stress_component { class DeferStressComponent : public Component { public: @@ -16,5 +15,4 @@ class DeferStressComponent : public Component { std::atomic executed_defers_{0}; }; -} // namespace defer_stress_component -} // namespace esphome +} // namespace esphome::defer_stress_component diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp index 28a05d3d45d..dd54381c350 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.cpp @@ -1,7 +1,6 @@ #include "loop_test_component.h" -namespace esphome { -namespace loop_test_component { +namespace esphome::loop_test_component { void LoopTestComponent::setup() { ESP_LOGI(TAG, "[%s] Setup called", this->name_.c_str()); } @@ -63,5 +62,4 @@ void LoopTestUpdateComponent::update() { this->update_count_, loop_disabled ? "YES" : "NO"); } -} // namespace loop_test_component -} // namespace esphome +} // namespace esphome::loop_test_component diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h index 3dca2da2e9f..1a814118619 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_component.h @@ -6,8 +6,7 @@ #include "esphome/core/automation.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace loop_test_component { +namespace esphome::loop_test_component { static const char *const TAG = "loop_test_component"; @@ -79,5 +78,4 @@ class LoopTestUpdateComponent : public PollingComponent { int disable_loop_after_{0}; }; -} // namespace loop_test_component -} // namespace esphome +} // namespace esphome::loop_test_component diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.cpp b/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.cpp index 30afec04223..b6f94aacf2d 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.cpp +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.cpp @@ -2,8 +2,7 @@ #include "esphome/core/hal.h" #include "esphome/core/application.h" -namespace esphome { -namespace loop_test_component { +namespace esphome::loop_test_component { static const char *const ISR_TAG = "loop_test_isr_component"; @@ -76,5 +75,4 @@ void IRAM_ATTR LoopTestISRComponent::simulate_isr_enable() { // For testing, we'll track the call count and log it from the main loop } -} // namespace loop_test_component -} // namespace esphome +} // namespace esphome::loop_test_component diff --git a/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.h b/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.h index 20e11b5ecdb..5537bd02333 100644 --- a/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.h +++ b/tests/integration/fixtures/external_components/loop_test_component/loop_test_isr_component.h @@ -4,8 +4,7 @@ #include "esphome/core/log.h" #include "esphome/core/hal.h" -namespace esphome { -namespace loop_test_component { +namespace esphome::loop_test_component { class LoopTestISRComponent : public Component { public: @@ -28,5 +27,4 @@ class LoopTestISRComponent : public Component { int isr_call_count_{0}; }; -} // namespace loop_test_component -} // namespace esphome +} // namespace esphome::loop_test_component diff --git a/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.cpp b/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.cpp index be85228c3cf..f6fd1b1de72 100644 --- a/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.cpp @@ -2,8 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/helpers.h" -namespace esphome { -namespace scheduler_bulk_cleanup_component { +namespace esphome::scheduler_bulk_cleanup_component { static const char *const TAG = "bulk_cleanup"; @@ -68,5 +67,4 @@ void SchedulerBulkCleanupComponent::trigger_bulk_cleanup() { } } -} // namespace scheduler_bulk_cleanup_component -} // namespace esphome +} // namespace esphome::scheduler_bulk_cleanup_component diff --git a/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.h b/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.h index f55472d426c..34b4a8e0d01 100644 --- a/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.h +++ b/tests/integration/fixtures/external_components/scheduler_bulk_cleanup_component/scheduler_bulk_cleanup_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/application.h" -namespace esphome { -namespace scheduler_bulk_cleanup_component { +namespace esphome::scheduler_bulk_cleanup_component { class SchedulerBulkCleanupComponent : public Component { public: @@ -14,5 +13,4 @@ class SchedulerBulkCleanupComponent : public Component { void trigger_bulk_cleanup(); }; -} // namespace scheduler_bulk_cleanup_component -} // namespace esphome +} // namespace esphome::scheduler_bulk_cleanup_component diff --git a/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.cpp b/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.cpp index 305d3595919..f75a2fdd920 100644 --- a/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.cpp @@ -6,8 +6,7 @@ #include #include -namespace esphome { -namespace scheduler_heap_stress_component { +namespace esphome::scheduler_heap_stress_component { static const char *const TAG = "scheduler_heap_stress"; @@ -100,5 +99,4 @@ void SchedulerHeapStressComponent::run_multi_thread_test() { ESP_LOGI(TAG, "All threads finished in %lldms. Created %d callbacks", thread_time, this->total_callbacks_.load()); } -} // namespace scheduler_heap_stress_component -} // namespace esphome +} // namespace esphome::scheduler_heap_stress_component diff --git a/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.h b/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.h index 5da32ca9f8a..9f7810d0adf 100644 --- a/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.h +++ b/tests/integration/fixtures/external_components/scheduler_heap_stress_component/heap_scheduler_stress_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace scheduler_heap_stress_component { +namespace esphome::scheduler_heap_stress_component { class SchedulerHeapStressComponent : public Component { public: @@ -18,5 +17,4 @@ class SchedulerHeapStressComponent : public Component { std::atomic executed_callbacks_{0}; }; -} // namespace scheduler_heap_stress_component -} // namespace esphome +} // namespace esphome::scheduler_heap_stress_component diff --git a/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.cpp b/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.cpp index b735c453f2d..0e5525d2656 100644 --- a/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.cpp @@ -6,8 +6,7 @@ #include #include -namespace esphome { -namespace scheduler_rapid_cancellation_component { +namespace esphome::scheduler_rapid_cancellation_component { static const char *const TAG = "scheduler_rapid_cancellation"; @@ -76,5 +75,4 @@ void SchedulerRapidCancellationComponent::run_rapid_cancellation_test() { }); } -} // namespace scheduler_rapid_cancellation_component -} // namespace esphome +} // namespace esphome::scheduler_rapid_cancellation_component diff --git a/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.h b/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.h index 0a01b2a8de7..f1ef9a72b61 100644 --- a/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.h +++ b/tests/integration/fixtures/external_components/scheduler_rapid_cancellation_component/rapid_cancellation_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace scheduler_rapid_cancellation_component { +namespace esphome::scheduler_rapid_cancellation_component { class SchedulerRapidCancellationComponent : public Component { public: @@ -18,5 +17,4 @@ class SchedulerRapidCancellationComponent : public Component { std::atomic total_executed_{0}; }; -} // namespace scheduler_rapid_cancellation_component -} // namespace esphome +} // namespace esphome::scheduler_rapid_cancellation_component diff --git a/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.cpp b/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.cpp index 2a08bd72a9f..6bc03f34c0d 100644 --- a/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.cpp @@ -1,8 +1,7 @@ #include "recursive_timeout_component.h" #include "esphome/core/log.h" -namespace esphome { -namespace scheduler_recursive_timeout_component { +namespace esphome::scheduler_recursive_timeout_component { static const char *const TAG = "scheduler_recursive_timeout"; @@ -36,5 +35,4 @@ void SchedulerRecursiveTimeoutComponent::run_recursive_timeout_test() { }); } -} // namespace scheduler_recursive_timeout_component -} // namespace esphome +} // namespace esphome::scheduler_recursive_timeout_component diff --git a/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.h b/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.h index 8d2c085a111..237f9785b21 100644 --- a/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.h +++ b/tests/integration/fixtures/external_components/scheduler_recursive_timeout_component/recursive_timeout_component.h @@ -2,8 +2,7 @@ #include "esphome/core/component.h" -namespace esphome { -namespace scheduler_recursive_timeout_component { +namespace esphome::scheduler_recursive_timeout_component { class SchedulerRecursiveTimeoutComponent : public Component { public: @@ -16,5 +15,4 @@ class SchedulerRecursiveTimeoutComponent : public Component { int nested_level_{0}; }; -} // namespace scheduler_recursive_timeout_component -} // namespace esphome +} // namespace esphome::scheduler_recursive_timeout_component diff --git a/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.cpp b/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.cpp index b4c2b8c6c2d..a817b9f508f 100644 --- a/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.cpp @@ -5,8 +5,7 @@ #include #include -namespace esphome { -namespace scheduler_simultaneous_callbacks_component { +namespace esphome::scheduler_simultaneous_callbacks_component { static const char *const TAG = "scheduler_simultaneous_callbacks"; @@ -105,5 +104,4 @@ void SchedulerSimultaneousCallbacksComponent::run_simultaneous_callbacks_test() }); } -} // namespace scheduler_simultaneous_callbacks_component -} // namespace esphome +} // namespace esphome::scheduler_simultaneous_callbacks_component diff --git a/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.h b/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.h index 1a36af4b3de..9746331aec1 100644 --- a/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.h +++ b/tests/integration/fixtures/external_components/scheduler_simultaneous_callbacks_component/simultaneous_callbacks_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace scheduler_simultaneous_callbacks_component { +namespace esphome::scheduler_simultaneous_callbacks_component { class SchedulerSimultaneousCallbacksComponent : public Component { public: @@ -20,5 +19,4 @@ class SchedulerSimultaneousCallbacksComponent : public Component { std::atomic max_concurrent_{0}; }; -} // namespace scheduler_simultaneous_callbacks_component -} // namespace esphome +} // namespace esphome::scheduler_simultaneous_callbacks_component diff --git a/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.cpp b/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.cpp index 8c3f665f197..cc1b9f78147 100644 --- a/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.cpp @@ -4,8 +4,7 @@ #include #include -namespace esphome { -namespace scheduler_string_lifetime_component { +namespace esphome::scheduler_string_lifetime_component { static const char *const TAG = "scheduler_string_lifetime"; @@ -258,5 +257,4 @@ void SchedulerStringLifetimeComponent::test_lambda_capture_lifetime() { }); } -} // namespace scheduler_string_lifetime_component -} // namespace esphome +} // namespace esphome::scheduler_string_lifetime_component diff --git a/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.h b/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.h index 95532328bb8..20185f128d1 100644 --- a/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.h +++ b/tests/integration/fixtures/external_components/scheduler_string_lifetime_component/string_lifetime_component.h @@ -4,8 +4,7 @@ #include #include -namespace esphome { -namespace scheduler_string_lifetime_component { +namespace esphome::scheduler_string_lifetime_component { class SchedulerStringLifetimeComponent : public Component { public: @@ -33,5 +32,4 @@ class SchedulerStringLifetimeComponent : public Component { int tests_failed_{0}; }; -} // namespace scheduler_string_lifetime_component -} // namespace esphome +} // namespace esphome::scheduler_string_lifetime_component diff --git a/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.cpp b/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.cpp index 9071e573bbf..677d371f255 100644 --- a/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.cpp +++ b/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.cpp @@ -7,8 +7,7 @@ #include #include -namespace esphome { -namespace scheduler_string_name_stress_component { +namespace esphome::scheduler_string_name_stress_component { static const char *const TAG = "scheduler_string_name_stress"; @@ -106,5 +105,4 @@ void SchedulerStringNameStressComponent::run_string_name_stress_test() { }); } -} // namespace scheduler_string_name_stress_component -} // namespace esphome +} // namespace esphome::scheduler_string_name_stress_component diff --git a/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.h b/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.h index 002a0a7b511..121bda62041 100644 --- a/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.h +++ b/tests/integration/fixtures/external_components/scheduler_string_name_stress_component/string_name_stress_component.h @@ -3,8 +3,7 @@ #include "esphome/core/component.h" #include -namespace esphome { -namespace scheduler_string_name_stress_component { +namespace esphome::scheduler_string_name_stress_component { class SchedulerStringNameStressComponent : public Component { public: @@ -18,5 +17,4 @@ class SchedulerStringNameStressComponent : public Component { std::atomic executed_callbacks_{0}; }; -} // namespace scheduler_string_name_stress_component -} // namespace esphome +} // namespace esphome::scheduler_string_name_stress_component From 7b6e2589f11dc8e01b346d9bd743f8d90d700928 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Fri, 8 May 2026 14:09:22 +1000 Subject: [PATCH 12/52] [modbus_server] Reduce log spam (#16283) --- esphome/components/modbus_server/modbus_server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/modbus_server/modbus_server.cpp b/esphome/components/modbus_server/modbus_server.cpp index 0063da3a1da..e5ea2efa4d0 100644 --- a/esphome/components/modbus_server/modbus_server.cpp +++ b/esphome/components/modbus_server/modbus_server.cpp @@ -10,7 +10,7 @@ static const char *const TAG = "modbus_server"; void ModbusServer::on_modbus_read_registers(uint8_t function_code, uint16_t start_address, uint16_t number_of_registers) { - ESP_LOGD(TAG, + ESP_LOGV(TAG, "Received read holding/input registers for device 0x%X. FC: 0x%X. Start address: 0x%X. Number of registers: " "0x%X.", this->address_, function_code, start_address, number_of_registers); @@ -30,7 +30,7 @@ void ModbusServer::on_modbus_read_registers(uint8_t function_code, uint16_t star break; } int64_t value = server_register->read_lambda(); - ESP_LOGD(TAG, "Matched register. Address: 0x%02X. Value type: %zu. Register count: %u. Value: %s.", + ESP_LOGV(TAG, "Matched register. Address: 0x%02X. Value type: %zu. Register count: %u. Value: %s.", server_register->address, static_cast(server_register->value_type), server_register->register_count, server_register->format_value(value).c_str()); @@ -47,7 +47,7 @@ void ModbusServer::on_modbus_read_registers(uint8_t function_code, uint16_t star if (!found) { if (this->server_courtesy_response_.enabled && (current_address <= this->server_courtesy_response_.register_last_address)) { - ESP_LOGD(TAG, + ESP_LOGV(TAG, "Could not match any register to address 0x%02X, but default allowed. " "Returning default value: %d.", current_address, this->server_courtesy_response_.register_value); From a970f05b69b5d04d198a5e1bcfa968bc4e47b982 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Fri, 8 May 2026 07:26:03 -0400 Subject: [PATCH 13/52] [clang-tidy] Enable readability-redundant-string-init (#16310) --- .clang-tidy | 1 - .clang-tidy.hash | 2 +- esphome/components/graph/graph.h | 2 +- esphome/components/nfc/ndef_message.cpp | 2 +- esphome/components/online_image/online_image.h | 6 +++--- esphome/components/remote_receiver/remote_receiver.h | 2 +- esphome/components/remote_transmitter/remote_transmitter.h | 2 +- esphome/components/rtttl/rtttl.h | 2 +- esphome/components/tuya/tuya.h | 2 +- esphome/components/uart/uart_component_host.h | 2 +- esphome/components/voice_assistant/voice_assistant.cpp | 6 +++--- esphome/components/voice_assistant/voice_assistant.h | 6 +++--- esphome/components/web_server_idf/web_server_idf.h | 2 +- 13 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 9aeeb1fc26c..ea7370a3b21 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -132,7 +132,6 @@ Checks: >- -readability-redundant-inline-specifier, -readability-redundant-member-init, -readability-redundant-parentheses, - -readability-redundant-string-init, -readability-redundant-typename, -readability-uppercase-literal-suffix, -readability-use-anyofallof, diff --git a/.clang-tidy.hash b/.clang-tidy.hash index 2f973e34d9f..4c4b4e5c9c7 100644 --- a/.clang-tidy.hash +++ b/.clang-tidy.hash @@ -1 +1 @@ -c1e4375738304baabf7e915e5f7ca50fb22ec9b4a2d8312827a32a659f3fa40c +edce6cd78b33b296cef3caa5869d237061345eb346e3f9cb21e3239d2711051f diff --git a/esphome/components/graph/graph.h b/esphome/components/graph/graph.h index 468583ca216..a601e9eeb1b 100644 --- a/esphome/components/graph/graph.h +++ b/esphome/components/graph/graph.h @@ -123,7 +123,7 @@ class GraphTrace { protected: sensor::Sensor *sensor_{nullptr}; - std::string name_{""}; + std::string name_; uint8_t line_thickness_{3}; enum LineType line_type_ { LINE_TYPE_SOLID }; Color line_color_{COLOR_ON}; diff --git a/esphome/components/nfc/ndef_message.cpp b/esphome/components/nfc/ndef_message.cpp index ba3aa77e340..d33f3f7b5cb 100644 --- a/esphome/components/nfc/ndef_message.cpp +++ b/esphome/components/nfc/ndef_message.cpp @@ -52,7 +52,7 @@ NdefMessage::NdefMessage(std::vector &data) { index += type_length; - std::string id_str = ""; + std::string id_str; if (il) { id_str = std::string(data.begin() + index, data.begin() + index + id_length); index += id_length; diff --git a/esphome/components/online_image/online_image.h b/esphome/components/online_image/online_image.h index 816d6525eaa..a967bb6c0e6 100644 --- a/esphome/components/online_image/online_image.h +++ b/esphome/components/online_image/online_image.h @@ -88,18 +88,18 @@ class OnlineImage : public PollingComponent, */ size_t download_buffer_initial_size_; - std::string url_{""}; + std::string url_; std::vector>> request_headers_; /** * The value of the ETag HTTP header provided in the last response. */ - std::string etag_ = ""; + std::string etag_; /** * The value of the Last-Modified HTTP header provided in the last response. */ - std::string last_modified_ = ""; + std::string last_modified_; uint32_t start_time_{0}; }; diff --git a/esphome/components/remote_receiver/remote_receiver.h b/esphome/components/remote_receiver/remote_receiver.h index 5da9283a6e7..cc707346ebb 100644 --- a/esphome/components/remote_receiver/remote_receiver.h +++ b/esphome/components/remote_receiver/remote_receiver.h @@ -90,7 +90,7 @@ class RemoteReceiverComponent : public remote_base::RemoteReceiverBase, uint32_t carrier_frequency_{0}; uint8_t carrier_duty_percent_{100}; esp_err_t error_code_{ESP_OK}; - std::string error_string_{""}; + std::string error_string_; #endif #if defined(USE_ESP8266) || defined(USE_LIBRETINY) || defined(USE_RP2040) || defined(USE_ESP32) diff --git a/esphome/components/remote_transmitter/remote_transmitter.h b/esphome/components/remote_transmitter/remote_transmitter.h index 6b4ebfe24bd..d30966e3daa 100644 --- a/esphome/components/remote_transmitter/remote_transmitter.h +++ b/esphome/components/remote_transmitter/remote_transmitter.h @@ -92,7 +92,7 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase, rmt_channel_handle_t channel_{NULL}; rmt_encoder_handle_t encoder_{NULL}; esp_err_t error_code_{ESP_OK}; - std::string error_string_{""}; + std::string error_string_; bool inverted_{false}; bool non_blocking_{false}; #endif diff --git a/esphome/components/rtttl/rtttl.h b/esphome/components/rtttl/rtttl.h index 9dac92be2ad..d060b6b024d 100644 --- a/esphome/components/rtttl/rtttl.h +++ b/esphome/components/rtttl/rtttl.h @@ -72,7 +72,7 @@ class Rtttl : public Component { void set_state_(State state); /// The RTTTL string to play. - std::string rtttl_{""}; + std::string rtttl_; /// The current position in the RTTTL string. size_t position_{0}; /// The default duration of a note (e.g. 4 for a quarter note). diff --git a/esphome/components/tuya/tuya.h b/esphome/components/tuya/tuya.h index 8ba8ac85a05..470b97e7e70 100644 --- a/esphome/components/tuya/tuya.h +++ b/esphome/components/tuya/tuya.h @@ -150,7 +150,7 @@ class Tuya : public Component, public uart::UARTDevice { int reset_pin_reported_ = -1; uint32_t last_command_timestamp_ = 0; uint32_t last_rx_char_timestamp_ = 0; - std::string product_ = ""; + std::string product_; std::vector listeners_; std::vector datapoints_; std::vector rx_message_; diff --git a/esphome/components/uart/uart_component_host.h b/esphome/components/uart/uart_component_host.h index 56ff525bc3d..a47e5649be8 100644 --- a/esphome/components/uart/uart_component_host.h +++ b/esphome/components/uart/uart_component_host.h @@ -25,7 +25,7 @@ class HostUartComponent : public UARTComponent, public Component { void update_error_(const std::string &error); void check_logger_conflict() override {} std::string port_name_; - std::string first_error_{""}; + std::string first_error_; int file_descriptor_ = -1; bool has_peek_{false}; uint8_t peek_byte_; diff --git a/esphome/components/voice_assistant/voice_assistant.cpp b/esphome/components/voice_assistant/voice_assistant.cpp index bff0026b242..50a82652977 100644 --- a/esphome/components/voice_assistant/voice_assistant.cpp +++ b/esphome/components/voice_assistant/voice_assistant.cpp @@ -676,7 +676,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) { break; case api::enums::VOICE_ASSISTANT_INTENT_PROGRESS: { ESP_LOGD(TAG, "Intent progress"); - std::string tts_url_for_trigger = ""; + std::string tts_url_for_trigger; #ifdef USE_MEDIA_PLAYER if (this->media_player_ != nullptr) { for (const auto &arg : msg.data) { @@ -782,8 +782,8 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) { break; } case api::enums::VOICE_ASSISTANT_ERROR: { - std::string code = ""; - std::string message = ""; + std::string code; + std::string message; for (const auto &arg : msg.data) { if (arg.name == "code") { code = arg.value; diff --git a/esphome/components/voice_assistant/voice_assistant.h b/esphome/components/voice_assistant/voice_assistant.h index faef09d8bd0..3de46730018 100644 --- a/esphome/components/voice_assistant/voice_assistant.h +++ b/esphome/components/voice_assistant/voice_assistant.h @@ -288,7 +288,7 @@ class VoiceAssistant : public Component { #endif #ifdef USE_MEDIA_PLAYER media_player::MediaPlayer *media_player_{nullptr}; - std::string tts_response_url_{""}; + std::string tts_response_url_; bool started_streaming_tts_{false}; MediaPlayerResponseState media_player_response_state_{MediaPlayerResponseState::IDLE}; @@ -296,9 +296,9 @@ class VoiceAssistant : public Component { bool local_output_{false}; - std::string conversation_id_{""}; + std::string conversation_id_; - std::string wake_word_{""}; + std::string wake_word_; std::shared_ptr ring_buffer_; diff --git a/esphome/components/web_server_idf/web_server_idf.h b/esphome/components/web_server_idf/web_server_idf.h index cdb58c2f046..c622d53e893 100644 --- a/esphome/components/web_server_idf/web_server_idf.h +++ b/esphome/components/web_server_idf/web_server_idf.h @@ -313,7 +313,7 @@ class AsyncEventSourceResponse { std::vector deferred_queue_; esphome::web_server::WebServer *web_server_; esphome::web_server::ListEntitiesIterator entities_iterator_; - std::string event_buffer_{""}; + std::string event_buffer_; size_t event_bytes_sent_; uint16_t consecutive_send_failures_{0}; static constexpr uint16_t MAX_CONSECUTIVE_SEND_FAILURES = 2500; // ~20 seconds at 125Hz loop rate From eb52ca61fe528df25110814ae3adcd24b816edd4 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Fri, 8 May 2026 07:26:14 -0400 Subject: [PATCH 14/52] [climate][ektf2232] Remove deprecations scheduled for 2026.5.0 (#16289) --- esphome/components/climate/climate_traits.h | 57 ------------------- .../ektf2232/touchscreen/__init__.py | 4 -- 2 files changed, 61 deletions(-) diff --git a/esphome/components/climate/climate_traits.h b/esphome/components/climate/climate_traits.h index 082b2127a9f..599894c8a9f 100644 --- a/esphome/components/climate/climate_traits.h +++ b/esphome/components/climate/climate_traits.h @@ -81,63 +81,6 @@ class ClimateTraits { bool has_feature_flags(uint32_t feature_flags) const { return this->feature_flags_ & feature_flags; } void set_feature_flags(uint32_t feature_flags) { this->feature_flags_ = feature_flags; } - ESPDEPRECATED("This method is deprecated, use get_feature_flags() instead", "2025.11.0") - bool get_supports_current_temperature() const { - return this->has_feature_flags(CLIMATE_SUPPORTS_CURRENT_TEMPERATURE); - } - ESPDEPRECATED("This method is deprecated, use add_feature_flags() instead", "2025.11.0") - void set_supports_current_temperature(bool supports_current_temperature) { - if (supports_current_temperature) { - this->add_feature_flags(CLIMATE_SUPPORTS_CURRENT_TEMPERATURE); - } else { - this->clear_feature_flags(CLIMATE_SUPPORTS_CURRENT_TEMPERATURE); - } - } - ESPDEPRECATED("This method is deprecated, use get_feature_flags() instead", "2025.11.0") - bool get_supports_current_humidity() const { return this->has_feature_flags(CLIMATE_SUPPORTS_CURRENT_HUMIDITY); } - ESPDEPRECATED("This method is deprecated, use add_feature_flags() instead", "2025.11.0") - void set_supports_current_humidity(bool supports_current_humidity) { - if (supports_current_humidity) { - this->add_feature_flags(CLIMATE_SUPPORTS_CURRENT_HUMIDITY); - } else { - this->clear_feature_flags(CLIMATE_SUPPORTS_CURRENT_HUMIDITY); - } - } - ESPDEPRECATED("This method is deprecated, use get_feature_flags() instead", "2025.11.0") - bool get_supports_two_point_target_temperature() const { - return this->has_feature_flags(CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE); - } - ESPDEPRECATED("This method is deprecated, use add_feature_flags() instead", "2025.11.0") - void set_supports_two_point_target_temperature(bool supports_two_point_target_temperature) { - if (supports_two_point_target_temperature) - // Use CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE to mimic previous behavior - { - this->add_feature_flags(CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE); - } else { - this->clear_feature_flags(CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE); - } - } - ESPDEPRECATED("This method is deprecated, use get_feature_flags() instead", "2025.11.0") - bool get_supports_target_humidity() const { return this->has_feature_flags(CLIMATE_SUPPORTS_TARGET_HUMIDITY); } - ESPDEPRECATED("This method is deprecated, use add_feature_flags() instead", "2025.11.0") - void set_supports_target_humidity(bool supports_target_humidity) { - if (supports_target_humidity) { - this->add_feature_flags(CLIMATE_SUPPORTS_TARGET_HUMIDITY); - } else { - this->clear_feature_flags(CLIMATE_SUPPORTS_TARGET_HUMIDITY); - } - } - ESPDEPRECATED("This method is deprecated, use get_feature_flags() instead", "2025.11.0") - bool get_supports_action() const { return this->has_feature_flags(CLIMATE_SUPPORTS_ACTION); } - ESPDEPRECATED("This method is deprecated, use add_feature_flags() instead", "2025.11.0") - void set_supports_action(bool supports_action) { - if (supports_action) { - this->add_feature_flags(CLIMATE_SUPPORTS_ACTION); - } else { - this->clear_feature_flags(CLIMATE_SUPPORTS_ACTION); - } - } - void set_supported_modes(ClimateModeMask modes) { this->supported_modes_ = modes; } void add_supported_mode(ClimateMode mode) { this->supported_modes_.insert(mode); } bool supports_mode(ClimateMode mode) const { return this->supported_modes_.count(mode); } diff --git a/esphome/components/ektf2232/touchscreen/__init__.py b/esphome/components/ektf2232/touchscreen/__init__.py index 123f03ca087..64bb17a7db6 100644 --- a/esphome/components/ektf2232/touchscreen/__init__.py +++ b/esphome/components/ektf2232/touchscreen/__init__.py @@ -15,7 +15,6 @@ EKTF2232Touchscreen = ektf2232_ns.class_( ) CONF_EKTF2232_ID = "ektf2232_id" -CONF_RTS_PIN = "rts_pin" # To be removed before 2026.4.0 CONFIG_SCHEMA = touchscreen.TOUCHSCREEN_SCHEMA.extend( cv.Schema( @@ -25,9 +24,6 @@ CONFIG_SCHEMA = touchscreen.TOUCHSCREEN_SCHEMA.extend( pins.internal_gpio_input_pin_schema ), cv.Required(CONF_RESET_PIN): pins.gpio_output_pin_schema, - cv.Optional(CONF_RTS_PIN): cv.invalid( - f"{CONF_RTS_PIN} has been renamed to {CONF_RESET_PIN}" - ), } ).extend(i2c.i2c_device_schema(0x15)) ) From 3d8fffbea954580a082792ae919d611e8890e5c8 Mon Sep 17 00:00:00 2001 From: Mat931 <49403702+Mat931@users.noreply.github.com> Date: Fri, 8 May 2026 13:17:14 +0000 Subject: [PATCH 15/52] [htu31d][kamstrup_kmp][ms8607] Use CRC functions from helpers.h (#16313) --- esphome/components/htu31d/htu31d.cpp | 32 ++----------------- .../components/kamstrup_kmp/kamstrup_kmp.cpp | 28 ++-------------- .../components/kamstrup_kmp/kamstrup_kmp.h | 3 -- esphome/components/ms8607/ms8607.cpp | 32 +------------------ tests/components/ms8607/common.yaml | 11 +++++++ tests/components/ms8607/test.esp32-idf.yaml | 8 +++++ tests/components/ms8607/test.esp8266-ard.yaml | 8 +++++ tests/components/ms8607/test.rp2040-ard.yaml | 8 +++++ 8 files changed, 42 insertions(+), 88 deletions(-) create mode 100644 tests/components/ms8607/common.yaml create mode 100644 tests/components/ms8607/test.esp32-idf.yaml create mode 100644 tests/components/ms8607/test.esp8266-ard.yaml create mode 100644 tests/components/ms8607/test.rp2040-ard.yaml diff --git a/esphome/components/htu31d/htu31d.cpp b/esphome/components/htu31d/htu31d.cpp index 0b679bf2b77..6821b8b69ef 100644 --- a/esphome/components/htu31d/htu31d.cpp +++ b/esphome/components/htu31d/htu31d.cpp @@ -43,32 +43,6 @@ static const uint8_t HTU31D_RESET = 0x1E; /** Diagnostics command. */ static const uint8_t HTU31D_DIAGNOSTICS = 0x08; -/** - * Computes a CRC result for the provided input. - * - * @returns the computed CRC result for the provided input - */ -uint8_t compute_crc(uint32_t value) { - uint32_t polynom = 0x98800000; // x^8 + x^5 + x^4 + 1 - uint32_t msb = 0x80000000; - uint32_t mask = 0xFF800000; - uint32_t threshold = 0x00000080; - uint32_t result = value; - - while (msb != threshold) { - // Check if msb of current value is 1 and apply XOR mask - if (result & msb) - result = ((result ^ polynom) & mask) | (result & ~mask); - - // Shift by one - msb >>= 1; - mask >>= 1; - polynom >>= 1; - } - - return result; -} - /** * Resets the sensor and ensures that the devices serial number can be read over * I2C. @@ -112,7 +86,7 @@ void HTU31DComponent::update() { // Calculate temperature value. uint16_t raw_temp = encode_uint16(thdata[0], thdata[1]); - uint8_t crc = compute_crc((uint32_t) raw_temp << 8); + uint8_t crc = crc8(thdata, 2, 0, 0x31, true); if (crc != thdata[2]) { this->status_set_warning(); ESP_LOGE(TAG, "Error validating temperature CRC"); @@ -131,7 +105,7 @@ void HTU31DComponent::update() { // Calculate humidty value. uint16_t raw_hum = encode_uint16(thdata[3], thdata[4]); - crc = compute_crc((uint32_t) raw_hum << 8); + crc = crc8(thdata + 3, 2, 0, 0x31, true); if (crc != thdata[5]) { this->status_set_warning(); ESP_LOGE(TAG, "Error validating humidty CRC"); @@ -197,7 +171,7 @@ uint32_t HTU31DComponent::read_serial_num_() { serial = encode_uint32(reply[0], reply[1], reply[2], padding); - uint8_t crc = compute_crc(serial); + uint8_t crc = crc8(reply, 3, 0, 0x31, true); if (crc != reply[3]) { ESP_LOGE(TAG, "Error validating serial CRC"); return 0; diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp index ed03c4d6df4..70f6d4eaa76 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.cpp @@ -1,5 +1,6 @@ #include "kamstrup_kmp.h" +#include "esphome/core/helpers.h" #include "esphome/core/log.h" namespace esphome::kamstrup_kmp { @@ -95,10 +96,7 @@ void KamstrupKMPComponent::send_message_(const uint8_t *msg, int msg_len) { buffer[i] = msg[i]; } - buffer[buffer_len - 2] = 0; - buffer[buffer_len - 1] = 0; - - uint16_t crc = crc16_ccitt(buffer, buffer_len); + uint16_t crc = crc16be(buffer, buffer_len - 2); buffer[buffer_len - 2] = crc >> 8; buffer[buffer_len - 1] = crc & 0xFF; @@ -192,7 +190,7 @@ void KamstrupKMPComponent::read_command_(uint16_t command) { } // Validate CRC - if (crc16_ccitt(msg, msg_len)) { + if (crc16be(msg, msg_len - 2) != encode_uint16(msg[msg_len - 2], msg[msg_len - 1])) { ESP_LOGE(TAG, "Received invalid message (CRC mismatch)"); return; } @@ -282,24 +280,4 @@ void KamstrupKMPComponent::set_sensor_value_(uint16_t command, float value, uint ESP_LOGD(TAG, "Received value for command 0x%04X: %.3f [%s]", command, value, unit); } -uint16_t crc16_ccitt(const uint8_t *buffer, int len) { - uint32_t poly = 0x1021; - uint32_t reg = 0x00; - for (int i = 0; i < len; i++) { - int mask = 0x80; - while (mask > 0) { - reg <<= 1; - if (buffer[i] & mask) { - reg |= 1; - } - mask >>= 1; - if (reg & 0x10000) { - reg &= 0xffff; - reg ^= poly; - } - } - } - return (uint16_t) reg; -} - } // namespace esphome::kamstrup_kmp diff --git a/esphome/components/kamstrup_kmp/kamstrup_kmp.h b/esphome/components/kamstrup_kmp/kamstrup_kmp.h index a05a0ee17af..a4eacec4532 100644 --- a/esphome/components/kamstrup_kmp/kamstrup_kmp.h +++ b/esphome/components/kamstrup_kmp/kamstrup_kmp.h @@ -123,7 +123,4 @@ class KamstrupKMPComponent : public PollingComponent, public uart::UARTDevice { void set_sensor_value_(uint16_t command, float value, uint8_t unit_idx); }; -// "true" CCITT CRC-16 -uint16_t crc16_ccitt(const uint8_t *buffer, int len); - } // namespace esphome::kamstrup_kmp diff --git a/esphome/components/ms8607/ms8607.cpp b/esphome/components/ms8607/ms8607.cpp index f733a8349d4..b9cbdc749b4 100644 --- a/esphome/components/ms8607/ms8607.cpp +++ b/esphome/components/ms8607/ms8607.cpp @@ -63,7 +63,6 @@ enum class MS8607Component::SetupStatus { }; static uint8_t crc4(uint16_t *buffer, size_t length); -static uint8_t hsensor_crc_check(uint16_t value); void MS8607Component::setup() { this->error_code_ = ErrorCode::NONE; @@ -244,35 +243,6 @@ static uint8_t crc4(uint16_t *buffer, size_t length) { return (crc_remainder >> 12) & 0xF; // only the most significant 4 bits } -/** - * @brief Calculates CRC value for the provided humidity (+ status bits) value - * - * CRC-8 check comes from other MS8607 libraries on github. I did not find it in the datasheet, - * and it differs from the crc8 implementation that's already part of esphome. - * - * @param value two byte humidity sensor value read from i2c - * @return uint8_t computed crc value - */ -static uint8_t hsensor_crc_check(uint16_t value) { - uint32_t polynom = 0x988000; // x^8 + x^5 + x^4 + 1 - uint32_t msb = 0x800000; - uint32_t mask = 0xFF8000; - uint32_t result = (uint32_t) value << 8; // Pad with zeros as specified in spec - - while (msb != 0x80) { - // Check if msb of current value is 1 and apply XOR mask - if (result & msb) { - result = ((result ^ polynom) & mask) | (result & ~mask); - } - - // Shift by one - msb >>= 1; - mask >>= 1; - polynom >>= 1; - } - return result & 0xFF; -} - void MS8607Component::request_read_temperature_() { // Tell MS8607 to start ADC conversion of temperature sensor if (!this->write_bytes(MS8607_CMD_CONV_D2_OSR_8K, nullptr, 0)) { @@ -338,7 +308,7 @@ void MS8607Component::read_humidity_(float temperature_float) { // Bit1 of the two LSBS must be set to '1'. Bit0 is currently not assigned" uint16_t humidity = encode_uint16(bytes[0], bytes[1]); uint8_t const expected_crc = bytes[2]; - uint8_t const actual_crc = hsensor_crc_check(humidity); + uint8_t const actual_crc = crc8(bytes, 2, 0, 0x31, true); if (expected_crc != actual_crc) { ESP_LOGE(TAG, "Incorrect Humidity CRC value. Provided value 0x%01X != calculated value 0x%01X", expected_crc, actual_crc); diff --git a/tests/components/ms8607/common.yaml b/tests/components/ms8607/common.yaml new file mode 100644 index 00000000000..09a3f5a617a --- /dev/null +++ b/tests/components/ms8607/common.yaml @@ -0,0 +1,11 @@ +sensor: + - platform: ms8607 + i2c_id: i2c_bus + temperature: + name: Temperature + humidity: + name: Humidity + pressure: + name: Pressure + address: 0x76 + update_interval: 15s diff --git a/tests/components/ms8607/test.esp32-idf.yaml b/tests/components/ms8607/test.esp32-idf.yaml new file mode 100644 index 00000000000..4598505c3a2 --- /dev/null +++ b/tests/components/ms8607/test.esp32-idf.yaml @@ -0,0 +1,8 @@ +substitutions: + i2c_scl: GPIO16 + i2c_sda: GPIO17 + +packages: + i2c: !include ../../test_build_components/common/i2c/esp32-idf.yaml + +<<: !include common.yaml diff --git a/tests/components/ms8607/test.esp8266-ard.yaml b/tests/components/ms8607/test.esp8266-ard.yaml new file mode 100644 index 00000000000..5565bb8c352 --- /dev/null +++ b/tests/components/ms8607/test.esp8266-ard.yaml @@ -0,0 +1,8 @@ +substitutions: + i2c_scl: GPIO5 + i2c_sda: GPIO4 + +packages: + i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml + +<<: !include common.yaml diff --git a/tests/components/ms8607/test.rp2040-ard.yaml b/tests/components/ms8607/test.rp2040-ard.yaml new file mode 100644 index 00000000000..888762a7423 --- /dev/null +++ b/tests/components/ms8607/test.rp2040-ard.yaml @@ -0,0 +1,8 @@ +substitutions: + i2c_scl: GPIO5 + i2c_sda: GPIO4 + +packages: + i2c: !include ../../test_build_components/common/i2c/rp2040-ard.yaml + +<<: !include common.yaml From 88c2a1c09639a28f140cc59d89e97b5d660f1994 Mon Sep 17 00:00:00 2001 From: John Boiles Date: Fri, 8 May 2026 11:43:55 -0700 Subject: [PATCH 16/52] [speaker] Add SPDIF output support (#8065) Co-authored-by: Keith Burzinski Co-authored-by: Kevin Ahrendt --- esphome/components/i2s_audio/__init__.py | 5 +- .../components/i2s_audio/speaker/__init__.py | 72 +- .../i2s_audio/speaker/i2s_audio_spdif.cpp | 629 ++++++++++++++++++ .../i2s_audio/speaker/i2s_audio_spdif.h | 34 + .../i2s_audio/speaker/i2s_audio_speaker.cpp | 2 +- .../i2s_audio/speaker/i2s_audio_speaker.h | 4 +- .../i2s_audio/speaker/spdif_encoder.cpp | 385 +++++++++++ .../i2s_audio/speaker/spdif_encoder.h | 146 ++++ esphome/core/defines.h | 1 + .../speaker/spdif_mode.esp32-idf.yaml | 25 + 10 files changed, 1291 insertions(+), 12 deletions(-) create mode 100644 esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp create mode 100644 esphome/components/i2s_audio/speaker/i2s_audio_spdif.h create mode 100644 esphome/components/i2s_audio/speaker/spdif_encoder.cpp create mode 100644 esphome/components/i2s_audio/speaker/spdif_encoder.h create mode 100644 tests/components/speaker/spdif_mode.esp32-idf.yaml diff --git a/esphome/components/i2s_audio/__init__.py b/esphome/components/i2s_audio/__init__.py index ffa63f5ee8e..951b8c04983 100644 --- a/esphome/components/i2s_audio/__init__.py +++ b/esphome/components/i2s_audio/__init__.py @@ -201,7 +201,7 @@ async def register_i2s_audio_component(var, config): CONFIG_SCHEMA = cv.Schema( { cv.GenerateID(): cv.declare_id(I2SAudioComponent), - cv.Required(CONF_I2S_LRCLK_PIN): pins.internal_gpio_output_pin_number, + cv.Optional(CONF_I2S_LRCLK_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_I2S_BCLK_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_I2S_MCLK_PIN): pins.internal_gpio_output_pin_number, }, @@ -290,7 +290,8 @@ async def to_code(config): # Helps avoid callbacks being skipped due to processor load add_idf_sdkconfig_option("CONFIG_I2S_ISR_IRAM_SAFE", True) - cg.add(var.set_lrclk_pin(config[CONF_I2S_LRCLK_PIN])) + if CONF_I2S_LRCLK_PIN in config: + cg.add(var.set_lrclk_pin(config[CONF_I2S_LRCLK_PIN])) if CONF_I2S_BCLK_PIN in config: cg.add(var.set_bclk_pin(config[CONF_I2S_BCLK_PIN])) if CONF_I2S_MCLK_PIN in config: diff --git a/esphome/components/i2s_audio/speaker/__init__.py b/esphome/components/i2s_audio/speaker/__init__.py index 99aa712c682..759cc40ca9e 100644 --- a/esphome/components/i2s_audio/speaker/__init__.py +++ b/esphome/components/i2s_audio/speaker/__init__.py @@ -18,10 +18,12 @@ from .. import ( CONF_I2S_DOUT_PIN, CONF_I2S_MODE, CONF_LEFT, + CONF_MCLK_MULTIPLE, CONF_MONO, CONF_PRIMARY, CONF_RIGHT, CONF_STEREO, + CONF_USE_APLL, I2SAudioOut, i2s_audio_component_schema, i2s_audio_ns, @@ -40,6 +42,15 @@ I2SAudioSpeaker = i2s_audio_ns.class_("I2SAudioSpeaker", I2SAudioSpeakerBase) CONF_DAC_TYPE = "dac_type" CONF_I2S_COMM_FMT = "i2s_comm_fmt" +CONF_SPDIF_MODE = "spdif_mode" + +I2SAudioSpeakerBase = i2s_audio_ns.class_( + "I2SAudioSpeakerBase", cg.Component, speaker.Speaker, I2SAudioOut +) +I2SAudioSpeaker = i2s_audio_ns.class_("I2SAudioSpeaker", I2SAudioSpeakerBase) +I2SAudioSpeakerSPDIF = i2s_audio_ns.class_("I2SAudioSpeakerSPDIF", I2SAudioSpeakerBase) + +I2SCommFmt = i2s_audio_ns.enum("I2SCommFmt", is_class=True) I2SCommFmt = i2s_audio_ns.enum("I2SCommFmt", is_class=True) @@ -77,7 +88,17 @@ def _set_num_channels_from_config(config): def _set_stream_limits(config): - if config[CONF_I2S_MODE] == CONF_PRIMARY: + if config.get(CONF_SPDIF_MODE, False): + # SPDIF mode: fixed to 16-bit stereo at configured sample rate + audio.set_stream_limits( + min_bits_per_sample=16, + max_bits_per_sample=16, + min_channels=2, + max_channels=2, + min_sample_rate=config.get(CONF_SAMPLE_RATE), + max_sample_rate=config.get(CONF_SAMPLE_RATE), + )(config) + elif config[CONF_I2S_MODE] == CONF_PRIMARY: # Primary mode has modifiable stream settings audio.set_stream_limits( min_bits_per_sample=8, @@ -101,6 +122,13 @@ def _set_stream_limits(config): return config +def _select_speaker_class(config): + """Override ID type when SPDIF mode is enabled.""" + if config.get(CONF_SPDIF_MODE, False): + config[CONF_ID].type = I2SAudioSpeakerSPDIF + return config + + def _validate_esp32_variant(config): variant = esp32.get_esp32_variant() if config[CONF_DAC_TYPE] == "internal": @@ -155,6 +183,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_I2S_COMM_FMT, default="stand_i2s"): cv.one_of( *I2C_COMM_FMT_OPTIONS, lower=True ), + cv.Optional(CONF_SPDIF_MODE, default=False): cv.boolean, } ), }, @@ -163,6 +192,7 @@ CONFIG_SCHEMA = cv.All( _validate_esp32_variant, _set_num_channels_from_config, _set_stream_limits, + _select_speaker_class, validate_mclk_divisible_by_3, ) @@ -175,6 +205,28 @@ def _final_validate(config): if config[CONF_I2S_COMM_FMT] == "stand_max": raise cv.Invalid("I2S standard max format is no longer supported.") + if config.get(CONF_SPDIF_MODE, False): + # SPDIF mode specific validations + if config[CONF_SAMPLE_RATE] not in [44100, 48000]: + raise cv.Invalid( + "SPDIF mode only supports 44100 Hz or 48000 Hz sample rates" + ) + if config[CONF_CHANNEL] != CONF_STEREO: + raise cv.Invalid("SPDIF mode only supports stereo channel configuration") + # bits_per_sample is converted to float by the schema + if config[CONF_BITS_PER_SAMPLE] != 16: + raise cv.Invalid("SPDIF mode only supports 16 bits per sample") + if not config[CONF_USE_APLL]: + raise cv.Invalid( + "SPDIF mode requires 'use_apll: true' for accurate clock generation" + ) + if config[CONF_I2S_MODE] != CONF_PRIMARY: + raise cv.Invalid("SPDIF mode requires 'i2s_mode: primary'") + if config[CONF_I2S_COMM_FMT] != "stand_i2s": + raise cv.Invalid("SPDIF mode requires 'i2s_comm_fmt: stand_i2s'") + if config[CONF_MCLK_MULTIPLE] != 256: + raise cv.Invalid("SPDIF mode requires 'mclk_multiple: 256'") + FINAL_VALIDATE_SCHEMA = _final_validate @@ -186,12 +238,18 @@ async def to_code(config): await speaker.register_speaker(var, config) cg.add(var.set_dout_pin(config[CONF_I2S_DOUT_PIN])) - fmt = I2SCommFmt.STANDARD # equals stand_i2s, stand_pcm_long, i2s_msb, pcm_long - if config[CONF_I2S_COMM_FMT] in ["stand_msb", "i2s_lsb"]: - fmt = I2SCommFmt.MSB - elif config[CONF_I2S_COMM_FMT] in ["stand_pcm_short", "pcm_short", "pcm"]: - fmt = I2SCommFmt.PCM - cg.add(var.set_i2s_comm_fmt(fmt)) + + is_spdif = config.get(CONF_SPDIF_MODE, False) + if is_spdif: + cg.add_define("USE_I2S_AUDIO_SPDIF_MODE") + else: + fmt = I2SCommFmt.STANDARD # equals stand_i2s, stand_pcm_long, i2s_msb, pcm_long + if config[CONF_I2S_COMM_FMT] in ["stand_msb", "i2s_lsb"]: + fmt = I2SCommFmt.MSB + elif config[CONF_I2S_COMM_FMT] in ["stand_pcm_short", "pcm_short", "pcm"]: + fmt = I2SCommFmt.PCM + cg.add(var.set_i2s_comm_fmt(fmt)) + if config[CONF_TIMEOUT] != CONF_NEVER: cg.add(var.set_timeout(config[CONF_TIMEOUT])) cg.add(var.set_buffer_duration(config[CONF_BUFFER_DURATION])) diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp new file mode 100644 index 00000000000..e2146de63ce --- /dev/null +++ b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp @@ -0,0 +1,629 @@ +#include "i2s_audio_spdif.h" + +#if defined(USE_ESP32) && defined(USE_I2S_AUDIO_SPDIF_MODE) + +#include + +#include "esphome/components/audio/audio.h" +#include "esphome/components/audio/audio_transfer_buffer.h" + +#include "esphome/core/hal.h" +#include "esphome/core/log.h" + +#include "esp_timer.h" + +namespace esphome::i2s_audio { + +static const char *const TAG = "i2s_audio.spdif"; + +// SPDIF mode adds overhead as each sample is encapsulated in a subframe; +// each DMA buffer can hold only 192 samples (~4ms each vs. ~15ms for standard I2S). +// To match the standard I2S buffering duration, we use more buffers to minimize +// the impact of the overhead, such as stuttering or audio/silence oscillation. +// 15 buffers x 4ms = 60ms of DMA buffering (same as 4 x 15ms for standard) +static constexpr size_t SPDIF_DMA_BUFFERS_COUNT = 15; + +// Timeout for flushing pending frames if no callback received. +static constexpr uint32_t SPDIF_FLUSH_TIMEOUT_MS = 20; + +// Number of DMA events between upstream callbacks (~16ms = 4 events x 4ms each). +// Matches non-SPDIF timing to prevent overwhelming upstream sync algorithms. +static constexpr uint32_t SPDIF_DMA_EVENTS_PER_CALLBACK = 4; + +// Consider TX stalled only if no DMA callbacks have arrived for this long. +// Zero-block non-blocking writes alone are not sufficient (they can happen when DMA is simply full). +static constexpr uint32_t SPDIF_STALL_NO_DMA_MS = 80; + +// Fallback stall detector: force recovery if silence writes make no forward progress for too long, +// even if occasional DMA callbacks are still observed. +static constexpr uint32_t SPDIF_STALL_ZERO_PROGRESS_MS = 1000; + +// Minimum spacing between re-prime attempts to avoid churn. +static constexpr uint32_t SPDIF_REPRIME_COOLDOWN_MS = 500; + +// Small waits used in SPDIF mode to keep DMA fed during rapid pipeline churn. +static constexpr uint32_t SPDIF_EMPTY_READ_DELAY_MS = 1; +static constexpr uint32_t SPDIF_SILENCE_LOOP_DELAY_MS = 1; +static constexpr uint32_t SPDIF_PLAY_RETRY_WAIT_MS = 5; + +static constexpr size_t SPDIF_I2S_EVENT_QUEUE_COUNT = SPDIF_DMA_BUFFERS_COUNT + 1; + +// Static silence buffer for SPDIF continuous mode +// 192 samples * 2 channels * 2 bytes per sample = 768 bytes +// Stored in flash (.rodata section) to avoid stack/heap usage +static const int16_t SPDIF_SILENCE_BUFFER[SPDIF_BLOCK_SAMPLES * 2] = {0}; + +// Static callback functions for SPDIF encoder (avoids std::function overhead) +static esp_err_t spdif_preload_cb(void *user_ctx, uint32_t *data, size_t size, TickType_t ticks_to_wait) { + auto *speaker = static_cast(user_ctx); + size_t bytes_written = 0; + esp_err_t err = i2s_channel_preload_data(speaker->get_tx_handle(), data, size, &bytes_written); + if (err != ESP_OK || bytes_written != size) { + ESP_LOGW(TAG, "Preload failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); + return (err != ESP_OK) ? err : ESP_ERR_NO_MEM; + } + return ESP_OK; +} + +static esp_err_t spdif_write_cb(void *user_ctx, uint32_t *data, size_t size, TickType_t ticks_to_wait) { + auto *speaker = static_cast(user_ctx); + size_t bytes_written = 0; + esp_err_t err = i2s_channel_write(speaker->get_tx_handle(), data, size, &bytes_written, ticks_to_wait); + // ESP_ERR_TIMEOUT is expected under DMA backpressure in SPDIF mode. + if (err != ESP_OK && err != ESP_ERR_TIMEOUT) { + ESP_LOGW(TAG, "I2S write failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); + } + return err; +} + +void I2SAudioSpeakerSPDIF::setup() { + I2SAudioSpeakerBase::setup(); + if (this->is_failed()) { + return; + } + + this->spdif_encoder_ = new SPDIFEncoder(); + if (!this->spdif_encoder_->setup()) { + ESP_LOGE(TAG, "Encoder setup failed"); + this->mark_failed(); + return; + } + + // Configure channel status block with the sample rate + this->spdif_encoder_->set_sample_rate(this->sample_rate_); + + // Separate callbacks for preload (during underflow recovery) and normal writes + this->spdif_encoder_->set_preload_callback(spdif_preload_cb, this); + this->spdif_encoder_->set_write_callback(spdif_write_cb, this); +} + +void I2SAudioSpeakerSPDIF::dump_config() { + I2SAudioSpeakerBase::dump_config(); + ESP_LOGCONFIG(TAG, + " SPDIF Mode: YES\n" + " Sample Rate: %" PRIu32 " Hz", + this->sample_rate_); +} + +void I2SAudioSpeakerSPDIF::on_task_stopped() { this->spdif_silence_start_ = 0; } + +size_t I2SAudioSpeakerSPDIF::play(const uint8_t *data, size_t length, TickType_t ticks_to_wait) { + if (this->is_failed()) { + ESP_LOGE(TAG, "Setup failed; cannot play audio"); + return 0; + } + + // In SPDIF mode, keep accepting upstream audio while the speaker task is active. + // This avoids transient drops during stop/start transitions. + const bool task_active = (this->speaker_task_handle_ != nullptr); + + if (this->state_ != speaker::STATE_RUNNING && this->state_ != speaker::STATE_STARTING) { + this->start(); + } + + if (!task_active && this->state_ != speaker::STATE_RUNNING) { + // Unable to write data to a running speaker, so delay the max amount of time so it can get ready + vTaskDelay(ticks_to_wait); + ticks_to_wait = 0; + } + + size_t bytes_written = 0; + if (this->state_ == speaker::STATE_RUNNING || task_active) { + std::shared_ptr temp_ring_buffer = this->audio_ring_buffer_.lock(); + if (temp_ring_buffer != nullptr) { + // In SPDIF mode, a tiny wait helps avoid transient 0-byte writes during short backpressure windows. + TickType_t effective_ticks_to_wait = ticks_to_wait; + if (effective_ticks_to_wait == 0) { + effective_ticks_to_wait = pdMS_TO_TICKS(1); + } + bytes_written = temp_ring_buffer->write_without_replacement((void *) data, length, effective_ticks_to_wait); + if (bytes_written == 0 && length > 0) { + // Retry once to catch short free-space windows during rapid seek/track transitions. + bytes_written = + temp_ring_buffer->write_without_replacement((void *) data, length, pdMS_TO_TICKS(SPDIF_PLAY_RETRY_WAIT_MS)); + } + } + } + + return bytes_written; +} + +void I2SAudioSpeakerSPDIF::run_speaker_task() { + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STARTING); + + // Reset SPDIF encoder at task start to ensure clean state + // (previous task may have left stale data in encoder buffer) + if (this->spdif_encoder_ != nullptr) { + this->spdif_encoder_->reset(); + } + + const uint32_t dma_buffers_duration_ms = DMA_BUFFER_DURATION_MS * SPDIF_DMA_BUFFERS_COUNT; + // Ensure ring buffer duration is at least the duration of all DMA buffers + const uint32_t ring_buffer_duration = std::max(dma_buffers_duration_ms, this->buffer_duration_ms_); + + // The DMA buffers may have more bits per sample, so calculate buffer sizes based on the input audio stream info + const size_t ring_buffer_size = this->current_stream_info_.ms_to_bytes(ring_buffer_duration); + + // For SPDIF mode, one DMA buffer = one SPDIF block = 192 PCM frames + const uint32_t frames_to_fill_single_dma_buffer = SPDIF_BLOCK_SAMPLES; + const size_t bytes_to_fill_single_dma_buffer = + this->current_stream_info_.frames_to_bytes(frames_to_fill_single_dma_buffer); + + bool successful_setup = false; + std::unique_ptr transfer_buffer = + audio::AudioSourceTransferBuffer::create(bytes_to_fill_single_dma_buffer); + + if (transfer_buffer != nullptr) { + std::shared_ptr temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size); + if (temp_ring_buffer.use_count() == 1) { + transfer_buffer->set_source(temp_ring_buffer); + this->audio_ring_buffer_ = temp_ring_buffer; + successful_setup = true; + } + } + + if (!successful_setup) { + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_ESP_NO_MEM); + } else { + // Preload DMA buffers with SPDIF-encoded silence before enabling the channel. + // This ensures the first data transmitted is valid SPDIF (not raw zeros from + // auto_clear) and prevents phantom DMA events before real audio is available. + // Track how many buffers were preloaded so the DMA event loop can skip + // frame accounting until the preloaded silence has fully drained. + uint32_t preload_buffers_remaining = 0; + this->spdif_encoder_->set_preload_mode(true); + for (size_t i = 0; i < SPDIF_DMA_BUFFERS_COUNT; i++) { + uint32_t preload_blocks = 0; + esp_err_t preload_err = this->spdif_encoder_->write(reinterpret_cast(SPDIF_SILENCE_BUFFER), + sizeof(SPDIF_SILENCE_BUFFER), + pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &preload_blocks); + if (preload_err != ESP_OK || preload_blocks == 0) { + break; // DMA buffers full or error + } + preload_buffers_remaining += preload_blocks; + } + this->spdif_encoder_->set_preload_mode(false); + this->spdif_encoder_->reset(); // Clean encoder state for the main loop + + // Now register the callback and enable the channel + xQueueReset(this->i2s_event_queue_); + const i2s_event_callbacks_t callbacks = {.on_sent = i2s_on_sent_cb}; + i2s_channel_register_event_callback(this->tx_handle_, &callbacks, this); + i2s_channel_enable(this->tx_handle_); + + bool stop_gracefully = false; + bool tx_dma_underflow = true; + + uint32_t frames_written = 0; + + // SPDIF Continuous Silence Mode + Callback Decimation + // + // Key principles: + // 1. NEVER stop the I2S channel - always output a valid SPDIF stream + // 2. When no audio data, output silence-encoded SPDIF blocks (not zeros!) + // 3. Fire callbacks every 4 DMA events (~16ms), matching non-SPDIF timing + // + // This eliminates gaps that cause SPDIF receivers to re-sync, and reduces + // callback rate to prevent overwhelming upstream sync algorithms. + const uint32_t spdif_callback_threshold = this->current_stream_info_.ms_to_frames(DMA_BUFFER_DURATION_MS); + uint32_t spdif_pending_frames = 0; + int64_t spdif_pending_timestamp = 0; + uint32_t spdif_last_callback_time = millis(); + // Count DMA events for decimation + uint32_t spdif_dma_event_count = 0; + uint32_t spdif_last_dma_event_time = millis(); + // Detect a stalled DMA path (many silence write attempts with zero accepted blocks). + uint32_t spdif_zero_block_streak = 0; + uint32_t spdif_last_block_progress_time = millis(); + uint32_t spdif_last_reprime_time = 0; + + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_RUNNING); + + // SPDIF continuous mode: loop runs indefinitely, outputting silence when no audio data + // to keep the receiver synced. Exits only via break (stream info change or silence timeout). + while (true) { + uint32_t event_group_bits = xEventGroupGetBits(this->event_group_); + + if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP) { + xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP); + // In SPDIF continuous mode, don't tear down or expose STOPPED here. + // Keep the task alive and transition to silence output. + this->spdif_silence_start_ = millis(); + ESP_LOGV(TAG, "COMMAND_STOP received, continuing in silence mode"); + } + if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY) { + xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY); + stop_gracefully = true; + } + + if (this->audio_stream_info_ != this->current_stream_info_) { + // Audio stream info changed, stop the speaker task so it will restart with the proper settings. + ESP_LOGV(TAG, "Exiting: stream info changed"); + break; + } + + int64_t write_timestamp; + while (xQueueReceive(this->i2s_event_queue_, &write_timestamp, 0)) { + spdif_last_dma_event_time = millis(); + + // Skip frame accounting for preloaded silence buffers still draining. + // These DMA events correspond to silence that was preloaded before the + // channel was enabled, not real audio written by the task. + if (preload_buffers_remaining > 0) { + preload_buffers_remaining--; + continue; + } + + // Receives timing events from the I2S on_sent callback. If actual audio data was sent in this event, it passes + // on the timing info via the audio_output_callback. + uint32_t frames_sent = frames_to_fill_single_dma_buffer; + if (frames_to_fill_single_dma_buffer > frames_written) { + tx_dma_underflow = true; + frames_sent = frames_written; + const uint32_t frames_zeroed = frames_to_fill_single_dma_buffer - frames_written; + write_timestamp -= this->current_stream_info_.frames_to_microseconds(frames_zeroed); + } else { + tx_dma_underflow = false; + } + frames_written -= frames_sent; + + // SPDIF Callback Decimation: fire every 4th DMA event (~16ms) + // This matches non-SPDIF timing and prevents overwhelming upstream. + if (spdif_callback_threshold > 0) { + spdif_dma_event_count++; + + // Accumulate frames; always keep the latest timestamp so the + // callback reports when the last sample left the wire, not the first. + if (frames_sent > 0) { + spdif_pending_timestamp = write_timestamp; + spdif_pending_frames += frames_sent; + } + + // Fire callback every 4 DMA events, or on timeout if we have pending frames + bool decimation_reached = (spdif_dma_event_count >= SPDIF_DMA_EVENTS_PER_CALLBACK); + bool timeout_flush = + (spdif_pending_frames > 0) && ((millis() - spdif_last_callback_time) >= SPDIF_FLUSH_TIMEOUT_MS); + + if (decimation_reached || timeout_flush) { + if (spdif_pending_frames > 0) { + this->audio_output_callback_(spdif_pending_frames, spdif_pending_timestamp); + spdif_pending_frames = 0; + spdif_last_callback_time = millis(); + } + spdif_dma_event_count = 0; // Reset decimation counter + } + } + } + + if (this->pause_state_) { + // Pause state is accessed atomically, so thread safe + // Delay so the task yields, then skip transferring audio data + vTaskDelay(pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS)); + continue; + } + + // Wait half the duration of the data already written to the DMA buffers for new audio data + // The millisecond helper modifies the frames_written variable, so use the microsecond helper and divide by 1000 + uint32_t read_delay = (this->current_stream_info_.frames_to_microseconds(frames_written) / 1000) / 2; + + // In SPDIF mode, if transfer buffer is empty (we're pumping silence), use a very short timeout. + // This ensures we can pump silence fast enough to keep the DMA fed (~250 blocks/sec needed). + // Otherwise the long timeout based on frames_written causes DMA to run dry. + if (transfer_buffer->available() == 0) { + read_delay = SPDIF_EMPTY_READ_DELAY_MS; + } + + size_t bytes_read = transfer_buffer->transfer_data_from_source(pdMS_TO_TICKS(read_delay)); + uint8_t *new_data = transfer_buffer->get_buffer_end() - bytes_read; + + if (bytes_read > 0) { + this->apply_software_volume_(new_data, bytes_read); + this->swap_esp32_mono_samples_(new_data, bytes_read); + } + + if (transfer_buffer->available() == 0) { + // SPDIF Continuous Silence Mode: always output valid SPDIF stream + // When no audio data, write silence-encoded blocks to keep receiver happy + if (this->spdif_encoder_ != nullptr) { + // "Graceful stop" means "drain buffered audio, then stop." In SPDIF + // continuous mode we never actually stop, so once audio is drained + // (we're here), reset the flag to re-enable silence writing and stall + // recovery. Without this, stop_gracefully stays true forever and + // blocks silence output, causing DMA to degrade on auto_clear zeros. + stop_gracefully = false; + + // Track when we entered silence mode + if (this->spdif_silence_start_ == 0) { + this->spdif_silence_start_ = millis(); + } + + // If silence persists past the configured timeout, stop the task + // so components expecting timeout semantics can recover. + if (this->timeout_.has_value()) { + const uint32_t silence_duration = millis() - this->spdif_silence_start_; + if (silence_duration >= this->timeout_.value()) { + ESP_LOGV(TAG, "Silence timeout reached (%" PRIu32 "ms) - stopping speaker", silence_duration); + break; + } + } + + // First flush any partial block with silence padding (non-blocking to avoid getting stuck). + // IMPORTANT: Credit any partial block frames to frames_written so the audio_output_callback_ + // fires for them. Without this, pending_playback_frames_ in the mixer's SourceSpeaker never + // reaches 0 when a stream ends on a non-192-frame boundary, permanently blocking teardown. + if (this->spdif_encoder_->has_pending_data()) { + uint32_t partial_frames = this->spdif_encoder_->get_pending_frames(); + // Use a tiny timeout to allow DMA queue progress without stalling the task. + esp_err_t flush_err = this->spdif_encoder_->flush_with_silence(pdMS_TO_TICKS(1)); + if (flush_err == ESP_OK && partial_frames > 0) { + frames_written += partial_frames; + } + } + + // CRITICAL: In SPDIF continuous mode, ALWAYS write silence when no audio data. + // We don't check tx_dma_underflow because: + // 1. When DMA runs empty, callbacks stop, so tx_dma_underflow doesn't update + // 2. The non-blocking write handles "DMA full" gracefully (just doesn't write) + // 3. We need continuous output to prevent receiver from losing sync + if (!stop_gracefully) { + uint32_t silence_blocks = 0; + esp_err_t write_err = this->spdif_encoder_->write( + reinterpret_cast(SPDIF_SILENCE_BUFFER), sizeof(SPDIF_SILENCE_BUFFER), pdMS_TO_TICKS(1), + &silence_blocks); // Non-blocking + // Don't count silence as frames_written - it's not real audio + + // Recovery path for a stalled SPDIF TX channel: + // if silence writes repeatedly produce zero blocks AND DMA callbacks have stopped, + // re-prime DMA using preload mode. + const uint32_t ms_since_dma = millis() - spdif_last_dma_event_time; + const bool dma_events_stalled = ms_since_dma >= SPDIF_STALL_NO_DMA_MS; + if (silence_blocks > 0) { + spdif_last_block_progress_time = millis(); + } + const bool long_zero_progress = (millis() - spdif_last_block_progress_time) >= SPDIF_STALL_ZERO_PROGRESS_MS; + if (dma_events_stalled && silence_blocks == 0 && (write_err == ESP_OK || write_err == ESP_ERR_TIMEOUT)) { + spdif_zero_block_streak++; + } else { + spdif_zero_block_streak = 0; + } + + const uint32_t now_ms = millis(); + const bool reprime_cooldown_elapsed = + (spdif_last_reprime_time == 0) || ((now_ms - spdif_last_reprime_time) >= SPDIF_REPRIME_COOLDOWN_MS); + + if ((spdif_zero_block_streak >= 100 || long_zero_progress) && reprime_cooldown_elapsed) { + ESP_LOGV(TAG, "TX appears stalled, attempting DMA re-prime"); + + i2s_channel_disable(this->tx_handle_); + + const i2s_event_callbacks_t null_callbacks = {.on_sent = nullptr}; + i2s_channel_register_event_callback(this->tx_handle_, &null_callbacks, this); + + this->spdif_encoder_->set_preload_mode(true); + uint32_t preload_blocks = 0; + esp_err_t preload_err = this->spdif_encoder_->write( + reinterpret_cast(SPDIF_SILENCE_BUFFER), sizeof(SPDIF_SILENCE_BUFFER), + pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &preload_blocks); + this->spdif_encoder_->set_preload_mode(false); + + xQueueReset(this->i2s_event_queue_); + const i2s_event_callbacks_t callbacks = {.on_sent = i2s_on_sent_cb}; + i2s_channel_register_event_callback(this->tx_handle_, &callbacks, this); + i2s_channel_enable(this->tx_handle_); + + if (preload_err == ESP_OK && preload_blocks > 0) { + tx_dma_underflow = false; + preload_buffers_remaining = preload_blocks; + frames_written = 0; // Stale after channel disable/enable cycle + ESP_LOGV(TAG, "DMA re-prime successful (%" PRIu32 " preload blocks)", preload_blocks); + spdif_last_block_progress_time = now_ms; + } else { + ESP_LOGW(TAG, "DMA re-prime failed (%s, blocks=%" PRIu32 ")", esp_err_to_name(preload_err), + preload_blocks); + } + spdif_last_reprime_time = now_ms; + spdif_zero_block_streak = 0; + } + } + } + + if (stop_gracefully && tx_dma_underflow) { + // In SPDIF continuous mode, don't break on graceful stop during silence + // Keep outputting silence until new audio arrives or explicit COMMAND_STOP + // (handled above which transitions to silence mode rather than breaking) + } + + // In SPDIF mode, use a shorter delay to pump silence faster + // We need ~250 blocks/sec to keep DMA fed, so max 4ms per iteration + vTaskDelay(pdMS_TO_TICKS(SPDIF_SILENCE_LOOP_DELAY_MS)); + } else { + // Have audio data to write + size_t bytes_written = 0; + + // Clear silence timer since we have audio data now + if (this->spdif_silence_start_ != 0) { + uint32_t silence_duration = millis() - this->spdif_silence_start_; + if (silence_duration > 100) { + ESP_LOGV(TAG, "Exiting silence mode after %" PRIu32 "ms, have audio data", silence_duration); + } + this->spdif_silence_start_ = 0; + } + + { + uint32_t blocks_sent = 0; + size_t pcm_bytes_consumed = 0; + + // Write audio data to encoder (which writes to DMA) + esp_err_t err = + this->spdif_encoder_->write(transfer_buffer->get_buffer_start(), transfer_buffer->available(), + pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &blocks_sent, &pcm_bytes_consumed); + if (err != ESP_OK && err != ESP_ERR_TIMEOUT) { + ESP_LOGW(TAG, "Write failed: %s", esp_err_to_name(err)); + } + + // Only consume source bytes that were actually accepted by the encoder. + bytes_written = pcm_bytes_consumed; + + // Update frame accounting based on complete blocks sent (192 frames per block) + if (bytes_written > 0) { + frames_written += blocks_sent * SPDIF_BLOCK_SAMPLES; + transfer_buffer->decrease_buffer_length(bytes_written); + // Audio blocks count as DMA progress for the stall detector. + // Without this, a long uninterrupted audio stream makes the + // progress timer stale, triggering a spurious re-prime the + // instant we transition to silence. + spdif_last_block_progress_time = millis(); + } + } + } + } + // If we reach here, the while loop exited - either via break or condition became false + // In SPDIF mode, loop exit is expected when: + // 1. Timeout reached (user configured timeout) + // 2. Stream info changed + // Only warn if timeout is "never" since that should never exit + if (!this->timeout_.has_value()) { + ESP_LOGW(TAG, "Unexpected loop exit; set 'timeout: never' to prevent this"); + } + } + + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STOPPING); + + // Reset SPDIF encoder state to prevent stale state on next start + if (this->spdif_encoder_ != nullptr) { + this->spdif_encoder_->set_preload_mode(false); + this->spdif_encoder_->reset(); + } + + if (transfer_buffer != nullptr) { + transfer_buffer.reset(); + } + + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STOPPED); + + while (true) { + // Continuously delay until the loop method deletes the task + vTaskDelay(pdMS_TO_TICKS(10)); + } +} + +esp_err_t I2SAudioSpeakerSPDIF::start_i2s_driver(audio::AudioStreamInfo &audio_stream_info) { + this->current_stream_info_ = audio_stream_info; + + // SPDIF mode validation + if (this->sample_rate_ != audio_stream_info.get_sample_rate()) { + ESP_LOGE(TAG, "Only supports a single sample rate (configured: %" PRIu32 " Hz, stream: %" PRIu32 " Hz)", + this->sample_rate_, audio_stream_info.get_sample_rate()); + return ESP_ERR_NOT_SUPPORTED; + } + if (audio_stream_info.get_bits_per_sample() != 16) { + ESP_LOGE(TAG, "Only supports 16 bits per sample"); + return ESP_ERR_NOT_SUPPORTED; + } + if (audio_stream_info.get_channels() != 2) { + ESP_LOGE(TAG, "Only supports stereo (2 channels)"); + return ESP_ERR_NOT_SUPPORTED; + } + + if (this->slot_bit_width_ != I2S_SLOT_BIT_WIDTH_AUTO && + (i2s_slot_bit_width_t) audio_stream_info.get_bits_per_sample() > this->slot_bit_width_) { + ESP_LOGE(TAG, "Stream bits per sample must be less than or equal to the speaker's configuration"); + return ESP_ERR_NOT_SUPPORTED; + } + + if (!this->parent_->try_lock()) { + ESP_LOGE(TAG, "Parent bus is busy"); + return ESP_ERR_INVALID_STATE; + } + + i2s_clock_src_t clk_src = I2S_CLK_SRC_DEFAULT; + +#if SOC_CLK_APLL_SUPPORTED + if (this->use_apll_) { + clk_src = i2s_clock_src_t::I2S_CLK_SRC_APLL; + } +#endif // SOC_CLK_APLL_SUPPORTED + + // SPDIF mode: fixed configuration for BMC encoding + // For new driver, dma_frame_num is in I2S frames (8 bytes each for 32-bit stereo) + uint32_t dma_buffer_length = SPDIF_BLOCK_I2S_FRAMES; // One SPDIF block = 384 I2S frames = 3072 bytes + + // Log DMA configuration for debugging + ESP_LOGV(TAG, "I2S DMA config: %zu buffers x %lu frames = %lu bytes total", (size_t) SPDIF_DMA_BUFFERS_COUNT, + (unsigned long) dma_buffer_length, + (unsigned long) (SPDIF_DMA_BUFFERS_COUNT * dma_buffer_length * 8)); // 8 bytes per frame for 32-bit stereo + + i2s_chan_config_t chan_cfg = { + .id = this->parent_->get_port(), + .role = this->i2s_role_, + .dma_desc_num = SPDIF_DMA_BUFFERS_COUNT, + .dma_frame_num = dma_buffer_length, + .auto_clear = true, + .intr_priority = 3, + }; + + // SPDIF: double sample rate for BMC, 32-bit stereo, only data pin needed + i2s_std_clk_config_t clk_cfg = { + .sample_rate_hz = this->sample_rate_ * 2, + .clk_src = clk_src, + .mclk_multiple = this->mclk_multiple_, + }; + + i2s_std_slot_config_t slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_STEREO); + + i2s_std_gpio_config_t gpio_cfg = { + .mclk = GPIO_NUM_NC, + .bclk = GPIO_NUM_NC, + .ws = GPIO_NUM_NC, + .dout = this->dout_pin_, + .din = GPIO_NUM_NC, + .invert_flags = + { + .mclk_inv = false, + .bclk_inv = false, + .ws_inv = false, + }, + }; + + i2s_std_config_t std_cfg = { + .clk_cfg = clk_cfg, + .slot_cfg = slot_cfg, + .gpio_cfg = gpio_cfg, + }; + + esp_err_t err = this->init_i2s_channel_(chan_cfg, std_cfg, SPDIF_I2S_EVENT_QUEUE_COUNT); + if (err != ESP_OK) { + return err; + } + + // Channel is NOT enabled here. The speaker task will preload DMA buffers + // with SPDIF-encoded silence before enabling, ensuring the first data on + // the wire is valid SPDIF (not raw zeros from auto_clear) and preventing + // phantom DMA events before real audio data is available. + + return ESP_OK; +} + +} // namespace esphome::i2s_audio + +#endif // USE_ESP32 && USE_I2S_AUDIO_SPDIF_MODE diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_spdif.h b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.h new file mode 100644 index 00000000000..ca7774123b4 --- /dev/null +++ b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.h @@ -0,0 +1,34 @@ +#pragma once + +#include "esphome/core/defines.h" + +#if defined(USE_ESP32) && defined(USE_I2S_AUDIO_SPDIF_MODE) + +#include "i2s_audio_speaker.h" +#include "spdif_encoder.h" + +namespace esphome::i2s_audio { + +/// @brief SPDIF speaker implementation. +/// Encodes PCM audio into IEC 60958-3 S/PDIF bitstream using BMC encoding, +/// outputting through a single I2S data pin. Maintains continuous output +/// (silence when no audio) to keep SPDIF receivers synchronized. +class I2SAudioSpeakerSPDIF : public I2SAudioSpeakerBase { + public: + void setup() override; + void dump_config() override; + + size_t play(const uint8_t *data, size_t length, TickType_t ticks_to_wait) override; + + protected: + void run_speaker_task() override; + esp_err_t start_i2s_driver(audio::AudioStreamInfo &audio_stream_info) override; + void on_task_stopped() override; + + SPDIFEncoder *spdif_encoder_{nullptr}; + uint32_t spdif_silence_start_{0}; // Timestamp when silence mode started (0 = not in silence) +}; + +} // namespace esphome::i2s_audio + +#endif // USE_ESP32 && USE_I2S_AUDIO_SPDIF_MODE diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index a71b7db3baf..f34839a3140 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -257,7 +257,7 @@ esp_err_t I2SAudioSpeakerBase::init_i2s_channel_(const i2s_chan_config_t &chan_c err = i2s_channel_init_std_mode(this->tx_handle_, &std_cfg); if (err != ESP_OK) { - ESP_LOGE(TAG, "Failed to initialize channel"); + ESP_LOGE(TAG, "Failed to initialize I2S channel"); i2s_del_channel(this->tx_handle_); this->tx_handle_ = nullptr; this->parent_->unlock(); diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h index c598ca1bf87..bfde455c755 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h @@ -18,7 +18,7 @@ namespace esphome::i2s_audio { -// Shared constants for I2S audio speaker implementations +// Shared constants used by both standard and SPDIF speaker implementations static constexpr uint32_t DMA_BUFFER_DURATION_MS = 15; static constexpr size_t TASK_STACK_SIZE = 4096; static constexpr ssize_t TASK_PRIORITY = 19; @@ -42,7 +42,7 @@ enum SpeakerEventGroupBits : uint32_t { /// @brief Abstract base class for I2S audio speaker implementations. /// Provides shared infrastructure (event groups, ring buffer, volume control, task lifecycle) -/// for derived I2S speaker classes. +/// for derived standard I2S and SPDIF speaker classes. class I2SAudioSpeakerBase : public I2SAudioOut, public speaker::Speaker, public Component { public: float get_setup_priority() const override { return esphome::setup_priority::PROCESSOR; } diff --git a/esphome/components/i2s_audio/speaker/spdif_encoder.cpp b/esphome/components/i2s_audio/speaker/spdif_encoder.cpp new file mode 100644 index 00000000000..a853f934bb2 --- /dev/null +++ b/esphome/components/i2s_audio/speaker/spdif_encoder.cpp @@ -0,0 +1,385 @@ +#include "spdif_encoder.h" + +#if defined(USE_ESP32) && defined(USE_I2S_AUDIO_SPDIF_MODE) + +#include "esphome/core/log.h" + +namespace esphome::i2s_audio { + +static const char *const TAG = "i2s_audio.spdif_encoder"; + +// S/PDIF preamble patterns (8 BMC bits each) +// These are the BMC-encoded sync patterns that violate normal BMC rules for easy detection. +// All preambles end at phase HIGH (last bit = 1), enabling consistent data encoding. +// Preamble is placed at bits 24-31 of word[0] for MSB-first transmission. +static constexpr uint8_t PREAMBLE_B = 0x17; // Block start (left channel, frame 0) +static constexpr uint8_t PREAMBLE_M = 0x1d; // Left channel (not block start) +static constexpr uint8_t PREAMBLE_W = 0x1b; // Right channel + +// BMC encoding of 4 zero bits starting at phase HIGH: 00_11_00_11 = 0x33 +// Since both aux nibbles (bits 4-7, 8-11) are zero for 16-bit audio and phase is preserved, both are 0x33. +static constexpr uint32_t BMC_ZERO_NIBBLE = 0x33; + +// Constexpr BMC encoder for compile-time LUT generation. +// Encodes with start phase=true (HIGH). The complement property allows phase=false +// via XOR: bmc_encode(v, N, false) == bmc_encode(v, N, true) ^ mask +static constexpr uint16_t bmc_lut_encode(uint32_t data, uint8_t num_bits) { + uint16_t bmc = 0; + bool phase = true; + for (uint8_t i = 0; i < num_bits; i++) { + bool bit = (data >> i) & 1; + uint8_t bmc_pair = phase ? (bit ? 0b01 : 0b00) : (bit ? 0b10 : 0b11); + bmc |= static_cast(bmc_pair) << ((num_bits - 1 - i) * 2); + if (!bit) + phase = !phase; + } + return bmc; +} + +// 4-bit BMC lookup table: 16 entries (16 bytes in flash) +// Index: 4-bit data value (0-15), always phase=true start +static constexpr auto BMC_LUT_4 = [] { + std::array t{}; + for (uint32_t i = 0; i < 16; i++) + t[i] = static_cast(bmc_lut_encode(i, 4)); + return t; +}(); + +// 8-bit BMC lookup table: 256 entries (512 bytes in flash) +// Index: 8-bit data value (0-255), always phase=true start +static constexpr auto BMC_LUT_8 = [] { + std::array t{}; + for (uint32_t i = 0; i < 256; i++) + t[i] = bmc_lut_encode(i, 8); + return t; +}(); + +// Initialize S/PDIF buffer +bool SPDIFEncoder::setup() { + this->spdif_block_buf_ = std::make_unique(SPDIF_BLOCK_SIZE_U32); + if (!this->spdif_block_buf_) { + ESP_LOGE(TAG, "Buffer allocation failed (%zu bytes)", SPDIF_BLOCK_SIZE_BYTES); + return false; + } + ESP_LOGV(TAG, "Buffer allocated (%zu bytes)", SPDIF_BLOCK_SIZE_BYTES); + + // Build initial channel status block with default sample rate + this->build_channel_status_(); + + this->reset(); + return true; +} + +void SPDIFEncoder::reset() { + this->spdif_block_ptr_ = this->spdif_block_buf_.get(); + this->frame_in_block_ = 0; + this->is_left_channel_ = true; +} + +void SPDIFEncoder::set_sample_rate(uint32_t sample_rate) { + if (this->sample_rate_ != sample_rate) { + this->sample_rate_ = sample_rate; + this->build_channel_status_(); + ESP_LOGD(TAG, "Sample rate set to %lu Hz", (unsigned long) sample_rate); + } +} + +void SPDIFEncoder::build_channel_status_() { + // IEC 60958-3 Consumer Channel Status Block (192 bits = 24 bytes) + // Transmitted LSB-first within each byte, one bit per frame via C bit + // + // Byte 0: Control bits + // Bit 0: 0 = Consumer format (not professional AES3) + // Bit 1: 0 = PCM audio (not non-audio data like AC3) + // Bit 2: 0 = No copyright assertion + // Bits 3-5: 000 = No pre-emphasis + // Bits 6-7: 00 = Mode 0 (basic consumer format) + // + // Byte 1: Category code (0x00 = general, 0x01 = CD, etc.) + // + // Byte 2: Source/channel numbers + // Bits 0-3: Source number (0 = unspecified) + // Bits 4-7: Channel number (0 = unspecified) + // + // Byte 3: Sample frequency and clock accuracy + // Bits 0-3: Sample frequency code + // Bits 4-5: Clock accuracy (00 = Level II, ±1000 ppm, appropriate for ESP32) + // Bits 6-7: Reserved (0) + // + // Bytes 4-23: Reserved (zeros for basic compliance) + + // Clear all bytes first + this->channel_status_.fill(0); + + // Byte 0: Consumer, PCM audio, no copyright, no pre-emphasis, Mode 0 + // All bits are 0, which is already set + + // Byte 1: Category code = 0x00 (general) + // Already 0 + + // Byte 2: Source/channel unspecified + // Already 0 + + // Byte 3: Sample frequency code (bits 0-3) + clock accuracy (bits 4-5) + // Clock accuracy = 00 (Level II, ±1000 ppm) - appropriate for ESP32 + uint8_t freq_code; + switch (this->sample_rate_) { + case 44100: + freq_code = 0x0; // 0000 + break; + case 48000: + freq_code = 0x2; // 0010 + break; + default: + // Other values are possible but they're not supported by ESPHome + freq_code = 0x1; // 0001 = not indicated + ESP_LOGW(TAG, "Unsupported sample rate %lu Hz, channel status will indicate 'not specified'", + (unsigned long) this->sample_rate_); + break; + } + // Byte 3: freq_code in bits 0-3, clock accuracy (00) in bits 4-5 + this->channel_status_[3] = freq_code; // Clock accuracy bits 4-5 are already 0 + + // Bytes 4-23 remain zero (word length not specified, no original sample freq, etc.) +} + +HOT void SPDIFEncoder::encode_sample_(const uint8_t *pcm_sample) { + // ============================================================================ + // Build raw 32-bit subframe (IEC 60958 format) + // ============================================================================ + // Bit layout: + // Bits 0-3: Preamble (handled separately, not in raw_subframe) + // Bits 4-7: Auxiliary audio data (zeros for 16-bit audio) + // Bits 8-11: Audio LSB extension (zeros for 16-bit audio) + // Bits 12-27: 16-bit audio sample (MSB-aligned in 20-bit audio field) + // Bit 28: V (Validity) - 0 = valid audio + // Bit 29: U (User data) - 0 + // Bit 30: C (Channel status) - from channel status block + // Bit 31: P (Parity) - even parity over bits 4-31 + // ============================================================================ + + // Place 16-bit audio sample at bits 12-27 (little-endian input: [0]=LSB, [1]=MSB) + uint32_t raw_subframe = (static_cast(pcm_sample[1]) << 20) | (static_cast(pcm_sample[0]) << 12); + + // V = 0 (valid audio), U = 0 (no user data) + // C = channel status bit for current frame (same bit used for both L and R subframes) + bool c_bit = this->get_channel_status_bit_(this->frame_in_block_); + if (c_bit) { + raw_subframe |= (1U << 30); + } + + // Calculate even parity over bits 4-30 + // This ensures consistent BMC ending phase regardless of audio content + uint32_t bits_4_30 = (raw_subframe >> 4) & 0x07FFFFFF; // 27 bits (4-30) + uint32_t ones_count = __builtin_popcount(bits_4_30); + uint32_t parity = ones_count & 1; // 1 if odd count, 0 if even + raw_subframe |= parity << 31; // Set P bit to make total even + + // ============================================================================ + // Select preamble based on position in block and channel + // ============================================================================ + // B = block start (left channel, frame 0 of 192-frame block) + // M = left channel (frames 1-191) + // W = right channel (all frames) + uint8_t preamble; + if (this->is_left_channel_) { + preamble = (this->frame_in_block_ == 0) ? PREAMBLE_B : PREAMBLE_M; + } else { + preamble = PREAMBLE_W; + } + + // ============================================================================ + // BMC encode the data portion (bits 4-31) using lookup tables + // ============================================================================ + // The I2S uses 16-bit halfword swap: bits 16-31 transmit before bits 0-15. + // This applies to BOTH word[0] and word[1]. + // + // word[0] transmission order: [16-23] → [24-31] → [0-7] → [8-15] + // For correct S/PDIF subframe order (preamble → aux → audio): + // - bits 16-23: preamble (8 BMC bits) + // - bits 24-31: BMC(subframe bits 4-7) - first aux nibble + // - bits 0-7: BMC(subframe bits 8-11) - second aux nibble + // - bits 8-15: BMC(subframe bits 12-15) - audio low nibble + // + // word[1] transmission order: [16-31] → [0-15] + // For correct S/PDIF subframe order: + // - bits 16-31: BMC(subframe bits 16-23) - audio mid byte + // - bits 0-15: BMC(subframe bits 24-31) - audio high nibble + VUCP + // ============================================================================ + + // All preambles end at phase HIGH. Bits 4-11 are always zero for 16-bit audio; + // two zero nibbles flip phase 8 times total → back to HIGH. + // So bits 12-15 always start encoding at phase=true. + + // Bits 12-15: 4-bit LUT lookup (always phase=true start) + uint32_t nibble = (raw_subframe >> 12) & 0xF; + uint32_t bmc_12_15 = BMC_LUT_4[nibble]; + + // Phase tracking via branchless XOR mask: + // - 0x0000 means phase=true (use LUT value directly) + // - 0xFFFF means phase=false (complement LUT value) + // End phase = start XOR (popcount & 1) since zero-bits flip phase, + // and for even bit widths: #zeros parity == popcount parity. + uint32_t phase_mask = -(__builtin_popcount(nibble) & 1u) & 0xFFFF; + + // Bits 16-23: 8-bit LUT lookup with phase correction + uint32_t byte_mid = (raw_subframe >> 16) & 0xFF; + uint32_t bmc_16_23 = BMC_LUT_8[byte_mid] ^ phase_mask; + phase_mask ^= -(__builtin_popcount(byte_mid) & 1u) & 0xFFFF; + + // Bits 24-31: 8-bit LUT lookup with phase correction + uint32_t byte_hi = (raw_subframe >> 24) & 0xFF; + uint32_t bmc_24_31 = BMC_LUT_8[byte_hi] ^ phase_mask; + + // ============================================================================ + // Combine with correct positioning for I2S transmission + // ============================================================================ + // I2S with halfword swap: transmits bits 16-31, then bits 0-15. + // Within each halfword, MSB (highest bit) is transmitted first. + // + // For upper halfword (bits 16-31): bit 31 → bit 16 + // For lower halfword (bits 0-15): bit 15 → bit 0 + // + // Desired S/PDIF order: preamble → bmc_4_7 → bmc_8_11 → bmc_12_15 + // + // word[0] layout for correct transmission: + // bits 24-31: preamble (transmitted 1st, as MSB of upper halfword) + // bits 16-23: BMC_ZERO_NIBBLE (transmitted 2nd, aux bits 4-7) + // bits 8-15: BMC_ZERO_NIBBLE (transmitted 3rd, aux bits 8-11) + // bits 0-7: bmc_12_15 (transmitted 4th, audio low nibble) + // + // word[1] layout: + // bits 16-31: bmc_16_23 (transmitted 5th) + // bits 0-15: bmc_24_31 (transmitted 6th) + this->spdif_block_ptr_[0] = + bmc_12_15 | (BMC_ZERO_NIBBLE << 8) | (BMC_ZERO_NIBBLE << 16) | (static_cast(preamble) << 24); + this->spdif_block_ptr_[1] = bmc_24_31 | (bmc_16_23 << 16); + this->spdif_block_ptr_ += 2; + + // ============================================================================ + // Update position tracking + // ============================================================================ + if (!this->is_left_channel_) { + // Completed a stereo frame, advance frame counter + if (++this->frame_in_block_ >= SPDIF_BLOCK_SAMPLES) { + this->frame_in_block_ = 0; + } + } + this->is_left_channel_ = !this->is_left_channel_; +} + +esp_err_t SPDIFEncoder::send_block_(TickType_t ticks_to_wait) { + // Use the appropriate callback and context based on preload mode + SPDIFBlockCallback callback; + void *ctx; + + if (this->preload_mode_) { + callback = this->preload_callback_; + ctx = this->preload_callback_ctx_; + } else { + callback = this->write_callback_; + ctx = this->write_callback_ctx_; + } + + if (callback == nullptr) { + return ESP_ERR_INVALID_STATE; + } + + esp_err_t err = callback(ctx, this->spdif_block_buf_.get(), SPDIF_BLOCK_SIZE_BYTES, ticks_to_wait); + + if (err == ESP_OK) { + // Reset pointer for next block; position tracking continues from where it left off + this->spdif_block_ptr_ = this->spdif_block_buf_.get(); + } + + return err; +} + +size_t SPDIFEncoder::get_pending_pcm_bytes() const { + if (this->spdif_block_ptr_ == nullptr || this->spdif_block_buf_ == nullptr) { + return 0; + } + // Each PCM sample (2 bytes) produces 2 uint32_t values in the SPDIF buffer + // So pending uint32s / 2 = pending samples, and each sample is 2 bytes + size_t pending_uint32s = this->spdif_block_ptr_ - this->spdif_block_buf_.get(); + size_t pending_samples = pending_uint32s / 2; + return pending_samples * 2; // 2 bytes per sample +} + +HOT esp_err_t SPDIFEncoder::write(const uint8_t *src, size_t size, TickType_t ticks_to_wait, uint32_t *blocks_sent, + size_t *bytes_consumed) { + const uint8_t *pcm_data = src; + const uint8_t *pcm_end = src + size; + uint32_t block_count = 0; + + while (pcm_data < pcm_end) { + // Check if there's a pending complete block from a previous failed send + if (this->spdif_block_ptr_ >= &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + esp_err_t err = this->send_block_(ticks_to_wait); + if (err != ESP_OK) { + if (blocks_sent != nullptr) { + *blocks_sent = block_count; + } + if (bytes_consumed != nullptr) { + *bytes_consumed = pcm_data - src; + } + return err; + } + ++block_count; + } + + // Encode one 16-bit sample + this->encode_sample_(pcm_data); + pcm_data += 2; + } + + // Send any complete block that was just finished + if (this->spdif_block_ptr_ >= &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + esp_err_t err = this->send_block_(ticks_to_wait); + if (err != ESP_OK) { + if (blocks_sent != nullptr) { + *blocks_sent = block_count; + } + if (bytes_consumed != nullptr) { + *bytes_consumed = pcm_data - src; + } + return err; + } + ++block_count; + } + + if (blocks_sent != nullptr) { + *blocks_sent = block_count; + } + if (bytes_consumed != nullptr) { + *bytes_consumed = size; + } + return ESP_OK; +} + +esp_err_t SPDIFEncoder::flush_with_silence(TickType_t ticks_to_wait) { + // First, send any pending complete block from a previous failed send + if (this->spdif_block_ptr_ >= &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + esp_err_t err = this->send_block_(ticks_to_wait); + if (err != ESP_OK) { + return err; + } + } + + if (!this->has_pending_data()) { + return ESP_OK; // Nothing to flush + } + + // Encode silence (zeros) until the block is complete + static const uint8_t SILENCE[2] = {0, 0}; + + while (this->spdif_block_ptr_ < &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + this->encode_sample_(SILENCE); + } + + return this->send_block_(ticks_to_wait); +} + +} // namespace esphome::i2s_audio + +#endif // USE_I2S_AUDIO_SPDIF_MODE diff --git a/esphome/components/i2s_audio/speaker/spdif_encoder.h b/esphome/components/i2s_audio/speaker/spdif_encoder.h new file mode 100644 index 00000000000..85166434329 --- /dev/null +++ b/esphome/components/i2s_audio/speaker/spdif_encoder.h @@ -0,0 +1,146 @@ +#pragma once + +#include "esphome/core/defines.h" + +#if defined(USE_ESP32) && defined(USE_I2S_AUDIO_SPDIF_MODE) + +#include +#include +#include +#include +#include "esp_err.h" +#include "esphome/core/helpers.h" + +namespace esphome::i2s_audio { + +// A SPDIF sample is 64-bits +static constexpr uint8_t SPDIF_BITS_PER_SAMPLE = 64; +// Number of samples in a SPDIF block +static constexpr uint16_t SPDIF_BLOCK_SAMPLES = 192; +// To emulate bi-phase mark code (BMC) (aka differential Manchester encoding) we send twice +// as many bits per sample so that we can generate the transitions this encoding requires. +static constexpr uint8_t EMULATED_BMC_BITS_PER_SAMPLE = SPDIF_BITS_PER_SAMPLE * 2; +static constexpr uint16_t SPDIF_BLOCK_SIZE_BYTES = SPDIF_BLOCK_SAMPLES * (EMULATED_BMC_BITS_PER_SAMPLE / 8); +static constexpr uint32_t SPDIF_BLOCK_SIZE_U32 = SPDIF_BLOCK_SIZE_BYTES / sizeof(uint32_t); // 3072 bytes / 4 = 768 +// I2S frame count for one SPDIF block (for new driver where frame = 8 bytes for 32-bit stereo) +static constexpr uint32_t SPDIF_BLOCK_I2S_FRAMES = SPDIF_BLOCK_SIZE_BYTES / 8; // 3072 / 8 = 384 frames +// PCM bytes needed for one complete SPDIF block (192 stereo frames * 2 bytes per sample * 2 channels) +static constexpr uint16_t SPDIF_PCM_BYTES_PER_BLOCK = SPDIF_BLOCK_SAMPLES * 2 * 2; // = 768 bytes + +/// Callback signature for block completion (raw function pointer for minimal overhead) +/// @param user_ctx User context pointer passed during callback registration +/// @param data Pointer to SPDIF encoded block data +/// @param size Size of the block in bytes (always SPDIF_BLOCK_SIZE_BYTES) +/// @param ticks_to_wait FreeRTOS ticks to wait for write completion +/// @return ESP_OK on success, or an error code +using SPDIFBlockCallback = esp_err_t (*)(void *user_ctx, uint32_t *data, size_t size, TickType_t ticks_to_wait); + +class SPDIFEncoder { + public: + /// @brief Initialize the SPDIF working buffer + /// @return true if setup was successful, false if allocation failed + bool setup(); + + /// @brief Set callback for normal writes (used when channel is running) + /// @param callback Function pointer to call when a block is ready + /// @param user_ctx Context pointer passed to callback (typically 'this' pointer of speaker) + void set_write_callback(SPDIFBlockCallback callback, void *user_ctx) { + this->write_callback_ = callback; + this->write_callback_ctx_ = user_ctx; + } + + /// @brief Set callback for preload writes (used when preloading to DMA before enabling channel) + /// @param callback Function pointer to call when a block is ready for preload + /// @param user_ctx Context pointer passed to callback (typically 'this' pointer of speaker) + void set_preload_callback(SPDIFBlockCallback callback, void *user_ctx) { + this->preload_callback_ = callback; + this->preload_callback_ctx_ = user_ctx; + } + + /// @brief Enable or disable preload mode + /// When in preload mode, completed blocks use the preload callback instead of write callback + void set_preload_mode(bool preload) { this->preload_mode_ = preload; } + + /// @brief Check if currently in preload mode + bool is_preload_mode() const { return this->preload_mode_; } + + /// @brief Convert PCM audio data to SPDIF BMC encoded data + /// @param src Source PCM audio data (16-bit stereo) + /// @param size Size of source data in bytes + /// @param ticks_to_wait Timeout for blocking writes + /// @param blocks_sent Optional pointer to receive the number of complete SPDIF blocks sent + /// @param bytes_consumed Optional pointer to receive the number of PCM bytes consumed from src + /// @return esp_err_t as returned from the callback + esp_err_t write(const uint8_t *src, size_t size, TickType_t ticks_to_wait, uint32_t *blocks_sent = nullptr, + size_t *bytes_consumed = nullptr); + + /// @brief Get the number of PCM bytes currently pending in the partial block buffer + /// @return Number of pending PCM bytes (0 to SPDIF_PCM_BYTES_PER_BLOCK - 1) + size_t get_pending_pcm_bytes() const; + + /// @brief Get the number of PCM frames currently pending in the partial block buffer + /// @return Number of pending PCM frames (0 to SPDIF_BLOCK_SAMPLES - 1) + uint32_t get_pending_frames() const { return this->get_pending_pcm_bytes() / 4; } + + /// @brief Check if there is a partial block pending + bool has_pending_data() const { return this->spdif_block_ptr_ != this->spdif_block_buf_.get(); } + + /// @brief Flush any pending partial block by padding with silence and sending + /// @param ticks_to_wait Timeout for blocking writes + /// @return esp_err_t as returned from the callback, or ESP_OK if nothing to flush + esp_err_t flush_with_silence(TickType_t ticks_to_wait); + + /// @brief Reset the SPDIF block buffer and position tracking, discarding any partial block + void reset(); + + /// @brief Set the sample rate for Channel Status Block encoding + /// @param sample_rate Sample rate in Hz (e.g., 44100, 48000, 96000) + /// Call this before writing audio data to ensure correct channel status. + void set_sample_rate(uint32_t sample_rate); + + /// @brief Get the currently configured sample rate + uint32_t get_sample_rate() const { return this->sample_rate_; } + + protected: + /// @brief Encode a single 16-bit PCM sample into the current block position + HOT void encode_sample_(const uint8_t *pcm_sample); + + /// @brief Send the completed block via the appropriate callback + esp_err_t send_block_(TickType_t ticks_to_wait); + + /// @brief Build the channel status block from current configuration + void build_channel_status_(); + + /// @brief Get the channel status bit for a specific frame + /// @param frame Frame number (0-191) + /// @return The C bit value for this frame + ESPHOME_ALWAYS_INLINE inline bool get_channel_status_bit_(uint8_t frame) const { + // Channel status is 192 bits transmitted over 192 frames + // Bit N is transmitted in frame N, LSB-first within each byte + return (this->channel_status_[frame >> 3] >> (frame & 7)) & 1; + } + + // Member ordering optimized to minimize padding (largest alignment first) + + // 4-byte aligned members (pointers and uint32_t) + SPDIFBlockCallback write_callback_{nullptr}; + SPDIFBlockCallback preload_callback_{nullptr}; + void *write_callback_ctx_{nullptr}; + void *preload_callback_ctx_{nullptr}; + std::unique_ptr spdif_block_buf_; // Working buffer for SPDIF block (heap allocated) + uint32_t *spdif_block_ptr_{nullptr}; // Current position in block buffer + uint32_t sample_rate_{48000}; // Sample rate for Channel Status Block encoding + + // 1-byte aligned members (grouped together to avoid internal padding) + uint8_t frame_in_block_{0}; // 0-191, tracks stereo frame position within block + bool is_left_channel_{true}; // Alternates L/R for stereo samples + bool preload_mode_{false}; // Whether to use preload callback vs write callback + + // Channel Status Block (192 bits = 24 bytes, transmitted over 192 frames) + // Placed last since std::array has 1-byte alignment + std::array channel_status_{}; +}; + +} // namespace esphome::i2s_audio + +#endif // USE_I2S_AUDIO_SPDIF_MODE diff --git a/esphome/core/defines.h b/esphome/core/defines.h index 85454d3cc00..162a6034b88 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -72,6 +72,7 @@ #define USE_GRAPHICAL_DISPLAY_MENU #define USE_HOMEASSISTANT_TIME #define USE_HTTP_REQUEST_OTA_WATCHDOG_TIMEOUT 8000 // NOLINT +#define USE_I2S_AUDIO_SPDIF_MODE #define USE_IMAGE #define USE_IMPROV_SERIAL #define USE_IMPROV_SERIAL_NEXT_URL diff --git a/tests/components/speaker/spdif_mode.esp32-idf.yaml b/tests/components/speaker/spdif_mode.esp32-idf.yaml new file mode 100644 index 00000000000..4d6859feaed --- /dev/null +++ b/tests/components/speaker/spdif_mode.esp32-idf.yaml @@ -0,0 +1,25 @@ +substitutions: + i2s_bclk_pin: GPIO27 + i2s_lrclk_pin: GPIO26 + i2s_mclk_pin: GPIO25 + i2s_dout_pin: GPIO12 + spdif_data_pin: GPIO4 + +packages: + i2c: !include ../../test_build_components/common/i2c/esp32-idf.yaml + +i2s_audio: + - id: i2s_output + +speaker: + - platform: i2s_audio + id: speaker_id + dac_type: external + i2s_dout_pin: ${spdif_data_pin} + spdif_mode: true + use_apll: true + timeout: 2s + sample_rate: 48000 + bits_per_sample: 16bit + channel: stereo + i2s_mode: primary From 70b9edfabebb9a433c6730eb4e22bd26a9406e64 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Fri, 8 May 2026 17:26:09 -0400 Subject: [PATCH 17/52] [i2s_audio] Refactor SPDIF output, fixing synchronization problems (#16319) --- .../i2s_audio/speaker/i2s_audio_spdif.cpp | 434 ++++++------------ .../i2s_audio/speaker/i2s_audio_speaker.cpp | 44 +- .../i2s_audio/speaker/i2s_audio_speaker.h | 8 +- .../i2s_audio/speaker/spdif_encoder.cpp | 24 +- .../i2s_audio/speaker/spdif_encoder.h | 5 +- 5 files changed, 205 insertions(+), 310 deletions(-) diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp index e2146de63ce..d257dd1d8f4 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_spdif.cpp @@ -23,35 +23,14 @@ static const char *const TAG = "i2s_audio.spdif"; // 15 buffers x 4ms = 60ms of DMA buffering (same as 4 x 15ms for standard) static constexpr size_t SPDIF_DMA_BUFFERS_COUNT = 15; -// Timeout for flushing pending frames if no callback received. -static constexpr uint32_t SPDIF_FLUSH_TIMEOUT_MS = 20; - // Number of DMA events between upstream callbacks (~16ms = 4 events x 4ms each). // Matches non-SPDIF timing to prevent overwhelming upstream sync algorithms. static constexpr uint32_t SPDIF_DMA_EVENTS_PER_CALLBACK = 4; -// Consider TX stalled only if no DMA callbacks have arrived for this long. -// Zero-block non-blocking writes alone are not sufficient (they can happen when DMA is simply full). -static constexpr uint32_t SPDIF_STALL_NO_DMA_MS = 80; - -// Fallback stall detector: force recovery if silence writes make no forward progress for too long, -// even if occasional DMA callbacks are still observed. -static constexpr uint32_t SPDIF_STALL_ZERO_PROGRESS_MS = 1000; - -// Minimum spacing between re-prime attempts to avoid churn. -static constexpr uint32_t SPDIF_REPRIME_COOLDOWN_MS = 500; - -// Small waits used in SPDIF mode to keep DMA fed during rapid pipeline churn. -static constexpr uint32_t SPDIF_EMPTY_READ_DELAY_MS = 1; -static constexpr uint32_t SPDIF_SILENCE_LOOP_DELAY_MS = 1; +// Brief retry wait used by play() to catch short free-space windows during rapid track transitions. static constexpr uint32_t SPDIF_PLAY_RETRY_WAIT_MS = 5; -static constexpr size_t SPDIF_I2S_EVENT_QUEUE_COUNT = SPDIF_DMA_BUFFERS_COUNT + 1; - -// Static silence buffer for SPDIF continuous mode -// 192 samples * 2 channels * 2 bytes per sample = 768 bytes -// Stored in flash (.rodata section) to avoid stack/heap usage -static const int16_t SPDIF_SILENCE_BUFFER[SPDIF_BLOCK_SAMPLES * 2] = {0}; +static constexpr size_t SPDIF_I2S_EVENT_QUEUE_COUNT = 2 * SPDIF_DMA_BUFFERS_COUNT; // Static callback functions for SPDIF encoder (avoids std::function overhead) static esp_err_t spdif_preload_cb(void *user_ctx, uint32_t *data, size_t size, TickType_t ticks_to_wait) { @@ -59,7 +38,7 @@ static esp_err_t spdif_preload_cb(void *user_ctx, uint32_t *data, size_t size, T size_t bytes_written = 0; esp_err_t err = i2s_channel_preload_data(speaker->get_tx_handle(), data, size, &bytes_written); if (err != ESP_OK || bytes_written != size) { - ESP_LOGW(TAG, "Preload failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); + ESP_LOGV(TAG, "Preload failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); return (err != ESP_OK) ? err : ESP_ERR_NO_MEM; } return ESP_OK; @@ -69,9 +48,8 @@ static esp_err_t spdif_write_cb(void *user_ctx, uint32_t *data, size_t size, Tic auto *speaker = static_cast(user_ctx); size_t bytes_written = 0; esp_err_t err = i2s_channel_write(speaker->get_tx_handle(), data, size, &bytes_written, ticks_to_wait); - // ESP_ERR_TIMEOUT is expected under DMA backpressure in SPDIF mode. - if (err != ESP_OK && err != ESP_ERR_TIMEOUT) { - ESP_LOGW(TAG, "I2S write failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); + if (err != ESP_OK) { + ESP_LOGV(TAG, "I2S write failed: %s (wrote %zu/%zu bytes)", esp_err_to_name(err), bytes_written, size); } return err; } @@ -157,6 +135,9 @@ void I2SAudioSpeakerSPDIF::run_speaker_task() { this->spdif_encoder_->reset(); } + // Reset lockstep records queue so it starts paired with the (also-reset) i2s_event_queue_. + xQueueReset(this->write_records_queue_); + const uint32_t dma_buffers_duration_ms = DMA_BUFFER_DURATION_MS * SPDIF_DMA_BUFFERS_COUNT; // Ensure ring buffer duration is at least the duration of all DMA buffers const uint32_t ring_buffer_duration = std::max(dma_buffers_duration_ms, this->buffer_duration_ms_); @@ -188,19 +169,16 @@ void I2SAudioSpeakerSPDIF::run_speaker_task() { // Preload DMA buffers with SPDIF-encoded silence before enabling the channel. // This ensures the first data transmitted is valid SPDIF (not raw zeros from // auto_clear) and prevents phantom DMA events before real audio is available. - // Track how many buffers were preloaded so the DMA event loop can skip - // frame accounting until the preloaded silence has fully drained. - uint32_t preload_buffers_remaining = 0; + // Each preloaded block pushes a 0-real-frame record so that the corresponding + // on_sent events drain in lockstep without crediting any audio frames. this->spdif_encoder_->set_preload_mode(true); for (size_t i = 0; i < SPDIF_DMA_BUFFERS_COUNT; i++) { - uint32_t preload_blocks = 0; - esp_err_t preload_err = this->spdif_encoder_->write(reinterpret_cast(SPDIF_SILENCE_BUFFER), - sizeof(SPDIF_SILENCE_BUFFER), - pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &preload_blocks); - if (preload_err != ESP_OK || preload_blocks == 0) { - break; // DMA buffers full or error + esp_err_t preload_err = this->spdif_encoder_->flush_with_silence(pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS)); + if (preload_err != ESP_OK) { + break; // DMA preload buffer full or error } - preload_buffers_remaining += preload_blocks; + const uint32_t silence_record = 0; + xQueueSendToBack(this->write_records_queue_, &silence_record, 0); } this->spdif_encoder_->set_preload_mode(false); this->spdif_encoder_->reset(); // Clean encoder state for the main loop @@ -211,299 +189,193 @@ void I2SAudioSpeakerSPDIF::run_speaker_task() { i2s_channel_register_event_callback(this->tx_handle_, &callbacks, this); i2s_channel_enable(this->tx_handle_); - bool stop_gracefully = false; - bool tx_dma_underflow = true; + // Always-fill model: each iteration produces exactly one SPDIF block (= one DMA buffer). + // We drain real PCM up to one block from the ring buffer and silence-pad any remainder. + // Blocking writes pace the loop at the DMA consumption rate. This mirrors the standard + // I2S speaker pattern (PR #16317): fill what you can, then silence-pad whatever is still + // missing to complete the DMA buffer. + const uint32_t block_duration_us = this->current_stream_info_.frames_to_microseconds(SPDIF_BLOCK_SAMPLES); + // Sized to absorb the worst case where every DMA buffer is full when we issue the write. + const TickType_t write_timeout_ticks = + pdMS_TO_TICKS(((block_duration_us * (SPDIF_DMA_BUFFERS_COUNT + 1)) + 999) / 1000); + // Brief read budget when the ring buffer is empty (~half a block). + const TickType_t read_timeout_ticks = pdMS_TO_TICKS(((block_duration_us / 2) + 999) / 1000); - uint32_t frames_written = 0; - - // SPDIF Continuous Silence Mode + Callback Decimation - // - // Key principles: - // 1. NEVER stop the I2S channel - always output a valid SPDIF stream - // 2. When no audio data, output silence-encoded SPDIF blocks (not zeros!) - // 3. Fire callbacks every 4 DMA events (~16ms), matching non-SPDIF timing - // - // This eliminates gaps that cause SPDIF receivers to re-sync, and reduces - // callback rate to prevent overwhelming upstream sync algorithms. - const uint32_t spdif_callback_threshold = this->current_stream_info_.ms_to_frames(DMA_BUFFER_DURATION_MS); + // SPDIF Callback Decimation: fire every 4th DMA event (~16ms), matching non-SPDIF timing. uint32_t spdif_pending_frames = 0; int64_t spdif_pending_timestamp = 0; - uint32_t spdif_last_callback_time = millis(); - // Count DMA events for decimation uint32_t spdif_dma_event_count = 0; - uint32_t spdif_last_dma_event_time = millis(); - // Detect a stalled DMA path (many silence write attempts with zero accepted blocks). - uint32_t spdif_zero_block_streak = 0; - uint32_t spdif_last_block_progress_time = millis(); - uint32_t spdif_last_reprime_time = 0; xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_RUNNING); // SPDIF continuous mode: loop runs indefinitely, outputting silence when no audio data - // to keep the receiver synced. Exits only via break (stream info change or silence timeout). + // to keep the receiver synced. Exits only via break (stream info change, silence timeout, + // lockstep desync, dropped event, or partial-write failure). while (true) { uint32_t event_group_bits = xEventGroupGetBits(this->event_group_); if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP) { xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP); - // In SPDIF continuous mode, don't tear down or expose STOPPED here. - // Keep the task alive and transition to silence output. + // The ISR pairs COMMAND_STOP with ERR_DROPPED_EVENT when it has to discard a completion + // event; that desyncs the lockstep queues permanently and the only safe recovery is a full + // task restart. + if (event_group_bits & SpeakerEventGroupBits::ERR_DROPPED_EVENT) { + ESP_LOGV(TAG, "Exiting: ISR dropped event, restarting to recover lockstep"); + break; + } + // User-initiated stop. In SPDIF continuous mode, transition to silence output rather + // than tearing the task down. this->spdif_silence_start_ = millis(); ESP_LOGV(TAG, "COMMAND_STOP received, continuing in silence mode"); } if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY) { + // SPDIF continuous mode never tears the channel down on graceful stop. Clear the flag and + // let the audio simply drain through the always-fill loop into the silence-timeout path. xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY); - stop_gracefully = true; } if (this->audio_stream_info_ != this->current_stream_info_) { - // Audio stream info changed, stop the speaker task so it will restart with the proper settings. ESP_LOGV(TAG, "Exiting: stream info changed"); break; } + // Drain ISR completion events, popping a matching record for each. int64_t write_timestamp; + bool lockstep_broken = false; while (xQueueReceive(this->i2s_event_queue_, &write_timestamp, 0)) { - spdif_last_dma_event_time = millis(); - - // Skip frame accounting for preloaded silence buffers still draining. - // These DMA events correspond to silence that was preloaded before the - // channel was enabled, not real audio written by the task. - if (preload_buffers_remaining > 0) { - preload_buffers_remaining--; - continue; + // Lockstep: pop the matching record (real audio frames packed into this DMA block). + // Records are pushed by the task right after each successful block commit, so the FIFO + // order matches DMA completion order. Empty records queue here means lockstep broke. + uint32_t real_frames = 0; + if (xQueueReceive(this->write_records_queue_, &real_frames, 0) != pdTRUE) { + ESP_LOGV(TAG, "Event without matching write record"); + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_LOCKSTEP_DESYNC); + lockstep_broken = true; + break; } - // Receives timing events from the I2S on_sent callback. If actual audio data was sent in this event, it passes - // on the timing info via the audio_output_callback. - uint32_t frames_sent = frames_to_fill_single_dma_buffer; - if (frames_to_fill_single_dma_buffer > frames_written) { - tx_dma_underflow = true; - frames_sent = frames_written; - const uint32_t frames_zeroed = frames_to_fill_single_dma_buffer - frames_written; + // Per-block timestamp adjustment: shift back by the silence-padding portion of the block + // so the reported timestamp reflects when the last real sample left the wire. + uint32_t frames_sent = real_frames; + if (real_frames < SPDIF_BLOCK_SAMPLES) { + const uint32_t frames_zeroed = SPDIF_BLOCK_SAMPLES - real_frames; write_timestamp -= this->current_stream_info_.frames_to_microseconds(frames_zeroed); - } else { - tx_dma_underflow = false; } - frames_written -= frames_sent; - // SPDIF Callback Decimation: fire every 4th DMA event (~16ms) - // This matches non-SPDIF timing and prevents overwhelming upstream. - if (spdif_callback_threshold > 0) { - spdif_dma_event_count++; + spdif_dma_event_count++; + // Accumulate frames; keep the latest timestamp so the callback reports when the last + // sample left the wire, not the first. + if (frames_sent > 0) { + spdif_pending_timestamp = write_timestamp; + spdif_pending_frames += frames_sent; + } - // Accumulate frames; always keep the latest timestamp so the - // callback reports when the last sample left the wire, not the first. - if (frames_sent > 0) { - spdif_pending_timestamp = write_timestamp; - spdif_pending_frames += frames_sent; - } + bool decimation_reached = (spdif_dma_event_count >= SPDIF_DMA_EVENTS_PER_CALLBACK); + // Partial blocks mark an end-of-stream boundary (silence-padded tail). Fire immediately + // so the back-shifted timestamp isn't overwritten by a later full audio block landing + // in the same decimation window. + bool partial_flush = (real_frames > 0 && real_frames < SPDIF_BLOCK_SAMPLES); - // Fire callback every 4 DMA events, or on timeout if we have pending frames - bool decimation_reached = (spdif_dma_event_count >= SPDIF_DMA_EVENTS_PER_CALLBACK); - bool timeout_flush = - (spdif_pending_frames > 0) && ((millis() - spdif_last_callback_time) >= SPDIF_FLUSH_TIMEOUT_MS); - - if (decimation_reached || timeout_flush) { - if (spdif_pending_frames > 0) { - this->audio_output_callback_(spdif_pending_frames, spdif_pending_timestamp); - spdif_pending_frames = 0; - spdif_last_callback_time = millis(); - } - spdif_dma_event_count = 0; // Reset decimation counter + if (decimation_reached || partial_flush) { + if (spdif_pending_frames > 0) { + this->audio_output_callback_(spdif_pending_frames, spdif_pending_timestamp); + spdif_pending_frames = 0; } + spdif_dma_event_count = 0; } } - - if (this->pause_state_) { - // Pause state is accessed atomically, so thread safe - // Delay so the task yields, then skip transferring audio data - vTaskDelay(pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS)); - continue; + if (lockstep_broken) { + ESP_LOGV(TAG, "Exiting: lockstep desync, restarting task"); + break; } - // Wait half the duration of the data already written to the DMA buffers for new audio data - // The millisecond helper modifies the frames_written variable, so use the microsecond helper and divide by 1000 - uint32_t read_delay = (this->current_stream_info_.frames_to_microseconds(frames_written) / 1000) / 2; + // Always-fill: produce exactly one SPDIF block this iteration. The blocking encoder write + // paces the task at the DMA consumption rate. + uint32_t real_frames_in_block = 0; + bool block_committed = false; + bool partial_write_failure = false; - // In SPDIF mode, if transfer buffer is empty (we're pumping silence), use a very short timeout. - // This ensures we can pump silence fast enough to keep the DMA fed (~250 blocks/sec needed). - // Otherwise the long timeout based on frames_written causes DMA to run dry. - if (transfer_buffer->available() == 0) { - read_delay = SPDIF_EMPTY_READ_DELAY_MS; - } - - size_t bytes_read = transfer_buffer->transfer_data_from_source(pdMS_TO_TICKS(read_delay)); - uint8_t *new_data = transfer_buffer->get_buffer_end() - bytes_read; - - if (bytes_read > 0) { - this->apply_software_volume_(new_data, bytes_read); - this->swap_esp32_mono_samples_(new_data, bytes_read); - } - - if (transfer_buffer->available() == 0) { - // SPDIF Continuous Silence Mode: always output valid SPDIF stream - // When no audio data, write silence-encoded blocks to keep receiver happy - if (this->spdif_encoder_ != nullptr) { - // "Graceful stop" means "drain buffered audio, then stop." In SPDIF - // continuous mode we never actually stop, so once audio is drained - // (we're here), reset the flag to re-enable silence writing and stall - // recovery. Without this, stop_gracefully stays true forever and - // blocks silence output, causing DMA to degrade on auto_clear zeros. - stop_gracefully = false; - - // Track when we entered silence mode - if (this->spdif_silence_start_ == 0) { - this->spdif_silence_start_ = millis(); + if (!this->pause_state_) { + while (real_frames_in_block < SPDIF_BLOCK_SAMPLES) { + if (transfer_buffer->available() == 0) { + size_t bytes_read = transfer_buffer->transfer_data_from_source(read_timeout_ticks); + if (bytes_read == 0) { + break; // No upstream data within the read budget; silence-pad the remainder. + } + uint8_t *new_data = transfer_buffer->get_buffer_end() - bytes_read; + this->apply_software_volume_(new_data, bytes_read); + this->swap_esp32_mono_samples_(new_data, bytes_read); } - // If silence persists past the configured timeout, stop the task - // so components expecting timeout semantics can recover. - if (this->timeout_.has_value()) { - const uint32_t silence_duration = millis() - this->spdif_silence_start_; - if (silence_duration >= this->timeout_.value()) { - ESP_LOGV(TAG, "Silence timeout reached (%" PRIu32 "ms) - stopping speaker", silence_duration); - break; - } - } + const uint32_t frames_still_needed = SPDIF_BLOCK_SAMPLES - real_frames_in_block; + const size_t bytes_still_needed = this->current_stream_info_.frames_to_bytes(frames_still_needed); + const size_t bytes_to_feed = std::min(transfer_buffer->available(), bytes_still_needed); - // First flush any partial block with silence padding (non-blocking to avoid getting stuck). - // IMPORTANT: Credit any partial block frames to frames_written so the audio_output_callback_ - // fires for them. Without this, pending_playback_frames_ in the mixer's SourceSpeaker never - // reaches 0 when a stream ends on a non-192-frame boundary, permanently blocking teardown. - if (this->spdif_encoder_->has_pending_data()) { - uint32_t partial_frames = this->spdif_encoder_->get_pending_frames(); - // Use a tiny timeout to allow DMA queue progress without stalling the task. - esp_err_t flush_err = this->spdif_encoder_->flush_with_silence(pdMS_TO_TICKS(1)); - if (flush_err == ESP_OK && partial_frames > 0) { - frames_written += partial_frames; - } - } - - // CRITICAL: In SPDIF continuous mode, ALWAYS write silence when no audio data. - // We don't check tx_dma_underflow because: - // 1. When DMA runs empty, callbacks stop, so tx_dma_underflow doesn't update - // 2. The non-blocking write handles "DMA full" gracefully (just doesn't write) - // 3. We need continuous output to prevent receiver from losing sync - if (!stop_gracefully) { - uint32_t silence_blocks = 0; - esp_err_t write_err = this->spdif_encoder_->write( - reinterpret_cast(SPDIF_SILENCE_BUFFER), sizeof(SPDIF_SILENCE_BUFFER), pdMS_TO_TICKS(1), - &silence_blocks); // Non-blocking - // Don't count silence as frames_written - it's not real audio - - // Recovery path for a stalled SPDIF TX channel: - // if silence writes repeatedly produce zero blocks AND DMA callbacks have stopped, - // re-prime DMA using preload mode. - const uint32_t ms_since_dma = millis() - spdif_last_dma_event_time; - const bool dma_events_stalled = ms_since_dma >= SPDIF_STALL_NO_DMA_MS; - if (silence_blocks > 0) { - spdif_last_block_progress_time = millis(); - } - const bool long_zero_progress = (millis() - spdif_last_block_progress_time) >= SPDIF_STALL_ZERO_PROGRESS_MS; - if (dma_events_stalled && silence_blocks == 0 && (write_err == ESP_OK || write_err == ESP_ERR_TIMEOUT)) { - spdif_zero_block_streak++; - } else { - spdif_zero_block_streak = 0; - } - - const uint32_t now_ms = millis(); - const bool reprime_cooldown_elapsed = - (spdif_last_reprime_time == 0) || ((now_ms - spdif_last_reprime_time) >= SPDIF_REPRIME_COOLDOWN_MS); - - if ((spdif_zero_block_streak >= 100 || long_zero_progress) && reprime_cooldown_elapsed) { - ESP_LOGV(TAG, "TX appears stalled, attempting DMA re-prime"); - - i2s_channel_disable(this->tx_handle_); - - const i2s_event_callbacks_t null_callbacks = {.on_sent = nullptr}; - i2s_channel_register_event_callback(this->tx_handle_, &null_callbacks, this); - - this->spdif_encoder_->set_preload_mode(true); - uint32_t preload_blocks = 0; - esp_err_t preload_err = this->spdif_encoder_->write( - reinterpret_cast(SPDIF_SILENCE_BUFFER), sizeof(SPDIF_SILENCE_BUFFER), - pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &preload_blocks); - this->spdif_encoder_->set_preload_mode(false); - - xQueueReset(this->i2s_event_queue_); - const i2s_event_callbacks_t callbacks = {.on_sent = i2s_on_sent_cb}; - i2s_channel_register_event_callback(this->tx_handle_, &callbacks, this); - i2s_channel_enable(this->tx_handle_); - - if (preload_err == ESP_OK && preload_blocks > 0) { - tx_dma_underflow = false; - preload_buffers_remaining = preload_blocks; - frames_written = 0; // Stale after channel disable/enable cycle - ESP_LOGV(TAG, "DMA re-prime successful (%" PRIu32 " preload blocks)", preload_blocks); - spdif_last_block_progress_time = now_ms; - } else { - ESP_LOGW(TAG, "DMA re-prime failed (%s, blocks=%" PRIu32 ")", esp_err_to_name(preload_err), - preload_blocks); - } - spdif_last_reprime_time = now_ms; - spdif_zero_block_streak = 0; - } - } - } - - if (stop_gracefully && tx_dma_underflow) { - // In SPDIF continuous mode, don't break on graceful stop during silence - // Keep outputting silence until new audio arrives or explicit COMMAND_STOP - // (handled above which transitions to silence mode rather than breaking) - } - - // In SPDIF mode, use a shorter delay to pump silence faster - // We need ~250 blocks/sec to keep DMA fed, so max 4ms per iteration - vTaskDelay(pdMS_TO_TICKS(SPDIF_SILENCE_LOOP_DELAY_MS)); - } else { - // Have audio data to write - size_t bytes_written = 0; - - // Clear silence timer since we have audio data now - if (this->spdif_silence_start_ != 0) { - uint32_t silence_duration = millis() - this->spdif_silence_start_; - if (silence_duration > 100) { - ESP_LOGV(TAG, "Exiting silence mode after %" PRIu32 "ms, have audio data", silence_duration); - } - this->spdif_silence_start_ = 0; - } - - { uint32_t blocks_sent = 0; - size_t pcm_bytes_consumed = 0; - - // Write audio data to encoder (which writes to DMA) - esp_err_t err = - this->spdif_encoder_->write(transfer_buffer->get_buffer_start(), transfer_buffer->available(), - pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS), &blocks_sent, &pcm_bytes_consumed); - if (err != ESP_OK && err != ESP_ERR_TIMEOUT) { - ESP_LOGW(TAG, "Write failed: %s", esp_err_to_name(err)); + size_t pcm_consumed = 0; + esp_err_t err = this->spdif_encoder_->write(transfer_buffer->get_buffer_start(), bytes_to_feed, + write_timeout_ticks, &blocks_sent, &pcm_consumed); + if (err != ESP_OK) { + // A failed (or timed-out) send leaves an unsent block in the encoder's stitch buffer; + // resuming would credit the next iteration's bytes against an old block. Bail and + // let loop() restart the task with a clean encoder. + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_PARTIAL_WRITE); + partial_write_failure = true; + break; } - // Only consume source bytes that were actually accepted by the encoder. - bytes_written = pcm_bytes_consumed; - - // Update frame accounting based on complete blocks sent (192 frames per block) - if (bytes_written > 0) { - frames_written += blocks_sent * SPDIF_BLOCK_SAMPLES; - transfer_buffer->decrease_buffer_length(bytes_written); - // Audio blocks count as DMA progress for the stall detector. - // Without this, a long uninterrupted audio stream makes the - // progress timer stale, triggering a spurious re-prime the - // instant we transition to silence. - spdif_last_block_progress_time = millis(); + if (pcm_consumed > 0) { + transfer_buffer->decrease_buffer_length(pcm_consumed); + real_frames_in_block += this->current_stream_info_.bytes_to_frames(pcm_consumed); + } + if (blocks_sent > 0) { + block_committed = true; + break; } } } - } - // If we reach here, the while loop exited - either via break or condition became false - // In SPDIF mode, loop exit is expected when: - // 1. Timeout reached (user configured timeout) - // 2. Stream info changed - // Only warn if timeout is "never" since that should never exit - if (!this->timeout_.has_value()) { - ESP_LOGW(TAG, "Unexpected loop exit; set 'timeout: never' to prevent this"); + + if (partial_write_failure) { + break; + } + + if (!block_committed) { + // Pad whatever real audio we managed to feed (if any) with silence to complete one block, + // or emit a full silence block if the encoder is empty. + esp_err_t err = this->spdif_encoder_->flush_with_silence(write_timeout_ticks); + if (err != ESP_OK) { + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_PARTIAL_WRITE); + break; + } + } + + // One block committed to DMA; push exactly one record carrying its real-audio frame count. + // Failure here means the records queue is full, which violates the lockstep invariant. + if (xQueueSendToBack(this->write_records_queue_, &real_frames_in_block, 0) != pdTRUE) { + xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_LOCKSTEP_DESYNC); + break; + } + + // Silence-timeout tracking and graceful-stop reset. + if (real_frames_in_block == 0) { + if (this->spdif_silence_start_ == 0) { + this->spdif_silence_start_ = millis(); + } + + if (this->timeout_.has_value()) { + const uint32_t silence_duration = millis() - this->spdif_silence_start_; + if (silence_duration >= this->timeout_.value()) { + ESP_LOGV(TAG, "Silence timeout reached (%" PRIu32 "ms) - stopping speaker", silence_duration); + break; + } + } + } else if (this->spdif_silence_start_ != 0) { + uint32_t silence_duration = millis() - this->spdif_silence_start_; + if (silence_duration > 100) { + ESP_LOGV(TAG, "Exiting silence mode after %" PRIu32 "ms, have audio data", silence_duration); + } + this->spdif_silence_start_ = 0; + } } } diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp index f34839a3140..27961050e6c 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp @@ -69,6 +69,17 @@ void I2SAudioSpeakerBase::loop() { } if (event_group_bits & SpeakerEventGroupBits::TASK_STOPPING) { ESP_LOGV(TAG, "Stopping"); + // Lockstep-breaking error bits are latched by the task and cleared along with all other bits + // when TASK_STOPPED is processed; log them here, exactly once, as the task winds down. + if (event_group_bits & SpeakerEventGroupBits::ERR_DROPPED_EVENT) { + ESP_LOGE(TAG, "ISR event queue overflow, restarting speaker task to recover timestamp sync"); + } + if (event_group_bits & SpeakerEventGroupBits::ERR_PARTIAL_WRITE) { + ESP_LOGE(TAG, "Partial DMA write broke buffer alignment, restarting speaker task"); + } + if (event_group_bits & SpeakerEventGroupBits::ERR_LOCKSTEP_DESYNC) { + ESP_LOGE(TAG, "Event/record queues desynced, restarting speaker task"); + } xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::TASK_STOPPING); this->state_ = speaker::STATE_STOPPING; } @@ -87,18 +98,11 @@ void I2SAudioSpeakerBase::loop() { this->state_ = speaker::STATE_STOPPED; } - // Log any errors encountered by the task if (event_group_bits & SpeakerEventGroupBits::ERR_ESP_NO_MEM) { ESP_LOGE(TAG, "Not enough memory"); xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::ERR_ESP_NO_MEM); } - // Warn if any playback timestamp events are dropped, which drastically reduces synced playback accuracy - if (event_group_bits & SpeakerEventGroupBits::WARN_DROPPED_EVENT) { - ESP_LOGW(TAG, "Event dropped, synchronized playback accuracy is reduced"); - xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::WARN_DROPPED_EVENT); - } - // Handle the speaker's state switch (this->state_) { case speaker::STATE_STARTING: @@ -271,6 +275,22 @@ esp_err_t I2SAudioSpeakerBase::init_i2s_channel_(const i2s_chan_config_t &chan_c xQueueReset(this->i2s_event_queue_); } + // Lockstep records queue. One record per in-flight DMA buffer; sized to match the I2S event queue + // so a fully-saturated DMA pipeline cannot overflow either side before drain. + if (this->write_records_queue_ == nullptr) { + this->write_records_queue_ = xQueueCreate(event_queue_size, sizeof(uint32_t)); + } else { + xQueueReset(this->write_records_queue_); + } + + if (this->i2s_event_queue_ == nullptr || this->write_records_queue_ == nullptr) { + ESP_LOGE(TAG, "Failed to allocate I2S event queue(s)"); + i2s_del_channel(this->tx_handle_); + this->tx_handle_ = nullptr; + this->parent_->unlock(); + return ESP_ERR_NO_MEM; + } + return ESP_OK; } @@ -293,10 +313,16 @@ bool IRAM_ATTR I2SAudioSpeakerBase::i2s_on_sent_cb(i2s_chan_handle_t handle, i2s I2SAudioSpeakerBase *this_speaker = (I2SAudioSpeakerBase *) user_ctx; if (xQueueIsQueueFullFromISR(this_speaker->i2s_event_queue_)) { - // Queue is full, so discard the oldest event and set the warning flag to inform the user + // Queue is full, so discard the oldest event. Once we drop a completion event, ``i2s_event_queue_`` + // and any per-buffer record queue maintained by the task are permanently desynced, so the task + // must restart to recover. Set both ERR_DROPPED_EVENT (so loop() can log it) and COMMAND_STOP + // (so the task bails immediately, closing the race where loop() could clear the error bit + // before the task observes it). int64_t dummy; xQueueReceiveFromISR(this_speaker->i2s_event_queue_, &dummy, &need_yield1); - xEventGroupSetBitsFromISR(this_speaker->event_group_, SpeakerEventGroupBits::WARN_DROPPED_EVENT, &need_yield2); + xEventGroupSetBitsFromISR(this_speaker->event_group_, + SpeakerEventGroupBits::ERR_DROPPED_EVENT | SpeakerEventGroupBits::COMMAND_STOP, + &need_yield2); } xQueueSendToBackFromISR(this_speaker->i2s_event_queue_, &now, &need_yield3); diff --git a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h index bfde455c755..c57af2775b3 100644 --- a/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +++ b/esphome/components/i2s_audio/speaker/i2s_audio_speaker.h @@ -35,7 +35,11 @@ enum SpeakerEventGroupBits : uint32_t { ERR_ESP_NO_MEM = (1 << 19), - WARN_DROPPED_EVENT = (1 << 20), + ERR_DROPPED_EVENT = (1 << 20), // ISR overflowed the event queue, dropping a completion event + ERR_PARTIAL_WRITE = (1 << 21), // a DMA write returned fewer bytes than requested (or the encoder + // failed to commit a complete block), which breaks the lockstep + // invariant for every subsequent event + ERR_LOCKSTEP_DESYNC = (1 << 22), // i2s_event_queue_ and write_records_queue_ fell out of sync ALL_BITS = 0x00FFFFFF, // All valid FreeRTOS event group bits }; @@ -141,7 +145,9 @@ class I2SAudioSpeakerBase : public I2SAudioOut, public speaker::Speaker, public TaskHandle_t speaker_task_handle_{nullptr}; EventGroupHandle_t event_group_{nullptr}; + // Lockstepped DMA buffer queues: i2s_event is outgoing, write_records is incoming QueueHandle_t i2s_event_queue_{nullptr}; + QueueHandle_t write_records_queue_{nullptr}; std::weak_ptr audio_ring_buffer_; diff --git a/esphome/components/i2s_audio/speaker/spdif_encoder.cpp b/esphome/components/i2s_audio/speaker/spdif_encoder.cpp index a853f934bb2..42a72346ccb 100644 --- a/esphome/components/i2s_audio/speaker/spdif_encoder.cpp +++ b/esphome/components/i2s_audio/speaker/spdif_encoder.cpp @@ -358,25 +358,15 @@ HOT esp_err_t SPDIFEncoder::write(const uint8_t *src, size_t size, TickType_t ti } esp_err_t SPDIFEncoder::flush_with_silence(TickType_t ticks_to_wait) { - // First, send any pending complete block from a previous failed send - if (this->spdif_block_ptr_ >= &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { - esp_err_t err = this->send_block_(ticks_to_wait); - if (err != ESP_OK) { - return err; + // If a complete block is already pending (from a previous failed send), emit just that block. + // Otherwise pad the partial block with silence (or generate a full silence block if empty) + // and send. Always emits exactly one block on success. + if (this->spdif_block_ptr_ < &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + static const uint8_t SILENCE[2] = {0, 0}; + while (this->spdif_block_ptr_ < &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { + this->encode_sample_(SILENCE); } } - - if (!this->has_pending_data()) { - return ESP_OK; // Nothing to flush - } - - // Encode silence (zeros) until the block is complete - static const uint8_t SILENCE[2] = {0, 0}; - - while (this->spdif_block_ptr_ < &this->spdif_block_buf_[SPDIF_BLOCK_SIZE_U32]) { - this->encode_sample_(SILENCE); - } - return this->send_block_(ticks_to_wait); } diff --git a/esphome/components/i2s_audio/speaker/spdif_encoder.h b/esphome/components/i2s_audio/speaker/spdif_encoder.h index 85166434329..8c5e0688419 100644 --- a/esphome/components/i2s_audio/speaker/spdif_encoder.h +++ b/esphome/components/i2s_audio/speaker/spdif_encoder.h @@ -85,9 +85,10 @@ class SPDIFEncoder { /// @brief Check if there is a partial block pending bool has_pending_data() const { return this->spdif_block_ptr_ != this->spdif_block_buf_.get(); } - /// @brief Flush any pending partial block by padding with silence and sending + /// @brief Emit one complete SPDIF block: pad any pending partial block with silence and send, + /// or send a full silence block if nothing is pending. Always produces exactly one block on success. /// @param ticks_to_wait Timeout for blocking writes - /// @return esp_err_t as returned from the callback, or ESP_OK if nothing to flush + /// @return esp_err_t as returned from the callback esp_err_t flush_with_silence(TickType_t ticks_to_wait); /// @brief Reset the SPDIF block buffer and position tracking, discarding any partial block From 3abf2c99a2421827980fd5454458de295efab2ae Mon Sep 17 00:00:00 2001 From: rwrozelle Date: Fri, 8 May 2026 17:35:47 -0400 Subject: [PATCH 18/52] [openthread] add coroutine-with-priority COMMUNICATION (#16318) --- esphome/components/openthread/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/components/openthread/__init__.py b/esphome/components/openthread/__init__.py index 21373b77dfb..bc1e91d6dac 100644 --- a/esphome/components/openthread/__init__.py +++ b/esphome/components/openthread/__init__.py @@ -21,7 +21,12 @@ from esphome.const import ( CONF_USE_ADDRESS, PLATFORM_ESP32, ) -from esphome.core import CORE, TimePeriodMilliseconds +from esphome.core import ( + CORE, + CoroPriority, + TimePeriodMilliseconds, + coroutine_with_priority, +) import esphome.final_validate as fv from esphome.types import ConfigType @@ -223,6 +228,7 @@ def _final_validate(_): FINAL_VALIDATE_SCHEMA = _final_validate +@coroutine_with_priority(CoroPriority.COMMUNICATION) async def to_code(config): # Re-enable openthread IDF component (excluded by default) include_builtin_idf_component("openthread") From 136525136565860489670ff9ca6c3ccbd0bc81e7 Mon Sep 17 00:00:00 2001 From: Mat931 <49403702+Mat931@users.noreply.github.com> Date: Fri, 8 May 2026 21:36:06 +0000 Subject: [PATCH 19/52] [ota] Add bootloader update functionality to ota component (#16238) Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: J. Nick Koston --- esphome/__main__.py | 66 +++++-- .../components/esphome/ota/ota_esphome.cpp | 17 +- esphome/components/ota/ota_backend.h | 3 + .../components/ota/ota_backend_esp_idf.cpp | 34 +++- esphome/components/ota/ota_backend_esp_idf.h | 13 ++ .../components/ota/ota_bootloader_esp_idf.cpp | 133 +++++++++++++ .../components/ota/ota_partitions_esp_idf.cpp | 53 +++--- esphome/core/__init__.py | 6 + esphome/espota2.py | 32 +++- tests/unit_tests/test_core.py | 17 ++ tests/unit_tests/test_espota2.py | 68 ++++++- tests/unit_tests/test_main.py | 179 +++++++++++++++++- 12 files changed, 570 insertions(+), 51 deletions(-) create mode 100644 esphome/components/ota/ota_bootloader_esp_idf.cpp diff --git a/esphome/__main__.py b/esphome/__main__.py index 825a502dbf3..c1451c5fafd 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -1125,11 +1125,18 @@ def upload_program( # MQTT and MQTTIP are also OTA paths; MQTTIP gets resolved to a real IP later by # _resolve_network_devices(). Only SERIAL and BOOTSEL are non-OTA upload paths. - if port_type in (PortType.SERIAL, PortType.BOOTSEL) and getattr( - args, "partition_table", False + is_partition_table = getattr(args, "partition_table", False) + is_bootloader = getattr(args, "bootloader", False) + if is_partition_table and is_bootloader: + raise EsphomeError( + "The options --partition-table and --bootloader can't be used together." + ) + option_string = "--partition-table" if is_partition_table else "--bootloader" + if port_type in (PortType.SERIAL, PortType.BOOTSEL) and ( + is_partition_table or is_bootloader ): raise EsphomeError( - "The option --partition-table can only be used for Over The Air updates." + f"The option {option_string} can only be used for Over The Air updates." ) if port_type == PortType.BOOTSEL: @@ -1158,9 +1165,9 @@ def upload_program( network_devices = _resolve_network_devices(devices, config, args) if chosen_platform == CONF_WEB_SERVER: - if getattr(args, "partition_table", False): + if is_partition_table or is_bootloader: raise EsphomeError( - "--partition-table is only supported with the esphome OTA platform; " + f"{option_string} is only supported with the esphome OTA platform; " "the web_server OTA path can only update the firmware image." ) binary = CORE.firmware_bin @@ -1228,25 +1235,34 @@ def _upload_via_native_api( remote_port = int(ota_conf[CONF_PORT]) password = ota_conf.get(CONF_PASSWORD) + def check_partition_access(option_string: str) -> None: + if not ota_conf.get("allow_partition_access"): + raise EsphomeError( + f"The option {option_string} requires 'allow_partition_access: true' on the " + "esphome OTA platform in the device's YAML configuration. Add it, recompile, " + f"flash a build with the option enabled, and then retry {option_string}." + ) + binary = CORE.firmware_bin ota_type = espota2.OTA_TYPE_UPDATE_APP if getattr(args, "partition_table", False): # Fail fast if the resolved ESPHome OTA config does not enable allow_partition_access. # The device-side handshake also rejects this with "Device only supports app updates", # but checking here surfaces the misconfiguration before opening a network connection. - if not ota_conf.get("allow_partition_access"): - raise EsphomeError( - "The option --partition-table requires 'allow_partition_access: true' on the " - "esphome OTA platform in the device's YAML configuration. Add it, recompile, " - "flash a build with the option enabled, and then retry --partition-table." - ) + check_partition_access("--partition-table") binary = CORE.partition_table_bin ota_type = espota2.OTA_TYPE_UPDATE_PARTITION_TABLE + elif getattr(args, "bootloader", False): + check_partition_access("--bootloader") + binary = CORE.bootloader_bin + ota_type = espota2.OTA_TYPE_UPDATE_BOOTLOADER if getattr(args, "file", None) is not None: binary = Path(args.file) if ota_type == espota2.OTA_TYPE_UPDATE_PARTITION_TABLE: _validate_partition_table_binary(binary) + if ota_type == espota2.OTA_TYPE_UPDATE_BOOTLOADER: + _validate_bootloader_binary(binary) return espota2.run_ota(network_devices, remote_port, password, binary, ota_type) @@ -1281,6 +1297,7 @@ def _upload_via_web_server( _PARTITION_TABLE_MAX_LEN = 0xC00 _ESP_PARTITION_MAGIC = 0x50AA _ESP_PARTITION_MAGIC_MD5 = 0xEBEB +_ESP_IMAGE_HEADER_MAGIC = 0xE9 def _validate_partition_table_binary(binary: Path) -> None: @@ -1326,6 +1343,28 @@ def _validate_partition_table_binary(binary: Path) -> None: ) +def _validate_bootloader_binary(binary: Path) -> None: + """Validate that ``binary`` looks like an ESP32 bootloader image.""" + try: + data = binary.read_bytes() + except OSError as err: + raise EsphomeError(f"Cannot read bootloader file '{binary}': {err}") from err + + if not data: + raise EsphomeError( + f"Bootloader file '{binary}' is empty. " + "This file does not look like an ESP32 bootloader." + ) + + first_magic = data[0] + if first_magic != _ESP_IMAGE_HEADER_MAGIC: + raise EsphomeError( + f"Bootloader file '{binary}' does not start with the expected " + f"image header magic 0x{_ESP_IMAGE_HEADER_MAGIC:02X} (got 0x{first_magic:02X}). " + "This file does not look like an ESP32 bootloader." + ) + + def show_logs(config: ConfigType, args: ArgsProtocol, devices: list[str]) -> int | None: try: module = importlib.import_module("esphome.components." + CORE.target_platform) @@ -2009,6 +2048,11 @@ def parse_args(argv): help="Upload as partition table (OTA).", action="store_true", ) + parser_upload.add_argument( + "--bootloader", + help="Upload as bootloader (OTA).", + action="store_true", + ) parser_logs = subparsers.add_parser( "logs", diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index 5d3deca4896..843028fc974 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -125,8 +125,11 @@ void ESPHomeOTAComponent::dump_config() { it = esp_partition_next(it); } esp_partition_iterator_release(it); -#endif -#endif + esp_bootloader_desc_t bootloader_desc; + esp_err_t err = esp_ota_get_bootloader_description(nullptr, &bootloader_desc); + ESP_LOGCONFIG(TAG, " Bootloader: ESP-IDF %s", (err == ESP_OK) ? bootloader_desc.idf_ver : "version unknown"); +#endif // USE_ESP32 +#endif // USE_OTA_PARTITIONS } void ESPHomeOTAComponent::loop() { @@ -336,7 +339,6 @@ void ESPHomeOTAComponent::handle_data_() { /// wakeable_delay() in read(); /// write() always returns immediately ota::OTAResponseTypes error_code = ota::OTA_RESPONSE_ERROR_UNKNOWN; - bool update_started = false; size_t total = 0; uint32_t last_progress = 0; uint32_t last_data_ms = 0; @@ -399,7 +401,6 @@ void ESPHomeOTAComponent::handle_data_() { error_code = this->backend_->begin(ota_size, ota_type); if (error_code != ota::OTA_RESPONSE_OK) goto error; // NOLINT(cppcoreguidelines-avoid-goto) - update_started = true; // Acknowledge prepare OK - 1 byte this->write_byte_(ota::OTA_RESPONSE_UPDATE_PREPARE_OK); @@ -510,8 +511,12 @@ void ESPHomeOTAComponent::handle_data_() { error: this->write_byte_(static_cast(error_code)); - // Abort backend before cleanup - cleanup_connection_() destroys the backend - if (this->backend_ != nullptr && update_started) { + // Abort backend before cleanup - cleanup_connection_() destroys the backend. + // Always call abort() unconditionally: backends register external partitions before + // esp_ota_begin (partition table / bootloader paths), and abort() is responsible for + // releasing those even if begin() failed before an OTA handle was opened. The IDF + // backend's esp_ota_abort(0) is documented as harmless. + if (this->backend_ != nullptr) { this->backend_->abort(); } diff --git a/esphome/components/ota/ota_backend.h b/esphome/components/ota/ota_backend.h index 5888a8e12d4..de236c19513 100644 --- a/esphome/components/ota/ota_backend.h +++ b/esphome/components/ota/ota_backend.h @@ -44,6 +44,8 @@ enum OTAResponseTypes { OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE = 0x8E, OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY = 0x8F, OTA_RESPONSE_ERROR_PARTITION_TABLE_UPDATE = 0x90, + OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY = 0x91, + OTA_RESPONSE_ERROR_BOOTLOADER_UPDATE = 0x92, OTA_RESPONSE_ERROR_UNKNOWN = 0xFF, }; @@ -58,6 +60,7 @@ enum OTAState { enum OTAType : uint8_t { OTA_TYPE_UPDATE_APP = 0x00, OTA_TYPE_UPDATE_PARTITION_TABLE = 0x01, + OTA_TYPE_UPDATE_BOOTLOADER = 0x02, }; /** Listener interface for OTA state changes. diff --git a/esphome/components/ota/ota_backend_esp_idf.cpp b/esphome/components/ota/ota_backend_esp_idf.cpp index 50a0988ba21..f391c1791aa 100644 --- a/esphome/components/ota/ota_backend_esp_idf.cpp +++ b/esphome/components/ota/ota_backend_esp_idf.cpp @@ -31,7 +31,13 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size, ota::OTAType ota_type) this->md5_.init(); return OTA_RESPONSE_OK; } - if (this->ota_type_ != ota::OTA_TYPE_UPDATE_APP) { + if (this->ota_type_ == ota::OTA_TYPE_UPDATE_BOOTLOADER) { + OTAResponseTypes result = this->prepare_bootloader_update_(image_size); + if (result != OTA_RESPONSE_OK) { + return result; + } + } + if (!this->is_app_or_bootloader_update_()) { return OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE; } #else @@ -55,6 +61,7 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size, ota::OTAType ota_type) esp_err_t err = esp_ota_begin(this->partition_, image_size, &this->update_handle_); if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_begin failed (err=0x%X)", err); esp_ota_abort(this->update_handle_); this->update_handle_ = 0; if (err == ESP_ERR_INVALID_SIZE) { @@ -64,6 +71,14 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size, ota::OTAType ota_type) } return OTA_RESPONSE_ERROR_UNKNOWN; } +#ifdef USE_OTA_PARTITIONS + if (this->ota_type_ == ota::OTA_TYPE_UPDATE_BOOTLOADER) { + OTAResponseTypes result = this->setup_bootloader_staging_(); + if (result != OTA_RESPONSE_OK) { + return result; + } + } +#endif this->md5_.init(); return OTA_RESPONSE_OK; } @@ -85,13 +100,14 @@ OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) { this->md5_.add(data, len); return OTA_RESPONSE_OK; } - if (this->ota_type_ != ota::OTA_TYPE_UPDATE_APP) { + if (!this->is_app_or_bootloader_update_()) { return OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE; } #endif esp_err_t err = esp_ota_write(this->update_handle_, data, len); this->md5_.add(data, len); if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_write failed (err=0x%X)", err); if (err == ESP_ERR_OTA_VALIDATE_FAILED) { return OTA_RESPONSE_ERROR_MAGIC; } else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) { @@ -114,12 +130,20 @@ OTAResponseTypes IDFOTABackend::end() { if (this->ota_type_ == ota::OTA_TYPE_UPDATE_PARTITION_TABLE) { return this->update_partition_table(); } - if (this->ota_type_ != ota::OTA_TYPE_UPDATE_APP) { + if (!this->is_app_or_bootloader_update_()) { return OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE; } #endif esp_err_t err = esp_ota_end(this->update_handle_); this->update_handle_ = 0; + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_end failed (err=0x%X)", err); + } +#ifdef USE_OTA_PARTITIONS + if (this->ota_type_ == ota::OTA_TYPE_UPDATE_BOOTLOADER) { + return this->finalize_bootloader_update_(err); + } +#endif if (err == ESP_OK) { err = esp_ota_set_boot_partition(this->partition_); if (err == ESP_OK) { @@ -146,6 +170,10 @@ void IDFOTABackend::abort() { esp_partition_deregister_external(this->partition_table_part_); this->partition_table_part_ = nullptr; } + if (this->bootloader_part_ != nullptr) { + esp_partition_deregister_external(this->bootloader_part_); + this->bootloader_part_ = nullptr; + } #endif // esp_ota_abort with handle 0 returns ESP_ERR_INVALID_ARG harmlessly, so this is safe whether // or not an update is in flight. diff --git a/esphome/components/ota/ota_backend_esp_idf.h b/esphome/components/ota/ota_backend_esp_idf.h index 54fdd24f934..73dd685df69 100644 --- a/esphome/components/ota/ota_backend_esp_idf.h +++ b/esphome/components/ota/ota_backend_esp_idf.h @@ -39,6 +39,18 @@ class IDFOTABackend final { OTAResponseTypes validate_new_partition_table_(uint32_t running_app_offset, size_t running_app_size, PartitionTablePlan &plan); OTAResponseTypes update_partition_table(); + OTAResponseTypes register_and_validate_partition_table_part_(); + // Defined in ota_bootloader_esp_idf.cpp: + OTAResponseTypes register_and_validate_bootloader_part_(); + OTAResponseTypes prepare_bootloader_update_(size_t image_size); + OTAResponseTypes setup_bootloader_staging_(); + OTAResponseTypes finalize_bootloader_update_(esp_err_t ota_end_err); + + // The OTA types that flow through esp_ota_begin/write/end. Partition-table updates take a + // separate code path that buffers the table in RAM and never touches the OTA handle. + bool is_app_or_bootloader_update_() const { + return this->ota_type_ == ota::OTA_TYPE_UPDATE_APP || this->ota_type_ == ota::OTA_TYPE_UPDATE_BOOTLOADER; + } #endif private: @@ -55,6 +67,7 @@ class IDFOTABackend final { size_t buf_written_{0}; size_t image_size_{0}; const esp_partition_t *partition_table_part_{nullptr}; + const esp_partition_t *bootloader_part_{nullptr}; ota::OTAType ota_type_{ota::OTA_TYPE_UPDATE_APP}; #endif }; diff --git a/esphome/components/ota/ota_bootloader_esp_idf.cpp b/esphome/components/ota/ota_bootloader_esp_idf.cpp new file mode 100644 index 00000000000..062e4d0811d --- /dev/null +++ b/esphome/components/ota/ota_bootloader_esp_idf.cpp @@ -0,0 +1,133 @@ +#ifdef USE_ESP32 +#include "ota_backend_esp_idf.h" + +#include "esphome/core/defines.h" + +#ifdef USE_OTA_PARTITIONS +#include "esphome/core/log.h" + +#include +#include + +namespace esphome::ota { + +static const char *const TAG = "ota.idf"; + +OTAResponseTypes IDFOTABackend::register_and_validate_bootloader_part_() { + // Register the bootloader partition + esp_err_t err = esp_partition_register_external(nullptr, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, + "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, + ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &this->bootloader_part_); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_partition_register_external failed (bootloader) (err=0x%X)", err); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + + // Verify existing bootloader to make sure ESP_PRIMARY_BOOTLOADER_OFFSET is correct + esp_image_metadata_t data = {}; + const esp_partition_pos_t part_pos = { + .offset = this->bootloader_part_->address, + .size = this->bootloader_part_->size, + }; + err = esp_image_verify(ESP_IMAGE_VERIFY, &part_pos, &data); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_image_verify failed (existing bootloader) (err=0x%X)", err); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + return OTA_RESPONSE_OK; +} + +// Pre-esp_ota_begin: enforce size limit, register/verify the existing bootloader, and validate the +// partition table to confirm the bootloader region is at the expected offset (and therefore the +// expected size). The partition table registration is released here; abort() cleans up the +// bootloader registration if any later step fails. +OTAResponseTypes IDFOTABackend::prepare_bootloader_update_(size_t image_size) { + if (image_size > ESP_BOOTLOADER_SIZE) { + ESP_LOGE(TAG, "Length of received data exceeds the available bootloader size: expected <=%zu bytes, got %zu", + ESP_BOOTLOADER_SIZE, image_size); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + OTAResponseTypes result = this->register_and_validate_bootloader_part_(); + if (result != OTA_RESPONSE_OK) { + return result; + } + result = this->register_and_validate_partition_table_part_(); + if (result != OTA_RESPONSE_OK) { + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + esp_partition_deregister_external(this->partition_table_part_); + this->partition_table_part_ = nullptr; + return OTA_RESPONSE_OK; +} + +// Post-esp_ota_begin: verify the staging app partition is large enough, erase it, and redirect the +// final write target to the bootloader partition. esp_ota_set_final_partition is called with +// `restore_old_data=false` because we erased the staging region in advance. +OTAResponseTypes IDFOTABackend::setup_bootloader_staging_() { + if (this->partition_->size < this->bootloader_part_->size) { + ESP_LOGE(TAG, "Staging partition too small"); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + // Erase full size of the bootloader partition in the staging partition + // to avoid copying old data to the bootloader partition later + esp_err_t err = esp_partition_erase_range(this->partition_, 0, this->bootloader_part_->size); + if (err != ESP_OK) { + ESP_LOGW(TAG, "esp_partition_erase_range failed (err=0x%X)", err); + // No critical error, don't return + } + err = esp_ota_set_final_partition(this->update_handle_, this->bootloader_part_, false); + if (err != ESP_OK) { + esp_ota_abort(this->update_handle_); + this->update_handle_ = 0; + ESP_LOGE(TAG, "esp_ota_set_final_partition failed (err=0x%X)", err); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + return OTA_RESPONSE_OK; +} + +// After esp_ota_end: copy the staged image into the bootloader partition. esp_partition_copy is +// the only window in which a power loss can render the device unbootable; everything before this +// point either preserves the existing bootloader or fails harmlessly. After a successful copy the +// first sector of staging is wiped so the device can't accidentally boot from it, and the +// bootloader partition is deregistered. +OTAResponseTypes IDFOTABackend::finalize_bootloader_update_(esp_err_t ota_end_err) { + if (ota_end_err != ESP_OK) { + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } + esp_bootloader_desc_t bootloader_desc; + esp_err_t desc_err = esp_ota_get_bootloader_description(this->partition_, &bootloader_desc); +#ifdef USE_ESP32_SRAM1_AS_IRAM + if (desc_err != ESP_OK) { + ESP_LOGE(TAG, "New bootloader does not support SRAM1 as IRAM"); + return OTA_RESPONSE_ERROR_BOOTLOADER_VERIFY; + } +#endif + ESP_LOGE(TAG, "Starting bootloader update.\n" + " DO NOT REMOVE POWER until the update completes successfully.\n" + " Loss of power during this operation may render the device\n" + " unable to boot until it is recovered via a serial flash."); + esp_err_t err = esp_partition_copy(this->bootloader_part_, 0, this->partition_, 0, this->bootloader_part_->size); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_partition_copy failed (err=0x%X)", err); + // Only if esp_partition_copy failed there's a chance of the device being unbootable + return OTA_RESPONSE_ERROR_BOOTLOADER_UPDATE; + } + ESP_LOGI(TAG, + "Successfully installed the new bootloader\n" + " ESP-IDF %s", + (desc_err == ESP_OK) ? bootloader_desc.idf_ver : "version unknown"); + // Wipe first sector of staging partition to make sure the device can't boot from it + err = esp_partition_erase_range(this->partition_, 0, this->partition_->erase_size); + if (err != ESP_OK) { + ESP_LOGW(TAG, "esp_partition_erase_range failed (err=0x%X)", err); + // No critical error, don't return + } + esp_partition_deregister_external(this->bootloader_part_); + this->bootloader_part_ = nullptr; + return OTA_RESPONSE_OK; +} + +} // namespace esphome::ota + +#endif // USE_OTA_PARTITIONS +#endif // USE_ESP32 diff --git a/esphome/components/ota/ota_partitions_esp_idf.cpp b/esphome/components/ota/ota_partitions_esp_idf.cpp index f7fd529986d..f91e88bde0a 100644 --- a/esphome/components/ota/ota_partitions_esp_idf.cpp +++ b/esphome/components/ota/ota_partitions_esp_idf.cpp @@ -45,32 +45,14 @@ static const esp_partition_t *find_app_partition_at(uint32_t address, size_t min // can write to it; abort() releases it on error. OTAResponseTypes IDFOTABackend::validate_new_partition_table_(uint32_t running_app_offset, size_t running_app_size, PartitionTablePlan &plan) { - esp_err_t err = esp_partition_register_external( - nullptr, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", - ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &this->partition_table_part_); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_partition_register_external failed (err=0x%X)", err); - return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; + OTAResponseTypes validate_result = this->register_and_validate_partition_table_part_(); + if (validate_result != OTA_RESPONSE_OK) { + return validate_result; } int num_partitions = 0; - const esp_partition_info_t *existing_partition_table = nullptr; - esp_partition_mmap_handle_t partition_table_map; - err = esp_partition_mmap(this->partition_table_part_, 0, ESP_PARTITION_TABLE_MAX_LEN, ESP_PARTITION_MMAP_DATA, - reinterpret_cast(&existing_partition_table), &partition_table_map); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_partition_mmap failed (err=0x%X)", err); - return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; - } - err = esp_partition_table_verify(existing_partition_table, true, &num_partitions); - esp_partition_munmap(partition_table_map); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_partition_table_verify failed (existing partition table) (err=0x%X)", err); - return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; - } - const esp_partition_info_t *new_partition_table = reinterpret_cast(this->buf_); - err = esp_partition_table_verify(new_partition_table, true, &num_partitions); + esp_err_t err = esp_partition_table_verify(new_partition_table, true, &num_partitions); if (err != ESP_OK) { ESP_LOGE(TAG, "esp_partition_table_verify failed (new partition table) (err=0x%X)", err); return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; @@ -288,6 +270,33 @@ OTAResponseTypes IDFOTABackend::update_partition_table() { return OTA_RESPONSE_OK; } +OTAResponseTypes IDFOTABackend::register_and_validate_partition_table_part_() { + esp_err_t err = esp_partition_register_external( + nullptr, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", + ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &this->partition_table_part_); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_partition_register_external failed (partition table) (err=0x%X)", err); + return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; + } + + int num_partitions = 0; + const esp_partition_info_t *existing_partition_table = nullptr; + esp_partition_mmap_handle_t partition_table_map; + err = esp_partition_mmap(this->partition_table_part_, 0, ESP_PARTITION_TABLE_MAX_LEN, ESP_PARTITION_MMAP_DATA, + reinterpret_cast(&existing_partition_table), &partition_table_map); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_partition_mmap failed (partition table) (err=0x%X)", err); + return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; + } + err = esp_partition_table_verify(existing_partition_table, true, &num_partitions); + esp_partition_munmap(partition_table_map); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_partition_table_verify failed (existing partition table) (err=0x%X)", err); + return OTA_RESPONSE_ERROR_PARTITION_TABLE_VERIFY; + } + return OTA_RESPONSE_OK; +} + // Process-scoped cache. Cannot be a backend member: backends are per-connection but the cache // must outlive a connection that called esp_partition_unload_all(), after which // esp_ota_get_running_partition() no longer returns valid data. diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index 94a48dd31b0..0cc207aa543 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -790,6 +790,12 @@ class EsphomeCore: ) return self.relative_pioenvs_path(self.name, "partitions.bin") + @property + def bootloader_bin(self) -> Path: + if self.data.get(KEY_NATIVE_IDF): + return self.relative_build_path("build", "bootloader", "bootloader.bin") + return self.relative_pioenvs_path(self.name, "bootloader.bin") + @property def target_platform(self): return self.data[KEY_CORE][KEY_TARGET_PLATFORM] diff --git a/esphome/espota2.py b/esphome/espota2.py index b2a1fd2a40a..576b1c6b2da 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -17,6 +17,7 @@ from esphome.helpers import ProgressBar, resolve_ip_address OTA_TYPE_UPDATE_APP = 0x00 OTA_TYPE_UPDATE_PARTITION_TABLE = 0x01 +OTA_TYPE_UPDATE_BOOTLOADER = 0x02 RESPONSE_OK = 0x00 RESPONSE_REQUEST_AUTH = 0x01 @@ -49,6 +50,8 @@ RESPONSE_ERROR_SIGNATURE_INVALID = 0x8D RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE = 0x8E RESPONSE_ERROR_PARTITION_TABLE_VERIFY = 0x8F RESPONSE_ERROR_PARTITION_TABLE_UPDATE = 0x90 +RESPONSE_ERROR_BOOTLOADER_VERIFY = 0x91 +RESPONSE_ERROR_BOOTLOADER_UPDATE = 0x92 RESPONSE_ERROR_UNKNOWN = 0xFF OTA_VERSION_1_0 = 1 @@ -66,7 +69,7 @@ SERVER_FEATURE_SUPPORTS_PARTITION_ACCESS = 0x02 # updates extend this set. Anything outside the set is rejected up front so callers # of perform_ota/run_ota get a clear error instead of a post-auth 0x8E from the device. _SUPPORTED_OTA_TYPES: frozenset[int] = frozenset( - {OTA_TYPE_UPDATE_APP, OTA_TYPE_UPDATE_PARTITION_TABLE} + {OTA_TYPE_UPDATE_APP, OTA_TYPE_UPDATE_PARTITION_TABLE, OTA_TYPE_UPDATE_BOOTLOADER} ) UPLOAD_BLOCK_SIZE = 8192 @@ -143,6 +146,16 @@ _ERROR_MESSAGES: dict[int, str] = { "the partition table update without rebooting the device. If the device " "fails to boot, recover it via a serial flash." ), + RESPONSE_ERROR_BOOTLOADER_VERIFY: ( + "The bootloader update could not be verified. No changes were " + "made to the bootloader. Check the logs for more information and retry." + ), + RESPONSE_ERROR_BOOTLOADER_UPDATE: ( + "An error occurred while updating the bootloader. The device is now " + "in a degraded state and may not be able to boot. Open the logs and retry " + "the bootloader update without rebooting the device. If the device " + "fails to boot, recover it via a serial flash." + ), RESPONSE_ERROR_UNKNOWN: "Unknown error from ESP", } @@ -325,15 +338,24 @@ def perform_ota( # Any non-app OTA type requires the extended protocol and the # partition-access server feature. Reject up front so the user gets # a clear capability error instead of a post-auth 0x8E from the device. + flag_name = { + OTA_TYPE_UPDATE_PARTITION_TABLE: "--partition-table", + OTA_TYPE_UPDATE_BOOTLOADER: "--bootloader", + }.get(ota_type, f"OTA type 0x{ota_type:02X}") if not extended_proto: raise OTAError( - f"Device does not support extended OTA protocol; " - f"OTA type 0x{ota_type:02X} requires it" + f"Device does not support the extended OTA protocol that " + f"{flag_name} requires. The running firmware is too old; " + f"recompile and upload a current ESPHome firmware via a " + f"regular OTA (without {flag_name}), then retry." ) if not (features & SERVER_FEATURE_SUPPORTS_PARTITION_ACCESS): raise OTAError( - f"Device does not support partition access; " - f"OTA type 0x{ota_type:02X} cannot be used" + f"The running firmware was built without " + f"'allow_partition_access: true', so {flag_name} cannot be " + f"used. Add the option to the esphome OTA platform in your " + f"YAML, recompile and upload (without {flag_name}), then " + f"retry {flag_name}." ) if features & SERVER_FEATURE_SUPPORTS_COMPRESSION: diff --git a/tests/unit_tests/test_core.py b/tests/unit_tests/test_core.py index 22be59653aa..9dc37918ae9 100644 --- a/tests/unit_tests/test_core.py +++ b/tests/unit_tests/test_core.py @@ -853,6 +853,23 @@ class TestEsphomeCore: target.testing_ensure_platform_registered("sensor") assert target.platform_counts["sensor"] == 3 + def test_bootloader_bin__native_idf(self, target): + """Native ESP-IDF builds emit the bootloader under build/bootloader/bootloader.bin.""" + target.data[const.KEY_NATIVE_IDF] = True + + assert target.bootloader_bin == Path( + "foo/build/build/bootloader/bootloader.bin" + ) + + def test_bootloader_bin__platformio(self, target): + """For PlatformIO builds bootloader.bin lives in the env-specific .pioenvs directory.""" + target.name = "test-device" + target.data[const.KEY_NATIVE_IDF] = False + + assert target.bootloader_bin == Path( + "foo/build/.pioenvs/test-device/bootloader.bin" + ) + def test_add_library__extracts_short_name_from_path(self, target): """Test add_library extracts short name from library paths like owner/lib.""" target.data[const.KEY_CORE] = { diff --git a/tests/unit_tests/test_espota2.py b/tests/unit_tests/test_espota2.py index 2cad1d2ec81..b22ad461132 100644 --- a/tests/unit_tests/test_espota2.py +++ b/tests/unit_tests/test_espota2.py @@ -201,6 +201,14 @@ def test_receive_exactly_socket_error(mock_socket: Mock) -> None: espota2.RESPONSE_ERROR_PARTITION_TABLE_UPDATE, "Error: An error occurred while updating the partition table", ), + ( + espota2.RESPONSE_ERROR_BOOTLOADER_VERIFY, + "Error: The bootloader update could not be verified", + ), + ( + espota2.RESPONSE_ERROR_BOOTLOADER_UPDATE, + "Error: An error occurred while updating the bootloader", + ), (espota2.RESPONSE_ERROR_UNKNOWN, "Unknown error from ESP"), ], ) @@ -992,7 +1000,8 @@ def test_perform_ota_non_app_type_requires_extended_protocol( mock_socket.recv.side_effect = recv_responses with pytest.raises( - espota2.OTAError, match="Device does not support extended OTA protocol" + espota2.OTAError, + match="Device does not support the extended OTA protocol", ): espota2.perform_ota( mock_socket, @@ -1026,7 +1035,8 @@ def test_perform_ota_non_app_type_requires_partition_access( mock_socket.recv.side_effect = recv_responses with pytest.raises( - espota2.OTAError, match="Device does not support partition access" + espota2.OTAError, + match=(r"running firmware was built without 'allow_partition_access: true'"), ): espota2.perform_ota( mock_socket, @@ -1037,6 +1047,60 @@ def test_perform_ota_non_app_type_requires_partition_access( ) +@pytest.mark.usefixtures("mock_time") +def test_perform_ota_partition_access_error_names_bootloader_flag( + mock_socket: Mock, mock_file: io.BytesIO +) -> None: + """Bootloader OTA against a stale device must point at the --bootloader flag.""" + recv_responses = [ + bytes([espota2.RESPONSE_OK]), + bytes([espota2.OTA_VERSION_2_0]), + bytes([espota2.RESPONSE_FEATURE_FLAGS]), + bytes([0]), # No partition access + ] + + mock_socket.recv.side_effect = recv_responses + + with pytest.raises( + espota2.OTAError, + match=r"--bootloader.*recompile and upload.*--bootloader.*retry --bootloader", + ): + espota2.perform_ota( + mock_socket, + "testpass", + mock_file, + "test.bin", + espota2.OTA_TYPE_UPDATE_BOOTLOADER, + ) + + +@pytest.mark.usefixtures("mock_time") +def test_perform_ota_partition_access_error_names_partition_table_flag( + mock_socket: Mock, mock_file: io.BytesIO +) -> None: + """Partition-table OTA against a stale device must point at the --partition-table flag.""" + recv_responses = [ + bytes([espota2.RESPONSE_OK]), + bytes([espota2.OTA_VERSION_2_0]), + bytes([espota2.RESPONSE_FEATURE_FLAGS]), + bytes([0]), # No partition access + ] + + mock_socket.recv.side_effect = recv_responses + + with pytest.raises( + espota2.OTAError, + match=r"--partition-table.*retry --partition-table", + ): + espota2.perform_ota( + mock_socket, + "testpass", + mock_file, + "test.bin", + espota2.OTA_TYPE_UPDATE_PARTITION_TABLE, + ) + + def test_check_error_detects_errors_when_expect_is_none() -> None: """check_error must surface device error bytes even when expect is None. diff --git a/tests/unit_tests/test_main.py b/tests/unit_tests/test_main.py index 4ab7bb3344b..4b0590cf76d 100644 --- a/tests/unit_tests/test_main.py +++ b/tests/unit_tests/test_main.py @@ -24,6 +24,7 @@ from esphome.__main__ import ( _get_configured_xtal_freq, _make_crystal_freq_callback, _resolve_network_devices, + _validate_bootloader_binary, _validate_partition_table_binary, choose_upload_log_host, command_analyze_memory, @@ -89,7 +90,11 @@ from esphome.const import ( PLATFORM_RP2040, ) from esphome.core import CORE, EsphomeError -from esphome.espota2 import OTA_TYPE_UPDATE_APP, OTA_TYPE_UPDATE_PARTITION_TABLE +from esphome.espota2 import ( + OTA_TYPE_UPDATE_APP, + OTA_TYPE_UPDATE_BOOTLOADER, + OTA_TYPE_UPDATE_PARTITION_TABLE, +) from esphome.util import BootselResult, FlashImage from esphome.zeroconf import _await_discovery, discover_mdns_devices @@ -1127,6 +1132,7 @@ class MockArgs: output: str | None = None ota_platform: str | None = None partition_table: bool = False + bootloader: bool = False def test_upload_program_serial_esp32( @@ -1816,6 +1822,27 @@ def test_validate_partition_table_binary_missing_file(tmp_path: Path) -> None: _validate_partition_table_binary(tmp_path / "does-not-exist.bin") +def test_validate_bootloader_binary_rejects_wrong_magic(tmp_path: Path) -> None: + data = bytearray(_make_bootloader_bytes()) + data[0] = 0x00 + f = tmp_path / "bootloader.bin" + f.write_bytes(bytes(data)) + with pytest.raises(EsphomeError, match="magic"): + _validate_bootloader_binary(f) + + +def test_validate_bootloader_binary_missing_file(tmp_path: Path) -> None: + with pytest.raises(EsphomeError, match="Cannot read bootloader file"): + _validate_bootloader_binary(tmp_path / "does-not-exist.bin") + + +def test_validate_bootloader_binary_rejects_empty_file(tmp_path: Path) -> None: + f = tmp_path / "bootloader.bin" + f.write_bytes(b"") + with pytest.raises(EsphomeError, match="is empty"): + _validate_bootloader_binary(f) + + def test_upload_program_ota_partition_table_invalid_file( mock_run_ota: Mock, mock_get_port_type: Mock, @@ -1869,7 +1896,155 @@ def test_upload_program_ota_partition_table_without_allow_flag( with pytest.raises( EsphomeError, - match="requires 'allow_partition_access: true'", + match=( + r"The option --partition-table requires 'allow_partition_access: true'.*" + r"retry --partition-table" + ), + ): + upload_program(config, args, devices) + mock_run_ota.assert_not_called() + + +def _make_bootloader_bytes() -> bytes: + """Build a minimal bootloader image accepted by _validate_bootloader_binary.""" + table = bytearray(b"\xff") + # Starts with: ESP_IMAGE_HEADER_MAGIC (0xE9) + table[0] = 0xE9 + return bytes(table) + + +def test_upload_program_ota_bootloader_with_file_arg( + mock_run_ota: Mock, + mock_get_port_type: Mock, + tmp_path: Path, +) -> None: + """Test upload_program with OTA and bootloader.""" + setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path) + + mock_get_port_type.return_value = "NETWORK" + mock_run_ota.return_value = (0, "192.168.1.100") + + bootloader_file = tmp_path / "bootloader.bin" + bootloader_file.write_bytes(_make_bootloader_bytes()) + + config = { + CONF_OTA: [ + { + CONF_PLATFORM: CONF_ESPHOME, + CONF_PORT: 3232, + "allow_partition_access": True, + } + ] + } + args = MockArgs(file=str(bootloader_file), bootloader=True) + devices = ["192.168.1.100"] + + exit_code, host = upload_program(config, args, devices) + + assert exit_code == 0 + assert host == "192.168.1.100" + mock_run_ota.assert_called_once_with( + ["192.168.1.100"], + 3232, + None, + bootloader_file, + OTA_TYPE_UPDATE_BOOTLOADER, + ) + + +def test_upload_program_ota_partition_table_and_bootloader_options( + mock_run_ota: Mock, + mock_get_port_type: Mock, + tmp_path: Path, +) -> None: + """--partition-table and --bootloader can't be used together.""" + setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path) + + mock_get_port_type.return_value = "NETWORK" + + config = { + CONF_OTA: [ + { + CONF_PLATFORM: CONF_ESPHOME, + CONF_PORT: 3232, + "allow_partition_access": True, + } + ] + } + args = MockArgs(file="partitions.bin", partition_table=True, bootloader=True) + devices = ["192.168.1.100"] + + with pytest.raises( + EsphomeError, + match="--partition-table and --bootloader", + ): + upload_program(config, args, devices) + mock_run_ota.assert_not_called() + + +def test_upload_program_ota_bootloader_without_allow_flag( + mock_run_ota: Mock, + mock_get_port_type: Mock, + tmp_path: Path, +) -> None: + """--bootloader must fail fast when allow_partition_access is not enabled in YAML.""" + setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path) + + mock_get_port_type.return_value = "NETWORK" + + config = { + CONF_OTA: [ + { + CONF_PLATFORM: CONF_ESPHOME, + CONF_PORT: 3232, + } + ] + } + args = MockArgs(file="bootloader.bin", bootloader=True) + devices = ["192.168.1.100"] + + with pytest.raises( + EsphomeError, + match=( + r"The option --bootloader requires 'allow_partition_access: true'.*" + r"retry --bootloader" + ), + ): + upload_program(config, args, devices) + mock_run_ota.assert_not_called() + + +def test_upload_program_ota_bootloader_platform_web_server( + mock_run_ota: Mock, + mock_get_port_type: Mock, + tmp_path: Path, +) -> None: + """Test bootloader upload with web_server OTA.""" + setup_core(platform=PLATFORM_ESP32, tmp_path=tmp_path) + + mock_get_port_type.return_value = "NETWORK" + + bootloader_file = tmp_path / "bootloader.bin" + bootloader_file.write_bytes(_make_bootloader_bytes()) + + config = { + CONF_OTA: [ + { + CONF_PLATFORM: CONF_WEB_SERVER, + CONF_WEB_SERVER: { + CONF_PORT: 80, + CONF_AUTH: {CONF_USERNAME: "admin", CONF_PASSWORD: "pw"}, + }, + "allow_partition_access": True, + } + ] + } + args = MockArgs(file=str(bootloader_file), bootloader=True) + devices = ["192.168.1.100"] + + with pytest.raises( + EsphomeError, + match="the web_server OTA path can only update the firmware image", ): upload_program(config, args, devices) mock_run_ota.assert_not_called() From ed10fbea3e920ed241ff691d350f7531b015525c Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 11 May 2026 07:25:49 +1200 Subject: [PATCH 20/52] [docker] Silence CopyIgnoredFile warning for build context root (#16311) --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index ccd466d8cba..d6fb5e82ae0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -115,4 +115,4 @@ examples/ Dockerfile .git/ tests/ -.* +.?* From 3c042e2e442330d6d2e6f2cb51c92e5064019e46 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Mon, 11 May 2026 09:58:18 +1000 Subject: [PATCH 21/52] [lvgl] Ensure that `on_value` events fire on checked change (#16119) --- esphome/components/lvgl/__init__.py | 38 ++-- esphome/components/lvgl/automation.py | 17 +- esphome/components/lvgl/defines.py | 130 +++++++++++--- esphome/components/lvgl/encoders.py | 7 +- esphome/components/lvgl/gradient.py | 10 +- esphome/components/lvgl/helpers.py | 25 --- esphome/components/lvgl/keypads.py | 4 +- esphome/components/lvgl/light/lvgl_light.h | 2 +- esphome/components/lvgl/lv_validation.py | 27 ++- esphome/components/lvgl/lvcode.py | 3 +- esphome/components/lvgl/lvgl_esphome.cpp | 4 +- esphome/components/lvgl/lvgl_esphome.h | 33 +++- esphome/components/lvgl/number/__init__.py | 3 +- esphome/components/lvgl/schemas.py | 8 +- esphome/components/lvgl/sensor/__init__.py | 2 - esphome/components/lvgl/styles.py | 14 +- esphome/components/lvgl/switch/__init__.py | 9 +- esphome/components/lvgl/text/__init__.py | 3 +- .../components/lvgl/text_sensor/__init__.py | 10 +- esphome/components/lvgl/touchscreens.py | 8 +- esphome/components/lvgl/trigger.py | 8 +- esphome/components/lvgl/widgets/__init__.py | 85 +++------ esphome/components/lvgl/widgets/animimg.py | 5 +- esphome/components/lvgl/widgets/button.py | 3 +- .../components/lvgl/widgets/buttonmatrix.py | 24 +-- esphome/components/lvgl/widgets/dropdown.py | 4 +- esphome/components/lvgl/widgets/keyboard.py | 14 +- esphome/components/lvgl/widgets/meter.py | 5 +- esphome/components/lvgl/widgets/msgbox.py | 2 +- esphome/components/lvgl/widgets/roller.py | 2 - .../lvgl/config/widget_state_test.yaml | 83 +++++++++ .../component_tests/lvgl/test_widget_state.py | 167 ++++++++++++++++++ 32 files changed, 532 insertions(+), 227 deletions(-) create mode 100644 tests/component_tests/lvgl/config/widget_state_test.yaml create mode 100644 tests/component_tests/lvgl/test_widget_state.py diff --git a/esphome/components/lvgl/__init__.py b/esphome/components/lvgl/__init__.py index ac0363ca696..31131d253f9 100644 --- a/esphome/components/lvgl/__init__.py +++ b/esphome/components/lvgl/__init__.py @@ -47,9 +47,15 @@ from esphome.helpers import write_file_if_changed from esphome.writer import clean_build from esphome.yaml_util import load_yaml -from . import defines as df, helpers, lv_validation as lvalid, widgets -from .automation import focused_widgets, layers_to_code, lvgl_update, refreshed_widgets -from .defines import CONF_ALIGN_TO_LAMBDA_ID +from . import defines as df, lv_validation as lvalid, widgets +from .automation import layers_to_code, lvgl_update +from .defines import ( + CONF_ALIGN_TO_LAMBDA_ID, + get_focused_widgets, + get_lv_images_used, + get_refreshed_widgets, + set_widgets_completed, +) from .encoders import ( ENCODERS_CONFIG, encoders_to_code, @@ -58,7 +64,7 @@ from .encoders import ( ) from .gradient import GRADIENT_SCHEMA, gradients_to_code from .keypads import KEYPADS_CONFIG, keypads_to_code -from .lv_validation import lv_bool, lv_images_used +from .lv_validation import lv_bool from .lvcode import LvContext, LvglComponent, lv_event_t_ptr, lvgl_static from .schemas import ( DISP_BG_SCHEMA, @@ -89,7 +95,6 @@ from .widgets import ( add_widgets, get_screen_active, set_obj_properties, - styles_used, ) # Import only what we actually use directly in this file @@ -144,7 +149,7 @@ def generate_lv_conf_h(): df.LV_DEFINES + tuple(f"LV_USE_{w.upper()}" for w in WIDGET_TYPES) ) # Get the defines that are actually used based on the config - lv_defines = df.get_data(df.KEY_LV_DEFINES) + lv_defines = df.get_defines() unused_defines = all_defines - set(lv_defines) # Create the content of lv_conf.h with the used defines set to their value, and the unused defines disabled definitions = [as_macro(m, v) for m, v in lv_defines.items()] + [ @@ -211,7 +216,7 @@ def final_validation(config_list): buffer_frac = config[CONF_BUFFER_SIZE] if CORE.is_esp32 and buffer_frac > 0.5 and PSRAM_DOMAIN not in global_config: df.LOGGER.warning("buffer_size: may need to be reduced without PSRAM") - for w in focused_widgets: + for w in get_focused_widgets(): path = global_config.get_path_for_id(w) widget_conf = global_config.get_config_for_path(path[:-1]) if ( @@ -222,7 +227,7 @@ def final_validation(config_list): "A non adjustable arc may not be focused", path, ) - for w in refreshed_widgets: + for w in get_refreshed_widgets(): path = global_config.get_path_for_id(w) widget_conf = global_config.get_config_for_path(path[:-1]) if not any(isinstance(v, (Lambda, dict)) for v in widget_conf.values()): @@ -230,7 +235,7 @@ def final_validation(config_list): f"Widget '{w}' does not have any dynamic properties to refresh", ) # Do per-widget type final validation for update actions - for widget_type, update_configs in df.get_data(df.KEY_UPDATED_WIDGETS).items(): + for widget_type, update_configs in df.get_updated_widgets().items(): for conf in update_configs: for id_conf in conf.get(CONF_ID, ()): name = id_conf[CONF_ID] @@ -279,7 +284,7 @@ async def to_code(configs): cg.RawExpression(f"ESPHOME_LOG_LEVEL_{config_0[CONF_LOG_LEVEL]}"), ) df.add_define("LV_COLOR_DEPTH", config_0[CONF_COLOR_DEPTH]) - for font in helpers.lv_fonts_used: + for font in df.get_lv_fonts_used(): df.add_define(f"LV_FONT_{font.upper()}") if config_0[CONF_COLOR_DEPTH] == 16: @@ -294,7 +299,7 @@ async def to_code(configs): cg.add_build_flag("-Isrc") cg.add_global(lvgl_ns.using) - for font in helpers.esphome_fonts_used: + for font in df.get_esphome_fonts_used(): await cg.get_variable(font) default_font = config_0[df.CONF_DEFAULT_FONT] if not lvalid.is_lv_font(default_font): @@ -377,8 +382,8 @@ async def to_code(configs): await lvgl_update(lv_component, config) await msgboxes_to_code(lv_component, config) # await disp_update(lv_component.get_disp(), config) - # Set this directly since we are limited in how many methods can be added to the Widget class. - Widget.widgets_completed = True + # Mark all widgets as completed so awaiters of ``wait_for_widgets`` proceed. + set_widgets_completed(True) async with LvContext(): await generate_triggers() await generate_align_tos(configs[0]) @@ -404,9 +409,8 @@ async def to_code(configs): ) # This must be done after all widgets are created - for comp in helpers.lvgl_components_required: - cg.add_define(f"USE_LVGL_{comp.upper()}") - for use in helpers.lv_uses: + styles_used = df.get_styles_used() + for use in df.get_lv_uses(): df.add_define(f"LV_USE_{use.upper()}") cg.add_define(f"USE_LVGL_{use.upper()}") @@ -433,7 +437,7 @@ async def to_code(configs): } & styles_used: lv_image_formats.add("A8") - for image_id in lv_images_used: + for image_id in get_lv_images_used(): await cg.get_variable(image_id) metadata = get_image_metadata(image_id.id) image_type = IMAGE_TYPE[metadata.image_type] diff --git a/esphome/components/lvgl/automation.py b/esphome/components/lvgl/automation.py index 977f1af9b49..bf9a3d74ad3 100644 --- a/esphome/components/lvgl/automation.py +++ b/esphome/components/lvgl/automation.py @@ -25,7 +25,9 @@ from .defines import ( PARTS, StaticCastExpression, add_warning, + get_focused_widgets, get_options, + get_refreshed_widgets, ) from .lv_validation import lv_bool, lv_milliseconds from .lvcode import ( @@ -70,9 +72,9 @@ from .widgets import ( wait_for_widgets, ) -# Record widgets that are used in a focused action here -focused_widgets = set() -refreshed_widgets = set() +# Widgets that are used in a focused/refreshed action are tracked in +# ``CORE.data`` (under the lvgl domain) so the state is cleared between +# successive compilations / unit tests via ``CORE.reset()``. async def layers_to_code(lv_component, config): @@ -316,7 +318,7 @@ async def resume_action_to_code(config, action_id, template_arg, args): ) async def obj_disable_to_code(config, action_id, template_arg, args): async def do_disable(widget: Widget): - widget.add_state(LV_STATE.DISABLED) + widget.set_state(LV_STATE.DISABLED, True) return await action_to_code( await get_widgets(config), do_disable, action_id, template_arg, args @@ -328,7 +330,7 @@ async def obj_disable_to_code(config, action_id, template_arg, args): ) async def obj_enable_to_code(config, action_id, template_arg, args): async def do_enable(widget: Widget): - widget.clear_state(LV_STATE.DISABLED) + widget.set_state(LV_STATE.DISABLED, False) return await action_to_code( await get_widgets(config), do_enable, action_id, template_arg, args @@ -361,7 +363,7 @@ async def obj_show_to_code(config, action_id, template_arg, args): def focused_id(value): value = cv.use_id(lv_pseudo_button_t)(value) - focused_widgets.add(value) + get_focused_widgets().add(value) return value @@ -446,8 +448,9 @@ async def obj_update_to_code(config, action_id, template_arg, args): def validate_refresh_config(config): + refreshed = get_refreshed_widgets() for w in config: - refreshed_widgets.add(w[CONF_ID]) + refreshed.add(w[CONF_ID]) return config diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 03bbaf8ddb4..7bfd26bb6ec 100644 --- a/esphome/components/lvgl/defines.py +++ b/esphome/components/lvgl/defines.py @@ -19,46 +19,134 @@ from esphome.cpp_generator import ( from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor from esphome.types import Expression, SafeExpType -from .helpers import requires_component - LOGGER = logging.getLogger(__name__) lvgl_ns = cg.esphome_ns.namespace("lvgl") DOMAIN = "lvgl" KEY_COLOR_FORMATS = "color_formats" +KEY_ESPHOME_FONTS_USED = "esphome_fonts_used" +KEY_FOCUSED_WIDGETS = "focused_widgets" KEY_LV_DEFINES = "lv_defines" +KEY_LV_FONTS_USED = "lv_fonts_used" +KEY_LV_IMAGES_USED = "lv_images_used" +KEY_LV_USES = "lv_uses" +KEY_NAMED_STYLES = "named_styles" +KEY_REFRESHED_WIDGETS = "refreshed_widgets" KEY_REMAPPED_USES = "remapped_uses" +KEY_STYLES_USED = "styles_used" +KEY_THEME_WIDGET_MAP = "theme_widget_map" KEY_UPDATED_WIDGETS = "updated_widgets" +KEY_WIDGET_MAP = "widget_map" +KEY_WIDGETS_COMPLETED = "widgets_completed" KEY_OPTIONS = "options" KEY_WARNINGS = "warnings" +# Initial set of LVGL features that are always enabled. +_INITIAL_LV_USES = frozenset( + { + "USER_DATA", + "LOG", + "STYLE", + "FONT_PLACEHOLDER", + "THEME_DEFAULT", + } +) -def get_data(key, default=None): + +# These collections accumulate state across a single compilation run. They +# are stored under ``CORE.data`` (which ``CORE.reset()`` clears between runs) +# rather than as module-level globals, otherwise they would leak between +# successive compilations / unit tests. + + +def _get_data(key: str, default: Any) -> Any: """ Get a data structure from the global data store by key :param key: A key for the data - :param default: The default data - the default is an empty dict + :param default: The default data :return: """ - return CORE.data.setdefault(DOMAIN, {}).setdefault( - key, {} if default is None else default - ) + return CORE.data.setdefault(DOMAIN, {}).setdefault(key, default) -def get_warnings(): - return get_data(KEY_WARNINGS, set()) +def get_lv_images_used() -> set[ID]: + return _get_data(KEY_LV_IMAGES_USED, set()) -def get_remapped_uses(): - return get_data(KEY_REMAPPED_USES, set()) +def get_lv_uses() -> set[str]: + return _get_data(KEY_LV_USES, set(_INITIAL_LV_USES)) -def add_warning(msg: str): +def get_lv_fonts_used() -> set[str]: + return _get_data(KEY_LV_FONTS_USED, set()) + + +def get_esphome_fonts_used() -> set[ID]: + return _get_data(KEY_ESPHOME_FONTS_USED, set()) + + +def add_lv_use(*names: str) -> None: + uses = get_lv_uses() + for name in names: + uses.add(name) + + +def get_warnings() -> set[str]: + return _get_data(KEY_WARNINGS, set()) + + +def get_remapped_uses() -> set[str]: + return _get_data(KEY_REMAPPED_USES, set()) + + +def add_warning(msg: str) -> None: get_warnings().add(msg) -def get_options(): - return get_data(KEY_OPTIONS) +def get_options() -> dict[str, Any]: + return _get_data(KEY_OPTIONS, {}) + + +def get_defines() -> dict[str, str]: + return _get_data(KEY_LV_DEFINES, {}) + + +def get_updated_widgets() -> dict: + return _get_data(KEY_UPDATED_WIDGETS, {}) + + +def get_theme_widget_map() -> dict[str, Any]: + return _get_data(KEY_THEME_WIDGET_MAP, {}) + + +def get_styles_used() -> set[str]: + return _get_data(KEY_STYLES_USED, set()) + + +def get_widget_map() -> dict[str, Any]: + return _get_data(KEY_WIDGET_MAP, {}) + + +def get_widgets_completed() -> bool: + # ``[value]`` rather than the bare value so that we can mutate the + # entry in place; ``CORE.data`` is reset for us between runs. + return _get_data(KEY_WIDGETS_COMPLETED, [False])[0] + + +def set_widgets_completed(value: bool) -> None: + _get_data(KEY_WIDGETS_COMPLETED, [False])[0] = value + + +def is_widget_completed(name: ID) -> bool: + return name in get_widget_map() + + +def get_focused_widgets() -> set: + return _get_data(KEY_FOCUSED_WIDGETS, set()) + + +def get_refreshed_widgets() -> set: + return _get_data(KEY_REFRESHED_WIDGETS, set()) class StaticCastExpression(Expression): @@ -72,8 +160,8 @@ class StaticCastExpression(Expression): return f"static_cast<{self.type}>({self.exp})" -def add_define(macro, value="1"): - lv_defines = get_data(KEY_LV_DEFINES) +def add_define(macro: str, value="1"): + lv_defines = get_defines() value = str(value) if lv_defines.setdefault(macro, value) != value: LOGGER.error( @@ -82,8 +170,8 @@ def add_define(macro, value="1"): lv_defines[macro] = value -def is_defined(macro): - return macro in get_data(KEY_LV_DEFINES) +def is_defined(macro) -> bool: + return macro in get_defines() def literal(arg) -> MockObj: @@ -96,7 +184,7 @@ def addr(arg) -> MockObj: return MockObj(f"&{arg}") -def call_lambda(lamb: LambdaExpression): +def call_lambda(lamb: LambdaExpression) -> Expression: """ Given a lambda, either reduce to a simple expression or call it, possibly with parameters from the surrounding context @@ -135,7 +223,7 @@ class LValidator: def __call__(self, value): if self.requires: - value = requires_component(self.requires)(value) + value = cv.requires_component(self.requires)(value) if isinstance(value, cv.Lambda): return cv.returning_lambda(value) return self.validator(value) @@ -196,7 +284,7 @@ class LvConstant(LValidator): cv.ensure_list(self.one_of), cg.uint32, retmapper=self.mapper ) - def mapper(self, value): + def mapper(self, value) -> Any: if not isinstance(value, list): value = [value] value = [ diff --git a/esphome/components/lvgl/encoders.py b/esphome/components/lvgl/encoders.py index bafda8382ee..e6527bbc9b5 100644 --- a/esphome/components/lvgl/encoders.py +++ b/esphome/components/lvgl/encoders.py @@ -13,8 +13,8 @@ from .defines import ( CONF_LONG_PRESS_REPEAT_TIME, CONF_LONG_PRESS_TIME, CONF_RIGHT_BUTTON, + add_lv_use, ) -from .helpers import lvgl_components_required, requires_component from .lvcode import lv, lv_add, lv_assign, lv_expr, lv_Pvariable from .schemas import ENCODER_SCHEMA from .types import lv_group_t, lv_indev_type_t, lv_key_t @@ -26,7 +26,8 @@ ENCODERS_CONFIG = cv.ensure_list( cv.Required(CONF_ENTER_BUTTON): cv.use_id(BinarySensor), cv.Required(CONF_SENSOR): cv.Any( cv.All( - cv.use_id(RotaryEncoderSensor), requires_component("rotary_encoder") + cv.use_id(RotaryEncoderSensor), + cv.requires_component("rotary_encoder"), ), cv.Schema( { @@ -48,7 +49,7 @@ def get_default_group(config): async def encoders_to_code(var, config, default_group): for enc_conf in config[CONF_ENCODERS]: - lvgl_components_required.add("KEY_LISTENER") + add_lv_use("KEY_LISTENER", "ROTARY_ENCODER") lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds lprt = enc_conf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds listener = cg.new_Pvariable( diff --git a/esphome/components/lvgl/gradient.py b/esphome/components/lvgl/gradient.py index e075433d03e..2f1be207722 100644 --- a/esphome/components/lvgl/gradient.py +++ b/esphome/components/lvgl/gradient.py @@ -12,8 +12,14 @@ from esphome.const import ( from esphome.core import ID from esphome.cpp_generator import MockObj -from .defines import CONF_GRADIENTS, CONF_OPA, LV_DITHER, add_define, add_warning -from .helpers import add_lv_use +from .defines import ( + CONF_GRADIENTS, + CONF_OPA, + LV_DITHER, + add_define, + add_lv_use, + add_warning, +) from .lv_validation import lv_color, lv_percentage, opacity from .lvcode import lv from .types import lv_color_t, lv_gradient_t, lv_opa_t diff --git a/esphome/components/lvgl/helpers.py b/esphome/components/lvgl/helpers.py index c2bd58f71c3..baa618d472b 100644 --- a/esphome/components/lvgl/helpers.py +++ b/esphome/components/lvgl/helpers.py @@ -5,23 +5,6 @@ from esphome.const import CONF_ARGS, CONF_FORMAT CONF_IF_NAN = "if_nan" -lv_uses = { - "USER_DATA", - "LOG", - "STYLE", - "FONT_PLACEHOLDER", - "THEME_DEFAULT", -} - - -def add_lv_use(*names): - for name in names: - lv_uses.add(name) - - -lv_fonts_used = set() -esphome_fonts_used = set() -lvgl_components_required = set() # noqa f_regex = re.compile( @@ -66,11 +49,3 @@ def validate_printf(value): "Use of 'if_nan' requires a single valid printf-pattern of type %f" ) return value - - -def requires_component(comp): - def validator(value): - lvgl_components_required.add(comp) - return cv.requires_component(comp)(value) - - return validator diff --git a/esphome/components/lvgl/keypads.py b/esphome/components/lvgl/keypads.py index 7d8b3dd1282..6d4abbc63b7 100644 --- a/esphome/components/lvgl/keypads.py +++ b/esphome/components/lvgl/keypads.py @@ -9,9 +9,9 @@ from .defines import ( CONF_KEYPADS, CONF_LONG_PRESS_REPEAT_TIME, CONF_LONG_PRESS_TIME, + add_lv_use, literal, ) -from .helpers import lvgl_components_required from .lvcode import lv, lv_assign, lv_expr, lv_Pvariable from .schemas import ENCODER_SCHEMA from .types import lv_group_t, lv_indev_type_t @@ -52,7 +52,7 @@ KEYPADS_CONFIG = cv.ensure_list( async def keypads_to_code(var, config, default_group): for enc_conf in config[CONF_KEYPADS]: - lvgl_components_required.add("KEY_LISTENER") + add_lv_use("KEY_LISTENER") lpt = enc_conf[CONF_LONG_PRESS_TIME].total_milliseconds lprt = enc_conf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds listener = cg.new_Pvariable( diff --git a/esphome/components/lvgl/light/lvgl_light.h b/esphome/components/lvgl/light/lvgl_light.h index 50da7af6021..bf019964c7b 100644 --- a/esphome/components/lvgl/light/lvgl_light.h +++ b/esphome/components/lvgl/light/lvgl_light.h @@ -37,7 +37,7 @@ class LVLight : public light::LightOutput { void set_value_(lv_color_t value) { lv_led_set_color(this->obj_, value); lv_led_on(this->obj_); - lv_obj_send_event(this->obj_, lv_api_event, nullptr); + lv_obj_send_event(this->obj_, lv_update_event, nullptr); } lv_obj_t *obj_{}; optional initial_value_{}; diff --git a/esphome/components/lvgl/lv_validation.py b/esphome/components/lvgl/lv_validation.py index 974eed9e817..a1b75182ebb 100644 --- a/esphome/components/lvgl/lv_validation.py +++ b/esphome/components/lvgl/lv_validation.py @@ -31,16 +31,14 @@ from .defines import ( LValidator, LvConstant, StaticCastExpression, + add_lv_use, call_lambda, + get_esphome_fonts_used, + get_lv_fonts_used, + get_lv_images_used, literal, ) -from .helpers import ( - CONF_IF_NAN, - add_lv_use, - esphome_fonts_used, - lv_fonts_used, - requires_component, -) +from .helpers import CONF_IF_NAN from .types import lv_coord_t, lv_gradient_t, lv_opa_t LV_OPA = LvConstant("LV_OPA_", "TRANSP", "COVER") @@ -370,14 +368,11 @@ def stop_value(value): return cv.int_range(0, 255)(value) -lv_images_used = set() - - def image_validator(value): - value = requires_component("image")(value) + value = cv.requires_component("image")(value) value = cv.use_id(Image_)(value) - lv_images_used.add(value) - add_lv_use("img", "label") + get_lv_images_used().add(value) + add_lv_use("label") return value @@ -496,7 +491,7 @@ class LvFont(LValidator): def __init__(self): def lv_builtin_font(value): fontval = cv.one_of(*LV_FONTS, lower=True)(value) - lv_fonts_used.add(fontval) + get_lv_fonts_used().add(fontval) return fontval def validator(value): @@ -506,8 +501,8 @@ class LvFont(LValidator): return lv_builtin_font(value) add_lv_use("font") fontval = cv.use_id(Font)(value) - esphome_fonts_used.add(fontval) - return requires_component("font")(fontval) + get_esphome_fonts_used().add(fontval) + return cv.requires_component("font")(fontval) # Use font::Font* as return type for lambdas returning ESPHome fonts # The inline overloads in lvgl_esphome.h handle conversion to lv_font_t* diff --git a/esphome/components/lvgl/lvcode.py b/esphome/components/lvgl/lvcode.py index eb8f7d4437c..32fb02e3d21 100644 --- a/esphome/components/lvgl/lvcode.py +++ b/esphome/components/lvgl/lvcode.py @@ -29,10 +29,9 @@ LvglComponent = lvgl_ns.class_("LvglComponent", cg.PollingComponent) LVGL_COMP_ARG = [(LvglComponent.operator("ptr"), LVGL_COMP)] lv_event_t_ptr = cg.global_ns.namespace("lv_event_t").operator("ptr") EVENT_ARG = [(lv_event_t_ptr, "event")] -# Two custom events; API_EVENT is fired when an entity is updated remotely by an API interaction; +# One custom event; # UPDATE_EVENT is fired when an entity is programmatically updated locally. # VALUE_CHANGED is the event generated by LVGL when an entity's value changes through user interaction. -API_EVENT = literal("lvgl::lv_api_event") UPDATE_EVENT = literal("lvgl::lv_update_event") diff --git a/esphome/components/lvgl/lvgl_esphome.cpp b/esphome/components/lvgl/lvgl_esphome.cpp index 3141c5f93c3..678ed9dbbfb 100644 --- a/esphome/components/lvgl/lvgl_esphome.cpp +++ b/esphome/components/lvgl/lvgl_esphome.cpp @@ -147,7 +147,6 @@ void LvglComponent::render_start_cb(lv_event_t *event) { comp->draw_start_(); } -lv_event_code_t lv_api_event; // NOLINT lv_event_code_t lv_update_event; // NOLINT void LvglComponent::dump_config() { ESP_LOGCONFIG(TAG, @@ -194,7 +193,6 @@ void LvglComponent::esphome_lvgl_init() { LV_GLOBAL_DEFAULT()->font_draw_buf_handlers.buf_free_cb = lv_free_core; lv_tick_set_cb([] { return millis(); }); lv_update_event = static_cast(lv_event_register_id()); - lv_api_event = static_cast(lv_event_register_id()); } void LvglComponent::add_event_cb(lv_obj_t *obj, event_callback_t callback, lv_event_code_t event) { @@ -547,7 +545,7 @@ void LvSelectable::set_selected_text(const std::string &text, lv_anim_enable_t a auto index = std::find(this->options_.begin(), this->options_.end(), text); if (index != this->options_.end()) { this->set_selected_index(index - this->options_.begin(), anim); - lv_obj_send_event(this->obj, lv_api_event, nullptr); + lv_obj_send_event(this->obj, lv_update_event, nullptr); } } diff --git a/esphome/components/lvgl/lvgl_esphome.h b/esphome/components/lvgl/lvgl_esphome.h index 32bf3ccac6b..218f9a60ab9 100644 --- a/esphome/components/lvgl/lvgl_esphome.h +++ b/esphome/components/lvgl/lvgl_esphome.h @@ -50,7 +50,6 @@ using lv_color_data = uint16_t; using lv_color_data = uint32_t; #endif -extern lv_event_code_t lv_api_event; // NOLINT extern lv_event_code_t lv_update_event; // NOLINT extern std::string lv_event_code_name_for(lv_event_t *event); @@ -227,11 +226,43 @@ class LvglComponent : public PollingComponent { * Initialize the LVGL library and register custom events. */ static void esphome_lvgl_init(); + + // Convenience overloads for adding a callback for one or more events static void add_event_cb(lv_obj_t *obj, event_callback_t callback, lv_event_code_t event); static void add_event_cb(lv_obj_t *obj, event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2); static void add_event_cb(lv_obj_t *obj, event_callback_t callback, lv_event_code_t event1, lv_event_code_t event2, lv_event_code_t event3); + // change the state of a widget and fire an event if changed (only needed for CHECKED) + + static void lv_obj_set_state_value(lv_obj_t *obj, lv_state_t state, bool value) { + if (value != lv_obj_has_state(obj, state)) { + if (value) { + lv_obj_add_state(obj, state); + } else { + lv_obj_remove_state(obj, state); + } + if (state == LV_STATE_CHECKED) + lv_obj_send_event(obj, lv_update_event, nullptr); + } + } + + // change the state of a buttonmatrix button and fire an event if changed (only needed for CHECKED) +#ifdef USE_LVGL_BUTTONMATRIX + static void lv_buttonmatrix_set_button_ctrl_value(lv_obj_t *obj, uint32_t index, lv_buttonmatrix_ctrl_t ctrl, + bool value) { + if (value != lv_buttonmatrix_has_button_ctrl(obj, index, ctrl)) { + if (value) { + lv_buttonmatrix_set_button_ctrl(obj, index, ctrl); + } else { + lv_buttonmatrix_clear_button_ctrl(obj, index, ctrl); + } + if (ctrl == LV_BUTTONMATRIX_CTRL_CHECKED) + lv_obj_send_event(obj, lv_update_event, nullptr); + } + } +#endif + void add_page(LvPageType *page); void show_page(size_t index, lv_screen_load_anim_t anim, uint32_t time); void show_next_page(lv_screen_load_anim_t anim, uint32_t time); diff --git a/esphome/components/lvgl/number/__init__.py b/esphome/components/lvgl/number/__init__.py index d80e93708bf..0c7e4b9524a 100644 --- a/esphome/components/lvgl/number/__init__.py +++ b/esphome/components/lvgl/number/__init__.py @@ -7,7 +7,6 @@ from esphome.cpp_generator import MockObj from ..defines import CONF_ANIMATED, CONF_UPDATE_ON_RELEASE, CONF_WIDGET from ..lv_validation import animated from ..lvcode import ( - API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, @@ -40,7 +39,7 @@ async def to_code(config): await widget.set_property( "value", MockObj("v") * MockObj(widget.get_scale()), config[CONF_ANIMATED] ) - lv_obj.send_event(widget.obj, API_EVENT, cg.nullptr) + lv_obj.send_event(widget.obj, UPDATE_EVENT, cg.nullptr) event_code = ( LV_EVENT.VALUE_CHANGED if not config[CONF_UPDATE_ON_RELEASE] diff --git a/esphome/components/lvgl/schemas.py b/esphome/components/lvgl/schemas.py index a9427a98520..6b71c2875e7 100644 --- a/esphome/components/lvgl/schemas.py +++ b/esphome/components/lvgl/schemas.py @@ -33,7 +33,7 @@ from .defines import ( get_remapped_uses, is_press_event, ) -from .helpers import CONF_IF_NAN, requires_component, validate_printf +from .helpers import CONF_IF_NAN, validate_printf from .layout import ( FLEX_OBJ_SCHEMA, GRID_CELL_SCHEMA, @@ -112,7 +112,7 @@ PRESS_TIME = cv.All( ENCODER_SCHEMA = cv.Schema( { cv.GenerateID(): cv.All( - cv.declare_id(LVEncoderListener), requires_component("binary_sensor") + cv.declare_id(LVEncoderListener), cv.requires_component("binary_sensor") ), cv.Optional(CONF_GROUP): cv.declare_id(lv_group_t), cv.Optional(df.CONF_INITIAL_FOCUS): cv.All( @@ -406,7 +406,7 @@ def _update_widget(widget_type: WidgetType) -> Callable[[dict], dict]: """ def validator(value: dict) -> dict: - df.get_data(df.KEY_UPDATED_WIDGETS).setdefault(widget_type, []).append(value) + df.get_updated_widgets().setdefault(widget_type, []).append(value) return value return validator @@ -573,7 +573,7 @@ def any_widget_schema(extras=None): container_validator = container_schema(widget_type, extras=extras) if required := widget_type.required_component: container_validator = cv.All( - container_validator, requires_component(required) + container_validator, cv.requires_component(required) ) # Apply custom validation path = [key] if is_dict else [index, key] diff --git a/esphome/components/lvgl/sensor/__init__.py b/esphome/components/lvgl/sensor/__init__.py index 167af9c6e19..682d84ede3e 100644 --- a/esphome/components/lvgl/sensor/__init__.py +++ b/esphome/components/lvgl/sensor/__init__.py @@ -3,7 +3,6 @@ import esphome.config_validation as cv from ..defines import CONF_WIDGET from ..lvcode import ( - API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, @@ -35,7 +34,6 @@ async def to_code(config): widget.obj, await lamb.get_lambda(), LV_EVENT.VALUE_CHANGED, - API_EVENT, UPDATE_EVENT, ) ) diff --git a/esphome/components/lvgl/styles.py b/esphome/components/lvgl/styles.py index c17f30383bb..c1441526f95 100644 --- a/esphome/components/lvgl/styles.py +++ b/esphome/components/lvgl/styles.py @@ -4,12 +4,18 @@ import esphome.config_validation as cv from esphome.const import CONF_ID from esphome.core import ID -from .defines import CONF_STYLE_DEFINITIONS, CONF_THEME, LValidator, literal -from .helpers import add_lv_use +from .defines import ( + CONF_STYLE_DEFINITIONS, + CONF_THEME, + LValidator, + add_lv_use, + get_theme_widget_map, + literal, +) from .lvcode import LambdaContext, lv from .schemas import ALL_STYLES, FULL_STYLE_SCHEMA, WIDGET_TYPES, remap_property from .types import ObjUpdateAction, lv_style_t -from .widgets import collect_parts, theme_widget_map, wait_for_widgets +from .widgets import collect_parts, wait_for_widgets def has_style_props(config) -> bool: @@ -97,4 +103,4 @@ async def theme_to_code(config): ) for state, props in states.items() } - theme_widget_map[w_name] = styles + get_theme_widget_map()[w_name] = styles diff --git a/esphome/components/lvgl/switch/__init__.py b/esphome/components/lvgl/switch/__init__.py index a43851b4a39..509e4f42ad7 100644 --- a/esphome/components/lvgl/switch/__init__.py +++ b/esphome/components/lvgl/switch/__init__.py @@ -7,14 +7,11 @@ from esphome.cpp_types import Component from ..defines import CONF_WIDGET, literal from ..lvcode import ( - API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, - LvConditional, LvContext, lv_add, - lv_obj, lvgl_static, ) from ..types import LV_EVENT, LV_STATE, lv_pseudo_button_t, lvgl_ns @@ -35,11 +32,7 @@ async def to_code(config): switch_id = MockObj(config[CONF_ID], "->") v = literal("v") async with LambdaContext([(cg.bool_, "v")]) as control: - with LvConditional(v) as cond: - widget.add_state(LV_STATE.CHECKED) - cond.else_() - widget.clear_state(LV_STATE.CHECKED) - lv_obj.send_event(widget.obj, API_EVENT, cg.nullptr) + widget.set_state(LV_STATE.CHECKED, literal("v")) control.add(switch_id.publish_state(v)) switch = cg.new_Pvariable(config[CONF_ID], await control.get_lambda()) await cg.register_component(switch, config) diff --git a/esphome/components/lvgl/text/__init__.py b/esphome/components/lvgl/text/__init__.py index 190ecacda52..61db5444e86 100644 --- a/esphome/components/lvgl/text/__init__.py +++ b/esphome/components/lvgl/text/__init__.py @@ -5,7 +5,6 @@ import esphome.config_validation as cv from ..defines import CONF_WIDGET from ..lvcode import ( - API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, @@ -33,7 +32,7 @@ async def to_code(config): await wait_for_widgets() async with LambdaContext([(cg.std_string, "text_value")]) as control: await widget.set_property("text", "text_value.c_str()") - lv_obj.send_event(widget.obj, API_EVENT, cg.nullptr) + lv_obj.send_event(widget.obj, UPDATE_EVENT, cg.nullptr) control.add(textvar.publish_state(widget.get_value())) async with LambdaContext(EVENT_ARG) as lamb: lv_add(textvar.publish_state(widget.get_value())) diff --git a/esphome/components/lvgl/text_sensor/__init__.py b/esphome/components/lvgl/text_sensor/__init__.py index 4728fd137a5..c3306ad57a0 100644 --- a/esphome/components/lvgl/text_sensor/__init__.py +++ b/esphome/components/lvgl/text_sensor/__init__.py @@ -6,14 +6,7 @@ from esphome.components.text_sensor import ( import esphome.config_validation as cv from ..defines import CONF_WIDGET -from ..lvcode import ( - API_EVENT, - EVENT_ARG, - UPDATE_EVENT, - LambdaContext, - LvContext, - lvgl_static, -) +from ..lvcode import EVENT_ARG, UPDATE_EVENT, LambdaContext, LvContext, lvgl_static from ..types import LV_EVENT, LvText from ..widgets import get_widgets, wait_for_widgets @@ -37,7 +30,6 @@ async def to_code(config): widget.obj, await pressed_ctx.get_lambda(), LV_EVENT.VALUE_CHANGED, - API_EVENT, UPDATE_EVENT, ) ) diff --git a/esphome/components/lvgl/touchscreens.py b/esphome/components/lvgl/touchscreens.py index 0eb9f22f12e..0bb5715439d 100644 --- a/esphome/components/lvgl/touchscreens.py +++ b/esphome/components/lvgl/touchscreens.py @@ -8,15 +8,17 @@ from .defines import ( CONF_LONG_PRESS_REPEAT_TIME, CONF_LONG_PRESS_TIME, CONF_TOUCHSCREENS, + add_lv_use, ) -from .helpers import lvgl_components_required from .schemas import PRESS_TIME from .types import LVTouchListener CONF_TOUCHSCREEN = "touchscreen" TOUCHSCREENS_CONFIG = cv.maybe_simple_value( { - cv.Required(CONF_TOUCHSCREEN_ID): cv.use_id(Touchscreen), + cv.Required(CONF_TOUCHSCREEN_ID): cv.All( + cv.use_id(Touchscreen), cv.requires_component(CONF_TOUCHSCREEN) + ), cv.Optional(CONF_LONG_PRESS_TIME, default="400ms"): PRESS_TIME, cv.Optional(CONF_LONG_PRESS_REPEAT_TIME, default="100ms"): PRESS_TIME, cv.GenerateID(): cv.declare_id(LVTouchListener), @@ -34,7 +36,7 @@ def touchscreen_schema(config): async def touchscreens_to_code(lv_component, config): for tconf in config[CONF_TOUCHSCREENS]: - lvgl_components_required.add(CONF_TOUCHSCREEN) + add_lv_use(CONF_TOUCHSCREEN) touchscreen = await cg.get_variable(tconf[CONF_TOUCHSCREEN_ID]) lpt = tconf[CONF_LONG_PRESS_TIME].total_milliseconds lprt = tconf[CONF_LONG_PRESS_REPEAT_TIME].total_milliseconds diff --git a/esphome/components/lvgl/trigger.py b/esphome/components/lvgl/trigger.py index b3d12ed1837..64590d56f61 100644 --- a/esphome/components/lvgl/trigger.py +++ b/esphome/components/lvgl/trigger.py @@ -24,11 +24,11 @@ from .defines import ( LV_SCREEN_EVENT_MAP, LV_SCREEN_EVENT_TRIGGERS, SWIPE_TRIGGERS, + get_widget_map, is_press_event, literal, ) from .lvcode import ( - API_EVENT, EVENT_ARG, UPDATE_EVENT, LambdaContext, @@ -39,7 +39,7 @@ from .lvcode import ( lvgl_static, ) from .types import LV_EVENT, lv_point_t -from .widgets import LvScrActType, get_screen_active, widget_map +from .widgets import LvScrActType, get_screen_active async def add_on_boot_triggers(triggers): @@ -58,7 +58,7 @@ async def generate_triggers(): all_triggers = ( LV_EVENT_TRIGGERS + LV_DISPLAY_EVENT_TRIGGERS + LV_SCREEN_EVENT_TRIGGERS ) - for w in widget_map.values(): + for w in get_widget_map().values(): config = w.config if isinstance(w.type, LvScrActType): w = get_screen_active(w.var) @@ -89,7 +89,6 @@ async def generate_triggers(): conf, w, LV_EVENT.VALUE_CHANGED, - API_EVENT, UPDATE_EVENT, ) @@ -104,6 +103,7 @@ async def generate_align_tos(config: dict): :param config: :return: """ + widget_map = get_widget_map() align_tos = tuple( w for w in widget_map.values() if w.config and CONF_ALIGN_TO in w.config ) diff --git a/esphome/components/lvgl/widgets/__init__.py b/esphome/components/lvgl/widgets/__init__.py index d35f84c4f26..534ebe0b93d 100644 --- a/esphome/components/lvgl/widgets/__init__.py +++ b/esphome/components/lvgl/widgets/__init__.py @@ -15,6 +15,7 @@ from esphome.const import ( from esphome.core import ID, EsphomeError, TimePeriod from esphome.coroutine import FakeAwaitable from esphome.cpp_generator import MockObj +from esphome.types import Expression from ..defines import ( CONF_FLEX_ALIGN_CROSS, @@ -38,11 +39,15 @@ from ..defines import ( TYPE_FLEX, TYPE_GRID, LValidator, + add_lv_use, call_lambda, + get_styles_used, + get_theme_widget_map, + get_widget_map, + get_widgets_completed, join_enums, literal, ) -from ..helpers import add_lv_use from ..lvcode import ( LvConditional, add_line_marks, @@ -52,6 +57,7 @@ from ..lvcode import ( lv_expr, lv_obj, lv_Pvariable, + lvgl_static, ) from ..types import ( LV_STATE, @@ -65,9 +71,6 @@ from ..types import ( EVENT_LAMB = "event_lamb__" -theme_widget_map = {} -styles_used = set() - class WidgetType: """ @@ -157,7 +160,7 @@ class WidgetType: await self.on_create(var, config) w = Widget.create(wid, var, self, config) - if theme := theme_widget_map.get(self.name): + if theme := get_theme_widget_map().get(self.name): for part, states in theme.items(): part = "LV_PART_" + part.upper() for state, style in states.items(): @@ -240,8 +243,6 @@ class Widget: This class has a lot of methods. Adding any more runs foul of lint checks ("too many public methods"). """ - widgets_completed = False - def __init__(self, var, wtype: WidgetType, config: dict = None): self.var = var self.type = wtype @@ -262,21 +263,14 @@ class Widget: @staticmethod def create(name, var, wtype: WidgetType, config: dict = None): w = Widget(var, wtype, config) - widget_map[name] = w + get_widget_map()[name] = w return w - def add_state(self, state): - if "|" in state: - state = f"(lv_state_t)({state})" - return lv_obj.add_state(self.obj, literal(state)) + def set_state(self, state: MockObj, value: bool | Expression): + lv_add(lvgl_static.lv_obj_set_state_value(self.obj, state, value)) - def clear_state(self, state): - if "|" in state: - state = f"(lv_state_t)({state})" - return lv_obj.remove_state(self.obj, literal(state)) - - def has_state(self, state): - return (lv_expr.obj_get_state(self.obj) & literal(state)) != 0 + def has_state(self, state: MockObj): + return lv_expr.obj_has_state(self.obj, state) def is_pressed(self): return self.has_state(LV_STATE.PRESSED) @@ -346,10 +340,10 @@ class Widget: ltype = ltype or self.__type_base() return cg.RawExpression(f"lv_{ltype}_get_{prop}({self.obj})") - def set_style(self, prop, value, state=LV_STATE.DEFAULT): + def set_style(self, prop: str, value, state=LV_STATE.DEFAULT): if value is None: return - styles_used.add(prop) + get_styles_used().add(prop) if isinstance(value, str): value = literal(value) lv.call(f"obj_set_style_{prop}", self.obj, value, state) @@ -403,14 +397,6 @@ class Widget: return self.type.get_scale(self.config) -# Map of widgets to their config, used for trigger generation -widget_map: dict[ID, Widget] = {} - - -def is_widget_completed(name: ID) -> bool: - return name in widget_map - - class LvScrActType(WidgetType): """ A "widget" representing the active screen. @@ -433,10 +419,11 @@ def get_widget_generator(wid): :param wid: :return: """ + widget_map = get_widget_map() while True: if obj := widget_map.get(wid): return obj - if Widget.widgets_completed: + if get_widgets_completed(): raise Invalid( f"Widget {wid} not found, yet all widgets should be defined by now" ) @@ -444,20 +431,20 @@ def get_widget_generator(wid): async def get_widget_(wid): - if obj := widget_map.get(wid): + if obj := get_widget_map().get(wid): return obj return await FakeAwaitable(get_widget_generator(wid)) def widgets_wait_generator(): while True: - if Widget.widgets_completed: + if get_widgets_completed(): return yield async def wait_for_widgets(): - if Widget.widgets_completed: + if get_widgets_completed(): return await FakeAwaitable(widgets_wait_generator()) @@ -608,30 +595,14 @@ async def set_obj_properties(w: Widget, config): cond.else_() w.clear_flag(flag) - if states := config.get(CONF_STATE): - adds = set() - clears = set() - lambs = {} - for key, value in states.items(): - if isinstance(value, cv.Lambda): - lambs[key] = value - elif value: - adds.add(key) - else: - clears.add(key) - if adds: - adds = join_enums(adds, "LV_STATE_") - w.add_state(adds) - if clears: - clears = join_enums(clears, "LV_STATE_") - w.clear_state(clears) - for key, value in lambs.items(): - lamb = await cg.process_lambda(value, [], capture="=", return_type=cg.bool_) - state = f"LV_STATE_{key.upper()}" - with LvConditional(call_lambda(lamb)) as cond: - w.add_state(state) - cond.else_() - w.clear_state(state) + for key, value in config.get(CONF_STATE, {}).items(): + if isinstance(value, cv.Lambda): + value = call_lambda( + await cg.process_lambda(value, [], capture="=", return_type=cg.bool_) + ) + state = getattr(LV_STATE, key.upper()) + w.set_state(state, value) + for property in OBJ_PROPERTIES: await w.set_property(property, config, lv_name="obj") diff --git a/esphome/components/lvgl/widgets/animimg.py b/esphome/components/lvgl/widgets/animimg.py index 8e2db5ff350..b6d59df7f25 100644 --- a/esphome/components/lvgl/widgets/animimg.py +++ b/esphome/components/lvgl/widgets/animimg.py @@ -4,7 +4,6 @@ from esphome.const import CONF_DURATION, CONF_ID from ..automation import action_to_code from ..defines import CONF_AUTO_START, CONF_MAIN, CONF_REPEAT_COUNT, CONF_SRC -from ..helpers import lvgl_components_required from ..lv_validation import lv_image_list, lv_milliseconds from ..lvcode import lv from ..types import LvType, ObjUpdateAction @@ -55,8 +54,6 @@ class AnimimgType(WidgetType): ) async def to_code(self, w: Widget, config): - lvgl_components_required.add(CONF_IMAGE) - lvgl_components_required.add(CONF_ANIMIMG) if srcs := config.get(CONF_SRC): srcs = await lv_image_list.process(srcs) lv.animimg_set_src(w.obj, srcs) @@ -68,7 +65,7 @@ class AnimimgType(WidgetType): lv.animimg_start(w.obj) def get_uses(self): - return "img", CONF_IMAGE, CONF_LABEL + return CONF_IMAGE, CONF_LABEL animimg_spec = AnimimgType() diff --git a/esphome/components/lvgl/widgets/button.py b/esphome/components/lvgl/widgets/button.py index b943a4d9aa6..0ad512cd8bb 100644 --- a/esphome/components/lvgl/widgets/button.py +++ b/esphome/components/lvgl/widgets/button.py @@ -2,8 +2,7 @@ from esphome import config_validation as cv from esphome.const import CONF_BUTTON, CONF_TEXT from esphome.cpp_generator import MockObj -from ..defines import CONF_MAIN, CONF_WIDGETS -from ..helpers import add_lv_use +from ..defines import CONF_MAIN, CONF_WIDGETS, add_lv_use from ..lv_validation import lv_text from ..lvcode import lv, lv_expr from ..schemas import TEXT_SCHEMA diff --git a/esphome/components/lvgl/widgets/buttonmatrix.py b/esphome/components/lvgl/widgets/buttonmatrix.py index f5ae0deba93..02dc9ed4ba8 100644 --- a/esphome/components/lvgl/widgets/buttonmatrix.py +++ b/esphome/components/lvgl/widgets/buttonmatrix.py @@ -5,6 +5,7 @@ from esphome.components.key_provider import KeyProvider import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_ITEMS, CONF_TEXT, CONF_WIDTH from esphome.cpp_generator import MockObj +from esphome.types import Expression from ..automation import action_to_code from ..defines import ( @@ -17,10 +18,10 @@ from ..defines import ( CONF_PAD_COLUMN, CONF_PAD_ROW, CONF_SELECTED, + get_widget_map, ) -from ..helpers import lvgl_components_required from ..lv_validation import key_code, lv_bool, padding -from ..lvcode import lv, lv_add, lv_expr +from ..lvcode import lv, lv_add, lv_expr, lvgl_static from ..schemas import automation_schema from ..types import ( LV_BTNMATRIX_CTRL, @@ -32,7 +33,7 @@ from ..types import ( char_ptr, lv_pseudo_button_t, ) -from . import Widget, WidgetType, get_widgets, widget_map +from . import Widget, WidgetType, get_widgets from .button import lv_button_t CONF_BUTTONMATRIX = "buttonmatrix" @@ -98,7 +99,7 @@ class MatrixButton(Widget): @staticmethod def create_button(id, parent, config: dict, index): w = MatrixButton(id, parent, config, index) - widget_map[id] = w + get_widget_map()[id] = w return w def __init__(self, id, parent: Widget, config, index): @@ -120,13 +121,13 @@ class MatrixButton(Widget): state = self.map_ctrls(state) return lv_expr.buttonmatrix_has_button_ctrl(self.obj, self.index, state) - def add_state(self, state): - state = self.map_ctrls(state) - return lv.buttonmatrix_set_button_ctrl(self.obj, self.index, state) - - def clear_state(self, state): - state = self.map_ctrls(state) - return lv.buttonmatrix_clear_button_ctrl(self.obj, self.index, state) + def set_state(self, state: MockObj, value: bool | Expression): + ctrl = self.map_ctrls(state) + lv_add( + lvgl_static.lv_buttonmatrix_set_button_ctrl_value( + self.obj, self.index, ctrl, value + ) + ) def is_pressed(self): return self.is_selected() & self.parent.has_state(LV_STATE.PRESSED) @@ -191,7 +192,6 @@ class ButtonMatrixType(WidgetType): ) async def to_code(self, w: Widget, config): - lvgl_components_required.add("BUTTONMATRIX") if CONF_ROWS not in config: return text_list, ctrl_list, width_list, key_list = await get_button_data( diff --git a/esphome/components/lvgl/widgets/dropdown.py b/esphome/components/lvgl/widgets/dropdown.py index ca89bb625be..34e6ef4e357 100644 --- a/esphome/components/lvgl/widgets/dropdown.py +++ b/esphome/components/lvgl/widgets/dropdown.py @@ -14,7 +14,6 @@ from ..defines import ( DIRECTIONS, literal, ) -from ..helpers import lvgl_components_required from ..lv_validation import lv_int, lv_text, option_string from ..lvcode import LocalVariable, lv, lv_add, lv_expr from ..schemas import part_schema @@ -95,7 +94,6 @@ class DropdownType(WidgetType): ) async def to_code(self, w: Widget, config): - lvgl_components_required.add(CONF_DROPDOWN) if options := config.get(CONF_OPTIONS): lv_add(w.var.set_options(options)) if symbol := config.get(CONF_SYMBOL): @@ -116,7 +114,7 @@ class DropdownType(WidgetType): await set_obj_properties(dwid, dlist) def get_uses(self): - return (CONF_LABEL,) + return CONF_LABEL, CONF_DROPDOWN dropdown_spec = DropdownType() diff --git a/esphome/components/lvgl/widgets/keyboard.py b/esphome/components/lvgl/widgets/keyboard.py index c5628cee3cd..bcd2d2ae597 100644 --- a/esphome/components/lvgl/widgets/keyboard.py +++ b/esphome/components/lvgl/widgets/keyboard.py @@ -5,10 +5,15 @@ from esphome.core import CORE from esphome.cpp_types import std_string from .. import LvContext -from ..defines import CONF_MAIN, KEYBOARD_MODES, literal -from ..helpers import lvgl_components_required +from ..defines import ( + CONF_MAIN, + KEYBOARD_MODES, + add_lv_use, + is_widget_completed, + literal, +) from ..types import LvCompound, LvType -from . import Widget, WidgetType, get_widgets, is_widget_completed +from . import Widget, WidgetType, get_widgets from .buttonmatrix import CONF_BUTTONMATRIX from .textarea import CONF_TEXTAREA, lv_textarea_t @@ -47,8 +52,7 @@ class KeyboardType(WidgetType): return CONF_KEYBOARD, CONF_TEXTAREA, CONF_BUTTONMATRIX async def to_code(self, w: Widget, config: dict): - lvgl_components_required.add("KEY_LISTENER") - lvgl_components_required.add(CONF_KEYBOARD) + add_lv_use("KEY_LISTENER") if mode := config.get(CONF_MODE): await w.set_property(CONF_MODE, await KEYBOARD_MODES.process(mode)) if textarea := config.get(CONF_TEXTAREA): diff --git a/esphome/components/lvgl/widgets/meter.py b/esphome/components/lvgl/widgets/meter.py index ab65a7c47d5..62ea14bddaf 100644 --- a/esphome/components/lvgl/widgets/meter.py +++ b/esphome/components/lvgl/widgets/meter.py @@ -41,10 +41,10 @@ from ..defines import ( LV_OBJ_FLAG, LV_PART, LV_SCALE_MODE, + add_lv_use, get_remapped_uses, get_warnings, ) -from ..helpers import add_lv_use from ..lv_validation import ( LV_OPA, LV_RADIUS, @@ -61,7 +61,6 @@ from ..lv_validation import ( padding, pixels, pixels_or_percent, - requires_component, size, ) from ..lvcode import LambdaContext, LocalVariable, lv, lv_add, lv_expr, lv_obj @@ -214,7 +213,7 @@ INDICATOR_SCHEMA = cv.Schema( cv.GenerateID(CONF_IMAGE_ID): cv.declare_id(lv_image_t), } ), - requires_component("image"), + cv.requires_component("image"), ), cv.Exclusive(CONF_ARC, CONF_INDICATORS): INDICATOR_ARC_SCHEMA.extend( { diff --git a/esphome/components/lvgl/widgets/msgbox.py b/esphome/components/lvgl/widgets/msgbox.py index d0e6bfa3a2b..29087009cb9 100644 --- a/esphome/components/lvgl/widgets/msgbox.py +++ b/esphome/components/lvgl/widgets/msgbox.py @@ -16,10 +16,10 @@ from ..defines import ( CONF_TITLE, LV_OBJ_FLAG, TYPE_FLEX, + add_lv_use, add_warning, literal, ) -from ..helpers import add_lv_use from ..lv_validation import lv_bool, lv_image, lv_text, pixels_or_percent from ..lvcode import EVENT_ARG, LambdaContext, LocalVariable, lv, lv_expr, lv_obj from ..schemas import ( diff --git a/esphome/components/lvgl/widgets/roller.py b/esphome/components/lvgl/widgets/roller.py index 6f9fee47d4b..f3caaa43499 100644 --- a/esphome/components/lvgl/widgets/roller.py +++ b/esphome/components/lvgl/widgets/roller.py @@ -11,7 +11,6 @@ from ..defines import ( ROLLER_MODES, literal, ) -from ..helpers import lvgl_components_required from ..lv_validation import animated, lv_int, lv_text, option_string from ..lvcode import lv_add from ..types import LvSelect @@ -55,7 +54,6 @@ class RollerType(WidgetType): ) async def to_code(self, w, config): - lvgl_components_required.add(CONF_ROLLER) if mode := config.get(CONF_MODE): mode = await ROLLER_MODES.process(mode) lv_add(w.var.set_mode(mode)) diff --git a/tests/component_tests/lvgl/config/widget_state_test.yaml b/tests/component_tests/lvgl/config/widget_state_test.yaml new file mode 100644 index 00000000000..644bf7dac73 --- /dev/null +++ b/tests/component_tests/lvgl/config/widget_state_test.yaml @@ -0,0 +1,83 @@ +esphome: + name: test + +esp32: + board: esp32dev + framework: + type: esp-idf + +spi: + - id: spi_bus + clk_pin: GPIO18 + mosi_pin: GPIO23 + +display: + - platform: mipi_spi + spi_id: spi_bus + model: st7789v + id: tft_display + dimensions: + width: 240 + height: 320 + cs_pin: GPIO22 + dc_pin: GPIO21 + auto_clear_enabled: false + invert_colors: false + update_interval: never + +lvgl: + id: lvgl_id + displays: tft_display + pages: + - id: main_page + widgets: + # Widget with multiple static states; one true, one false. + - button: + id: btn_static + state: + checked: true + disabled: false + + # Widget with a templated (lambda) state. + - button: + id: btn_lambda + state: + pressed: !lambda return true; + + # Button referenced by enable/disable actions; the on_click handler + # exercises both branches of the obj_disable/obj_enable code path. + - button: + id: btn_actions + on_click: + - lvgl.widget.disable: btn_actions + - lvgl.widget.enable: btn_actions + + # Button matrix with two buttons; matrix_btn_a is targeted by + # lvgl.widget.disable/enable actions to exercise the + # MatrixButton.set_state code path. + - buttonmatrix: + id: matrix + rows: + - buttons: + - id: matrix_btn_a + text: A + control: + checkable: true + - id: matrix_btn_b + text: B + control: + checkable: true + on_click: + - lvgl.widget.disable: matrix_btn_a + - lvgl.widget.enable: matrix_btn_a + + # Switch derived from an LVGL switch widget – exercises + # set_state(LV_STATE.CHECKED, v) inside the control lambda. + - switch: + id: switch_widget + +switch: + - platform: lvgl + id: lvgl_switch + name: LVGL Switch + widget: switch_widget diff --git a/tests/component_tests/lvgl/test_widget_state.py b/tests/component_tests/lvgl/test_widget_state.py new file mode 100644 index 00000000000..2d87bb382e2 --- /dev/null +++ b/tests/component_tests/lvgl/test_widget_state.py @@ -0,0 +1,167 @@ +"""Tests for LVGL widget state code generation. + +These tests cover the change from the old ``add_state``/``clear_state`` helpers +on :class:`Widget` (and on :class:`MatrixButton`) to a single ``set_state`` +method that delegates to the new C++ helpers +``LvglComponent::lv_obj_set_state_value`` and +``LvglComponent::lv_buttonmatrix_set_button_ctrl_value``. +""" + +from __future__ import annotations + +from pathlib import Path + +import pytest + +from esphome.__main__ import generate_cpp_contents +from esphome.config import read_config +from esphome.core import CORE + + +@pytest.fixture(scope="module") +def main_cpp(request: pytest.FixtureRequest) -> str: + """Generate the C++ output for the shared widget-state YAML config once + per module. + + Module-scoped so the (relatively expensive) codegen runs a single time; + the function-scoped fixtures from ``conftest.py`` (e.g. ``generate_main``) + can't be requested from a higher-scoped fixture, so the small amount of + setup is inlined here. The captured string is independent of + ``CORE.reset()`` calls that the per-test autouse fixtures perform after + this fixture has produced its value. + """ + config_path = Path(request.fspath).parent / "config" / "widget_state_test.yaml" + original_path = CORE.config_path + try: + CORE.config_path = config_path + CORE.config = read_config({}) + generate_cpp_contents(CORE.config) + return CORE.cpp_global_section + CORE.cpp_main_section + finally: + CORE.config_path = original_path + CORE.reset() + + +def test_static_state_emits_set_state_value(main_cpp: str) -> None: + """A widget with ``state: { checked: true, disabled: false }`` should + generate one ``lv_obj_set_state_value`` call per entry, with the + appropriate boolean argument. + """ + assert ( + "LvglComponent::lv_obj_set_state_value(btn_static, LV_STATE_CHECKED, true)" + in main_cpp + ) + assert ( + "LvglComponent::lv_obj_set_state_value(btn_static, LV_STATE_DISABLED, false)" + in main_cpp + ) + + +def test_lambda_state_emits_set_state_value_with_lambda(main_cpp: str) -> None: + """A widget with ``state: { pressed: !lambda return true; }`` should + generate ``lv_obj_set_state_value(..., LV_STATE_PRESSED, )`` where + ```` is the lambda's return value (cast or inlined), not a static + bool. + """ + # The set_state call is emitted for the templated state. + assert ( + "LvglComponent::lv_obj_set_state_value(btn_lambda, LV_STATE_PRESSED," + in main_cpp + ) + # And it must NOT have collapsed the lambda to a literal true/false. + assert ( + "LvglComponent::lv_obj_set_state_value(btn_lambda, LV_STATE_PRESSED, true)" + not in main_cpp + ) + # The legacy if/else over add_state/remove_state is gone. + assert "lv_obj_add_state(btn_lambda, LV_STATE_PRESSED)" not in main_cpp + assert "lv_obj_remove_state(btn_lambda, LV_STATE_PRESSED)" not in main_cpp + + +def test_widget_disable_action_uses_set_state_value(main_cpp: str) -> None: + """``lvgl.widget.disable: btn_actions`` should emit a + ``set_state_value(..., LV_STATE_DISABLED, true)`` call rather than the + legacy ``lv_obj_add_state``. + """ + assert ( + "LvglComponent::lv_obj_set_state_value(btn_actions, LV_STATE_DISABLED, true)" + in main_cpp + ) + # No leftover legacy add_state for the DISABLED state of this widget. + assert "lv_obj_add_state(btn_actions, LV_STATE_DISABLED)" not in main_cpp + + +def test_widget_enable_action_uses_set_state_value(main_cpp: str) -> None: + """``lvgl.widget.enable: btn_actions`` should emit a + ``set_state_value(..., LV_STATE_DISABLED, false)`` call rather than the + legacy ``lv_obj_remove_state``. + """ + assert ( + "LvglComponent::lv_obj_set_state_value(btn_actions, LV_STATE_DISABLED, false)" + in main_cpp + ) + assert "lv_obj_remove_state(btn_actions, LV_STATE_DISABLED)" not in main_cpp + + +def test_buttonmatrix_disable_action_uses_helper(main_cpp: str) -> None: + """``lvgl.widget.disable: matrix_btn_a`` should route through the new + ``lv_buttonmatrix_set_button_ctrl_value`` helper for button index 0 + with the ``DISABLED`` control bit set to ``true``, instead of the + legacy ``lv_buttonmatrix_set_button_ctrl``. + + The button matrix obj is the compound's ``obj`` member and the index + is the position of the button in the row layout. + """ + assert ( + "LvglComponent::lv_buttonmatrix_set_button_ctrl_value(matrix->obj, 0, " + "LV_BUTTONMATRIX_CTRL_DISABLED, true)" + ) in main_cpp + + +def test_buttonmatrix_enable_action_uses_helper(main_cpp: str) -> None: + """``lvgl.widget.enable: matrix_btn_a`` should route through the new + ``lv_buttonmatrix_set_button_ctrl_value`` helper for button index 0 + with the ``DISABLED`` control bit set to ``false``, instead of the + legacy ``lv_buttonmatrix_clear_button_ctrl``. + """ + assert ( + "LvglComponent::lv_buttonmatrix_set_button_ctrl_value(matrix->obj, 0, " + "LV_BUTTONMATRIX_CTRL_DISABLED, false)" + ) in main_cpp + # The legacy clear_button_ctrl path is gone for the matrix button enable + # action. + assert ( + "lv_buttonmatrix_clear_button_ctrl(matrix->obj, 0, LV_BUTTONMATRIX_CTRL_DISABLED)" + not in main_cpp + ) + + +def test_lvgl_switch_control_calls_set_state_value(main_cpp: str) -> None: + """The LVGL switch platform installs a control lambda that mirrors the + switch's bool value into ``LV_STATE_CHECKED`` via + ``lv_obj_set_state_value`` (replacing the previous if/else over + ``add_state``/``clear_state`` plus an explicit ``send_event`` of + ``lv_api_event``). + """ + # The control lambda calls the new helper with the bool ``v`` parameter. + assert ( + "LvglComponent::lv_obj_set_state_value(switch_widget, LV_STATE_CHECKED, v)" + in main_cpp + ) + # The deprecated lv_api_event symbol must no longer appear anywhere. + assert "lv_api_event" not in main_cpp + + +def test_default_state_does_not_emit_set_state_value(main_cpp: str) -> None: + """A widget without a ``state:`` block must not generate any + ``lv_obj_set_state_value`` calls for it. (Sanity-check that the + new code path is opt-in driven by the YAML.) + """ + assert ( + "LvglComponent::lv_obj_set_state_value(switch_widget, LV_STATE_DISABLED" + not in main_cpp + ) + assert ( + "LvglComponent::lv_obj_set_state_value(btn_static, LV_STATE_PRESSED" + not in main_cpp + ) From 930d539969db8a38970ccc53b20d98af218b6e4b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 10 May 2026 19:07:15 -0500 Subject: [PATCH 22/52] [config_validation] Add a visibility UI-hint kwarg (#16267) --- esphome/components/time/__init__.py | 9 +- esphome/config_validation.py | 115 ++++++++++++- script/build_language_schema.py | 12 ++ tests/unit_tests/test_config_validation.py | 184 +++++++++++++++++++++ 4 files changed, 313 insertions(+), 7 deletions(-) diff --git a/esphome/components/time/__init__.py b/esphome/components/time/__init__.py index 3295366fea3..29bb01b499d 100644 --- a/esphome/components/time/__init__.py +++ b/esphome/components/time/__init__.py @@ -345,7 +345,14 @@ TIME_SCHEMA = cv.Schema( } ), } -).extend(cv.polling_component_schema("15min")) +).extend( + # ``visibility=ADVANCED`` flags the inherited ``update_interval`` + # field for visual editors — the 15min default is correct for + # essentially every user, so editors should keep it tucked under + # "advanced" so it doesn't crowd the form. Validation is + # unaffected; YAML can override as before. + cv.polling_component_schema("15min", visibility=cv.Visibility.ADVANCED) +) def _emit_dst_rule_fields(prefix, rule): diff --git a/esphome/config_validation.py b/esphome/config_validation.py index fbafc5cb07b..c993c1dcc5e 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -89,6 +89,7 @@ from esphome.core import ( TimePeriodNanoseconds, TimePeriodSeconds, ) +from esphome.enum import StrEnum from esphome.expression import SUBSTITUTION_VARIABLE_PROG as VARIABLE_PROG from esphome.helpers import add_class_to_obj, docs_url, list_starts_with from esphome.schema_extractors import ( @@ -281,6 +282,54 @@ RESERVED_IDS = [ ] +class Visibility(StrEnum): + """Schema-driven UI hint for visual editors. + + The values describe how a schema-aware editor (e.g. the + device-builder dashboard catalog via + ``script/build_language_schema.py``) should render the field. + They do NOT affect validation — the YAML still accepts the key + the same way. ESPHome itself ignores the value at runtime; + consumers downstream of the schema dump act on it. + + A field with no ``visibility`` set (the default) renders on the + editor's main form. The two values below are points along a + single axis of "how prominently to surface this": + + - ``ADVANCED`` — render under the editor's "advanced settings" + disclosure. Use for fields whose default is right for ~all + users (e.g. ``update_interval`` on time platforms — 15 min is + universally correct, but power users can still tune the YAML + directly). + - ``YAML_ONLY`` — never render in a visual editor. Use for + knobs that are dangerous to expose in a UI even as advanced + (``setup_priority`` is the canonical example — casual UI + tweaks can break boot). The YAML escape hatch stays + available for the rare power-user override. + + The single-axis shape encodes "yaml-only is strictly stronger + than advanced" at the type level — there's no way to ask for + both at once, and no way to set a contradictory state like + "advanced=False, yaml_only=True". + + Per-field; the dumper walks recursively into nested schemas + and emits each field's setting independently. Cascading + semantics — "a stricter parent makes its descendants at-least + as strict" — belong on the consumer side: the schema marker + is faithfully what the field author wrote, and a consumer that + cares about effective visibility walks the parent chain and + takes the strictest setting. ``YAML_ONLY`` is strictly stronger + than ``ADVANCED``, which is strictly stronger than no setting. + Inner fields can declare their own visibility; an inner + ``YAML_ONLY`` under an ``ADVANCED`` parent stays ``YAML_ONLY``, + and the consumer's cascade keeps siblings under the parent at + ``ADVANCED`` regardless of their own (less-strict) setting. + """ + + ADVANCED = "advanced" + YAML_ONLY = "yaml_only" + + class Optional(vol.Optional): """Mark a field as optional and optionally define a default for the field. @@ -295,22 +344,45 @@ class Optional(vol.Optional): In ESPHome, all configuration defaults should be defined with the Optional class during config validation - specifically *not* in the C++ code or the code generation phase. + + See :class:`Visibility` for the ``visibility`` kwarg — a UI + hint for schema-driven editors that doesn't affect validation. """ - def __init__(self, key, default=UNDEFINED): + def __init__( + self, + key, + default=UNDEFINED, + *, + visibility: Visibility | None = None, + ): super().__init__(key, default=default) + self.visibility: Visibility | None = visibility class Required(vol.Required): """Define a field to be required to be set. The validated configuration is guaranteed to contain this key. - All required values should be acceessed with the `config[CONF_]` syntax in code + All required values should be accessed with the `config[CONF_]` syntax in code - *not* the `config.get(CONF_)` syntax. + + See :class:`Visibility` for the ``visibility`` kwarg — a UI + hint for schema-driven editors that doesn't affect validation. + Required fields rarely need it (a required field by definition + needs the user's attention) but the kwarg is exposed for + symmetry so consumers can apply uniform logic across key markers. """ - def __init__(self, key, msg=None): + def __init__( + self, + key, + msg=None, + *, + visibility: Visibility | None = None, + ): super().__init__(key, msg=msg) + self.visibility: Visibility | None = visibility class FinalExternalInvalid(Invalid): @@ -2162,16 +2234,45 @@ ENTITY_BASE_SCHEMA = Schema( ENTITY_BASE_SCHEMA.add_extra(_entity_base_validator) -COMPONENT_SCHEMA = Schema({Optional(CONF_SETUP_PRIORITY): float_}) +COMPONENT_SCHEMA = Schema( + { + # ``setup_priority`` controls the relative order in which + # components are brought up at boot. Wrong values can break + # the boot sequence in subtle ways (e.g. an i2c device set + # to higher priority than the bus). Mark it ``YAML_ONLY`` so + # visual editors never render it — the YAML escape hatch + # stays available for the rare component author who really + # needs to override the default. + Optional(CONF_SETUP_PRIORITY, visibility=Visibility.YAML_ONLY): float_, + } +) -def polling_component_schema(default_update_interval): +def polling_component_schema( + default_update_interval, *, visibility: Visibility | None = None +): """Validate that this component represents a PollingComponent with a configurable update_interval. :param default_update_interval: The default update interval to set for the integration. + :param visibility: When set, propagate to the inherited + ``update_interval`` field's :class:`Visibility` UI hint. Set + this for components whose default cadence is already correct + for ~all users (e.g. time platforms — pass + ``Visibility.ADVANCED``). + + Only honoured on the optional-default branch. When + ``default_update_interval`` is ``None`` the field becomes + ``Required`` (the component has no sensible default cadence and + needs the user to choose), and hiding a Required field behind + an advanced disclosure would be a UX hazard — collapsed-by-default + editors could let the user submit without realising the form has + an unfilled required field. The kwarg is silently ignored on that + path so callers can pass it unconditionally. """ if default_update_interval is None: + # Required → don't honour ``visibility``. + # See the docstring for the UX rationale. return COMPONENT_SCHEMA.extend( { Required(CONF_UPDATE_INTERVAL): update_interval, @@ -2181,7 +2282,9 @@ def polling_component_schema(default_update_interval): return COMPONENT_SCHEMA.extend( { Optional( - CONF_UPDATE_INTERVAL, default=default_update_interval + CONF_UPDATE_INTERVAL, + default=default_update_interval, + visibility=visibility, ): update_interval, } ) diff --git a/script/build_language_schema.py b/script/build_language_schema.py index 05ac47bfcce..a7142fa8b5e 100755 --- a/script/build_language_schema.py +++ b/script/build_language_schema.py @@ -1103,6 +1103,18 @@ def convert_keys(converted, schema, path): if default_value is not None: result["default"] = str(default_value) + # UI hint from ``cv.Optional`` / ``cv.Required`` — surfaced + # for schema consumers (visual editors) that want to render + # advanced / yaml-only fields differently. ESPHome itself + # ignores it at runtime; emitting only when set keeps the + # dump compact and backwards-compatible with markers that + # don't carry the attribute. The value is the str form of + # ``cv.Visibility`` (e.g. ``"advanced"`` / ``"yaml_only"``) + # so consumers don't need an enum import to read it. + visibility = getattr(k, "visibility", None) + if visibility is not None: + result["visibility"] = str(visibility) + # Do value convert(v, result, path + f"/{str(k)}") if "schema" not in converted: diff --git a/tests/unit_tests/test_config_validation.py b/tests/unit_tests/test_config_validation.py index f038272d8b0..fd6c0e95f2a 100644 --- a/tests/unit_tests/test_config_validation.py +++ b/tests/unit_tests/test_config_validation.py @@ -793,3 +793,187 @@ def test_update_interval__never_passes_through() -> None: """update_interval: never must still map to SCHEDULER_DONT_RUN.""" result = config_validation.update_interval("never") assert result.total_milliseconds == SCHEDULER_DONT_RUN + + +# --------------------------------------------------------------------------- +# Visibility UI-hint kwarg +# --------------------------------------------------------------------------- + + +def test_optional_default_visibility_is_none() -> None: + """An ``Optional`` with no ``visibility`` kwarg reports ``None``. + + Consumers can read the attribute directly with plain attribute + access; absence (``None``) means "render on the editor's main + form." + """ + o = config_validation.Optional("foo") + assert o.visibility is None + + +def test_optional_visibility_advanced() -> None: + """``visibility=Visibility.ADVANCED`` is recorded on the marker.""" + o = config_validation.Optional( + "foo", visibility=config_validation.Visibility.ADVANCED + ) + assert o.visibility is config_validation.Visibility.ADVANCED + + +def test_optional_visibility_yaml_only() -> None: + """``visibility=Visibility.YAML_ONLY`` is recorded on the marker.""" + o = config_validation.Optional( + "foo", visibility=config_validation.Visibility.YAML_ONLY + ) + assert o.visibility is config_validation.Visibility.YAML_ONLY + + +def test_visibility_str_values_match_dump_emission() -> None: + """``Visibility`` is a ``StrEnum`` whose values are the literal + strings the schema dumper emits. + + The schema bundle consumers (catalog generators, third-party + schema-aware tooling) shouldn't need an enum import to read the + field — pinning the on-the-wire spelling here keeps the dump + contract stable. + """ + assert str(config_validation.Visibility.ADVANCED) == "advanced" + assert str(config_validation.Visibility.YAML_ONLY) == "yaml_only" + + +def test_optional_visibility_does_not_affect_validation() -> None: + """The kwarg is an advisory UI hint — it must not change how the + validator behaves. A schema with ``visibility`` applied must + accept and reject the same values it would without it. + """ + plain = config_validation.Schema( + {config_validation.Optional("foo", default=42): config_validation.int_} + ) + flagged = config_validation.Schema( + { + config_validation.Optional( + "foo", + default=42, + visibility=config_validation.Visibility.YAML_ONLY, + ): config_validation.int_ + } + ) + # Same accept / default-fill behavior. + assert plain({"foo": 7}) == flagged({"foo": 7}) == {"foo": 7} + assert plain({}) == flagged({}) == {"foo": 42} + # Same rejection on bad input. + with pytest.raises(Invalid): + plain({"foo": "not-an-int"}) + with pytest.raises(Invalid): + flagged({"foo": "not-an-int"}) + + +def test_required_default_visibility_is_none() -> None: + """``Required`` mirrors ``Optional`` for the ``visibility`` kwarg.""" + r = config_validation.Required("foo") + assert r.visibility is None + + +def test_required_visibility_kwarg() -> None: + """``Required`` accepts ``visibility`` for symmetry with ``Optional``. + + Required fields rarely need the kwarg, but exposing it lets + consumers apply uniform logic across key markers. + """ + r = config_validation.Required( + "foo", visibility=config_validation.Visibility.ADVANCED + ) + assert r.visibility is config_validation.Visibility.ADVANCED + + +def test_polling_component_schema_visibility_opt_in() -> None: + """``visibility=`` propagates to the inherited ``update_interval``. + + Time platforms pass ``Visibility.ADVANCED``; sensors and other + polling components leave it ``None`` and keep the un-flagged shape. + """ + default = config_validation.polling_component_schema("15min") + advanced = config_validation.polling_component_schema( + "15min", visibility=config_validation.Visibility.ADVANCED + ) + default_keys = {str(k): k for k in default.schema} + advanced_keys = {str(k): k for k in advanced.schema} + assert default_keys["update_interval"].visibility is None + assert ( + advanced_keys["update_interval"].visibility + is config_validation.Visibility.ADVANCED + ) + # The opt-in only touches update_interval — setup_priority + # still inherits its YAML_ONLY visibility from COMPONENT_SCHEMA + # in both shapes. + assert ( + default_keys["setup_priority"].visibility + is config_validation.Visibility.YAML_ONLY + ) + assert ( + advanced_keys["setup_priority"].visibility + is config_validation.Visibility.YAML_ONLY + ) + + +def test_polling_component_schema_no_default_ignores_visibility() -> None: + """``visibility`` is silently ignored when the field is Required. + + When ``default_update_interval=None`` the field becomes + ``Required``. Hiding a Required field behind an advanced + disclosure is a UX hazard — a collapsed-by-default editor could + let the user submit without noticing the form has an unfilled + required field. The helper accepts the kwarg unconditionally + for caller ergonomics but doesn't honour it on this branch. + """ + schema = config_validation.polling_component_schema( + None, visibility=config_validation.Visibility.ADVANCED + ) + keys = {str(k): k for k in schema.schema} + assert isinstance(keys["update_interval"], config_validation.Required) + assert keys["update_interval"].visibility is None + + +def test_visibility_marker_is_per_field_no_mutation() -> None: + """Each field's ``visibility`` is recorded as the author wrote it. + + Cascading semantics — "a stricter parent forces its descendants + at-least as strict" — live on the consumer side, not in the + marker itself. The schema marker stays as-written so consumers + can walk the parent chain and compute the effective visibility + themselves; mutating the marker would lose the per-field author + intent. + + Pin both directions of the no-mutation contract: an inner + ``YAML_ONLY`` under an ``ADVANCED`` parent stays ``YAML_ONLY`` + on the marker (the consumer's effective-visibility cascade + would also report ``YAML_ONLY`` since it's stricter), and an + un-marked inner field stays ``None`` on the marker (the + cascade's job is to compute ``ADVANCED`` from the parent — a + detail this test deliberately doesn't pin, since it's a + consumer concern). + """ + inner_unset = config_validation.Optional("baz") + inner_yaml_only = config_validation.Optional( + "qux", visibility=config_validation.Visibility.YAML_ONLY + ) + parent = config_validation.Optional( + "foo", visibility=config_validation.Visibility.ADVANCED + ) + + # Wire them into a nested schema — none of the markers' own + # ``visibility`` should change as a result. + schema = config_validation.Schema( + { + parent: config_validation.Schema( + { + inner_unset: config_validation.int_, + inner_yaml_only: config_validation.string, + } + ) + } + ) + assert schema # touch the schema so any deferred mutation runs + + assert parent.visibility is config_validation.Visibility.ADVANCED + assert inner_unset.visibility is None + assert inner_yaml_only.visibility is config_validation.Visibility.YAML_ONLY From 17080ddce6c98a10ebdd50544fbd688c226e5c44 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 10 May 2026 19:56:56 -0500 Subject: [PATCH 23/52] [wifi][rp2040] Add stable wifi-capability helpers for device-builder (#16300) --- esphome/components/rp2040/__init__.py | 16 +++- esphome/components/wifi/__init__.py | 61 +++++++++++++- tests/unit_tests/components/test_rp2040.py | 29 +++++++ tests/unit_tests/components/test_wifi.py | 96 ++++++++++++++++++++++ 4 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 tests/unit_tests/components/test_rp2040.py create mode 100644 tests/unit_tests/components/test_wifi.py diff --git a/esphome/components/rp2040/__init__.py b/esphome/components/rp2040/__init__.py index 79ed00cb416..7e450578cdd 100644 --- a/esphome/components/rp2040/__init__.py +++ b/esphome/components/rp2040/__init__.py @@ -48,7 +48,21 @@ def board_has_wifi() -> bool: Returns True for unknown/custom boards to avoid rejecting valid configurations for boards not in the generated list. """ - board_info = boards.BOARDS.get(get_board()) + return board_id_has_wifi(get_board()) + + +def board_id_has_wifi(board_id: str) -> bool: + """Return True if *board_id* has WiFi (CYW43 wireless chip). + + Returns True for unknown/custom boards to avoid rejecting valid + configurations for boards not in the generated list. + + Used by device-builder (esphome/device-builder) — separate + explicit-arg helper so callers outside the compile pipeline + don't need ``CORE`` set up to query the board map. Please keep + the signature stable. + """ + board_info = boards.BOARDS.get(board_id) if board_info is None: return True return board_info.get("wifi", False) diff --git a/esphome/components/wifi/__init__.py b/esphome/components/wifi/__init__.py index 69544f36367..316d4321403 100644 --- a/esphome/components/wifi/__init__.py +++ b/esphome/components/wifi/__init__.py @@ -67,9 +67,66 @@ _LOGGER = logging.getLogger(__name__) AUTO_LOAD = ["network"] -_LOGGER = logging.getLogger(__name__) - NO_WIFI_VARIANTS = [const.VARIANT_ESP32H2, const.VARIANT_ESP32P4] + + +def variant_has_wifi(variant: str) -> bool: + """Return True if *variant* has a native WiFi PHY. + + Variants without a native PHY (ESP32-H2, ESP32-P4) need the + ``esp32_hosted`` co-processor to use ``wifi:``. + + Used by device-builder (esphome/device-builder) to decide whether + its basic-setup wizard emits a ``wifi:`` block — please keep the + signature stable. + """ + return variant not in NO_WIFI_VARIANTS + + +_WIFI_FIRST_PLATFORMS: frozenset[str] = frozenset( + { + Platform.ESP8266, + Platform.BK72XX, + Platform.RTL87XX, + Platform.LN882X, + # Legacy umbrella key for the LibreTiny families (bk72xx / + # rtl87xx / ln882x); still produced by older configs that + # haven't migrated to the per-family keys. + Platform.LIBRETINY_OLDSTYLE, + } +) + + +def has_native_wifi( + *, platform: str, board: str | None = None, variant: str | None = None +) -> bool: + """Return True when the given platform/board/variant has native WiFi. + + Single dispatch entry point for tooling that needs to decide + whether emitting a ``wifi:`` block produces a compilable + config. Caller passes whichever platform-relevant fields they + have (``variant`` for ESP32, ``board`` for RP2040), and this + function routes to the right per-platform check internally. + + Allowlist-based: unknown / Wi-Fi-less platforms (``host``, + ``nrf52``) return False so a future platform added to ESPHome + fails closed in external tooling rather than silently emitting + a ``wifi:`` block the new platform's component would reject. + + Used by device-builder (esphome/device-builder)'s basic-setup + wizard. Centralised here so callers don't have to special-case + each platform — as ESPHome adds new platforms, this dispatcher + is the one place to teach them about Wi-Fi capability. + """ + if platform == Platform.ESP32: + return variant_has_wifi(variant) if variant else True + if platform == Platform.RP2040: + from esphome.components.rp2040 import board_id_has_wifi + + return board_id_has_wifi(board) if board else True + return platform in _WIFI_FIRST_PLATFORMS + + CONF_SAVE = "save" CONF_BAND_MODE = "band_mode" CONF_MIN_AUTH_MODE = "min_auth_mode" diff --git a/tests/unit_tests/components/test_rp2040.py b/tests/unit_tests/components/test_rp2040.py new file mode 100644 index 00000000000..25a9ade567b --- /dev/null +++ b/tests/unit_tests/components/test_rp2040.py @@ -0,0 +1,29 @@ +"""Tests for RP2040 component public helpers.""" + +from esphome.components.rp2040 import board_id_has_wifi + + +def test_board_id_has_wifi_for_known_wifi_board() -> None: + """``rpipicow`` is the canonical Pico W → True.""" + assert board_id_has_wifi("rpipicow") is True + + +def test_board_id_has_wifi_for_known_non_wifi_board() -> None: + """Plain ``rpipico`` has no CYW43 → False.""" + assert board_id_has_wifi("rpipico") is False + + +def test_board_id_has_wifi_for_rp2350_w_variant() -> None: + """``rpipico2w`` is the RP2350 Pico 2 W → True.""" + assert board_id_has_wifi("rpipico2w") is True + + +def test_board_id_has_wifi_for_unknown_board_returns_true() -> None: + """Unknown ids fail open so a custom board is not rejected. + + The validator falls back to ESPHome's compile-time check; the + helper returning True here means the wizard emits a ``wifi:`` + block and any genuinely-unsupported config trips the existing + "no CYW43" guard at compile time. + """ + assert board_id_has_wifi("not-a-real-board-id") is True diff --git a/tests/unit_tests/components/test_wifi.py b/tests/unit_tests/components/test_wifi.py new file mode 100644 index 00000000000..e93ae4b5036 --- /dev/null +++ b/tests/unit_tests/components/test_wifi.py @@ -0,0 +1,96 @@ +"""Tests for WiFi component public helpers.""" + +import pytest + +from esphome.components.esp32 import const +from esphome.components.wifi import has_native_wifi, variant_has_wifi +from esphome.const import Platform + + +@pytest.mark.parametrize( + "variant", + [ + const.VARIANT_ESP32, + const.VARIANT_ESP32S2, + const.VARIANT_ESP32S3, + const.VARIANT_ESP32C3, + const.VARIANT_ESP32C6, + ], +) +def test_variant_has_wifi_for_native_phy_variants(variant: str) -> None: + """Variants with a native WiFi PHY → True.""" + assert variant_has_wifi(variant) is True + + +@pytest.mark.parametrize( + "variant", + [ + const.VARIANT_ESP32H2, + const.VARIANT_ESP32P4, + ], +) +def test_variant_has_wifi_for_no_phy_variants(variant: str) -> None: + """Variants that need ``esp32_hosted`` → False.""" + assert variant_has_wifi(variant) is False + + +def test_has_native_wifi_dispatches_esp32_to_variant_check() -> None: + """ESP32 platform routes through ``variant_has_wifi``.""" + assert ( + has_native_wifi(platform=Platform.ESP32, variant=const.VARIANT_ESP32C3) is True + ) + assert ( + has_native_wifi(platform=Platform.ESP32, variant=const.VARIANT_ESP32H2) is False + ) + + +def test_has_native_wifi_dispatches_rp2040_to_board_check() -> None: + """RP2040 platform routes through ``rp2040.board_id_has_wifi``.""" + assert has_native_wifi(platform=Platform.RP2040, board="rpipicow") is True + assert has_native_wifi(platform=Platform.RP2040, board="rpipico") is False + + +def test_has_native_wifi_returns_false_for_nrf52() -> None: + """nRF52 family is BLE-only — no Wi-Fi PHY in the platform.""" + assert has_native_wifi(platform=Platform.NRF52) is False + + +def test_has_native_wifi_returns_false_for_host() -> None: + """``host`` platform compiles ESPHome to a host binary — no radio at all.""" + assert has_native_wifi(platform=Platform.HOST) is False + + +def test_has_native_wifi_returns_false_for_unknown_platform() -> None: + """Unknown platform string fails closed. + + A future platform added to ESPHome that's missed here returns + False rather than silently emitting a ``wifi:`` block external + tooling would have to compile and reject — fail-closed surfaces + the gap as an obvious "needs wifi support added" signal. + """ + assert has_native_wifi(platform="not-a-real-platform") is False + + +@pytest.mark.parametrize( + "platform", + [ + Platform.ESP8266, + Platform.BK72XX, + Platform.RTL87XX, + Platform.LN882X, + Platform.LIBRETINY_OLDSTYLE, + ], +) +def test_has_native_wifi_returns_true_for_wifi_first_platforms(platform: str) -> None: + """Catch-all Wi-Fi-first platforms → True regardless of board / variant.""" + assert has_native_wifi(platform=platform) is True + + +def test_has_native_wifi_esp32_without_variant_assumes_wifi() -> None: + """ESP32 without a variant id falls open to True (the chip family default).""" + assert has_native_wifi(platform=Platform.ESP32) is True + + +def test_has_native_wifi_rp2040_without_board_assumes_wifi() -> None: + """RP2040 without a board id falls open to True (custom-board default).""" + assert has_native_wifi(platform=Platform.RP2040) is True From 66e2dcffc448ae60e8c1209bbc0aeca1b50f371d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 10 May 2026 20:00:09 -0500 Subject: [PATCH 24/52] [cli] Tighten command_rename: scoped name rewrite, target-collision check (#16296) --- esphome/__main__.py | 62 ++++- tests/unit_tests/test_main.py | 461 ++++++++++++++++++++++++++++++++++ 2 files changed, 519 insertions(+), 4 deletions(-) diff --git a/esphome/__main__.py b/esphome/__main__.py index c1451c5fafd..a0ee5a359f4 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -1813,11 +1813,32 @@ def command_rename(args: ArgsProtocol, config: ConfigType) -> int | None: old_name = yaml[CONF_ESPHOME][CONF_NAME] match = re.match(r"^\$\{?([a-zA-Z0-9_]+)\}?$", old_name) if match is None: - new_raw = re.sub( - rf"name:\s+[\"']?{old_name}[\"']?", - f'name: "{new_name}"', - raw_contents, + # Only swap the ``name:`` line that sits directly under the + # top-level ``esphome:`` block. A naked ``re.sub`` would + # also clobber any other ``name:`` line whose value happens + # to match (e.g. a sensor / output / wifi entry sharing the + # device's hostname), silently rewriting unrelated user + # configuration. The pattern anchors: + # - at the start of the line so ``friendly_name:``, + # ``device_name:`` etc. don't match the trailing ``name:`` + # substring; and + # - at the end of the value (lookahead for whitespace + + # comment + EOL) so ``old_name`` doesn't match as a + # prefix of a longer value (``kitchen`` vs ``kitchen2``). + name_pattern = re.compile( + rf"^(\s*)name:\s+[\"']?{re.escape(old_name)}[\"']?(?=\s*(?:#|$))" ) + out_lines: list[str] = [] + in_esphome_block = False + for line in raw_contents.splitlines(keepends=True): + if line and not line[0].isspace() and line.strip(): + in_esphome_block = line.lstrip().startswith("esphome:") + out_lines.append(line) + continue + if in_esphome_block: + line = name_pattern.sub(rf'\1name: "{new_name}"', line, count=1) + out_lines.append(line) + new_raw = "".join(out_lines) else: old_name = yaml[CONF_SUBSTITUTIONS][match.group(1)] if ( @@ -1840,7 +1861,40 @@ def command_rename(args: ArgsProtocol, config: ConfigType) -> int | None: flags=re.MULTILINE, ) + # ``new_name == old_name`` (after substitution resolution) is + # a no-op rewrite that would still queue a pointless re-flash. + # Catch it before the path-equality check below — covers the + # case where the config filename doesn't match the device name + # (e.g. ``weird-file.yaml`` whose ``esphome.name`` is + # ``kitchen``; running ``esphome rename weird-file.yaml kitchen`` + # would otherwise just re-flash the same hostname). + if new_name == old_name: + print( + color( + AnsiFore.BOLD_RED, + f"'{new_name}' is already the device's name.", + ) + ) + return 1 + new_path: Path = CORE.config_dir / (new_name + ".yaml") + if new_path.resolve() == CORE.config_path.resolve(): + print( + color( + AnsiFore.BOLD_RED, + f"'{new_name}' is already the device's name.", + ) + ) + return 1 + if new_path.exists(): + print( + color( + AnsiFore.BOLD_RED, + f"Cannot rename: {new_path} already exists. " + "Refusing to overwrite an existing configuration.", + ) + ) + return 1 print( f"Updating {color(AnsiFore.CYAN, str(CORE.config_path))} to {color(AnsiFore.CYAN, str(new_path))}" ) diff --git a/tests/unit_tests/test_main.py b/tests/unit_tests/test_main.py index 4b0590cf76d..2823310f0e4 100644 --- a/tests/unit_tests/test_main.py +++ b/tests/unit_tests/test_main.py @@ -3595,6 +3595,467 @@ esp32: assert "Rename failed" in captured.out +def test_command_rename_install_failure_reverts( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename when the install (esphome run) step fails.""" + config_file = tmp_path / "oldname.yaml" + config_file.write_text(""" +esphome: + name: oldname + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "oldname"}} + + args = MockArgs(name="newname", dashboard=False) + + # First call (config validation) succeeds; second (esphome run) fails. + mock_run_external_process.side_effect = [0, 1] + + result = command_rename(args, {}) + + assert result == 1 + + # New file was unlinked when install failed. + new_file = tmp_path / "newname.yaml" + assert not new_file.exists() + + # Old file is preserved so the device stays reachable under the + # original hostname. + assert config_file.exists() + + +def test_command_rename_target_exists_refuses( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename refuses when the target filename already exists. + + Without this guard, the rename would overwrite the unrelated + device's YAML and OTA-install our firmware to the wrong device. + """ + config_file = tmp_path / "oldname.yaml" + config_file.write_text(""" +esphome: + name: oldname + +esp32: + board: nodemcu-32s +""") + target_file = tmp_path / "newname.yaml" + target_file.write_text(""" +esphome: + name: someoneelse + +esp32: + board: nodemcu-32s +""") + target_original = target_file.read_text() + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "oldname"}} + + args = MockArgs(name="newname", dashboard=False) + + result = command_rename(args, {}) + + assert result == 1 + # No subprocess work happened — refusal is up-front. + mock_run_external_process.assert_not_called() + # Target file untouched: same content, still on disk. + assert target_file.exists() + assert target_file.read_text() == target_original + # Source file untouched. + assert config_file.exists() + + captured = capfd.readouterr() + assert "already exists" in captured.out + + +def test_command_rename_same_name_refuses( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename refuses when the new name matches the current name. + + A same-name rename would otherwise re-write the YAML and queue + a redundant compile + install — wasted work the user almost + certainly didn't intend. + """ + config_file = tmp_path / "samename.yaml" + config_file.write_text(""" +esphome: + name: samename + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "samename"}} + + args = MockArgs(name="samename", dashboard=False) + + result = command_rename(args, {}) + + assert result == 1 + mock_run_external_process.assert_not_called() + # File preserved verbatim — no rewrite happened. + assert config_file.exists() + + captured = capfd.readouterr() + assert "already" in captured.out.lower() + + +def test_command_rename_does_not_touch_friendly_name_substring( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + r"""Test rename does not match the ``name:`` substring of ``friendly_name:``. + + Without anchoring the regex at line start, the pattern + ``\s*name:\s+`` could match the trailing ``name:`` + substring inside ``friendly_name: ``. The rewrite would + flip both lines to the new name, leaving the user with a + silently corrupted ``friendly_name``. + """ + config_file = tmp_path / "oldname.yaml" + config_file.write_text(""" +esphome: + name: oldname + friendly_name: oldname + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "oldname"}} + + args = MockArgs(name="newname", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + new_file = tmp_path / "newname.yaml" + content = new_file.read_text() + # esphome.name swapped. + assert 'name: "newname"' in content + # friendly_name kept verbatim. + assert "friendly_name: oldname" in content + + +def test_command_rename_does_not_match_old_name_as_value_prefix( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + r"""Test rename does not match ``old_name`` as a prefix of a longer value. + + With ``old_name = kitchen`` the value ``kitchen2`` (a sensor + or wifi entry) would otherwise match the unanchored + ``["']?kitchen["']?`` pattern at the prefix and get + rewritten to the new name. The end-of-value lookahead keeps + the match restricted to whole tokens. + """ + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: kitchen + +esp32: + board: nodemcu-32s + +wifi: + ap: + ssid: kitchen2 +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="garage", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + new_file = tmp_path / "garage.yaml" + content = new_file.read_text() + assert 'name: "garage"' in content + # The wifi ssid value is unrelated and stays intact. + assert "ssid: kitchen2" in content + + +def test_command_rename_same_resolved_name_refuses( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename refuses when ``new_name`` matches the resolved device name. + + The path-equality check only catches the case where the + config filename matches the device name. For a config whose + filename and ``esphome.name`` differ (here ``weird-file.yaml`` + holds ``esphome.name: kitchen``), running + ``esphome rename weird-file.yaml kitchen`` would otherwise + fall through to the rewrite + install: the YAML's name stays + ``kitchen``, the file is renamed to ``kitchen.yaml``, and the + device gets a redundant flash. Refuse up-front so the + "already the device's name" message matches reality. + """ + config_file = tmp_path / "weird-file.yaml" + config_file.write_text(""" +esphome: + name: kitchen + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="kitchen", dashboard=False) + + result = command_rename(args, {}) + + assert result == 1 + mock_run_external_process.assert_not_called() + # Source file untouched, no derived target written. + assert config_file.exists() + assert not (tmp_path / "kitchen.yaml").exists() + + captured = capfd.readouterr() + assert "already" in captured.out.lower() + + +def test_command_rename_target_path_equals_source_refuses( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename refuses when the new path resolves to the source file. + + Reachable only when the YAML's filename and ``esphome.name`` + disagree — here ``kitchen.yaml`` holds ``esphome.name: garage`` + and the user runs ``esphome rename kitchen.yaml kitchen``. The + name-equality check above passes (``garage != kitchen``), but + ``/kitchen.yaml`` resolves to the source file + itself, so the rewrite would clobber the source mid-rename. + Refuse rather than silently overwriting. + """ + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: garage + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "garage"}} + + args = MockArgs(name="kitchen", dashboard=False) + + result = command_rename(args, {}) + + assert result == 1 + mock_run_external_process.assert_not_called() + # Source file still present and unmodified. + assert config_file.exists() + assert "name: garage" in config_file.read_text() + + captured = capfd.readouterr() + assert "already" in captured.out.lower() + + +def test_command_rename_does_not_touch_lookalike_name_in_other_blocks( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + """Test rename only swaps the esphome.name line. + + A device whose name happens to match a sensor's / output's + ``name:`` value must not have those other names rewritten — + they're independent. Without an anchor for the esphome block + a naive regex would clobber every line whose value matches. + """ + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: kitchen + +esp32: + board: nodemcu-32s + +sensor: + - platform: template + name: kitchen + lambda: 'return 0;' +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="garage", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + + new_file = tmp_path / "garage.yaml" + content = new_file.read_text() + # esphome.name renamed. + assert 'name: "garage"' in content + # Sensor's name is the user's entity name — must not be touched. + assert " name: kitchen\n" in content + + +def test_command_rename_preserves_trailing_comment( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + """Test rename preserves a trailing ``# comment`` on the name line.""" + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: kitchen # primary device + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="garage", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + + new_file = tmp_path / "garage.yaml" + content = new_file.read_text() + assert "# primary device" in content + + +def test_command_rename_handles_double_quoted_value( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + """Test rename matches when the existing value is double-quoted.""" + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: "kitchen" + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="garage", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + new_file = tmp_path / "garage.yaml" + assert 'name: "garage"' in new_file.read_text() + + +def test_command_rename_handles_single_quoted_value( + tmp_path: Path, + mock_run_external_process: Mock, +) -> None: + """Test rename matches when the existing value is single-quoted.""" + config_file = tmp_path / "kitchen.yaml" + config_file.write_text(""" +esphome: + name: 'kitchen' + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = {CONF_ESPHOME: {CONF_NAME: "kitchen"}} + + args = MockArgs(name="garage", dashboard=False) + mock_run_external_process.return_value = 0 + + result = command_rename(args, {}) + + assert result == 0 + new_file = tmp_path / "garage.yaml" + assert 'name: "garage"' in new_file.read_text() + + +def test_command_rename_too_many_substitution_matches_refuses( + tmp_path: Path, + capfd: CaptureFixture[str], + mock_run_external_process: Mock, +) -> None: + """Test rename refuses when ``${var}`` resolves to multiple matches. + + When ``esphome.name: ${device_name}`` and the substitution + definition ``device_name: foo`` appears more than once in the + YAML (e.g. inside multiple included blocks), the regex rewrite + can't tell which one to flip. Rather than silently picking one + or rewriting both, the command refuses. + """ + config_file = tmp_path / "oldname.yaml" + config_file.write_text(""" +substitutions: + device_name: oldname + +esphome: + name: ${device_name} + +# A copy-pasted block that re-declares the substitution at the +# same indent level - happens when users splice in a packaged +# fragment without renaming the variable. +example: + device_name: oldname + +esp32: + board: nodemcu-32s +""") + setup_core(tmp_path=tmp_path) + CORE.config_path = config_file + CORE.config = { + CONF_ESPHOME: {CONF_NAME: "oldname"}, + CONF_SUBSTITUTIONS: {"device_name": "oldname"}, + } + + args = MockArgs(name="newname", dashboard=False) + + result = command_rename(args, {}) + + assert result == 1 + mock_run_external_process.assert_not_called() + # File untouched. + assert config_file.exists() + assert "device_name: oldname" in config_file.read_text() + + captured = capfd.readouterr() + assert "Too many matches" in captured.out + + def test_command_update_all_path_string_conversion( tmp_path: Path, mock_run_external_process: Mock, From e9cc10fedca583767a5351b520cc2c64126babd8 Mon Sep 17 00:00:00 2001 From: Diorcet Yann Date: Mon, 11 May 2026 04:12:07 +0200 Subject: [PATCH 25/52] [core] Native idf full support (#14678) Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Co-authored-by: Jonathan Swoboda Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- .github/workflows/ci.yml | 86 ++ esphome/__main__.py | 124 ++- esphome/build_gen/espidf.py | 24 +- esphome/components/esp32/__init__.py | 91 +- esphome/components/ethernet/__init__.py | 3 +- esphome/components/neopixelbus/light.py | 1 + esphome/components/nrf52/ota.py | 2 +- esphome/const.py | 9 +- esphome/core/__init__.py | 25 +- esphome/espidf/__init__.py | 0 esphome/espidf/api.py | 499 ++++++++++ esphome/espidf/component.py | 937 ++++++++++++++++++ esphome/espidf/framework.py | 1098 +++++++++++++++++++++ esphome/espidf/get_idf_tool_paths.py | 51 + esphome/espidf/get_idf_version.py | 14 + esphome/espidf/runner.py | 223 +++++ esphome/espidf_api.py | 274 ----- esphome/espota2.py | 2 +- esphome/helpers.py | 13 +- esphome/web_server_ota.py | 2 +- script/ci-custom.py | 2 +- script/test_build_components.py | 51 +- tests/component_tests/esp32/test_esp32.py | 4 +- tests/unit_tests/test_core.py | 4 +- tests/unit_tests/test_espidf_component.py | 357 +++++++ tests/unit_tests/test_espota2.py | 3 +- tests/unit_tests/test_main.py | 2 + 27 files changed, 3537 insertions(+), 364 deletions(-) create mode 100644 esphome/espidf/__init__.py create mode 100644 esphome/espidf/api.py create mode 100644 esphome/espidf/component.py create mode 100644 esphome/espidf/framework.py create mode 100644 esphome/espidf/get_idf_tool_paths.py create mode 100644 esphome/espidf/get_idf_version.py create mode 100644 esphome/espidf/runner.py delete mode 100644 esphome/espidf_api.py create mode 100644 tests/unit_tests/test_espidf_component.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f43c46dd006..9909d7a5ddf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -783,6 +783,91 @@ jobs: # Run compilation with grouping and isolation python3 script/test_build_components.py -e compile -c "$components_csv" -f --isolate "$directly_changed_csv" + test-native-idf: + name: Test components with native ESP-IDF + runs-on: ubuntu-24.04 + needs: + - common + - determine-jobs + if: github.event_name == 'pull_request' + env: + ESPHOME_ESP_IDF_PREFIX: ~/.esphome-idf + TEST_COMPONENTS: esp32,api,heatpumpir,bme280_i2c,bh1750,aht10,esp32_ble,esp32_ble_beacon,esp32_ble_client,esp32_ble_server,esp32_ble_tracker,ble_client,ble_presence,ble_rssi,ble_scanner + steps: + - name: Check out code from GitHub + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Restore Python + uses: ./.github/actions/restore-python + with: + python-version: ${{ env.DEFAULT_PYTHON }} + cache-key: ${{ needs.common.outputs.cache-key }} + + - name: Cache ESPHome + uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + with: + path: ~/.esphome-idf + key: ${{ runner.os }}-esphome-${{ needs.common.outputs.cache-key }} + + - name: Run native ESP-IDF compile test + run: | + . venv/bin/activate + + # Check if /mnt has more free space than / before bind mounting + # Extract available space in KB for comparison + root_avail=$(df -k / | awk 'NR==2 {print $4}') + mnt_avail=$(df -k /mnt 2>/dev/null | awk 'NR==2 {print $4}') + + echo "Available space: / has ${root_avail}KB, /mnt has ${mnt_avail}KB" + + # Only use /mnt if it has more space than / + if [ -n "$mnt_avail" ] && [ "$mnt_avail" -gt "$root_avail" ]; then + echo "Using /mnt for build files (more space available)" + # Bind mount PlatformIO directory to /mnt (tools, packages, build cache all go there) + sudo mkdir -p /mnt/esphome-idf + sudo chown $USER:$USER /mnt/esphome-idf + mkdir -p ~/.esphome-idf + sudo mount --bind /mnt/esphome-idf ~/.esphome-idf + + # Bind mount test build directory to /mnt + sudo mkdir -p /mnt/test_build_components_build + sudo chown $USER:$USER /mnt/test_build_components_build + mkdir -p tests/test_build_components/build + sudo mount --bind /mnt/test_build_components_build tests/test_build_components/build + else + echo "Using / for build files (more space available than /mnt or /mnt unavailable)" + fi + + echo "Testing components: $TEST_COMPONENTS" + echo "" + + # Show disk space before validation (after bind mounts setup) + echo "Disk space before config validation:" + df -h + echo "" + + # Run config validation (auto-grouped by test_build_components.py) + python3 script/test_build_components.py -e config -t esp32-idf -c "$TEST_COMPONENTS" -f --toolchain esp-idf + + echo "" + echo "Config validation passed! Starting compilation..." + echo "" + + # Show disk space before compilation + echo "Disk space before compilation:" + df -h + echo "" + + # Run compilation (auto-grouped by test_build_components.py) + python3 script/test_build_components.py -e compile -t esp32-idf -c "$TEST_COMPONENTS" -f --toolchain esp-idf + + - name: Save ESPHome cache + if: github.ref == 'refs/heads/dev' + uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + with: + path: ~/.esphome-idf + key: ${{ runner.os }}-esphome-${{ needs.common.outputs.cache-key }} + pre-commit-ci-lite: name: pre-commit.ci lite runs-on: ubuntu-latest @@ -1114,6 +1199,7 @@ jobs: - determine-jobs - device-builder - test-build-components-split + - test-native-idf - pre-commit-ci-lite - memory-impact-target-branch - memory-impact-pr-branch diff --git a/esphome/__main__.py b/esphome/__main__.py index a0ee5a359f4..01b33eb8acf 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -52,12 +52,12 @@ from esphome.const import ( CONF_WEB_SERVER, ENV_NOGITIGNORE, KEY_CORE, - KEY_NATIVE_IDF, KEY_TARGET_PLATFORM, PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040, SECRETS_FILES, + Toolchain, ) from esphome.core import CORE, EsphomeError, coroutine from esphome.enum import StrEnum @@ -155,7 +155,6 @@ class ArgsProtocol(Protocol): configuration: str name: str upload_speed: str | None - native_idf: bool def choose_prompt(options, purpose: str = None): @@ -720,17 +719,14 @@ def _wrap_to_code(name, comp, yaml_util): return wrapped -def write_cpp(config: ConfigType, native_idf: bool = False) -> int: +def write_cpp(config: ConfigType) -> int: from esphome import writer if not get_bool_env(ENV_NOGITIGNORE): writer.write_gitignore() - # Store native_idf flag so esp32 component can check it - CORE.data[KEY_NATIVE_IDF] = native_idf - generate_cpp_contents(config) - return write_cpp_file(native_idf=native_idf) + return write_cpp_file() def generate_cpp_contents(config: ConfigType) -> None: @@ -746,13 +742,13 @@ def generate_cpp_contents(config: ConfigType) -> None: CORE.flush_tasks() -def write_cpp_file(native_idf: bool = False) -> int: +def write_cpp_file() -> int: from esphome import writer code_s = indent(CORE.cpp_main_section) writer.write_cpp(code_s) - if native_idf and CORE.is_esp32 and CORE.target_framework == "esp-idf": + if CORE.using_toolchain_esp_idf: from esphome.build_gen import espidf espidf.write_project() @@ -765,22 +761,21 @@ def write_cpp_file(native_idf: bool = False) -> int: def compile_program(args: ArgsProtocol, config: ConfigType) -> int: - native_idf = getattr(args, "native_idf", False) - # NOTE: "Build path:" format is parsed by script/ci_memory_impact_extract.py # If you change this format, update the regex in that script as well _LOGGER.info("Compiling app... Build path: %s", CORE.build_path) - if native_idf and CORE.is_esp32 and CORE.target_framework == "esp-idf": - from esphome import espidf_api + if CORE.using_toolchain_esp_idf: + from esphome.espidf import api - rc = espidf_api.run_compile(config, CORE.verbose) + rc = api.run_compile(config, CORE.verbose) if rc != 0: return rc - # Create factory.bin and ota.bin - espidf_api.create_factory_bin() - espidf_api.create_ota_bin() + # Create factory.bin, ota.bin, and firmware.elf copy + api.create_factory_bin() + api.create_ota_bin() + api.create_elf_copy() else: from esphome import platformio_api @@ -883,6 +878,10 @@ def upload_using_esptool( if file is not None: flash_images = [FlashImage(path=file, offset="0x0")] + elif CORE.using_toolchain_esp_idf: + from esphome.espidf import api + + flash_images = [FlashImage(path=api.get_factory_firmware_path(), offset="0x0")] else: from esphome import platformio_api @@ -1447,8 +1446,7 @@ def command_vscode(args: ArgsProtocol) -> int | None: def command_compile(args: ArgsProtocol, config: ConfigType) -> int | None: - native_idf = getattr(args, "native_idf", False) - exit_code = write_cpp(config, native_idf=native_idf) + exit_code = write_cpp(config) if exit_code != 0: return exit_code if args.only_generate: @@ -1458,9 +1456,14 @@ def command_compile(args: ArgsProtocol, config: ConfigType) -> int | None: if exit_code != 0: return exit_code if CORE.is_host: - from esphome.platformio_api import get_idedata + if CORE.using_toolchain_esp_idf: + from esphome.espidf import api - program_path = str(get_idedata(config).firmware_elf_path) + program_path = str(api.get_elf_path()) + else: + from esphome.platformio_api import get_idedata + + program_path = str(get_idedata(config).firmware_elf_path) _LOGGER.info("Successfully compiled program to path '%s'", program_path) else: _LOGGER.info("Successfully compiled program.") @@ -1503,8 +1506,7 @@ def command_logs(args: ArgsProtocol, config: ConfigType) -> int | None: def command_run(args: ArgsProtocol, config: ConfigType) -> int | None: - native_idf = getattr(args, "native_idf", False) - exit_code = write_cpp(config, native_idf=native_idf) + exit_code = write_cpp(config) if exit_code != 0: return exit_code exit_code = compile_program(args, config) @@ -1512,9 +1514,14 @@ def command_run(args: ArgsProtocol, config: ConfigType) -> int | None: return exit_code _LOGGER.info("Successfully compiled program.") if CORE.is_host: - from esphome.platformio_api import get_idedata + if CORE.using_toolchain_esp_idf: + from esphome.espidf import api - program_path = str(get_idedata(config).firmware_elf_path) + program_path = str(api.get_elf_path()) + else: + from esphome.platformio_api import get_idedata + + program_path = str(get_idedata(config).firmware_elf_path) _LOGGER.info("Running program from path '%s'", program_path) return run_external_process(program_path) @@ -1705,6 +1712,13 @@ def command_update_all(args: ArgsProtocol) -> int | None: def command_idedata(args: ArgsProtocol, config: ConfigType) -> int: import json + if not CORE.using_toolchain_platformio: + _LOGGER.error( + "The idedata command is not compatible with %s toolchain", + CORE.toolchain.value, + ) + return 1 + from esphome import platformio_api logging.disable(logging.INFO) @@ -1724,7 +1738,6 @@ def command_analyze_memory(args: ArgsProtocol, config: ConfigType) -> int: This command compiles the configuration and performs memory analysis. Compilation is fast if sources haven't changed (just relinking). """ - from esphome import platformio_api from esphome.analyze_memory.cli import MemoryAnalyzerCLI from esphome.analyze_memory.ram_strings import RamStringsAnalyzer @@ -1738,12 +1751,25 @@ def command_analyze_memory(args: ArgsProtocol, config: ConfigType) -> int: _LOGGER.info("Successfully compiled program.") # Get idedata for analysis - idedata = platformio_api.get_idedata(config) - if idedata is None: - _LOGGER.error("Failed to get IDE data for memory analysis") - return 1 + idedata = None + if CORE.using_toolchain_esp_idf: + from esphome.espidf import api - firmware_elf = Path(idedata.firmware_elf_path) + objdump_path = str(api.get_objdump_path()) + readelf_path = str(api.get_readelf_path()) + + firmware_elf = api.get_elf_path() + else: + from esphome import platformio_api + + idedata = platformio_api.get_idedata(config) + if idedata is None: + _LOGGER.error("Failed to get IDE data for memory analysis") + return 1 + objdump_path = idedata.objdump_path + readelf_path = idedata.readelf_path + + firmware_elf = Path(idedata.firmware_elf_path) # Extract external components from config external_components = detect_external_components(config) @@ -1753,8 +1779,8 @@ def command_analyze_memory(args: ArgsProtocol, config: ConfigType) -> int: _LOGGER.info("Analyzing memory usage...") analyzer = MemoryAnalyzerCLI( str(firmware_elf), - idedata.objdump_path, - idedata.readelf_path, + objdump_path, + readelf_path, external_components, idedata=idedata, ) @@ -1770,7 +1796,7 @@ def command_analyze_memory(args: ArgsProtocol, config: ConfigType) -> int: try: ram_analyzer = RamStringsAnalyzer( str(firmware_elf), - objdump_path=idedata.objdump_path, + objdump_path=objdump_path, platform=CORE.target_platform, ) ram_analyzer.analyze() @@ -2015,6 +2041,17 @@ def parse_args(argv): action="store_true", default=False, ) + options_parser.add_argument( + "--toolchain", + type=Toolchain, + default=None, + choices=list(Toolchain), + metavar="{" + ",".join(t.value for t in Toolchain) + "}", + help=( + "Select toolchain for compiling. Overrides '.toolchain' in YAML. " + f"Default: {Toolchain.PLATFORMIO.value}." + ), + ) parser = argparse.ArgumentParser( description=f"ESPHome {const.__version__}", parents=[options_parser] @@ -2059,11 +2096,6 @@ def parse_args(argv): help="Only generate source code, do not compile.", action="store_true", ) - parser_compile.add_argument( - "--native-idf", - help="Build with native ESP-IDF instead of PlatformIO (ESP32 esp-idf framework only).", - action="store_true", - ) parser_upload = subparsers.add_parser( "upload", @@ -2171,11 +2203,6 @@ def parse_args(argv): help="Reset the device before starting serial logs.", default=os.getenv("ESPHOME_SERIAL_LOGGING_RESET"), ) - parser_run.add_argument( - "--native-idf", - help="Build with native ESP-IDF instead of PlatformIO (ESP32 esp-idf framework only).", - action="store_true", - ) parser_run.add_argument( "--ota-platform", choices=[CONF_ESPHOME, CONF_WEB_SERVER], @@ -2398,6 +2425,9 @@ def run_esphome(argv): CORE.config_path = conf_path CORE.dashboard = args.dashboard + if args.toolchain is not None: + # CLI toolchain wins over esp32.toolchain in YAML. + CORE.toolchain = args.toolchain # Commands that don't need fresh external components: logs just connects # to the device, and clean is about to delete the build directory. @@ -2410,6 +2440,12 @@ def run_esphome(argv): return 2 CORE.config = config + # Fallback for platforms whose validators didn't set the toolchain + # (only the esp32 component reads esp32.framework.toolchain). All + # other platforms only support PlatformIO today. + if CORE.toolchain is None: + CORE.toolchain = Toolchain.PLATFORMIO + if args.command not in POST_CONFIG_ACTIONS: safe_print(f"Unknown command {args.command}") return 1 diff --git a/esphome/build_gen/espidf.py b/esphome/build_gen/espidf.py index 01923baaac2..b1443edac31 100644 --- a/esphome/build_gen/espidf.py +++ b/esphome/build_gen/espidf.py @@ -6,6 +6,7 @@ from pathlib import Path from esphome.components.esp32 import get_esp32_variant from esphome.core import CORE from esphome.helpers import mkdir_p, write_file_if_changed +from esphome.writer import update_storage_json def get_available_components() -> list[str] | None: @@ -54,7 +55,7 @@ def get_project_cmakelists() -> str: idf_target = variant.lower().replace("-", "") # Extract compile definitions from build flags (-DXXX -> XXX) - compile_defs = [flag for flag in CORE.build_flags if flag.startswith("-D")] + compile_defs = [flag for flag in sorted(CORE.build_flags) if flag.startswith("-D")] extra_compile_options = "\n".join( f'idf_build_set_property(COMPILE_OPTIONS "{compile_def}" APPEND)' for compile_def in compile_defs @@ -64,6 +65,22 @@ def get_project_cmakelists() -> str: # Auto-generated by ESPHome cmake_minimum_required(VERSION 3.16) +# On Windows, Ninja can fail with: +# "CreateProcess: The parameter is incorrect (is the command line too long?)" +# when compiler/linker command lines exceed the OS length limit. +# +# The following settings force CMake/Ninja to use *response files* (@file.rsp) +# to pass long lists of includes, objects, and other arguments indirectly, +# avoiding command-line length limits and fixing the build failure. +# +# This is especially useful for large ESP-IDF / ESPHome projects with many +# source files or include directories. +set(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES 1) +set(CMAKE_C_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1) +set(CMAKE_NINJA_FORCE_RESPONSE_FILE 1) + set(IDF_TARGET {idf_target}) set(EXTRA_COMPONENT_DIRS ${{CMAKE_SOURCE_DIR}}/src) @@ -124,6 +141,11 @@ target_link_options(${{COMPONENT_LIB}} PUBLIC def write_project(minimal: bool = False) -> None: """Write ESP-IDF project files.""" + # Refresh /storage/.yaml.json so the dashboard's + # /info and /downloads endpoints can locate the build (they 404 + # otherwise). This mirrors the PlatformIO build-gen path's call + # in build_gen/platformio.py:write_ini(). + update_storage_json() mkdir_p(CORE.build_path) mkdir_p(CORE.relative_src_path()) diff --git a/esphome/components/esp32/__init__.py b/esphome/components/esp32/__init__.py index 582721ef736..ba32d13ab34 100644 --- a/esphome/components/esp32/__init__.py +++ b/esphome/components/esp32/__init__.py @@ -31,6 +31,7 @@ from esphome.const import ( CONF_SAFE_MODE, CONF_SIZE, CONF_SOURCE, + CONF_TOOLCHAIN, CONF_TYPE, CONF_VARIANT, CONF_VERSION, @@ -38,16 +39,17 @@ from esphome.const import ( KEY_CORE, KEY_FRAMEWORK_VERSION, KEY_NAME, - KEY_NATIVE_IDF, KEY_TARGET_FRAMEWORK, KEY_TARGET_PLATFORM, PLATFORM_ESP32, ThreadModel, + Toolchain, __version__, ) -from esphome.core import CORE, HexInt +from esphome.core import CORE, HexInt, Library from esphome.core.config import BOARD_MAX_LENGTH from esphome.coroutine import CoroPriority, coroutine_with_priority +from esphome.espidf.component import generate_idf_component import esphome.final_validate as fv from esphome.helpers import copy_file_if_changed, rmtree, write_file_if_changed from esphome.types import ConfigType @@ -465,6 +467,9 @@ def set_core_data(config): if conf[CONF_TYPE] == FRAMEWORK_ESP_IDF: CORE.data[KEY_ESP32][KEY_IDF_VERSION] = framework_ver elif (idf_ver := ARDUINO_IDF_VERSION_LOOKUP.get(framework_ver)) is not None: + if CORE.using_toolchain_esp_idf: + # Official ESP-IDF frameworks don't use extra + idf_ver = cv.Version(idf_ver.major, idf_ver.minor, idf_ver.patch) CORE.data[KEY_ESP32][KEY_IDF_VERSION] = idf_ver else: raise cv.Invalid( @@ -652,7 +657,7 @@ def _format_framework_arduino_version(ver: cv.Version) -> str: return f"{ARDUINO_FRAMEWORK_PKG}@https://github.com/espressif/arduino-esp32/releases/download/{ver}/{filename}" -def _format_framework_espidf_version( +def _format_framework_pio_espidf_version( ver: cv.Version, release: str | None = None ) -> str: # format the given espidf (https://github.com/pioarduino/esp-idf/releases) version to @@ -741,6 +746,7 @@ ESP_IDF_FRAMEWORK_VERSION_LOOKUP = { "latest": cv.Version(5, 5, 4), "dev": cv.Version(5, 5, 4), } + ESP_IDF_PLATFORM_VERSION_LOOKUP = { cv.Version( 6, 0, 1 @@ -774,7 +780,7 @@ PLATFORM_VERSION_LOOKUP = { } -def _check_versions(config): +def _check_pio_versions(config): config = config.copy() value = config[CONF_FRAMEWORK] @@ -785,7 +791,7 @@ def _check_versions(config): ) platform_lookup = PLATFORM_VERSION_LOOKUP[value[CONF_VERSION]] - value[CONF_PLATFORM_VERSION] = _parse_platform_version(str(platform_lookup)) + value[CONF_PLATFORM_VERSION] = _parse_pio_platform_version(str(platform_lookup)) if value[CONF_TYPE] == FRAMEWORK_ARDUINO: version = ARDUINO_FRAMEWORK_VERSION_LOOKUP[value[CONF_VERSION]] @@ -813,7 +819,7 @@ def _check_versions(config): platform_lookup = ESP_IDF_PLATFORM_VERSION_LOOKUP.get(version) value[CONF_SOURCE] = value.get( CONF_SOURCE, - _format_framework_espidf_version(version, value.get(CONF_RELEASE)), + _format_framework_pio_espidf_version(version, value.get(CONF_RELEASE)), ) if _is_framework_url(value[CONF_SOURCE]): value[CONF_SOURCE] = f"pioarduino/framework-espidf@{value[CONF_SOURCE]}" @@ -823,7 +829,7 @@ def _check_versions(config): raise cv.Invalid( "Framework version not recognized; please specify platform_version" ) - value[CONF_PLATFORM_VERSION] = _parse_platform_version(str(platform_lookup)) + value[CONF_PLATFORM_VERSION] = _parse_pio_platform_version(str(platform_lookup)) if version != recommended_version: _LOGGER.warning( @@ -831,7 +837,7 @@ def _check_versions(config): "If there are connectivity or build issues please remove the manual version." ) - if value[CONF_PLATFORM_VERSION] != _parse_platform_version( + if value[CONF_PLATFORM_VERSION] != _parse_pio_platform_version( str(PLATFORM_VERSION_LOOKUP["recommended"]) ): _LOGGER.warning( @@ -842,7 +848,38 @@ def _check_versions(config): return config -def _parse_platform_version(value): +def _check_esp_idf_versions(config): + config = _check_pio_versions(config) + value = config[CONF_FRAMEWORK] + + # Remove unwanted keys if present + for key in (CONF_SOURCE, CONF_PLATFORM_VERSION): + value.pop(key, None) + + # Official ESP-IDF frameworks don't use extra + version = cv.Version.parse(value[CONF_VERSION]) + version = cv.Version(version.major, version.minor, version.patch) + + value[CONF_VERSION] = str(version) + + return config + + +def _validate_toolchain(value) -> Toolchain: + return Toolchain(cv.one_of(*(t.value for t in Toolchain), lower=True)(value)) + + +def _check_versions(config): + # Resolve toolchain: CLI (already on CORE.toolchain) > YAML > default. + if CORE.toolchain is None: + CORE.toolchain = config.get(CONF_TOOLCHAIN, Toolchain.PLATFORMIO) + + if CORE.using_toolchain_esp_idf: + return _check_esp_idf_versions(config) + return _check_pio_versions(config) + + +def _parse_pio_platform_version(value): try: ver = cv.Version.parse(cv.version_number(value)) release = f"{ver.major}.{ver.minor:02d}.{ver.patch:02d}" @@ -1272,7 +1309,7 @@ FRAMEWORK_SCHEMA = cv.Schema( cv.Optional(CONF_VERSION, default="recommended"): cv.string_strict, cv.Optional(CONF_RELEASE): cv.string_strict, cv.Optional(CONF_SOURCE): cv.string_strict, - cv.Optional(CONF_PLATFORM_VERSION): _parse_platform_version, + cv.Optional(CONF_PLATFORM_VERSION): _parse_pio_platform_version, cv.Optional(CONF_SDKCONFIG_OPTIONS, default={}): { cv.string_strict: cv.string_strict }, @@ -1524,6 +1561,7 @@ CONFIG_SCHEMA = cv.All( ), cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True), cv.Optional(CONF_FRAMEWORK): FRAMEWORK_SCHEMA, + cv.Optional(CONF_TOOLCHAIN): _validate_toolchain, cv.Optional(CONF_WATCHDOG_TIMEOUT, default="5s"): cv.All( cv.positive_time_period_seconds, cv.Range(min=cv.TimePeriod(seconds=5), max=cv.TimePeriod(seconds=60)), @@ -1672,11 +1710,11 @@ async def to_code(config): framework_ver: cv.Version = CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] conf = config[CONF_FRAMEWORK] - # Check if using native ESP-IDF build (--native-idf) - use_platformio = not CORE.data.get(KEY_NATIVE_IDF, False) + # Check if using ESP-IDF toolchain + use_platformio = not CORE.using_toolchain_esp_idf if use_platformio: # Clear IDF environment variables to avoid conflicts with PlatformIO's ESP-IDF - # but keep them when using --native-idf for native ESP-IDF builds + # but keep them when using ESP-IDF toolchain for clean_var in ("IDF_PATH", "IDF_TOOLS_PATH"): os.environ.pop(clean_var, None) @@ -1716,6 +1754,8 @@ async def to_code(config): ) else: cg.add_build_flag("-Wno-error=format") + cg.add_build_flag("-Wno-error=missing-field-initializers") + cg.add_build_flag("-Wno-error=volatile") cg.set_cpp_standard("gnu++20") cg.add_build_flag("-DUSE_ESP32") @@ -1792,7 +1832,7 @@ async def to_code(config): if (idf_ver := ARDUINO_IDF_VERSION_LOOKUP.get(framework_ver)) is not None: cg.add_platformio_option( "platform_packages", - [_format_framework_espidf_version(idf_ver)], + [_format_framework_pio_espidf_version(idf_ver)], ) # Use stub package to skip downloading precompiled libs stubs_dir = CORE.relative_build_path("arduino_libs_stub") @@ -2424,6 +2464,14 @@ def _write_sdkconfig(): clean_build(clear_pio_cache=False) +def _platformio_library_to_dependency(library: Library) -> tuple[str, dict[str, str]]: + dependency: dict[str, str] = {} + name, version, path = generate_idf_component(library) + dependency["override_path"] = str(path) + dependency["version"] = version + return name, dependency + + def _write_idf_component_yml(): yml_path = CORE.relative_build_path("src/idf_component.yml") dependencies: dict[str, dict] = {} @@ -2465,6 +2513,21 @@ def _write_idf_component_yml(): if stub_path.exists(): rmtree(stub_path) + if CORE.using_toolchain_esp_idf: + add_idf_component( + name="espressif/arduino-esp32", + ref=str(CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]), + ) + + if CORE.using_toolchain_esp_idf: + # Try to convert PlatformIO library to ESP-IDF components + for name, library in CORE.platformio_libraries.items(): + # Don't process arduino libraries + if name in ARDUINO_DISABLED_LIBRARIES: + continue + dependency_name, dependency = _platformio_library_to_dependency(library) + dependencies[dependency_name] = dependency + if CORE.data[KEY_ESP32][KEY_COMPONENTS]: components: dict = CORE.data[KEY_ESP32][KEY_COMPONENTS] for name, component in components.items(): diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 10f9a73863d..3f88f8ef9a4 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -36,7 +36,6 @@ from esphome.const import ( CONF_VALUE, KEY_CORE, KEY_FRAMEWORK_VERSION, - KEY_NATIVE_IDF, Platform, PlatformFramework, ) @@ -705,7 +704,7 @@ def _filter_source_files() -> list[str]: # and pioarduino doesn't have it builtin (IDF 5.4.2 to 5.x) if eth_type != "JL1101": excluded.append("esp_eth_phy_jl1101.c") - elif CORE.is_esp32 and not CORE.data.get(KEY_NATIVE_IDF, False): + elif CORE.is_esp32 and not CORE.using_toolchain_esp_idf: from esphome.components.esp32 import idf_version # pioarduino has JL1101 builtin on IDF 5.4.2-5.x; exclude custom driver diff --git a/esphome/components/neopixelbus/light.py b/esphome/components/neopixelbus/light.py index 104762c69e0..943fd141f69 100644 --- a/esphome/components/neopixelbus/light.py +++ b/esphome/components/neopixelbus/light.py @@ -244,6 +244,7 @@ async def to_code(config): # disable built in rgb support as it uses the new RMT drivers and will # conflict with NeoPixelBus which uses the legacy drivers cg.add_build_flag("-DESP32_ARDUINO_NO_RGB_BUILTIN") + cg.add_library("SPI", None) cg.add_library("makuna/NeoPixelBus", "2.8.0") else: cg.add_library("makuna/NeoPixelBus", "2.7.3") diff --git a/esphome/components/nrf52/ota.py b/esphome/components/nrf52/ota.py index e4b26b45eb6..eb1caa55958 100644 --- a/esphome/components/nrf52/ota.py +++ b/esphome/components/nrf52/ota.py @@ -142,7 +142,7 @@ async def _smpmgr_upload_connected( with open(firmware, "rb") as file: image = file.read() upload_size = len(image) - progress = ProgressBar() + progress = ProgressBar("Uploading") progress.update(0) try: async for offset in smp_client.upload(image): diff --git a/esphome/const.py b/esphome/const.py index c2bf86d5321..c39225fdec0 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -15,6 +15,13 @@ VALID_SUBSTITUTIONS_CHARACTERS = ( ARGUMENT_HELP_DEVICE = "Manually specify the serial port/address to use, for example /dev/ttyUSB0. Can be specified multiple times for fallback addresses. Use 'OTA' for resolving from MQTT, DNS or mDNS and avoiding the interactive prompt." +class Toolchain(StrEnum): + """Toolchain identifiers for ESPHome.""" + + PLATFORMIO = "platformio" + ESP_IDF = "esp-idf" + + class Platform(StrEnum): """Platform identifiers for ESPHome.""" @@ -1036,6 +1043,7 @@ CONF_TO = "to" CONF_TO_NTC_RESISTANCE = "to_ntc_resistance" CONF_TO_NTC_TEMPERATURE = "to_ntc_temperature" CONF_TOLERANCE = "tolerance" +CONF_TOOLCHAIN = "toolchain" CONF_TOPIC = "topic" CONF_TOPIC_PREFIX = "topic_prefix" CONF_TOTAL = "total" @@ -1393,7 +1401,6 @@ KEY_FRAMEWORK_VERSION = "framework_version" KEY_NAME = "name" KEY_VARIANT = "variant" KEY_PAST_SAFE_MODE = "past_safe_mode" -KEY_NATIVE_IDF = "native_idf" # Entity categories ENTITY_CATEGORY_NONE = "" diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index 0cc207aa543..ef0eddc603a 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -17,7 +17,6 @@ from esphome.const import ( CONF_WEB_SERVER, CONF_WIFI, KEY_CORE, - KEY_NATIVE_IDF, KEY_TARGET_FRAMEWORK, KEY_TARGET_PLATFORM, PLATFORM_BK72XX, @@ -28,6 +27,7 @@ from esphome.const import ( PLATFORM_NRF52, PLATFORM_RP2040, PLATFORM_RTL87XX, + Toolchain, ) # pylint: disable=unused-import @@ -618,6 +618,10 @@ class EsphomeCore: # When True, skip network freshness checks for cached external files # (e.g. for `esphome logs`, where remote downloads aren't needed) self.skip_external_update: bool = False + # Toolchain used for building the configuration. None until resolved + # by CLI (--toolchain) or by `esphome.toolchain:` in YAML during + # preload_core_config; defaults to PLATFORMIO if neither sets it. + self.toolchain: Toolchain | None = None def reset(self): from esphome.pins import PIN_SCHEMA_REGISTRY @@ -648,6 +652,7 @@ class EsphomeCore: self.address_cache = None self._config_hash = None self.skip_external_update = False + self.toolchain = None PIN_SCHEMA_REGISTRY.reset() @contextmanager @@ -772,8 +777,8 @@ class EsphomeCore: @property def firmware_bin(self) -> Path: - # Check if using native ESP-IDF build (--native-idf) - if self.data.get(KEY_NATIVE_IDF, False): + # Check if using ESP-IDF toolchain + if self.using_toolchain_esp_idf: return self.relative_build_path("build", f"{self.name}.bin") if self.is_libretiny: return self.relative_pioenvs_path(self.name, "firmware.uf2") @@ -781,10 +786,10 @@ class EsphomeCore: @property def partition_table_bin(self) -> Path: - # Native ESP-IDF (--native-idf): the partition table image is emitted under + # Native ESP-IDF (--toolchain esp-idf): the partition table image is emitted under # build/partition_table/partition-table.bin alongside firmware.bin. PlatformIO writes the # equivalent file as partitions.bin in the env-specific .pioenvs directory. - if self.data.get(KEY_NATIVE_IDF): + if self.using_toolchain_esp_idf: return self.relative_build_path( "build", "partition_table", "partition-table.bin" ) @@ -792,7 +797,7 @@ class EsphomeCore: @property def bootloader_bin(self) -> Path: - if self.data.get(KEY_NATIVE_IDF): + if self.using_toolchain_esp_idf: return self.relative_build_path("build", "bootloader", "bootloader.bin") return self.relative_pioenvs_path(self.name, "bootloader.bin") @@ -853,6 +858,14 @@ class EsphomeCore: ) return self.target_framework == "esp-idf" + @property + def using_toolchain_esp_idf(self): + return self.toolchain == Toolchain.ESP_IDF + + @property + def using_toolchain_platformio(self): + return self.toolchain == Toolchain.PLATFORMIO + @property def using_zephyr(self): return self.target_framework == "zephyr" diff --git a/esphome/espidf/__init__.py b/esphome/espidf/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/esphome/espidf/api.py b/esphome/espidf/api.py new file mode 100644 index 00000000000..847de249a7f --- /dev/null +++ b/esphome/espidf/api.py @@ -0,0 +1,499 @@ +"""ESP-IDF direct build API for ESPHome.""" + +from dataclasses import dataclass, field +import json +import logging +import os +from pathlib import Path +import re +import shutil +import subprocess + +from esphome.components.esp32.const import KEY_ESP32, KEY_FLASH_SIZE, KEY_IDF_VERSION +from esphome.core import CORE, EsphomeError +from esphome.espidf.framework import check_esp_idf_install, get_framework_env + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = "espidf_api" + + +@dataclass +class _CacheData: + paths: dict[str, tuple] = field(default_factory=dict) + env: dict[str, dict[str, str]] = field(default_factory=dict) + cmake_output: dict[Path, str] = field(default_factory=dict) + cmake_tools: dict[Path, dict[str, Path]] = field(default_factory=dict) + + +def _cache() -> _CacheData: + if DOMAIN not in CORE.data: + CORE.data[DOMAIN] = _CacheData() + return CORE.data[DOMAIN] + + +def _get_core_framework_version(): + return str(CORE.data[KEY_ESP32][KEY_IDF_VERSION]) + + +def _get_esphome_esp_idf_paths( + version: str | None = None, +) -> tuple[os.PathLike, os.PathLike]: + version = version or _get_core_framework_version() + paths = _cache().paths + if version not in paths: + paths[version] = check_esp_idf_install(version) + return paths[version] + + +def _get_idf_path(version: str | None = None) -> Path | None: + """Get IDF_PATH from environment or common locations.""" + # Use provided IDF framework if available + if "IDF_PATH" in os.environ: + return Path(os.environ["IDF_PATH"]) + return Path(_get_esphome_esp_idf_paths(version)[0]) + + +def _get_idf_env(version: str | None = None) -> dict[str, str]: + """Get environment variables needed for ESP-IDF build.""" + version = version or _get_core_framework_version() + env_cache = _cache().env + if version not in env_cache: + env_cache[version] = os.environ.copy() + + # Use provided IDF framework if available + if "IDF_PATH" not in os.environ: + env_cache[version] |= get_framework_env( + *_get_esphome_esp_idf_paths(version) + ) + return env_cache[version] + + +def _get_cmake_output(build_dir) -> str: + cmake_output_cache = _cache().cmake_output + if build_dir not in cmake_output_cache: + cmd = ["cmake", "-LA", "-N", "."] + + env = _get_idf_env() + result = subprocess.run( + cmd, + cwd=build_dir, + env=env, + capture_output=True, + text=True, + check=False, + ) + + if result.returncode != 0: + raise RuntimeError(f"CMake failed: {result.stderr}") + + cmake_output_cache[build_dir] = result.stdout + return cmake_output_cache[build_dir] + + +def _get_cmake_tool_path(var_name: str) -> Path: + build_dir = CORE.relative_build_path("build") + cmake_output = _get_cmake_output(build_dir) + + cmake_tools_cache = _cache().cmake_tools + if build_dir not in cmake_tools_cache: + cmake_tools_cache[build_dir] = {} + + if var_name not in cmake_tools_cache[build_dir]: + pattern = rf"^{var_name}:FILEPATH=(.+)$" + match = re.search(pattern, cmake_output, re.MULTILINE) + + if not match: + raise RuntimeError(f"{var_name} not found in CMake output") + + path = match.group(1).strip() + cmake_tools_cache[build_dir][var_name] = Path(path) + + return cmake_tools_cache[build_dir][var_name] + + +def _get_idf_tool(name: str) -> str: + """Return the path to an executable from the ESP-IDF environment PATH or raise if not found.""" + env = _get_idf_env() + executable = shutil.which(name, path=env.get("PATH", None)) + if executable is None: + raise EsphomeError( + f"{name} executable not found in ESP-IDF environment. " + "Check that the IDF environment is correctly set up." + ) + return executable + + +def run_idf_py( + *args, cwd: Path | None = None, capture_output: bool = False +) -> int | str: + """Run idf.py with the given arguments.""" + idf_path = _get_idf_path() + if idf_path is None: + raise EsphomeError("ESP-IDF not found") + + env = _get_idf_env() + python_executable = _get_idf_tool("python") + idf_py = idf_path / "tools" / "idf.py" + # Dispatch idf.py through esphome.espidf.runner, which wraps + # sys.stdout/sys.stderr so ``isatty()`` reports True. This keeps CMake, + # Ninja, and idf.py's own progress-bar code emitting TTY-format output + # (``\r`` cursor moves, ANSI colors, fancy progress bars) even when our + # real stdout is a pipe — e.g. when esphome is running under the Home + # Assistant dashboard add-on. The runner is a plain script (not a + # ``python -m`` module) because IDF's Python venv does not have the + # esphome package installed. + runner_py = Path(__file__).parent / "runner.py" + + cmd = [python_executable, str(runner_py), str(idf_py)] + list(args) + + if cwd is None: + cwd = CORE.build_path + + _LOGGER.debug("Running: %s", " ".join(cmd)) + _LOGGER.debug(" in directory: %s", cwd) + + if capture_output: + result = subprocess.run( + cmd, + cwd=cwd, + env=env, + capture_output=True, + text=True, + check=False, + ) + if result.returncode != 0: + _LOGGER.error("idf.py failed:\n%s", result.stderr) + return result.stdout + result = subprocess.run( + cmd, + cwd=cwd, + env=env, + check=False, + ) + return result.returncode + + +def _get_sdkconfig_args() -> list[str]: + """Get cmake -D flags for the sdkconfig file, if it exists.""" + sdkconfig_path = CORE.relative_build_path(f"sdkconfig.{CORE.name}") + if sdkconfig_path.is_file(): + return ["-D", f"SDKCONFIG={sdkconfig_path}"] + return [] + + +def run_reconfigure() -> int: + """Run cmake reconfigure only (no build).""" + return run_idf_py(*_get_sdkconfig_args(), "reconfigure") + + +def has_outdated_files(): + """Check if the build configuration is stale. + + Returns True if required build files are missing or if configuration inputs + are newer than the generated CMake/Ninja build artifacts. + """ + cmakecache_txt_path = CORE.relative_build_path("build/CMakeCache.txt") + + cmakelists_txt_build_path = CORE.relative_build_path("CMakeLists.txt") + cmakelists_txt_src_path = CORE.relative_src_path("CMakeLists.txt") + build_config_path = CORE.relative_build_path("build/config") + sdkconfig_internal_path = CORE.relative_build_path( + f"sdkconfig.{CORE.name}.esphomeinternal" + ) + dependency_lock_path = CORE.relative_build_path("dependencies.lock") + build_ninja_path = CORE.relative_build_path("build/build.ninja") + + if not os.path.isdir(build_config_path) or not os.listdir(build_config_path): + return True + if not os.path.isfile(cmakecache_txt_path): + return True + if not os.path.isfile(build_ninja_path): + return True + if os.path.isfile(dependency_lock_path) and os.path.getmtime( + dependency_lock_path + ) > os.path.getmtime(build_ninja_path): + return True + + cmakecache_txt_mtime = os.path.getmtime(cmakecache_txt_path) + return any( + os.path.getmtime(f) > cmakecache_txt_mtime + for f in [ + _get_idf_path(), + cmakelists_txt_build_path, + cmakelists_txt_src_path, + sdkconfig_internal_path, + build_config_path, + ] + if f and os.path.exists(f) + ) + + +def need_reconfigure() -> bool: + from esphome.build_gen.espidf import has_discovered_components + + # We need to reconfigure either if the files are outdated or if there is no component discovered + return has_outdated_files() or not has_discovered_components() + + +def _patch_memory_segments(): + """Patch memory.ld to expand IRAM/DRAM for testing mode. + + Mirrors the PlatformIO iram_fix.py.script logic for native IDF builds. + Must be called after cmake configure (which generates memory.ld) and + before the build/link step. + """ + # Same sizes as iram_fix.py.script + testing_iram_size = 0x200000 # 2MB + testing_dram_size = 0x200000 # 2MB + + memory_ld = CORE.relative_build_path( + "build", "esp-idf", "esp_system", "ld", "memory.ld" + ) + if not memory_ld.is_file(): + _LOGGER.warning("Could not find linker script at %s", memory_ld) + return + + content = memory_ld.read_text() + patches = [] + + def _patch_segment(text, segment_name, new_size): + pattern = rf"({re.escape(segment_name)}\s*\([^)]*\)\s*:\s*org\s*=\s*.+?,\s*len\s*=\s*)(\S+[^\n]*)" + if match := re.search(pattern, text, re.DOTALL): + replacement = f"{match.group(1)}{new_size:#x}" + new_text = text[: match.start()] + replacement + text[match.end() :] + if new_text != text: + return new_text, True + return text, False + + content, patched = _patch_segment(content, "iram0_0_seg", testing_iram_size) + if patched: + patches.append(f"IRAM={testing_iram_size:#x}") + + content, patched = _patch_segment(content, "dram0_0_seg", testing_dram_size) + if patched: + patches.append(f"DRAM={testing_dram_size:#x}") + + if patches: + memory_ld.write_text(content) + _LOGGER.info("Patched %s in %s for testing mode", ", ".join(patches), memory_ld) + else: + _LOGGER.warning("Could not patch memory segments in %s", memory_ld) + + +def run_compile(config, verbose: bool) -> int: + """Compile the ESP-IDF project. + + Uses two-phase configure to auto-discover available components: + 1. If no previous build, configure with minimal REQUIRES to discover components + 2. Regenerate CMakeLists.txt with discovered components + 3. Run full build + """ + from esphome.build_gen.espidf import write_project + + # Check if we need to do discovery phase + if need_reconfigure(): + _LOGGER.info("Discovering available ESP-IDF components...") + write_project(minimal=True) + rc = run_reconfigure() + if rc != 0: + _LOGGER.error("Component discovery failed") + return rc + _LOGGER.info("Regenerating CMakeLists.txt with discovered components...") + write_project(minimal=False) + if CORE.testing_mode: + # Reconfigure again so cmake is up to date with the full component + # list. This ensures idf.py build won't re-run cmake, which would + # regenerate memory.ld and wipe the DRAM/IRAM patches applied below. + rc = run_reconfigure() + if rc != 0: + _LOGGER.error("Reconfigure with discovered components failed") + return rc + + # In testing mode, generate the linker script first, patch DRAM/IRAM sizes, + # then build. memory.ld is regenerated by ninja during the build phase, + # so we must patch after it's generated but before linking (same timing + # as iram_fix.py.script's AddPreAction hook in the PlatformIO path). + if CORE.testing_mode: + memory_ld = CORE.relative_build_path( + "build", "esp-idf", "esp_system", "ld", "memory.ld" + ) + build_dir = CORE.relative_build_path("build") + # Build just the memory.ld target - ninja needs the path relative to build dir + memory_ld_target = os.path.relpath(str(memory_ld), str(build_dir)) + env = _get_idf_env() + ninja_executable = _get_idf_tool("ninja") + result = subprocess.run( + [ninja_executable, "-C", str(build_dir), memory_ld_target], + env=env, + check=False, + ) + if result.returncode != 0: + _LOGGER.error("Failed to generate linker script") + return result.returncode + _patch_memory_segments() + + # Build + args = [] + + if verbose: + args.append("-v") + + args.extend(_get_sdkconfig_args()) + args.append("build") + + return run_idf_py(*args) + + +def get_firmware_path() -> Path: + """Get the path to the compiled firmware binary. + + This is the file idf.py writes directly (named after the project), + not the copy used for OTA/factory downloads below. + """ + build_dir = CORE.relative_build_path("build") + return build_dir / f"{CORE.name}.bin" + + +def get_factory_firmware_path() -> Path: + """Get the path to the factory firmware (with bootloader). + + Uses the PlatformIO ``firmware.factory.bin`` naming convention so + the dashboard's download handler — which requests files by name + relative to ``firmware_bin_path.parent`` — finds it. Without this, + the native IDF path produced ``.factory.bin`` and the + dashboard returned 500 trying to locate ``firmware.factory.bin``. + """ + build_dir = CORE.relative_build_path("build") + return build_dir / "firmware.factory.bin" + + +def get_ota_firmware_path() -> Path: + """Get the path to the OTA firmware binary. + + Uses the PlatformIO ``firmware.ota.bin`` naming convention for the + same dashboard-compatibility reason as ``get_factory_firmware_path``. + """ + build_dir = CORE.relative_build_path("build") + return build_dir / "firmware.ota.bin" + + +def get_elf_path() -> Path: + """Get the path to the firmware ELF file. + + idf.py writes ``/.elf`` directly; this returns the + ``/firmware.elf`` copy created by ``create_elf_copy`` so + the dashboard's "download ELF" link can find it under the + PlatformIO-convention name. + """ + build_dir = CORE.relative_build_path("build") + return build_dir / "firmware.elf" + + +def get_objdump_path() -> Path: + return _get_cmake_tool_path("CMAKE_OBJDUMP") + + +def get_readelf_path() -> Path: + return _get_cmake_tool_path("CMAKE_READELF") + + +def get_addr2line_path() -> Path: + return _get_cmake_tool_path("CMAKE_ADDR2LINE") + + +def create_factory_bin() -> bool: + """Create factory.bin by merging bootloader, partition table, and app.""" + build_dir = CORE.relative_build_path("build") + flasher_args_path = build_dir / "flasher_args.json" + + if not flasher_args_path.is_file(): + _LOGGER.warning("flasher_args.json not found, cannot create factory.bin") + return False + + try: + with open(flasher_args_path, encoding="utf-8") as f: + flash_data = json.load(f) + except (json.JSONDecodeError, OSError) as e: + _LOGGER.error("Failed to read flasher_args.json: %s", e) + return False + + # Get flash size from config + flash_size = CORE.data[KEY_ESP32][KEY_FLASH_SIZE] + + # Build esptool merge command + sections = [] + for addr, fname in sorted( + flash_data.get("flash_files", {}).items(), key=lambda kv: int(kv[0], 16) + ): + file_path = build_dir / fname + if file_path.is_file(): + sections.extend([addr, str(file_path)]) + else: + _LOGGER.warning("Flash file not found: %s", file_path) + + if not sections: + _LOGGER.warning("No flash sections found") + return False + + output_path = get_factory_firmware_path() + chip = flash_data.get("extra_esptool_args", {}).get("chip", "esp32") + + env = _get_idf_env() + python_executable = _get_idf_tool("python") + cmd = [ + python_executable, + "-m", + "esptool", + "--chip", + chip, + "merge_bin", + "--flash_size", + flash_size, + "--output", + str(output_path), + ] + sections + + _LOGGER.info("Creating factory.bin...") + result = subprocess.run(cmd, env=env, capture_output=True, text=True, check=False) + + if result.returncode != 0: + _LOGGER.error("Failed to create factory.bin: %s", result.stderr) + return False + + _LOGGER.info("Created: %s", output_path) + return True + + +def create_ota_bin() -> bool: + """Copy the firmware to firmware.ota.bin for ESPHome OTA compatibility.""" + firmware_path = get_firmware_path() + ota_path = get_ota_firmware_path() + + if not firmware_path.is_file(): + _LOGGER.warning("Firmware not found: %s", firmware_path) + return False + + shutil.copy(firmware_path, ota_path) + _LOGGER.info("Created: %s", ota_path) + return True + + +def create_elf_copy() -> bool: + """Copy the ELF binary to firmware.elf for dashboard compatibility. + + idf.py writes the ELF at ``/.elf``; the dashboard's + "download ELF" link requests the literal filename ``firmware.elf`` + (PlatformIO convention), so copy it to that name. + """ + build_dir = CORE.relative_build_path("build") + src_elf = build_dir / f"{CORE.name}.elf" + dst_elf = get_elf_path() + + if not src_elf.is_file(): + _LOGGER.warning("ELF not found: %s", src_elf) + return False + + shutil.copy(src_elf, dst_elf) + _LOGGER.info("Created: %s", dst_elf) + return True diff --git a/esphome/espidf/component.py b/esphome/espidf/component.py new file mode 100644 index 00000000000..bb675d2c77c --- /dev/null +++ b/esphome/espidf/component.py @@ -0,0 +1,937 @@ +from collections.abc import Callable +import glob +import hashlib +import itertools +import json +import logging +import os +from pathlib import Path +import re +import tempfile +from typing import TypeVar +from urllib.parse import urlparse, urlsplit, urlunsplit + +from esphome import git, yaml_util +from esphome.const import KEY_CORE, KEY_FRAMEWORK_VERSION +from esphome.core import CORE, Library +from esphome.espidf.framework import archive_extract_all, download_from_mirrors, rmdir +from esphome.helpers import write_file_if_changed + +_LOGGER = logging.getLogger(__name__) + +PathType = str | os.PathLike + +# +# Constants from platformio +# + +FILTER_REGEX = re.compile(r"([+-])<([^>]+)>") +DEFAULT_BUILD_SRC_FILTER = ( + "+<*> -<.git/> -<.svn/> - - - -" +) +DEFAULT_BUILD_SRC_DIRS = "src" +DEFAULT_BUILD_INCLUDE_DIR = "include" +DEFAULT_BUILD_FLAGS = [] +SRC_FILE_EXTENSIONS = [ + ".c", + ".cpp", + ".cc", + ".cxx", + ".c++", + ".S", + ".spp", + ".SPP", + ".sx", + ".s", + ".asm", + ".ASM", +] + +ESP32_PLATFORM = "espressif32" +DOMAIN = "pio_components" + +# +# Constants for workarounds +# + +REQUIRES_DETECT_PATTERNS = { + "mbedtls": [re.compile(r'^\s*#\s*include\s*[<"]mbedtls[^">]*[">]', re.MULTILINE)], + "esp_netif": [ + re.compile(r'^\s*#\s*include\s*[<"]esp_netif[^">]*[">]', re.MULTILINE) + ], + "esp_driver_gpio": [ + re.compile(r'^\s*#\s*include\s*[<"]driver/gpio\.h[^">]*[">]', re.MULTILINE) + ], + "esp_timer": [ + re.compile(r'^\s*#\s*include\s*[<"]esp_timer\.h[^">]*[">]', re.MULTILINE) + ], + "esp_wifi": [ + re.compile( + r'^\s*#\s*include\s*[<"]WiFi\.h[^">]*[">]', re.MULTILINE + ) # Arduino WiFi + ], +} + +ESPHOME_DATA_KEY = "ESPHOME" +ESPHOME_DATA_EXTRA_CMAKE_KEY = "EXTRA_CMAKE" + + +class Source: + def download(self, dir_suffix: str, force: bool = False) -> Path: + raise NotImplementedError() + + +class URLSource(Source): + def __init__(self, url: str): + self.url = url + + def download(self, dir_suffix: str, force: bool = False) -> Path: + base_dir = Path(CORE.data_dir) / DOMAIN + h = hashlib.new("sha256") + h.update(self.url.encode()) + path = base_dir / h.hexdigest()[:8] / dir_suffix + # Marker file written last to signal a complete extraction. Using a + # marker (instead of just `path.is_dir()`) means an interrupted + # extraction is correctly detected and re-run on the next invocation, + # and lets us extract directly into ``path`` — avoiding a + # post-extraction rename that races with antivirus on Windows. + extracted_marker = path / ".esphome_extracted" + if not extracted_marker.is_file() or force: + rmdir(path, msg=f"Clean up library directory {path}") + + # Download in temporary file + with tempfile.NamedTemporaryFile() as tmp: + _LOGGER.info("Downloading %s ...", self.url) + _LOGGER.debug("Location: %s", path) + + download_from_mirrors([self.url], {}, tmp.file) + + _LOGGER.debug("Extracting archive to %s ...", path) + archive_extract_all(tmp.file, path) + extracted_marker.touch() + return path + + def __str__(self): + return self.url + + +class GitSource(Source): + def __init__(self, url: str, ref: str): + self.url = url + self.ref = ref + + def download(self, dir_suffix: str, force: bool = False) -> Path: + path, _ = git.clone_or_update( + url=self.url, + ref=self.ref, + refresh=git.NEVER_REFRESH if not force else None, + domain=DOMAIN, + submodules=[], + subpath=Path(dir_suffix), + ) + return path + + def __str__(self): + return f"{self.url}#{self.ref}" + + +class InvalidIDFComponent(Exception): + pass + + +class IDFComponent: + def __init__(self, name: str, version: str, source: Source | None): + self.name = name + self.version = version + self.source = source + self.data = {} + self.dependencies: list[IDFComponent] = [] + self._path: Path | None = None + + def __str__(self): + return f"{self.name}@{self.version}={self.source}" + + @property + def path(self) -> Path: + if self._path is None: + raise RuntimeError(f"path not set for component {self}") + return self._path + + @path.setter + def path(self, value: Path) -> None: + self._path = value + + def get_sanitized_name(self): + return re.sub(r"[^a-zA-Z0-9_.\-/]", "_", self.name) + + def get_require_name(self): + return self.get_sanitized_name().replace("/", "__") + + def download(self, force: bool = False): + """ + The dependency name should match the directory name at the end of the override path. + The ESP-IDF build system uses the directory name as the component name, so the directory of the override_path should match the component name. + If you want to specify the full name of the component with the namespace, replace / in the component name with __. + @see https://docs.espressif.com/projects/idf-component-manager/en/latest/reference/manifest_file.html + """ + self.path = self.source.download(self.get_sanitized_name(), force=force) + + +def _sanitize_version(version: str) -> str: + """ + Sanitize a version string by removing common requirement prefixes or a leading v. + + Args: + version: Version string to clean. + + Returns: + Cleaned version string without common requirement symbols. + """ + version = version.strip() + + prefixes = ( + "^", + "~=", + "~", + ">=", + "<=", + "==", + "!=", + ">", + "<", + "=", + "v", + "V", + ) + + for p in prefixes: + if version.startswith(p): + version = version[len(p) :] + break + + return version.strip() + + +def _get_package_from_pio_registry( + username: str | None, pkgname: str, requirements: str +) -> tuple[str, str, str | None, str | None]: + """ + Fetch package information from PlatformIO registry. + + This function queries the PlatformIO registry to find a library package + that matches the given criteria and returns its metadata including version + and download URL. + + Args: + username: The owner/username of the package (can be None) + pkgname: The name of the package + requirements: Version requirements (e.g., "^1.0.0") + + Returns: + tuple[str, str, str | None, str | None]: + A tuple containing (owner, name, version, download_url) + where version and download_url can be None if not found + """ + + from platformio.package.manager._registry import PackageManagerRegistryMixin + from platformio.package.meta import PackageSpec + + # Create a minimal PackageManagerRegistry class + class PackageManagerRegistry(PackageManagerRegistryMixin): + def __init__(self): + self._registry_client = None + self.pkg_type = "library" + + @staticmethod + def is_system_compatible(value, custom_system=None): + return True + + pio_registry = PackageManagerRegistry() + + # Fetch package metadata from registry + package = pio_registry.fetch_registry_package( + PackageSpec( + owner=username, + name=pkgname, + ) + ) + owner = package["owner"]["username"] + name = package["name"] + + # Find the best matching version based on requirements + version = pio_registry.pick_best_registry_version( + package.get("versions"), + PackageSpec(owner=username, name=pkgname, requirements=requirements), + ) + + # If no version found, return with None for version and URL + if not version: + return owner, name, None, None + + # Find the compatible package file for this version + pkgfile = pio_registry.pick_compatible_pkg_file(version["files"]) + + # If no package file found, return with None for URL but valid version + if not pkgfile: + return owner, name, version["name"], None + + return owner, name, version["name"], pkgfile["download_url"] + + +def _patch_component(component: IDFComponent, first_pass: bool): + """ + Apply patches/workarounds to specific components that have known issues. + + This function modifies component data to fix compatibility issues or missing + dependencies for certain libraries. It applies different patches based on + whether it's the first or second pass of processing. + + Args: + component: The IDFComponent object to potentially patch + first_pass: Boolean indicating if this is the first pass of processing + """ + + # Patch only on the second step + if not first_pass and CORE.using_arduino: + # Add the missing dependency to Arduino framework. Source is None so + # the IDF component manager resolves it from the registry instead of + # cloning the 2 GB arduino-esp32 git history. + component.dependencies.append( + IDFComponent( + "espressif/arduino-esp32", + str(CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]), + None, + ) + ) + + # + # fastled/FastLED + # + + # Patch only on the first step + if ( + first_pass + and component.name == _owner_pkgname_to_name("fastled", "FastLED") + and not (component.path / "idf_component.yml").is_file() + ): + # Force fake idf_component: This project already support ESP-IDF + (component.path / "idf_component.yml").write_text("") + + +T = TypeVar("T") + + +def _ensure_list(obj: T | list[T]) -> list[T]: + """ + Convert an object to a list if it isn't already a list. + + Args: + obj: Object that may or may not already be a list. + + Returns: + list[T]: The original list if ``obj`` is a list, otherwise a single-item + list containing ``obj``. + """ + return [obj] if not isinstance(obj, list) else obj + + +def _owner_pkgname_to_name(owner: str | None, pkgname: str) -> str: + """ + Convert owner and package name to a standardized component name. + + This function combines owner and package name with a forward slash when + both are provided, otherwise returns just the package name. + + Args: + owner: The owner/username of the package (can be None) + pkgname: The name of the package + + Returns: + str: The standardized component name in "owner/pkgname" format or just "pkgname" + """ + return f"{owner}/{pkgname}" if owner else pkgname + + +def _collect_filtered_files(src_dir: PathType, src_filters: list[str]) -> list[str]: + """ + Recursively match files in a directory according to include/exclude patterns. + + This function processes a list of filter strings that indicate which files + to include or exclude. Each filter is parsed into patterns with a sign: + '+' for inclusion and '-' for exclusion. Directory patterns ending with '/' + are normalized to include all their contents recursively. + + Args: + src_dir (PathType): Root directory to search within. + src_filters (list[str]): List of filter strings, which may contain multiple + patterns. Each pattern can start with '+' or '-' to indicate inclusion + or exclusion. + + Returns: + list[str]: List of matched file paths as strings. Only files (not directories) + are returned, even if a directory matches a pattern. + """ + matches = list( + itertools.chain.from_iterable( + FILTER_REGEX.findall(src_filter) for src_filter in src_filters + ) + ) + + selected = set() + + for sign, pattern in matches: + pattern = pattern.strip() + + if pattern.endswith("/"): + pattern = pattern.rstrip("/") + "/**" + + full_pattern = os.path.join(glob.escape(str(src_dir)), pattern) + + matched = [] + for item in glob.glob(full_pattern, recursive=True): + if not os.path.isdir(item): + matched.append(item) + else: + # PlatformIO quirk: a directory matched with "*" should include all its + # nested files and subdirectories, not just the directory itself. + for root, _, files in os.walk(item): + matched.extend([os.path.join(root, f) for f in files]) + + if sign == "+": + selected.update(matched) + elif sign == "-": + selected.difference_update(matched) + + return [r for r in selected if os.path.isfile(r)] + + +def _convert_library_to_component(library: Library) -> IDFComponent: + """ + Convert a Library object to an IDFComponent object by resolving its metadata. + + This function handles the conversion of library specifications to component + objects, resolving versions through PlatformIO registry when needed or + parsing direct repository URLs. + + Args: + library: The Library object containing name, version, and/or repository information + + Returns: + IDFComponent: The resolved component with name, version, and URL + + Raises: + ValueError: If a repository URL is missing a reference (#) + RuntimeError: If no artifact can be found for the library + """ + name = None + version = None + source = None + + # Repository is provided directly + if library.repository: + # Parse repository URL to extract name and version + split_result = urlsplit(library.repository) + if not split_result.fragment.strip(): + raise ValueError(f"Missing ref in URL {library.repository}") + + # Sanitize name + name = str(split_result.path).strip("/") + name = name.removesuffix(".git") + + # Sanitize version + version = _sanitize_version(split_result.fragment) + repository = urlunsplit(split_result._replace(fragment="")) + + source = GitSource(str(repository), split_result.fragment) + + # Version is provided - resolve using PlatformIO registry + elif library.version: + name = library.name + if "/" not in name: + owner, pkgname = None, name + else: + owner, pkgname = name.split("/", 1) + + owner, pkgname, version, url = _get_package_from_pio_registry( + owner, pkgname, library.version + ) + if url is None: + raise RuntimeError( + f"Can't find an pkg file from PlatformIO registry for library {library}" + ) + + name = _owner_pkgname_to_name(owner, pkgname) + source = URLSource(url) + + if source is None: + raise RuntimeError(f"Can't find an artifact associated to library {library}") + + assert name, "Missing library name" + assert version, "Missing library version" + + return IDFComponent(name, version, source) + + +def _detect_requires(build_src_files: list[str]) -> set[str]: + """ + Detect required components from source files. + + Args: + build_src_files: List of source file paths to analyze + + Returns: + Set of detected required components + """ + detected = set() + + # 1. Process each source file + for file in build_src_files: + path = Path(file) + + if not path.is_file(): + continue + + try: + content = path.read_text(encoding="utf-8", errors="ignore") + except Exception: # pylint: disable=broad-exception-caught + continue + + # 2. Add required component if one of these patterns matches + for require_name, patterns in REQUIRES_DETECT_PATTERNS.items(): + if require_name in detected: + continue # already found + + for pattern in patterns: + if pattern.search(content): + detected.add(require_name) + break + + return detected + + +def _split_list_by_condition( + items: list[str], match_fn: Callable[[str], str | None] +) -> tuple[list[str], list[str]]: + """ + Splits a list into two lists based on a matching function. + + Args: + items: List of items to split. + match_fn: Function that returns a value for items that should go into the "matched" list. + + Returns: + A tuple (matched, non_matched) + """ + matched = [] + non_matched = [] + for item in items: + result = match_fn(item) + if result: + matched.append(result) + else: + non_matched.append(item) + return matched, non_matched + + +def generate_cmakelists_txt(component: IDFComponent) -> str: + """ + Generate a CMakeLists.txt file for an ESP-IDF component. + + This function creates the necessary CMake configuration to build a library + with ESP-IDF, including source files, include directories, dependencies, + and build flags. + + Args: + component: The IDFComponent object containing library metadata and path + + Returns: + str: The complete CMakeLists.txt content as a string + """ + + def escape_entry(p: PathType) -> str: + # In CMakeLists.txt, backslashes need to be escaped + return f'"{str(p)}"'.replace("\\", "\\\\") + + # Extract the values + build_src_dir = component.data.get("build", {}).get("srcDir", None) + if not build_src_dir: + for d in ["src", "Src", "."]: + if (component.path / Path(d)).is_dir(): + build_src_dir = d + break + + build_include_dir = component.data.get("build", {}).get( + "includeDir", DEFAULT_BUILD_INCLUDE_DIR + ) + build_src_filter = _ensure_list( + component.data.get("build", {}).get("srcFilter", DEFAULT_BUILD_SRC_FILTER) + ) + build_flags = _ensure_list( + component.data.get("build", {}).get("flags", DEFAULT_BUILD_FLAGS) + ) + + # List all sources files + build_src_files = _collect_filtered_files( + component.path / Path(build_src_dir), build_src_filter + ) + + # Detect in the files which requirements to add + # By default in platformio, all the components are added: we need to detect them when using ESP-IDF + requires = _detect_requires(build_src_files) + + # Dependencies are required + for dependency in component.dependencies: + requires.add(dependency.get_require_name()) + + # Only keep sources + build_src_files = [os.path.relpath(p, component.path) for p in build_src_files] + build_src_files = [ + f for f in build_src_files if os.path.splitext(f)[1] in SRC_FILE_EXTENSIONS + ] + + # Handle build flags + include_dir_flags, build_flags = _split_list_by_condition( + build_flags, lambda a: a[2:].strip() if a.startswith("-I") else None + ) + link_directories, build_flags = _split_list_by_condition( + build_flags, lambda a: a[2:].strip() if a.startswith("-L") else None + ) + link_libraries, build_flags = _split_list_by_condition( + build_flags, lambda a: a[2:].strip() if a.startswith("-l") else None + ) + + # Split include directories from build_flags + # Only keep an include directory if it exists + build_include_dirs = [build_include_dir, build_src_dir] + include_dir_flags + build_include_dirs = [ + d for d in build_include_dirs if (component.path / Path(d)).is_dir() + ] + + # Split build_flags list into private and public lists + private_build_flags, public_build_flags = _split_list_by_condition( + build_flags, lambda a: a if a.startswith("-W") else None + ) + + # Generate the component + content = "idf_component_register(\n" + if build_src_files: + str_srcs = " ".join([escape_entry(p) for p in sorted(build_src_files)]) + content += f" SRCS {str_srcs}\n" + if build_include_dirs: + str_include_dirs = " ".join([escape_entry(p) for p in build_include_dirs]) + content += f" INCLUDE_DIRS {str_include_dirs}\n" + if requires: + str_requires = " ".join(sorted(requires)) + content += f" REQUIRES {str_requires}\n" + content += ")\n" + + # Add public and private build flags + if public_build_flags: + content += "target_compile_options(${COMPONENT_LIB} PUBLIC\n" + for build_flag in public_build_flags: + str_build_flag = escape_entry(build_flag) + content += f" {str_build_flag}\n" + content += ")\n" + if private_build_flags: + content += "target_compile_options(${COMPONENT_LIB} PRIVATE\n" + for build_flag in private_build_flags: + str_build_flag = escape_entry(build_flag) + content += f" {str_build_flag}\n" + content += ")\n" + + # Add library paths and files + if link_directories: + content += "target_link_directories(${COMPONENT_LIB} INTERFACE\n" + for link_directory in link_directories: + str_build_flag = escape_entry(link_directory) + content += f" {str_build_flag}\n" + content += ")\n" + + if link_libraries: + content += "target_link_libraries(${COMPONENT_LIB} INTERFACE\n" + for link_library in link_libraries: + str_build_flag = escape_entry(link_library) + content += f" {str_build_flag}\n" + content += ")\n" + + # Add custom CMake scripts + content += "\n".join( + component.data.get(ESPHOME_DATA_KEY, {}).get(ESPHOME_DATA_EXTRA_CMAKE_KEY, []) + ) + + return content + + +def generate_idf_component_yml(component: IDFComponent) -> str: + """ + Generate ESP-IDF component YAML configuration for a library. + + Args: + component: IDFComponent object to generate YAML for + + Returns: + YAML string representation of ESP-IDF component configuration + """ + data = {} + + description = component.data.get("description") + if description: + data["description"] = description + + # Do not use the version from library.json/library.properties; it may be incorrect. + data["version"] = component.version + + repository = component.data.get("repository", {}).get("url", None) + if repository: + data["repository"] = repository + + for dependency in component.dependencies: + # Initialize dependencies section if needed + if "dependencies" not in data: + data["dependencies"] = {} + + # Add this dependency to dependencies + dep = {} + dep["version"] = dependency.version + + # Should use dependency.path as override path + try: + dep["override_path"] = str(dependency.path) + except RuntimeError as e: + # No local path; let the IDF component manager resolve. + # GitSource gives an explicit URL; arduino-esp32 is resolved by + # version from the registry. Anything else is a bug. + if isinstance(dependency.source, GitSource): + dep["git"] = dependency.source.url + elif dependency.name != "espressif/arduino-esp32": + raise e + + data["dependencies"][dependency.get_sanitized_name()] = dep + + return yaml_util.dump(data) + + +def _check_library_data(data: dict): + """ + Check if a library data is compatible with the ESP-IDF framework. + + Args: + component: IDFComponent object being processed + + Raises: + ValueError: If library has unsupported platforms or frameworks + """ + platforms = data.get("platforms", "*") + if isinstance(platforms, str): + platforms = [a.strip() for a in platforms.split(",")] + platforms = _ensure_list(platforms) + + # Check if library supports ESP-IDF platform + valid_platforms = "*" in platforms or ESP32_PLATFORM in platforms + + if not valid_platforms: + raise InvalidIDFComponent(f"Unsupported library platforms: {platforms}") + + frameworks = data.get("frameworks", "*") + if isinstance(frameworks, str): + frameworks = [a.strip() for a in frameworks.split(",")] + frameworks = _ensure_list(frameworks) + + # Check if library supports ESP-IDF framework + framework = "arduino" if CORE.using_arduino else "espidf" + valid_framework = "*" in frameworks or framework in frameworks + + if not valid_framework: + raise InvalidIDFComponent(f"Unsupported library frameworks: {frameworks}") + + extra_script = data.get("build", {}).get("extraScript", None) + if extra_script: + _LOGGER.warning( + 'Extra scripts are not supported. The script "%s" will not be executed.', + extra_script, + ) + + +def _process_dependencies(component: IDFComponent): + """ + Process library dependencies and generate ESP-IDF components. + + Args: + component: IDFComponent object being processed + + Returns: + None + """ + + name, version = component.name, component.version + dependencies = component.data.get("dependencies") + if not dependencies: + return + + _LOGGER.info("Processing %s@%s component dependencies...", name, version) + for dependency in dependencies: + # Validate dependency structure + if not all(k in dependency for k in ("name", "version")): + _LOGGER.debug("Ignore invalid library: %s", dependency) + continue + + try: + _check_library_data(dependency) + except InvalidIDFComponent as e: + _LOGGER.debug( + "Skip %s@%s: %s", dependency["name"], dependency["version"], str(e) + ) + continue + + # The version field may actually contain a URL + version = dependency["version"] + url = None + try: + result = urlparse(version) + if all([result.scheme, result.netloc]): + url, version = version, None + except (TypeError, ValueError): + pass + + # Generate ESP-IDF component from PlatformIO library + component.dependencies.append( + _generate_idf_component( + Library( + _owner_pkgname_to_name( + dependency.get("owner", None), dependency.get("name") + ), + version, + url, + ) + ) + ) + + +def _parse_library_json(library_json_path: PathType): + """ + Load and parse a JSON file describing a library. + + Args: + library_json_path (PathType): Path to the JSON file. + + Returns: + dict: Parsed JSON content as a Python dictionary. + """ + with open(library_json_path, encoding="utf8") as fp: + return json.load(fp) + + +def _parse_library_properties(library_properties_path: PathType): + """ + Parse a key-value platformio .properties style file into a dictionary. + + Args: + library_properties_path (PathType): Path to the properties file. + + Returns: + dict[str, str]: Mapping of parsed property keys to values. + """ + with open(library_properties_path, encoding="utf8") as fp: + data = {} + for line in fp.read().splitlines(): + line = line.strip() + if not line or "=" not in line: + continue + # skip comments + if line.startswith("#"): + continue + key, value = line.split("=", 1) + if not value.strip(): + continue + data[key.strip()] = value.strip() + return data + + +def _generate_idf_component(library: Library, force: bool = False) -> IDFComponent: + """ + Generate an ESP-IDF component from a library specification. + + This function resolves the library, downloads it, processes metadata files, + and generates necessary ESP-IDF build files (CMakeLists.txt, idf_component.yml). + + Args: + library: The library specification containing name, version, and repository URL + force: If True, forces re-download of the library even if it exists locally + + Returns: + IDFComponent: The generated component object with resolved metadata + """ + _LOGGER.info("Generate IDF component for %s library ...", library) + + # Resolve component name, version and url + component = _convert_library_to_component(library) + name, version = component.name, component.version + + # Download the library + component.download(force) + + # Paths to component metadata and build files + library_json_path = component.path / "library.json" + library_properties_path = component.path / "library.properties" + cmakelists_txt_path = component.path / "CMakeLists.txt" + idf_component_yml_path = component.path / "idf_component.yml" + + # Apply patches to the library metadata + _patch_component(component, True) + + if cmakelists_txt_path.is_file() and idf_component_yml_path.is_file(): + # Already an ESP-IDF component + return component + + if library_json_path.is_file(): + component.data = _parse_library_json(library_json_path) + elif library_properties_path.is_file(): + component.data = _parse_library_properties(library_properties_path) + else: + raise RuntimeError( + "Invalid PIO library: missing library.json and/or library.properties" + ) + + # Apply additional patches to the library metadata + _patch_component(component, False) + + # Check if the component is usable with ESP-IDF + _check_library_data(component.data) + + # Handle the dependencies (convert PlatformIO library to ESP-IDF component if needed) + _process_dependencies(component) + + # Generate files + _LOGGER.debug("Generating CMakeLists.txt for %s@%s ...", name, version) + write_file_if_changed( + cmakelists_txt_path, + generate_cmakelists_txt(component), + ) + + _LOGGER.debug("Generating idf_component.yml for %s@%s ...", name, version) + write_file_if_changed( + idf_component_yml_path, + generate_idf_component_yml(component), + ) + + return component + + +def generate_idf_component( + library: Library, force: bool = False +) -> tuple[str, str, Path]: + """ + Generate an ESP-IDF component and return its name, version, and path. + + This is a wrapper function that calls _generate_idf_component and returns + the standardized tuple format (name, version, path). + + Args: + library: The library specification containing name, version, and repository URL + force: If True, forces re-download of the library even if it exists locally + + Returns: + tuple[str, str, Path]: A tuple containing (component_name, component_version, component_path) + """ + component = _generate_idf_component(library, force) + return component.get_sanitized_name(), component.version, component.path diff --git a/esphome/espidf/framework.py b/esphome/espidf/framework.py new file mode 100644 index 00000000000..7ff373aba83 --- /dev/null +++ b/esphome/espidf/framework.py @@ -0,0 +1,1098 @@ +"""ESP-IDF framework tools for ESPHome.""" + +from collections.abc import Iterable +from contextlib import ExitStack +import io +import json +import logging +import os +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +from typing import IO + +import requests + +from esphome.config_validation import Version +from esphome.core import CORE +from esphome.helpers import ProgressBar, get_str_env, rmtree + +PathType = str | os.PathLike + +_LOGGER = logging.getLogger(__name__) + +_SCRIPTS_DIR = Path(__file__).parent + + +def _str_to_lst_of_str(a: str) -> list[str]: + """ + Convert a string to a list of string + + Args: + a: A string containing semicolon-separated values + + Returns: + list of strings + """ + return list(f.strip() for f in a.split(";") if f.strip()) + + +ESPHOME_STAMP_FILE = ".esphome.stamp.json" + +# Cache-buster baked into the stamp file. Bump this whenever a change would +# make pre-existing stamped installs invalid, e.g.: +# - the inlined Python helpers (_get_idf_version, _get_idf_tool_paths) are +# rewritten in a way that's incompatible with prior installs +# - the stamp_info schema changes (keys added/renamed/removed) +# - the tool selection or env-construction logic changes meaning +# Bumping triggers a full reinstall on every user's next run. +STAMP_SCHEMA_VERSION = "0" + +ESPHOME_IDF_DEFAULT_TARGETS = _str_to_lst_of_str( + os.environ.get("ESPHOME_IDF_DEFAULT_TARGETS", "all") +) + +ESPHOME_IDF_DEFAULT_TOOLS = _str_to_lst_of_str( + os.environ.get("ESPHOME_IDF_DEFAULT_TOOLS", "cmake;ninja") +) + +ESPHOME_IDF_DEFAULT_TOOLS_FORCE = _str_to_lst_of_str( + os.environ.get("ESPHOME_IDF_DEFAULT_TOOLS_FORCE", "required") +) + +ESPHOME_IDF_DEFAULT_FEATURES = _str_to_lst_of_str( + os.environ.get("ESPHOME_IDF_DEFAULT_FEATURES", "core") +) + +ESPHOME_IDF_FRAMEWORK_MIRRORS = _str_to_lst_of_str( + os.environ.get( + "ESPHOME_IDF_FRAMEWORK_MIRRORS", + "https://github.com/espressif/esp-idf/releases/download/v{VERSION}/esp-idf-v{VERSION}.zip;https://github.com/espressif/esp-idf/releases/download/v{MAJOR}.{MINOR}/esp-idf-v{MAJOR}.{MINOR}.zip", + ) +) + +ESP_IDF_CONSTRAINTS_MIRRORS = _str_to_lst_of_str( + os.environ.get( + "ESP_IDF_CONSTRAINTS_MIRRORS", + "https://dl.espressif.com/dl/esp-idf/espidf.constraints.v{VERSION}.txt", + ) +) + + +def _get_idf_tools_path() -> Path: + """ + Get the path to the ESP-IDF tools directory. + + Returns: + Path object pointing to the ESP-IDF tools directory + """ + if "ESPHOME_ESP_IDF_PREFIX" in os.environ: + return Path(get_str_env("ESPHOME_ESP_IDF_PREFIX", None)).expanduser() + return CORE.data_dir / "idf" + + +def _get_framework_path(version: str) -> Path: + """ + Get the path to the ESPHome ESP-IDF framework directory for a specific version. + + Args: + version: ESP-IDF version string + + Returns: + Path object pointing to the framework directory + """ + return _get_idf_tools_path() / "frameworks" / f"{version}" + + +def _get_python_env_path(version: str) -> Path: + """ + Get the path to the ESPHome ESP-IDF Python environment directory for a specific version. + + Args: + version: ESP-IDF version string + + Returns: + Path object pointing to the Python environment directory + """ + return _get_idf_tools_path() / "penvs" / f"{version}" + + +def rmdir(directory: PathType, msg: str | None = None): + """ + Remove a directory and its contents recursively if it exists. + + Args: + directory: Path to the directory to be removed + msg: Optional debug message to log before removal or it an error occurs + + Returns: + None + + Raises: + RuntimeError: If directory removal fails + """ + if os.path.isdir(directory): + try: + if msg: + _LOGGER.debug(msg) + rmtree(directory) + except OSError as e: + raise RuntimeError( + f"Error during {msg}: can't remove `{directory}`. Please remove it manually!" + ) from e + + +def _get_pythonexe_path() -> str: + """ + Get the path to the Python executable. + + Returns: + Path to Python executable as string + """ + # Try to get PYTHONEXEPATH environment variable + # Fallback to sys.executable if not set + return os.environ.get("PYTHONEXEPATH", os.path.normpath(sys.executable)) + + +def _get_python_env_executable_path(root: PathType, binary: str) -> Path: + """ + Get the path to a Python environment executable file. + + Args: + root: Root directory of the Python environment + binary: Name of the executable binary + + Returns: + Path object pointing to the executable file + """ + if os.name == "nt": + return Path(root) / "Scripts" / f"{binary}.exe" + return Path(root) / "bin" / binary + + +def _check_stamp(file: PathType, data: dict[str, str]) -> bool: + """ + Check if a stamp file contains the expected data. + + Args: + file: Path to the stamp file + data: Dictionary containing expected data + + Returns: + True if file exists and contains expected data, False otherwise + """ + if not Path(file).is_file(): + return False + + try: + with open(file, encoding="utf-8") as f: + return json.load(f) == data + except (json.JSONDecodeError, OSError): + return False + + +def _write_stamp(file: PathType, data: dict[str, str]): + """ + Write data to a stamp file in JSON format. + + Args: + file: Path to the stamp file to write + data: Dictionary containing data to write + """ + with open(file, "w", encoding="utf8") as fp: + json.dump(data, fp) + + +def _exec( + cmd: list[str], + msg: str | None = None, + env: dict[str, str] | None = None, + stream_output: bool = False, +) -> tuple[bool, str | None, str | None]: + """ + Execute a command and return results. + + Args: + cmd: list of command arguments + msg: Optional custom message for logging + env: Optional dictionary of environment variables to set + stream_output: If True, inherit parent stdio so the subprocess prints + directly to the terminal (useful for commands that produce their + own progress output). stdout/stderr are not captured in this mode. + + Returns: + tuple of (success: bool, stdout: str or None, stderr: str or None). + When stream_output is True, stdout and stderr are always None. + """ + cmd_str = msg or " ".join(cmd) + try: + _LOGGER.debug("%s - running ...", cmd_str) + + run_env = os.environ.copy() + if env: + run_env.update(env) + + if stream_output: + result = subprocess.run(cmd, check=False, env=run_env) + stdout = stderr = None + else: + result = subprocess.run( + cmd, + capture_output=True, + text=True, + check=False, + env=run_env, + ) + stdout = result.stdout + stderr = result.stderr + + if result.returncode != 0: + if stream_output: + _LOGGER.error("%s - failed (returncode=%s)", cmd_str, result.returncode) + else: + tail = (stderr or stdout or "").strip()[-1000:] + _LOGGER.error( + "%s - failed (returncode=%s). Tail:\n%s", + cmd_str, + result.returncode, + tail, + ) + return False, stdout, stderr + + _LOGGER.debug("%s - executed successfully", cmd_str) + return True, stdout, stderr + + except (subprocess.SubprocessError, OSError) as e: + _LOGGER.error("%s - error: %s", cmd_str, str(e)) + return False, None, None + + +def _exec_ok(*args, **kwargs) -> bool: + """ + Execute a command and return only the success status. + + Args: + *args: Positional arguments to pass to _exec function + **kwargs: Keyword arguments to pass to _exec function + + Returns: + True if command executed successfully, False otherwise + """ + return _exec(*args, **kwargs)[0] + + +def _get_idf_version( + idf_framework_root: PathType, env: dict[str, str] | None = None +) -> str: + """ + Get the ESP-IDF version from the specified framework root. + + Args: + idf_framework_root: Path to the ESP-IDF framework root directory + env: Optional dictionary of environment variables to set + + Returns: + String containing ESP-IDF version + + Raises: + RuntimeError: If ESP-IDF version cannot be determined + """ + + cmd = [ + _get_pythonexe_path(), + str(_SCRIPTS_DIR / "get_idf_version.py"), + str(idf_framework_root), + ] + + success, stdout, stderr = _exec( + cmd, + msg="ESP-IDF version", + env=(env or os.environ) + | {"PYTHONPATH": str(Path(idf_framework_root) / "tools")}, + ) + if stdout: + stdout = stdout.strip() + if not success or not stdout: + detail = (stderr or "").strip() + raise RuntimeError( + f"Can't get ESP-IDF version of {idf_framework_root}" + + (f": {detail}" if detail else "") + ) + return stdout + + +def _get_idf_tool_paths( + idf_framework_root: PathType, env: dict[str, str] | None = None +) -> tuple[list[str], dict[str, str]]: + """ + Get ESP-IDF tool paths and environment variables needed for building. + + Args: + idf_framework_root: Path to the ESP-IDF framework root directory + env: Optional dictionary of environment variables to set + + Returns: + tuple containing (list of tool paths, dictionary of environment variables) + + Raises: + RuntimeError: If ESP-IDF tool paths cannot be determined + """ + + cmd = [ + _get_pythonexe_path(), + str(_SCRIPTS_DIR / "get_idf_tool_paths.py"), + str(idf_framework_root), + ] + + success, stdout, stderr = _exec( + cmd, + msg="ESP-IDF tool paths", + env=(env or os.environ) + | {"PYTHONPATH": str(Path(idf_framework_root) / "tools")}, + ) + if not success or not stdout: + detail = (stderr or "").strip() + raise RuntimeError( + f"Can't get ESP-IDF tool paths of {idf_framework_root}" + + (f": {detail}" if detail else "") + ) + + # Extract json values + try: + data = json.loads(stdout) + return data["paths_to_export"], data["export_vars"] + except Exception as e: + raise RuntimeError( + f"Can't extract ESP-IDF tool paths of {idf_framework_root}" + ) from e + + +def _get_python_version( + python_executable: PathType, + env: dict[str, str] | None = None, + throw_exception=False, +) -> str | None: + """ + Get the Python version from the specified executable. + + Args: + python_executable: Path to the Python executable to check + env: Optional dictionary of environment variables to set + throw_exception: If True, raise RuntimeError when version can't be determined + + Returns: + String containing Python version in "major.minor.patch" format, or None if failed + """ + + script = """ +import sys +print(".".join([str(x) for x in sys.version_info])) +""" + cmd = [python_executable, "-c", script] + + success, stdout, _ = _exec(cmd, msg="Python version", env=env) + + if stdout: + stdout = stdout.strip() + if throw_exception and (not success or not stdout): + raise RuntimeError(f"Can't get Python version of {python_executable}") + return stdout + + +def _create_venv(root: PathType, msg: str | None = None): + """ + Create a Python virtual environment. + + Args: + root: Path to the virtual environment directory + msg: Optional message for logging + + Returns: + None + + Raises: + Exception: If virtual environment creation fails + """ + cmd = [_get_pythonexe_path(), "-m", "venv", "--clear", root] + if not _exec_ok(cmd, msg=f"Create Python virtual environment for {msg}"): + raise RuntimeError(f"Can't create Python virtual environment for {msg}") + + +def _detect_archive_root(names: Iterable[str]) -> str | None: + """Detect a single top-level directory shared by all archive entries. + + Returns the directory name if every non-empty entry sits under the same + top-level directory, else ``None``. Extraction helpers use this to strip + the wrapper directory commonly found in source archives during extraction + rather than renaming it afterwards — post-extraction renames are + unreliable on Windows because antivirus and the search indexer briefly + hold handles on freshly written files. + """ + root: str | None = None + has_descendant = False + for raw in names: + name = raw.replace("\\", "/").strip("/") + if not name: + continue + first, sep, _ = name.partition("/") + if root is None: + root = first + elif root != first: + return None + if sep: + has_descendant = True + return root if has_descendant else None + + +def _tar_extract_all( + data: io.BufferedIOBase, + extract_dir: PathType = ".", + progress_header: str | None = None, +): + """ + Extract a TAR archive to the specified directory. + + Implementation is inspired by Python 3.12's tarfile data filtering logic. + This can be replaced with the standard library implementation once + support for Python 3.11 is no longer required. + + Args: + data: File-like object containing the TAR archive + extract_dir: Directory to extract contents to + progress_header: If set, show a progress bar with this header + """ + import stat + import tarfile + + extract_dir = os.fspath(extract_dir) + abs_dest = os.path.abspath(extract_dir) + + with tarfile.open(fileobj=data, mode="r") as tar_ref: + all_members = tar_ref.getmembers() + + # Detect a single common top-level directory and strip it during + # extraction so we don't have to flatten it via a rename afterwards. + strip_root = _detect_archive_root(m.name for m in all_members) + strip_prefix = f"{strip_root}/" if strip_root is not None else None + + safe_members = [] + + for member in all_members: + name = member.name + + # 1. Strip leading slashes + name = name.lstrip("/" + os.sep) + + # 2. Reject absolute paths (incl. Windows drive) + if os.path.isabs(name) or ( + os.name == "nt" and ":" in name.split(os.sep)[0] + ): + continue + + # 3. Strip wrapper directory if one was detected + if strip_prefix is not None: + norm = name.replace("\\", "/") + if norm in (strip_root, strip_prefix): + continue + if not norm.startswith(strip_prefix): + continue + name = norm[len(strip_prefix) :] + + # 4. Compute final path + target_path = os.path.realpath(os.path.join(abs_dest, name)) + if os.path.commonpath([abs_dest, target_path]) != abs_dest: + continue + + # 5. Validate links properly + if member.issym() or member.islnk(): + linkname = member.linkname + + # Reject absolute link targets + if os.path.isabs(linkname): + continue + + # Strip leading slashes + linkname = os.path.normpath(linkname) + + if member.issym(): + link_target = os.path.join( + abs_dest, os.path.dirname(name), linkname + ) + else: + link_target = os.path.join(abs_dest, linkname) + link_target = os.path.realpath(link_target) + + if os.path.commonpath([abs_dest, link_target]) != abs_dest: + continue + + # write back normalized linkname + member.linkname = linkname + + # 6. Sanitize permissions + mode = member.mode + if mode is not None: + # Strip high bits & group/other write bits + mode &= ( + stat.S_IRWXU + | stat.S_IRGRP + | stat.S_IXGRP + | stat.S_IROTH + | stat.S_IXOTH + ) + if member.isfile() or member.islnk(): + # remove exec bits unless explicitly user-executable + if not (mode & stat.S_IXUSR): + mode &= ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + mode |= stat.S_IRUSR | stat.S_IWUSR + elif member.isdir() or member.issym(): + # Ignore mode for directories & symlinks + mode = None + else: + # Block special files + continue + + member.mode = mode + + # 7. Strip ownership + member.uid = None + member.gid = None + member.uname = None + member.gname = None + + # 8. Assign sanitized name back + member.name = name + + safe_members.append(member) + + total = len(safe_members) + progress = ( + ProgressBar(progress_header) if progress_header and total > 0 else None + ) + for i, member in enumerate(safe_members, 1): + tar_ref.extract(member, abs_dest) + if progress is not None: + progress.update(i / total) + if progress is not None: + progress.update(1) + + +def _zip_extract_all( + data: io.BufferedIOBase, + extract_dir: PathType = ".", + progress_header: str | None = None, +): + """ + Extract a ZIP archive to the specified directory. + + Args: + data: File-like object containing the ZIP archive + extract_dir: Directory to extract contents to + progress_header: If set, show a progress bar with this header + """ + import zipfile + + extract_dir = os.path.abspath(extract_dir) + + with zipfile.ZipFile(data, "r") as zip_ref: + all_members = zip_ref.infolist() + + # Detect a single common top-level directory and strip it during + # extraction so we don't have to flatten it via a rename afterwards. + strip_root = _detect_archive_root(m.filename for m in all_members) + strip_prefix = f"{strip_root}/" if strip_root is not None else None + + total = len(all_members) + progress = ( + ProgressBar(progress_header) if progress_header and total > 0 else None + ) + + for i, member in enumerate(all_members, 1): + # 1. Normalize name + name = member.filename.lstrip("/\\") + + # 2. Reject absolute paths / Windows drives + if os.path.isabs(name) or ( + os.name == "nt" and ":" in name.split(os.sep)[0] + ): + continue + + # 3. Strip wrapper directory if one was detected + if strip_prefix is not None: + norm = name.replace("\\", "/") + if norm in (strip_root, strip_prefix): + continue + if not norm.startswith(strip_prefix): + continue + name = norm[len(strip_prefix) :] + + # 4. Compute safe target path + target_path = os.path.abspath(os.path.join(extract_dir, name)) + + if os.path.commonpath([extract_dir, target_path]) != extract_dir: + raise ValueError(f"Unsafe path detected: {member.filename}") + + # 5. Assign sanitized name back + member.filename = name + + # 6. Extract + zip_ref.extract(member, extract_dir) + + if progress is not None: + progress.update(i / total) + if progress is not None: + progress.update(1) + + +_ARCHIVE_MAGIC_MAP = { + b"\x1f\x8b\x08": _tar_extract_all, + b"\x42\x5a\x68": _tar_extract_all, + b"\xfd\x37\x7a\x58\x5a\x00": _tar_extract_all, + b"\x50\x4b\x03\x04": _zip_extract_all, +} + + +def archive_extract_all( + archive: PathType | io.RawIOBase | IO[bytes], + extract_dir: PathType = ".", + progress_header: str | None = None, +): + """ + Extract an archive file to the specified directory. + + Args: + archive: Path to archive file or file-like object + extract_dir: Directory to extract contents to + progress_header: If set, show a progress bar with this header + + Raises: + TypeError: If archive is not a valid type + ValueError: If archive format is unsupported + """ + + # 1. Handle different archive input types + with ExitStack() as stack: + archive_ref: io.BufferedIOBase + if isinstance(archive, (str, os.PathLike)): + archive_ref = stack.enter_context(open(archive, "rb")) + elif isinstance(archive, (io.BufferedReader, io.BufferedRandom)): + archive_ref = archive + elif isinstance(archive, io.RawIOBase): + archive_ref = io.BufferedReader(archive) + else: + raise TypeError( + f"archive must be str, Path, or file-like object: {type(archive)}" + ) + + # 2. Detect archive format and select appropriate extraction function + matched_fct = None + magic_len = max(len(k) for k in _ARCHIVE_MAGIC_MAP) + header = archive_ref.peek(magic_len) + for magic, fct in _ARCHIVE_MAGIC_MAP.items(): + if header.startswith(magic): + matched_fct = fct + break + if matched_fct is None: + raise ValueError("Unsupported archive format") + matched_fct(archive_ref, extract_dir, progress_header=progress_header) + + +def download_from_mirrors( + mirrors: list[str], + substitutions: dict[str, str], + target: io.RawIOBase | IO[bytes] | PathType, + timeout: int = 30, +) -> str | None: + """ + Download file from multiple mirrors with substitution support. + + Args: + mirrors: list of mirror URLs + substitutions: Dictionary of substitutions to apply to URLs + target: Target file path or file-like object + timeout: Download timeout in seconds + + Returns: + The source URL. + + Raises: + Exception: If all download attempts fail + """ + # 1. Open target file for writing if path given + with ExitStack() as stack: + if isinstance(target, (str, os.PathLike)): + f = stack.enter_context(open(target, "wb")) + elif isinstance(target, (io.RawIOBase, io.IOBase)): + f = target + else: + raise TypeError( + f"target must be str, Path, or file-like object: {type(target)}" + ) + + # 2. Try each mirror in order + last_exception = None + + for mirror in mirrors: + # 3. Apply substitutions to URL + url = mirror.format(**substitutions) + + _LOGGER.debug("Trying downloading from %s", url) + + try: + # 4. Reset file pointer and download + f.seek(0) + f.truncate(0) + + with requests.get(url, stream=True, timeout=timeout) as r: + r.raise_for_status() + + total_size = int(r.headers.get("content-length", 0)) + downloaded = 0 + + progress = ProgressBar("Downloading") if total_size > 0 else None + + for chunk in r.iter_content(chunk_size=8192): + if chunk: + f.write(chunk) + + downloaded += len(chunk) + + if progress is not None: + progress.update(downloaded / total_size) + + if progress is not None: + progress.update(1) + + _LOGGER.debug("Downloaded successfully from: %s", url) + + # 6. Reset file pointer and return + f.seek(0) + return url + + except Exception as e: # pylint: disable=broad-exception-caught + _LOGGER.debug("Failed to download %s: %s", url, str(e)) + last_exception = e + + # 7. Raise last exception if all mirrors failed + if last_exception: + raise last_exception + return None + + +def _check_esphome_idf_framework_install( + version: str, + targets: list[str], + tools: list[str], + force: bool = False, + env: dict[str, str] | None = None, +) -> tuple[Path, bool]: + """ + Check and install ESP-IDF framework. + + Args: + version: ESP-IDF version to check/install + targets: Target platforms to install + tools: list of tools to install + force: If True, force reinstallation + env: Optional dictionary of environment variables to set + + Returns: + tuple of (framework_path, install_flag) + """ + + # Sanitize inputs + targets = sorted(set(targets)) + tools = sorted(set(tools)) + + stamp_info = {} + stamp_info["schema_version"] = STAMP_SCHEMA_VERSION + stamp_info["targets"] = targets + stamp_info["tools"] = tools + # TODO: Add stamp with this module version + + # 1. Get framework path and stamp file path + framework_path = _get_framework_path(version) + extracted_marker = framework_path / ".esphome_extracted" + env_stamp_file = framework_path / ESPHOME_STAMP_FILE + idf_tools_path = framework_path / "tools" / "idf_tools.py" + _LOGGER.info("Checking ESP-IDF %s framework ...", version) + + # 2. Download and extract the framework if not already extracted. + # The marker is written last after extraction succeeds, so its presence + # is the authoritative "extraction complete" signal — no half-extracted + # tree can pass for installed. Extracting directly into framework_path + # avoids post-extraction renames that race with antivirus on Windows. + # Tool install state is tracked separately by the stamp file in step 3, + # so we only re-extract when extraction itself is missing or incomplete. + install = force or not extracted_marker.is_file() + if install: + rmdir(framework_path, msg=f"Clean up ESP-IDF {version} framework") + + # Download in temporary file + with tempfile.NamedTemporaryFile() as tmp: + _LOGGER.info("Downloading ESP-IDF %s framework ...", version) + + # Create substitutions for the URLs + substitutions = {"VERSION": version} + try: + ver = Version.parse(version) + substitutions["MAJOR"] = str(ver.major) + substitutions["MINOR"] = str(ver.minor) + substitutions["PATCH"] = str(ver.patch) + substitutions["EXTRA"] = ver.extra + except ValueError: + pass + + download_from_mirrors( + ESPHOME_IDF_FRAMEWORK_MIRRORS, substitutions, tmp.file + ) + + _LOGGER.info("Extracting ESP-IDF %s framework ...", version) + archive_extract_all(tmp.file, framework_path, progress_header="Extracting") + extracted_marker.touch() + + # 3. Check if the framework tools are the same and correctly installed + if not install: + install = True + if _check_stamp(env_stamp_file, stamp_info): + _LOGGER.info("Checking ESP-IDF %s framework installation ...", version) + cmd = [ + _get_pythonexe_path(), + str(idf_tools_path), + "--non-interactive", + "check", + ] + if _exec_ok(cmd, msg=f"ESP-IDF {version} check", env=env): + install = False + + # 4. Install framework tools if not installed or needs update + if install: + _LOGGER.info("Installing ESP-IDF %s framework ...", version) + targets_str = ",".join(targets) + cmd = [ + _get_pythonexe_path(), + str(idf_tools_path), + "--non-interactive", + "install", + f"--targets={targets_str}", + ] + tools + if not _exec_ok( + cmd, + msg=f"ESP-IDF {version} framework installation", + env=env, + stream_output=True, + ): + raise RuntimeError(f"ESP-IDF {version} framework installation failure") + + _write_stamp(env_stamp_file, stamp_info) + + return framework_path, install + + +def _check_esp_idf_python_env_install( + version: str, + features: list[str], + force: bool = False, + env: dict[str, str] | None = None, +) -> tuple[Path, bool]: + """ + Check and install ESP-IDF Python environment. + + Args: + version: ESP-IDF version to check/install + features: Features to install + force: If True, force reinstallation + env: Environment variables to use + + Returns: + tuple of (python_env_path, install_flag) + """ + + # Sanitize inputs + features = sorted(set(features)) + + stamp_info = {} + stamp_info["schema_version"] = STAMP_SCHEMA_VERSION + stamp_info["features"] = features + + framework_path = _get_framework_path(version) + python_env_path = _get_python_env_path(version) + env_stamp_file = python_env_path / ESPHOME_STAMP_FILE + env_python_path = _get_python_env_executable_path(python_env_path, "python") + + _LOGGER.info("Checking ESP-IDF %s Python environment ...", version) + install = force or not python_env_path.is_dir() or not env_python_path.is_file() + if not install: + # Check it against the stamp file + install = True + python_version = _get_python_version(env_python_path, env=env) + if python_version: + stamp_info["python_version"] = python_version + if _check_stamp(env_stamp_file, stamp_info): + install = False + + if install: + rmdir(python_env_path, msg=f"Clean up ESP-IDF {version} Python environment") + + _create_venv(python_env_path, msg=f"ESP-IDF {version}") + + esp_idf_version = _get_idf_version(framework_path, env=env) + constraint_file_path = ( + _get_idf_tools_path() / f"espidf.constraints.v{esp_idf_version}.txt" + ) + _LOGGER.debug("ESP-IDF version %s", esp_idf_version) + + _LOGGER.info("Downloading constraints file for ESP-IDF %s ...", esp_idf_version) + download_from_mirrors( + ESP_IDF_CONSTRAINTS_MIRRORS, + {"VERSION": esp_idf_version}, + constraint_file_path, + ) + + cmd_pip_install = [ + str(env_python_path), + "-m", + "pip", + "install", + "--upgrade", + "--constraint", + constraint_file_path, + ] + + _LOGGER.info("Installing ESP-IDF %s Python dependencies ...", version) + cmd = cmd_pip_install + [ + "pip", + "setuptools", + ] + if not _exec_ok( + cmd, + msg=f"Upgrade ESP-IDF {version} Python environment packages", + env=env, + ): + raise RuntimeError( + f"Upgrade ESP-IDF {version} Python environment packages failure" + ) + + for feature in features: + requirements_file = ( + framework_path + / "tools" + / "requirements" + / f"requirements.{feature}.txt" + ) + cmd = cmd_pip_install + [ + "-r", + str(requirements_file), + ] + if not _exec_ok( + cmd, + msg=f"Install ESP-IDF {version} Python dependencies for {feature}", + env=env, + ): + raise RuntimeError( + f"Install ESP-IDF {version} Python dependencies for {feature} failure" + ) + + stamp_info["python_version"] = _get_python_version( + env_python_path, env=env, throw_exception=True + ) + _write_stamp(env_stamp_file, stamp_info) + + return python_env_path, install + + +def check_esp_idf_install( + version: str, + targets: list[str] | None = None, + tools: list[str] | None = None, + features: list[str] | None = None, + force: bool = False, +) -> tuple[Path, Path]: + """ + Check and install ESP-IDF framework and Python environment. + + Args: + version: ESP-IDF version to check/install + targets: Target platforms to install + tools: list of tools to install + features: Features to install + force: If True, force reinstallation + + Returns: + tuple of (framework_path, python_env_path) + """ + env = {} + env["IDF_TOOLS_PATH"] = str(_get_idf_tools_path()) + env["IDF_PATH"] = "" + + targets = targets or ESPHOME_IDF_DEFAULT_TARGETS + + # Determine which tools need to be installed if not provided + if tools is None: + tools = [] + for tool in set(ESPHOME_IDF_DEFAULT_TOOLS) | set( + ESPHOME_IDF_DEFAULT_TOOLS_FORCE + ): + # Check if the tool exist + if tool in ESPHOME_IDF_DEFAULT_TOOLS_FORCE or not shutil.which(tool): + tools.append(tool) + + # 1) Framework + framework_path, installed = _check_esphome_idf_framework_install( + version, targets, tools, force=force, env=env + ) + + features = features or ESPHOME_IDF_DEFAULT_FEATURES + + # 2) Python env + python_env_path, installed = _check_esp_idf_python_env_install( + version, features, force=force or installed, env=env + ) + + return framework_path, python_env_path + + +def get_framework_env( + framework_path: PathType, + python_env_path: PathType | None = None, + env: dict[str, str] | None = None, +): + """ + Get environment variables for ESP-IDF framework. + + Args: + framework_path: Path to the ESP-IDF framework + python_env_path: Optional path to Python environment + env: Optional dictionary of environment variables to set + + Returns: + Dictionary containing updated environment variables + """ + # 1. Initialize base environment with extra ESP-IDF environment variables + env = env.copy() if env else {} + env["IDF_TOOLS_PATH"] = str(_get_idf_tools_path()) + env["IDF_PATH"] = "" + + # 2. Get existing PATH from env or os.environ + if "PATH" in env: + path_list = env["PATH"].split(os.pathsep) + else: + path_list = os.environ["PATH"].split(os.pathsep) + + # 3. If Python environment path is provided, add it to PATH and set IDF_PYTHON_ENV_PATH + if python_env_path: + python_path = _get_python_env_executable_path(python_env_path, "python") + path_list.insert(0, str(python_path.parent)) + env["IDF_PYTHON_ENV_PATH"] = str(python_env_path) + + # 4. Set framework-specific environment variables + env["IDF_PATH"] = str(framework_path) + env["ESP_IDF_VERSION"] = _get_idf_version(framework_path, env) + + # 5. Get and add tool paths and environment variables + paths_to_export, export_vars = _get_idf_tool_paths(framework_path, env) + env.update(export_vars) + env["PATH"] = os.pathsep.join(paths_to_export + path_list) + + return env diff --git a/esphome/espidf/get_idf_tool_paths.py b/esphome/espidf/get_idf_tool_paths.py new file mode 100644 index 00000000000..2e8859631d0 --- /dev/null +++ b/esphome/espidf/get_idf_tool_paths.py @@ -0,0 +1,51 @@ +"""Print JSON ``{paths_to_export, export_vars}`` for ESP-IDF tools. + +Run via ``python ``. PYTHONPATH must include +``/tools`` so ``idf_tools`` is importable. Exits with +status 1 and prints ``Missing ESP-IDF tools: ...`` on stderr if any tool is +not installed. +""" + +# pylint: disable=import-error # idf_tools is on PYTHONPATH at runtime only + +import json +import os +import sys +from types import SimpleNamespace + +from idf_tools import ( + TOOLS_FILE, + IDFEnv, + IDFTool, + filter_tools_info, + g, + load_tools_info, + process_tool, +) + +g.idf_path = sys.argv[1] +g.idf_tools_path = os.environ.get("IDF_TOOLS_PATH") +g.tools_json = os.path.join(g.idf_path, TOOLS_FILE) + +tools_info = filter_tools_info(IDFEnv.get_idf_env(), load_tools_info()) +args = SimpleNamespace(prefer_system=False) +paths_to_export: list[str] = [] +export_vars: dict[str, str] = {} +missing_tools: list[str] = [] + +for name, tool in tools_info.items(): + if tool.get_install_type() == IDFTool.INSTALL_NEVER: + continue + tool_paths, tool_vars, found = process_tool( + tool, name, args, "install_cmd", "prefer_system_hint" + ) + if not found: + missing_tools.append(name) + paths_to_export += tool_paths + export_vars |= tool_vars + +if missing_tools: + print("Missing ESP-IDF tools: " + ", ".join(missing_tools), file=sys.stderr) + raise SystemExit(1) + +print(json.dumps({"paths_to_export": paths_to_export, "export_vars": export_vars})) diff --git a/esphome/espidf/get_idf_version.py b/esphome/espidf/get_idf_version.py new file mode 100644 index 00000000000..5be51275ec3 --- /dev/null +++ b/esphome/espidf/get_idf_version.py @@ -0,0 +1,14 @@ +"""Print the ESP-IDF version of a given framework root. + +Run via ``python ``. PYTHONPATH must include +``/tools`` so ``idf_tools`` is importable. +""" + +# pylint: disable=import-error # idf_tools is on PYTHONPATH at runtime only + +import sys + +from idf_tools import g, get_idf_version + +g.idf_path = sys.argv[1] +print(get_idf_version()) diff --git a/esphome/espidf/runner.py b/esphome/espidf/runner.py new file mode 100644 index 00000000000..e740ab72854 --- /dev/null +++ b/esphome/espidf/runner.py @@ -0,0 +1,223 @@ +r"""Subprocess entry point for running ``idf.py`` with stdio wrapping. + +Invoked as ``python runner.py [script args...]``. + +Wraps ``sys.stdout`` and ``sys.stderr`` with a ``_FilteringTTYStream`` +shim so that: + +1. ``isatty()`` unconditionally returns True. CMake, Ninja, and idf.py's + own progress-bar code all check ``stream.isatty()`` to decide between + TTY-format output (``\\r`` cursor moves, ANSI colors, fancy progress + bars) and a plain fallback. With the wrapper in place they always + emit TTY format, even when our real stdout is a pipe to the parent + process (e.g. running under the Home Assistant dashboard add-on). + Downstream consumers — local terminals and the HA dashboard log + viewer — render the TTY control sequences correctly. + +2. ``FILTER_IDF_LINES`` is applied inside the shim's ``write()`` so + noisy idf.py output is dropped before it leaves this subprocess. + Filtering is skipped when ``-v`` / ``--verbose`` appears in argv so + verbose mode still shows everything. + +ESP-IDF runs under its own Python virtual environment which does not +have the ``esphome`` package installed, so the runner is intentionally +self-contained: no imports from ``esphome`` at all. The line-filtering +wrapper is inlined below rather than imported from +``esphome.util.RedirectText`` for that reason. +""" + +import sys + +# Regex patterns matched against each line of idf.py / CMake / Ninja +# output. Lines that match are dropped before reaching the parent +# process. Patterns are anchored at the start of the line (the shim +# uses ``re.match``). Disabled when the user passes ``-v`` / +# ``--verbose`` to ``esphome compile``. +FILTER_IDF_LINES: list[str] = [ + # idf.py's "how to flash" block at the end of a successful build. + # ESPHome handles flashing itself, so these instructions just clutter + # the output. + r"Project build complete\.", + r" idf\.py ", + r" python -m esptool ", + r"or$", + r"or from the ", + # CMake dumps the full list of IDF component paths on one giant line. + # It's purely informational and bloats the log. + r"-- Component paths:", + # CMake lists every linker script it adds (dozens of lines) and the + # complete flat list of IDF components on one giant line. Neither + # has diagnostic value for end users. + r"-- Adding linker script ", + r"-- Components:", + # IDF component manager notices: emitted on first build (no lock), + # once per stubbed dependency, plus the final "Processing N + # dependencies" enumeration. Patterns allow a leading run of dots + # because the component manager prints progress dots on the same + # line, so a NOTICE often arrives prefixed with ".NOTICE:" or + # "...........NOTICE:". + r"\.*NOTICE: ", +] + + +def main() -> int: + # ---- sys.path fix-up --------------------------------------------------- + # + # When Python runs this file as ``python runner.py``, it prepends the + # script's directory — ``/esphome/espidf/`` — to + # ``sys.path[0]``. That directory is part of the esphome package whose + # sibling ``types.py`` (in ``esphome/``) collides with stdlib ``types``. + # Any subsequent import that transitively touches ``types`` (``runpy``, + # ``pathlib``, ``functools``, ``typing``, ...) could resolve the wrong + # module. Drop the entry pre-emptively. ``sys`` is a built-in so + # importing it at module level earlier did not trigger the shadow. + if sys.path and sys.path[0]: + sys.path.pop(0) + # ---- end sys.path fix-up ----------------------------------------------- + + import os + import re + import runpy + + # Patch ``os.get_terminal_size`` to return a fallback size instead + # of raising ``OSError`` when the underlying fd isn't a real + # terminal. + # + # idf.py's ``fit_text_in_terminal`` (in ``idf_py_actions/tools.py``) + # unconditionally calls ``os.get_terminal_size()`` to format ninja + # progress lines. When that raises ``[Errno 25] Inappropriate + # ioctl for device`` on our pipe-backed stdout, idf.py catches the + # exception as ``EnvironmentError`` and silently exits its stdout + # reader coroutine — dropping all ninja build output from that + # point on. Returning a valid value keeps the coroutine alive so + # progress and error lines continue to flow through to the parent + # process. + # + # Honour the ``COLUMNS`` / ``LINES`` env vars if the caller set + # them explicitly. Otherwise fall back to ``(0, 0)``, which + # ``fit_text_in_terminal`` treats as "unknown width, don't + # truncate" (see the ``if not terminal_width: return out`` guard). + # Downstream log viewers (local terminals, the HA dashboard) wrap + # or scroll long lines themselves, so we'd rather emit the full + # file path than have idf.py elide its middle. + _orig_get_terminal_size = os.get_terminal_size + + def _get_terminal_size_fallback(fd: int = 1) -> os.terminal_size: + try: + return _orig_get_terminal_size(fd) + except OSError: + try: + columns = int(os.environ.get("COLUMNS", "0")) + except ValueError: + columns = 0 + try: + lines = int(os.environ.get("LINES", "0")) + except ValueError: + lines = 0 + return os.terminal_size((columns, lines)) + + os.get_terminal_size = _get_terminal_size_fallback # type: ignore[assignment] + + # Strip ANSI escape sequences before comparing a line against the filter + # patterns, so colorized lines still match plain-text patterns. + ansi_escape = re.compile(r"\033[@-_][0-?]*[ -/]*[@-~]") + + class _FilteringTTYStream: + r"""Minimal stdout/stderr wrapper. + + * ``isatty()`` unconditionally returns True, tricking downstream + code into emitting TTY-format output. + * Input is split on ``\\n`` / ``\\r`` via + ``str.splitlines(keepends=True)`` and any complete line whose + ANSI-stripped, right-stripped form matches one of + ``filter_lines`` is dropped. + * Incomplete trailing chunks are held in a buffer until a + terminator arrives. + + Mirrors the matching semantics of ``esphome.util.RedirectText`` + so filter patterns behave identically in both the PlatformIO + and IDF runner paths. + """ + + def __init__(self, stream, filter_lines: list[str] | None) -> None: + self._stream = stream + if filter_lines: + combined = r"|".join(r"(?:" + p + r")" for p in filter_lines) + self._filter_pattern: re.Pattern[str] | None = re.compile(combined) + else: + self._filter_pattern = None + self._line_buffer = "" + + def __getattr__(self, name: str): + return getattr(self._stream, name) + + def isatty(self) -> bool: + return True + + def flush(self) -> None: + self._stream.flush() + + def write(self, data) -> int: + # Text streams normally hand us ``str``; decode in case + # somebody writes bytes directly. + if not isinstance(data, str): + data = data.decode(errors="replace") + + if self._filter_pattern is None: + self._stream.write(data) + return len(data) + + self._line_buffer += data + for line in self._line_buffer.splitlines(keepends=True): + if "\n" not in line and "\r" not in line: + # Incomplete — hold until we see a terminator. + self._line_buffer = line + break + self._line_buffer = "" + + stripped = ansi_escape.sub("", line).rstrip() + if self._filter_pattern.match(stripped) is not None: + continue + self._stream.write(line) + return len(data) + + if len(sys.argv) < 2: + print( + "usage: runner.py [args...]", + file=sys.stderr, + ) + return 2 + + script_path = sys.argv[1] + + # Mirror the platformio_runner behaviour: verbose mode disables the + # line filter so all output reaches the user. + is_verbose = any(arg in ("-v", "--verbose") for arg in sys.argv[2:]) + filter_lines = None if is_verbose else FILTER_IDF_LINES or None + + sys.stdout = _FilteringTTYStream(sys.stdout, filter_lines) # type: ignore[assignment] + sys.stderr = _FilteringTTYStream(sys.stderr, filter_lines) # type: ignore[assignment] + + # Shift argv so the target script sees its own path as argv[0] and + # its own arguments starting at argv[1]. runpy.run_path does not + # modify sys.argv itself. + sys.argv = [script_path] + sys.argv[2:] + + # Emulate Python's default behaviour of prepending the script's + # directory to sys.path[0] when running ``python script.py``. + # runpy.run_path does not do this automatically, but idf.py relies + # on it to import its sibling modules (python_version_checker, + # idf_py_actions, ...). + script_dir = os.path.dirname(os.path.abspath(script_path)) + if script_dir not in sys.path: + sys.path.insert(0, script_dir) + + # If idf.py calls sys.exit(), SystemExit propagates out of run_path + # and carries the exit code back to our caller. For normal returns, + # fall through and exit with 0. + runpy.run_path(script_path, run_name="__main__") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/esphome/espidf_api.py b/esphome/espidf_api.py deleted file mode 100644 index 9ebcc48513c..00000000000 --- a/esphome/espidf_api.py +++ /dev/null @@ -1,274 +0,0 @@ -"""ESP-IDF direct build API for ESPHome.""" - -import json -import logging -import os -from pathlib import Path -import shutil -import subprocess - -from esphome.components.esp32.const import KEY_ESP32, KEY_FLASH_SIZE -from esphome.core import CORE, EsphomeError - -_LOGGER = logging.getLogger(__name__) - - -def _get_idf_path() -> Path | None: - """Get IDF_PATH from environment or common locations.""" - # Check environment variable first - if "IDF_PATH" in os.environ: - path = Path(os.environ["IDF_PATH"]) - if path.is_dir(): - return path - - # Check common installation locations - common_paths = [ - Path.home() / "esp" / "esp-idf", - Path.home() / ".espressif" / "esp-idf", - Path("/opt/esp-idf"), - ] - - for path in common_paths: - if path.is_dir() and (path / "tools" / "idf.py").is_file(): - return path - - return None - - -def _get_idf_env() -> dict[str, str]: - """Get environment variables needed for ESP-IDF build. - - Requires the user to have sourced export.sh before running esphome. - """ - env = os.environ.copy() - - idf_path = _get_idf_path() - if idf_path is None: - raise EsphomeError( - "ESP-IDF not found. Please install ESP-IDF and source export.sh:\n" - " git clone -b v5.3.2 --recursive https://github.com/espressif/esp-idf.git ~/esp-idf\n" - " cd ~/esp-idf && ./install.sh\n" - " source ~/esp-idf/export.sh\n" - "See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/" - ) - - env["IDF_PATH"] = str(idf_path) - return env - - -def run_idf_py( - *args, cwd: Path | None = None, capture_output: bool = False -) -> int | str: - """Run idf.py with the given arguments.""" - idf_path = _get_idf_path() - if idf_path is None: - raise EsphomeError("ESP-IDF not found") - - env = _get_idf_env() - idf_py = idf_path / "tools" / "idf.py" - - cmd = ["python", str(idf_py)] + list(args) - - if cwd is None: - cwd = CORE.build_path - - _LOGGER.debug("Running: %s", " ".join(cmd)) - _LOGGER.debug(" in directory: %s", cwd) - - if capture_output: - result = subprocess.run( - cmd, - cwd=cwd, - env=env, - capture_output=True, - text=True, - check=False, - ) - if result.returncode != 0: - _LOGGER.error("idf.py failed:\n%s", result.stderr) - return result.stdout - result = subprocess.run( - cmd, - cwd=cwd, - env=env, - check=False, - ) - return result.returncode - - -def run_reconfigure() -> int: - """Run cmake reconfigure only (no build).""" - return run_idf_py("reconfigure") - - -def has_outdated_files(): - """Check if the build configuration is stale. - - Returns True if required build files are missing or if configuration inputs - are newer than the generated CMake/Ninja build artifacts. - """ - cmakecache_txt_path = CORE.relative_build_path("build/CMakeCache.txt") - - cmakelists_txt_build_path = CORE.relative_build_path("CMakeLists.txt") - cmakelists_txt_src_path = CORE.relative_src_path("CMakeLists.txt") - build_config_path = CORE.relative_build_path("build/config") - sdkconfig_internal_path = CORE.relative_build_path( - f"sdkconfig.{CORE.name}.esphomeinternal" - ) - dependency_lock_path = CORE.relative_build_path("dependencies.lock") - build_ninja_path = CORE.relative_build_path("build/build.ninja") - - if not os.path.isdir(build_config_path) or not os.listdir(build_config_path): - return True - if not os.path.isfile(cmakecache_txt_path): - return True - if not os.path.isfile(build_ninja_path): - return True - if os.path.isfile(dependency_lock_path) and os.path.getmtime( - dependency_lock_path - ) > os.path.getmtime(build_ninja_path): - return True - - cmakecache_txt_mtime = os.path.getmtime(cmakecache_txt_path) - return any( - os.path.getmtime(f) > cmakecache_txt_mtime - for f in [ - _get_idf_path(), - cmakelists_txt_build_path, - cmakelists_txt_src_path, - sdkconfig_internal_path, - build_config_path, - ] - if f and os.path.exists(f) - ) - - -def need_reconfigure() -> bool: - from esphome.build_gen.espidf import has_discovered_components - - # We need to reconfigure either if the files are outdated or if there is no component discovered - return has_outdated_files() or not has_discovered_components() - - -def run_compile(config, verbose: bool) -> int: - """Compile the ESP-IDF project. - - Uses two-phase configure to auto-discover available components: - 1. If no previous build, configure with minimal REQUIRES to discover components - 2. Regenerate CMakeLists.txt with discovered components - 3. Run full build - """ - from esphome.build_gen.espidf import write_project - - # Check if we need to do discovery phase - if need_reconfigure(): - _LOGGER.info("Discovering available ESP-IDF components...") - write_project(minimal=True) - rc = run_reconfigure() - if rc != 0: - _LOGGER.error("Component discovery failed") - return rc - _LOGGER.info("Regenerating CMakeLists.txt with discovered components...") - write_project(minimal=False) - - # Build - args = [] - - if verbose: - args.append("-v") - - args.append("build") - - # Set the sdkconfig file - sdkconfig_path = CORE.relative_build_path(f"sdkconfig.{CORE.name}") - if sdkconfig_path.is_file(): - args.extend(["-D", f"SDKCONFIG={sdkconfig_path}"]) - - return run_idf_py(*args) - - -def get_firmware_path() -> Path: - """Get the path to the compiled firmware binary.""" - build_dir = CORE.relative_build_path("build") - return build_dir / f"{CORE.name}.bin" - - -def get_factory_firmware_path() -> Path: - """Get the path to the factory firmware (with bootloader).""" - build_dir = CORE.relative_build_path("build") - return build_dir / f"{CORE.name}.factory.bin" - - -def create_factory_bin() -> bool: - """Create factory.bin by merging bootloader, partition table, and app.""" - build_dir = CORE.relative_build_path("build") - flasher_args_path = build_dir / "flasher_args.json" - - if not flasher_args_path.is_file(): - _LOGGER.warning("flasher_args.json not found, cannot create factory.bin") - return False - - try: - with open(flasher_args_path, encoding="utf-8") as f: - flash_data = json.load(f) - except (json.JSONDecodeError, OSError) as e: - _LOGGER.error("Failed to read flasher_args.json: %s", e) - return False - - # Get flash size from config - flash_size = CORE.data[KEY_ESP32][KEY_FLASH_SIZE] - - # Build esptool merge command - sections = [] - for addr, fname in sorted( - flash_data.get("flash_files", {}).items(), key=lambda kv: int(kv[0], 16) - ): - file_path = build_dir / fname - if file_path.is_file(): - sections.extend([addr, str(file_path)]) - else: - _LOGGER.warning("Flash file not found: %s", file_path) - - if not sections: - _LOGGER.warning("No flash sections found") - return False - - output_path = get_factory_firmware_path() - chip = flash_data.get("extra_esptool_args", {}).get("chip", "esp32") - - cmd = [ - "python", - "-m", - "esptool", - "--chip", - chip, - "merge_bin", - "--flash_size", - flash_size, - "--output", - str(output_path), - ] + sections - - _LOGGER.info("Creating factory.bin...") - result = subprocess.run(cmd, capture_output=True, text=True, check=False) - - if result.returncode != 0: - _LOGGER.error("Failed to create factory.bin: %s", result.stderr) - return False - - _LOGGER.info("Created: %s", output_path) - return True - - -def create_ota_bin() -> bool: - """Copy the firmware to .ota.bin for ESPHome OTA compatibility.""" - firmware_path = get_firmware_path() - ota_path = firmware_path.with_suffix(".ota.bin") - - if not firmware_path.is_file(): - _LOGGER.warning("Firmware not found: %s", firmware_path) - return False - - shutil.copy(firmware_path, ota_path) - _LOGGER.info("Created: %s", ota_path) - return True diff --git a/esphome/espota2.py b/esphome/espota2.py index 576b1c6b2da..c13c3ea207f 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -441,7 +441,7 @@ def perform_ota( start_time = time.perf_counter() offset = 0 - progress = ProgressBar() + progress = ProgressBar("Uploading") while True: chunk = upload_contents[offset : offset + UPLOAD_BLOCK_SIZE] if not chunk: diff --git a/esphome/helpers.py b/esphome/helpers.py index 9d341af1461..62ddc489ba2 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -11,7 +11,7 @@ import shutil import stat import sys import tempfile -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TextIO from urllib.parse import urlparse from esphome.const import __version__ as ESPHOME_VERSION @@ -617,10 +617,15 @@ def sanitize(value): class ProgressBar: """A simple terminal progress bar for upload operations.""" - def __init__(self) -> None: + def __init__(self, header: str, stream: TextIO | None = None) -> None: + self.header = header + self.stream = stream or sys.stderr self.last_progress: int | None = None + self.enabled = hasattr(self.stream, "isatty") and self.stream.isatty() def update(self, progress: float) -> None: + if not self.enabled: + return bar_length = 60 status = "" if progress >= 1: @@ -631,11 +636,13 @@ class ProgressBar: return self.last_progress = new_progress block = int(round(bar_length * progress)) - text = f"\rUploading: [{'=' * block + ' ' * (bar_length - block)}] {new_progress}% {status}" + text = f"\r{self.header}: [{'=' * block + ' ' * (bar_length - block)}] {new_progress}% {status}" sys.stderr.write(text) sys.stderr.flush() def done(self) -> None: + if not self.enabled: + return sys.stderr.write("\n") sys.stderr.flush() diff --git a/esphome/web_server_ota.py b/esphome/web_server_ota.py index a49f46b270d..7c31c1b1232 100644 --- a/esphome/web_server_ota.py +++ b/esphome/web_server_ota.py @@ -60,7 +60,7 @@ class _MultipartStreamer: self._idx = 0 self._total = len(prefix) + file_size + len(suffix) self._sent = 0 - self.progress = ProgressBar() + self.progress = ProgressBar("Uploading") def __len__(self) -> int: return self._total diff --git a/script/ci-custom.py b/script/ci-custom.py index 8cd8fd75444..25db32105c6 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -562,7 +562,7 @@ def lint_constants_usage(): # Maximum allowed CONF_ constants in esphome/const.py. # This file is frozen — new constants go in esphome/components/const/__init__.py. # Decrease this number when constants are moved out of const.py. -CONST_PY_MAX_CONF = 1011 +CONST_PY_MAX_CONF = 1012 @lint_content_check(include=["esphome/const.py"]) diff --git a/script/test_build_components.py b/script/test_build_components.py index 82d05f78b23..10c5e5463fe 100755 --- a/script/test_build_components.py +++ b/script/test_build_components.py @@ -175,7 +175,7 @@ def group_components_by_platform( } -def format_github_summary(test_results: list[TestResult]) -> str: +def format_github_summary(test_results: list[TestResult], toolchain=None) -> str: """Format test results as GitHub Actions job summary markdown. Args: @@ -225,11 +225,12 @@ def format_github_summary(test_results: list[TestResult]) -> str: lines.append("```bash\n") # Generate one command per platform and test type + extra_arguments = f" --toolchain {toolchain}" if toolchain else "" platform_components = group_components_by_platform(failed_results) for platform, test_type in sorted(platform_components.keys()): components_csv = ",".join(platform_components[(platform, test_type)]) lines.append( - f"script/test_build_components.py -c {components_csv} -t {platform} -e {test_type}\n" + f"script/test_build_components.py -c {components_csv} -t {platform} -e {test_type}{extra_arguments}\n" ) lines.append("```\n") @@ -274,13 +275,15 @@ def format_github_summary(test_results: list[TestResult]) -> str: return "".join(lines) -def write_github_summary(test_results: list[TestResult]) -> None: +def write_github_summary( + test_results: list[TestResult], toolchain: str | None = None +) -> None: """Write GitHub Actions job summary with test results and timing. Args: test_results: List of all test results """ - summary_content = format_github_summary(test_results) + summary_content = format_github_summary(test_results, toolchain) with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as f: f.write(summary_content) @@ -308,6 +311,7 @@ def run_esphome_test( esphome_command: str, continue_on_fail: bool, use_testing_mode: bool = False, + toolchain: str | None = None, ) -> TestResult: """Run esphome test for a single component. @@ -367,8 +371,14 @@ def run_esphome_test( ] ) - # Add command and config file - cmd.extend([esphome_command, str(output_file)]) + if toolchain: + cmd.extend(["--toolchain", toolchain]) + + # Add command + cmd.append(esphome_command) + + # Add config file + cmd.append(str(output_file)) # Build command string for display/logging cmd_str = " ".join(cmd) @@ -432,6 +442,7 @@ def run_grouped_test( tests_dir: Path, esphome_command: str, continue_on_fail: bool, + toolchain: str | None = None, ) -> TestResult: """Run esphome test for a group of components with shared bus configs. @@ -510,10 +521,16 @@ def run_grouped_test( "-s", "target_platform", platform, - esphome_command, - str(output_file), ] + if toolchain: + cmd.extend(["--toolchain", toolchain]) + + # Add command + cmd.append(esphome_command) + + cmd.append(str(output_file)) + # Build command string for display/logging cmd_str = " ".join(cmd) @@ -576,6 +593,7 @@ def run_grouped_component_tests( esphome_command: str, continue_on_fail: bool, additional_isolated: set[str] | None = None, + toolchain: str | None = None, ) -> tuple[set[tuple[str, str]], list[TestResult]]: """Run grouped component tests. @@ -879,6 +897,7 @@ def run_grouped_component_tests( tests_dir=tests_dir, esphome_command=esphome_command, continue_on_fail=continue_on_fail, + toolchain=toolchain, ) # Mark all components as tested @@ -902,6 +921,7 @@ def run_individual_component_test( continue_on_fail: bool, tested_components: set[tuple[str, str]], test_results: list[TestResult], + toolchain: str | None = None, ) -> None: """Run an individual component test if not already tested in a group. @@ -930,6 +950,7 @@ def run_individual_component_test( build_dir=build_dir, esphome_command=esphome_command, continue_on_fail=continue_on_fail, + toolchain=toolchain, ) test_results.append(test_result) @@ -942,6 +963,7 @@ def test_components( enable_grouping: bool = True, isolated_components: set[str] | None = None, base_only: bool = False, + toolchain: str | None = None, ) -> int: """Test components with optional intelligent grouping. @@ -1018,6 +1040,7 @@ def test_components( esphome_command=esphome_command, continue_on_fail=continue_on_fail, additional_isolated=isolated_components, + toolchain=toolchain, ) test_results.extend(grouped_results) @@ -1046,6 +1069,7 @@ def test_components( continue_on_fail=continue_on_fail, tested_components=tested_components, test_results=test_results, + toolchain=toolchain, ) else: # Platform-specific test @@ -1078,6 +1102,7 @@ def test_components( continue_on_fail=continue_on_fail, tested_components=tested_components, test_results=test_results, + toolchain=toolchain, ) # Separate results into passed and failed @@ -1098,17 +1123,18 @@ def test_components( print("\n" + "=" * 80) print("Commands to reproduce failures (copy-paste to reproduce locally):") print("=" * 80) + extra_arguments = f" --toolchain {toolchain}" if toolchain else "" platform_components = group_components_by_platform(failed_results) for platform, test_type in sorted(platform_components.keys()): components_csv = ",".join(platform_components[(platform, test_type)]) print( - f"script/test_build_components.py -c {components_csv} -t {platform} -e {test_type}" + f"script/test_build_components.py -c {components_csv} -t {platform} -e {test_type}{extra_arguments}" ) print() # Write GitHub Actions job summary if in CI if os.environ.get("GITHUB_STEP_SUMMARY"): - write_github_summary(test_results) + write_github_summary(test_results, toolchain=toolchain) if failed_results: return 1 @@ -1161,6 +1187,10 @@ def main() -> int: action="store_true", help="Only test base test files (test.*.yaml), not variant files (test-*.yaml)", ) + parser.add_argument( + "--toolchain", + help="Select toolchain for compiling.", + ) args = parser.parse_args() @@ -1180,6 +1210,7 @@ def main() -> int: enable_grouping=not args.no_grouping, isolated_components=isolated_components, base_only=args.base_only, + toolchain=args.toolchain, ) diff --git a/tests/component_tests/esp32/test_esp32.py b/tests/component_tests/esp32/test_esp32.py index 203f4841072..f0f96e9adcc 100644 --- a/tests/component_tests/esp32/test_esp32.py +++ b/tests/component_tests/esp32/test_esp32.py @@ -16,8 +16,8 @@ from esphome.const import ( CONF_ESPHOME, CONF_IGNORE_PIN_VALIDATION_ERROR, CONF_NUMBER, - KEY_NATIVE_IDF, PlatformFramework, + Toolchain, ) from esphome.core import CORE from tests.component_tests.types import SetCoreConfigCallable @@ -266,7 +266,7 @@ def test_native_idf_enables_reproducible_build( CORE.config_path = component_config_path("reproducible_build.yaml") CORE.config = read_config({}) - CORE.data[KEY_NATIVE_IDF] = True + CORE.toolchain = Toolchain.ESP_IDF generate_cpp_contents(CORE.config) sdkconfig = CORE.data[KEY_ESP32][KEY_SDKCONFIG_OPTIONS] diff --git a/tests/unit_tests/test_core.py b/tests/unit_tests/test_core.py index 9dc37918ae9..1a52e6b29ed 100644 --- a/tests/unit_tests/test_core.py +++ b/tests/unit_tests/test_core.py @@ -855,7 +855,7 @@ class TestEsphomeCore: def test_bootloader_bin__native_idf(self, target): """Native ESP-IDF builds emit the bootloader under build/bootloader/bootloader.bin.""" - target.data[const.KEY_NATIVE_IDF] = True + target.toolchain = const.Toolchain.ESP_IDF assert target.bootloader_bin == Path( "foo/build/build/bootloader/bootloader.bin" @@ -864,7 +864,7 @@ class TestEsphomeCore: def test_bootloader_bin__platformio(self, target): """For PlatformIO builds bootloader.bin lives in the env-specific .pioenvs directory.""" target.name = "test-device" - target.data[const.KEY_NATIVE_IDF] = False + target.toolchain = const.Toolchain.PLATFORMIO assert target.bootloader_bin == Path( "foo/build/.pioenvs/test-device/bootloader.bin" diff --git a/tests/unit_tests/test_espidf_component.py b/tests/unit_tests/test_espidf_component.py new file mode 100644 index 00000000000..caef10eea32 --- /dev/null +++ b/tests/unit_tests/test_espidf_component.py @@ -0,0 +1,357 @@ +import json +import os +from unittest.mock import MagicMock + +import pytest + +from esphome.const import ( + KEY_CORE, + KEY_TARGET_FRAMEWORK, + KEY_TARGET_PLATFORM, + Framework, + Platform, +) +from esphome.core import CORE, Library +import esphome.espidf.component +from esphome.espidf.component import ( + GitSource, + IDFComponent, + InvalidIDFComponent, + URLSource, + _check_library_data, + _collect_filtered_files, + _convert_library_to_component, + _detect_requires, + _parse_library_json, + _parse_library_properties, + _process_dependencies, + _split_list_by_condition, + generate_cmakelists_txt, + generate_idf_component_yml, +) + + +@pytest.fixture(name="tmp_component") +def fixture_tmp_component(tmp_path): + c = IDFComponent("owner/name", "1.0.0", source=MagicMock()) + c.path = tmp_path + return c + + +@pytest.fixture(name="esp32_idf_core") +def fixture_esp32_idf_core(): + CORE.data[KEY_CORE] = {} + CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = str(Platform.ESP32) + CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = str(Framework.ESP_IDF) + + +def test_idf_component_str(): + c = IDFComponent("foo/bar", "1.0", source=URLSource("http://dummy.com")) + assert str(c) == "foo/bar@1.0=http://dummy.com" + + +def test_idf_component_sanitized_name(): + c = IDFComponent("foo/bar bar-bar", "1.0", source=URLSource("http://dummy.com")) + assert c.get_sanitized_name() == "foo/bar_bar-bar" + + +def test_idf_component_require_name(): + c = IDFComponent("foo/bar", "1.0", source=URLSource("http://dummy.com")) + assert c.get_require_name() == "foo__bar" + + +def test_collect_filtered_files_basic(tmp_path): + f1 = tmp_path / "a.c" + f2 = tmp_path / "b" / "b.cpp" + f1.write_text("int a;") + f2.parent.mkdir(parents=True) + f2.write_text("int b;") + + result = _collect_filtered_files(tmp_path, ["+<*>"]) + assert str(f1) in result + assert str(f2) in result + + +def test_collect_filtered_files_exclude(tmp_path): + f1 = tmp_path / "a.c" + f2 = tmp_path / "b.cpp" + f1.write_text("int a;") + f2.write_text("int b;") + + result = _collect_filtered_files(tmp_path, ["+<*> -<*.cpp>"]) + assert str(f1) in result + assert str(f2) not in result + + +def test_detect_requires(tmp_path): + f = tmp_path / "main.c" + f.write_text('#include "mbedtls/foo.h"') + + result = _detect_requires([str(f)]) + assert "mbedtls" in result + + +def test_detect_requires_ignores_invalid_file(tmp_path): + result = _detect_requires([str(tmp_path / "missing.c")]) + assert result == set() + + +def test_split_list_by_condition(): + items = ["-Iinclude", "-Llib", "-Wall"] + + matched, rest = _split_list_by_condition( + items, lambda x: x[2:] if x.startswith("-I") else None + ) + + assert matched == ["include"] + assert "-Llib" in rest + assert "-Wall" in rest + + +def test_generate_cmakelists_txt_basic(tmp_component): + src_dir = tmp_component.path / "src" + src_dir.mkdir() + f = src_dir / "main.c" + f.write_text("int main() {}") + + tmp_component.data = {} + + content = generate_cmakelists_txt(tmp_component) + + assert "idf_component_register" in content + assert "main.c" in content + + +def test_generate_cmakelists_txt_with_flags(tmp_component, tmp_path): + src_dir = tmp_component.path / "src" + src_dir.mkdir() + (src_dir / "main.c").write_text("int main() {}") + + dep = IDFComponent("dep", "1.0", source=URLSource("http://dummy.com")) + dep.path = tmp_path / "dep" + tmp_component.dependencies = [dep] + + tmp_component.data = { + "build": {"flags": ["-Iinclude", "-Llib", "-lmylib", "-Wall", "-DTEST"]} + } + + content = generate_cmakelists_txt(tmp_component) + sep = "\\\\" if os.name == "nt" else "/" + assert ( + content + == f"""idf_component_register( + SRCS "src{sep}main.c" + INCLUDE_DIRS "src" + REQUIRES dep +) +target_compile_options(${{COMPONENT_LIB}} PUBLIC + "-DTEST" +) +target_compile_options(${{COMPONENT_LIB}} PRIVATE + "-Wall" +) +target_link_directories(${{COMPONENT_LIB}} INTERFACE + "lib" +) +target_link_libraries(${{COMPONENT_LIB}} INTERFACE + "mylib" +) +""" + ) + + +def test_generate_idf_component_yml_basic(tmp_component): + tmp_component.data = {"description": "test", "repository": {"url": "http://aaa"}} + result = generate_idf_component_yml(tmp_component) + + assert result == "description: test\nversion: 1.0.0\nrepository: http://aaa\n" + + +def test_generate_idf_component_yml_with_dependencies(tmp_component, tmp_path): + dep = IDFComponent("dep", "1.0", source=URLSource("http://dummy.com")) + dep.path = tmp_path / "dep" + + tmp_component.dependencies = [dep] + tmp_component.data = {} + + result = generate_idf_component_yml(tmp_component) + + assert ( + result + == f"""version: 1.0.0 +dependencies: + dep: + version: '1.0' + override_path: {dep.path} +""" + ) + + +def test_generate_idf_component_yml_arduino_registry_dep(tmp_component): + # Synthetic arduino-esp32 dep with no source / no path: should emit a + # version-only entry so the IDF component manager resolves it from the + # registry instead of via git. + dep = IDFComponent("espressif/arduino-esp32", "3.3.8", source=None) + + tmp_component.dependencies = [dep] + tmp_component.data = {} + + result = generate_idf_component_yml(tmp_component) + + assert ( + result + == """version: 1.0.0 +dependencies: + espressif/arduino-esp32: + version: 3.3.8 +""" + ) + + +def test_generate_idf_component_yml_missing_path_reraises(tmp_component): + # A dep without a path and without a recognised source should re-raise + # the underlying RuntimeError instead of silently producing a bad manifest. + dep = IDFComponent("foo/bar", "1.0", source=None) + + tmp_component.dependencies = [dep] + tmp_component.data = {} + + with pytest.raises(RuntimeError): + generate_idf_component_yml(tmp_component) + + +def test_check_library_data_valid(esp32_idf_core): + _check_library_data({"platforms": "*", "frameworks": "*"}) + + +def test_check_library_data_valid2(esp32_idf_core): + _check_library_data({"platforms": "*"}) + + +def test_check_library_data_valid3(esp32_idf_core): + _check_library_data({}) + + +def test_check_library_data_valid4(esp32_idf_core): + _check_library_data({"platforms": "espressif32", "frameworks": "*"}) + + +def test_check_library_data_valid5(esp32_idf_core): + _check_library_data({"platforms": "*", "frameworks": "espidf"}) + + +def test_check_library_data_invalid_platform(esp32_idf_core): + with pytest.raises(InvalidIDFComponent): + _check_library_data({"platforms": ["other"], "frameworks": "*"}) + + +def test_check_library_data_invalid_framework(esp32_idf_core): + with pytest.raises(InvalidIDFComponent): + _check_library_data({"platforms": "*", "frameworks": ["other"]}) + + +def test_extra_script_logs_warning(caplog, esp32_idf_core): + extra_script = "myscript.sh" + + with caplog.at_level("WARNING"): + _check_library_data({"build": {"extraScript": extra_script}}) + + assert "not supported" in caplog.text + assert "myscript.sh" in caplog.text + + +def test_parse_library_json(tmp_path): + f = tmp_path / "library.json" + f.write_text(json.dumps({"name": "test"})) + + result = _parse_library_json(f) + assert result["name"] == "test" + + +def test_parse_library_properties(tmp_path): + f = tmp_path / "library.properties" + f.write_text( + """ +name=Test +version=1.0 +# description=ABCD +empty= +""" + ) + + result = _parse_library_properties(f) + + assert result["name"] == "Test" + assert result["version"] == "1.0" + assert "empty" not in result + + +def test_convert_library_with_repository(): + lib = Library("name", None, "https://github.com/foo/bar.git#v1.2.3") + + result = _convert_library_to_component(lib) + + assert result.name == "foo/bar" + assert result.version == "1.2.3" + assert isinstance(result.source, GitSource) + + +def test_convert_library_missing_ref(): + lib = Library("name", None, "https://github.com/foo/bar.git") + + with pytest.raises(ValueError): + _convert_library_to_component(lib) + + +def test_convert_library_registry(monkeypatch): + lib = Library("foo/bar", "^1.0.0", None) + + monkeypatch.setattr( + esphome.espidf.component, + "_get_package_from_pio_registry", + lambda o, n, r: ("foo", "bar", "1.2.3", "http://example.com/pkg.zip"), + ) + + result = _convert_library_to_component(lib) + + assert result.name == "foo/bar" + assert result.version == "1.2.3" + assert isinstance(result.source, URLSource) + + +def test_process_dependencies_adds_valid_dependency(tmp_component, monkeypatch): + tmp_component.data = { + "dependencies": [ + { + "name": "foo", + "version": "1.0", + } + ] + } + + monkeypatch.setattr( + esphome.espidf.component, + "_generate_idf_component", + lambda lib: esphome.espidf.component.IDFComponent( + lib.name, lib.version, source=URLSource("http://dummy.com") + ), + ) + + monkeypatch.setattr(esphome.espidf.component, "_check_library_data", lambda x: None) + + _process_dependencies(tmp_component) + + assert len(tmp_component.dependencies) == 1 + + +def test_process_dependencies_skips_invalid(tmp_component): + tmp_component.data = { + "dependencies": [ + {"name": "foo", "version": "1.0", "platforms": ["arduino"]}, + {"invalid": "entry"}, + ] + } + + _process_dependencies(tmp_component) + + assert tmp_component.dependencies == [] diff --git a/tests/unit_tests/test_espota2.py b/tests/unit_tests/test_espota2.py index b22ad461132..d7fcedfd66d 100644 --- a/tests/unit_tests/test_espota2.py +++ b/tests/unit_tests/test_espota2.py @@ -604,7 +604,8 @@ def test_run_ota_wrapper(mock_run_ota_impl: Mock) -> None: def test_progress_bar(capsys: CaptureFixture[str]) -> None: """Test ProgressBar functionality.""" - progress = espota2.ProgressBar() + progress = espota2.ProgressBar("Uploading") + progress.enabled = True # Fake TTY # Test initial update progress.update(0.0) diff --git a/tests/unit_tests/test_main.py b/tests/unit_tests/test_main.py index 2823310f0e4..3eb50de76b4 100644 --- a/tests/unit_tests/test_main.py +++ b/tests/unit_tests/test_main.py @@ -88,6 +88,7 @@ from esphome.const import ( PLATFORM_ESP32, PLATFORM_ESP8266, PLATFORM_RP2040, + Toolchain, ) from esphome.core import CORE, EsphomeError from esphome.espota2 import ( @@ -148,6 +149,7 @@ def setup_core( config[CONF_WIFI] = {CONF_USE_ADDRESS: address} CORE.config = config + CORE.toolchain = Toolchain.PLATFORMIO if platform is not None: CORE.data[KEY_CORE] = {} From c4e85fbfc1b17a78514ba92851321fa85beb6b11 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 11 May 2026 16:57:10 +1200 Subject: [PATCH 26/52] [ci] sync-device-classes: mint least-privilege App token (#16350) --- .github/workflows/sync-device-classes.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-device-classes.yml b/.github/workflows/sync-device-classes.yml index be1457387d9..c6c829fbb4e 100644 --- a/.github/workflows/sync-device-classes.yml +++ b/.github/workflows/sync-device-classes.yml @@ -6,12 +6,27 @@ on: schedule: - cron: "45 6 * * *" +# Repo writes (branch push, PR open) happen via the App token minted below, +# so the workflow's GITHUB_TOKEN does not need any write scopes. +permissions: + contents: read # actions/checkout for this repo and home-assistant/core + jobs: sync: name: Sync Device Classes runs-on: ubuntu-latest if: github.repository == 'esphome/esphome' steps: + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 + with: + client-id: ${{ vars.ESPHOME_GITHUB_APP_CLIENT_ID }} + private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} + # Scope the minted App token to the minimum needed by peter-evans/create-pull-request. + permission-contents: write # git.createCommit + refs.create/update to push the sync/device-classes branch + permission-pull-requests: write # pulls.create / pulls.update to open or refresh the sync PR + - name: Checkout uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -50,4 +65,4 @@ jobs: delete-branch: true title: "Synchronise Device Classes from Home Assistant" body-path: .github/PULL_REQUEST_TEMPLATE.md - token: ${{ secrets.DEVICE_CLASS_SYNC_TOKEN }} + token: ${{ steps.generate-token.outputs.token }} From 5dadfe636771f06c4113abe13dc9f3b491231ece Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 11 May 2026 17:04:09 +1200 Subject: [PATCH 27/52] [ci] codeowner-review-request: mint least-privilege App token (#16351) --- .github/workflows/codeowner-review-request.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeowner-review-request.yml b/.github/workflows/codeowner-review-request.yml index 76be6ecd7bf..cd6c1d34c65 100644 --- a/.github/workflows/codeowner-review-request.yml +++ b/.github/workflows/codeowner-review-request.yml @@ -17,9 +17,10 @@ on: - release - beta +# PR/review writes (requestReviewers, issues.createComment) are performed with the App token minted below, +# so the workflow's GITHUB_TOKEN only needs read access for checkout. permissions: - pull-requests: write - contents: read + contents: read # actions/checkout to read CODEOWNERS and the shared codeowners.js helper jobs: request-codeowner-reviews: @@ -32,9 +33,20 @@ jobs: with: ref: ${{ github.event.pull_request.base.sha }} + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 + with: + client-id: ${{ vars.ESPHOME_GITHUB_APP_CLIENT_ID }} + private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} + # Scope the minted App token to the minimum needed by the github-script step below. + permission-pull-requests: write # pulls.listFiles, pulls.get, pulls.listReviews, pulls.requestReviewers + permission-issues: write # issues.listComments and issues.createComment (PR comments use the issues API) + - name: Request reviews from component codeowners uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: + github-token: ${{ steps.generate-token.outputs.token }} script: | const { loadCodeowners, getEffectiveOwners } = require('./.github/scripts/codeowners.js'); From fe66f9ba41927c05e211056f818d381c62959eda Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 11 May 2026 17:15:53 +1200 Subject: [PATCH 28/52] [ci] Tighten workflow permissions to least-privilege (#16349) --- .github/workflows/auto-label-pr.yml | 9 +++++++-- .github/workflows/ci-api-proto.yml | 4 ++-- .github/workflows/ci-clang-tidy-hash.yml | 4 ++-- .github/workflows/ci-docker.yml | 3 +-- .github/workflows/ci-memory-impact-comment.yml | 6 +++--- .github/workflows/ci.yml | 6 +++--- .../close-pr-from-fork-default-branch.yml | 4 ++-- .../codeowner-approved-label-update.yml | 6 +++--- .github/workflows/codeql.yml | 16 +++++++--------- .github/workflows/external-component-bot.yml | 5 ++--- .github/workflows/issue-codeowner-notify.yml | 4 ++-- .github/workflows/lock.yml | 6 ++++++ .github/workflows/pr-title-check.yml | 4 ++-- .github/workflows/release.yml | 17 ++++++++++------- .github/workflows/stale.yml | 4 ++-- .github/workflows/status-check-labels.yml | 3 +++ 16 files changed, 57 insertions(+), 44 deletions(-) diff --git a/.github/workflows/auto-label-pr.yml b/.github/workflows/auto-label-pr.yml index ea22f75ef04..2d000658a2d 100644 --- a/.github/workflows/auto-label-pr.yml +++ b/.github/workflows/auto-label-pr.yml @@ -6,9 +6,10 @@ on: pull_request_target: types: [labeled, opened, reopened, synchronize, edited] +# All PR/label/review writes are performed with the App token minted below, +# so the workflow's GITHUB_TOKEN only needs read access for checkout. permissions: - pull-requests: write - contents: read + contents: read # actions/checkout reads the workflow source env: SMALL_PR_THRESHOLD: 30 @@ -31,6 +32,10 @@ jobs: with: client-id: ${{ vars.ESPHOME_GITHUB_APP_CLIENT_ID }} private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} + # Scope the minted App token to the minimum needed by auto-label-pr/*.js. + permission-contents: read # repos.getContent for CODEOWNERS and file lookups in detectors.js + permission-issues: write # listLabelsOnIssue, addLabels, removeLabel, list/createComment + permission-pull-requests: write # pulls.listFiles, list/create/update/dismissReview - name: Auto Label PR uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 diff --git a/.github/workflows/ci-api-proto.yml b/.github/workflows/ci-api-proto.yml index e5143911d94..2f7fd271ba2 100644 --- a/.github/workflows/ci-api-proto.yml +++ b/.github/workflows/ci-api-proto.yml @@ -12,8 +12,8 @@ on: - ".github/workflows/ci-api-proto.yml" permissions: - contents: read - pull-requests: write + contents: read # actions/checkout for the PR head + pull-requests: write # pulls.createReview / listReviews / dismissReview when generated proto files are stale jobs: check: diff --git a/.github/workflows/ci-clang-tidy-hash.yml b/.github/workflows/ci-clang-tidy-hash.yml index 40cdff0cba7..d9148fb06dc 100644 --- a/.github/workflows/ci-clang-tidy-hash.yml +++ b/.github/workflows/ci-clang-tidy-hash.yml @@ -12,8 +12,8 @@ on: - ".github/workflows/ci-clang-tidy-hash.yml" permissions: - contents: read - pull-requests: write + contents: read # actions/checkout for the PR head + pull-requests: write # pulls.createReview / listReviews / dismissReview when the clang-tidy hash is out of date jobs: verify-hash: diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml index 4009ac1e174..3fd17888c7c 100644 --- a/.github/workflows/ci-docker.yml +++ b/.github/workflows/ci-docker.yml @@ -22,8 +22,7 @@ on: - "script/platformio_install_deps.py" permissions: - contents: read - packages: read + contents: read # actions/checkout only; the build does not push images concurrency: # yamllint disable-line rule:line-length diff --git a/.github/workflows/ci-memory-impact-comment.yml b/.github/workflows/ci-memory-impact-comment.yml index fbcf5ea5841..025b9609859 100644 --- a/.github/workflows/ci-memory-impact-comment.yml +++ b/.github/workflows/ci-memory-impact-comment.yml @@ -7,9 +7,9 @@ on: types: [completed] permissions: - contents: read - pull-requests: write - actions: read + contents: read # actions/checkout of the base repo at the PR's target branch + pull-requests: write # gh api to look up the PR by head SHA and post/update the memory-impact comment + actions: read # gh run download for the memory-analysis artifacts produced by the CI workflow run jobs: memory-impact-comment: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9909d7a5ddf..7cb8e07afa8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ on: merge_group: permissions: - contents: read + contents: read # actions/checkout for all jobs; individual jobs add their own scopes when they need to write env: DEFAULT_PYTHON: "3.11" @@ -1147,8 +1147,8 @@ jobs: - memory-impact-pr-branch if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && fromJSON(needs.determine-jobs.outputs.memory_impact).should_run == 'true' && needs.memory-impact-target-branch.outputs.skip != 'true' permissions: - contents: read - pull-requests: write + contents: read # actions/checkout to load the comment-posting script + pull-requests: write # ci_memory_impact_comment.py posts/updates the memory-impact comment on the PR env: GH_TOKEN: ${{ github.token }} steps: diff --git a/.github/workflows/close-pr-from-fork-default-branch.yml b/.github/workflows/close-pr-from-fork-default-branch.yml index 1cd70f5efcd..5180a071806 100644 --- a/.github/workflows/close-pr-from-fork-default-branch.yml +++ b/.github/workflows/close-pr-from-fork-default-branch.yml @@ -6,8 +6,8 @@ on: types: [opened, reopened] permissions: - pull-requests: write - issues: write + pull-requests: write # pulls.update to close the PR opened from a fork's default branch + issues: write # issues.createComment to explain to the contributor why the PR was closed jobs: close: diff --git a/.github/workflows/codeowner-approved-label-update.yml b/.github/workflows/codeowner-approved-label-update.yml index 49653b6fb3b..013517bde6d 100644 --- a/.github/workflows/codeowner-approved-label-update.yml +++ b/.github/workflows/codeowner-approved-label-update.yml @@ -15,9 +15,9 @@ on: - beta permissions: - issues: write - pull-requests: read - contents: read + issues: write # issues.addLabels / removeLabel to manage the 'code-owner-approved' label on the PR + pull-requests: read # listReviews to determine whether a codeowner has approved + contents: read # actions/checkout to read CODEOWNERS and the shared codeowners.js helper jobs: codeowner-approved: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 949e45e45c9..0a4dd9a92dd 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -16,6 +16,9 @@ on: schedule: - cron: "30 18 * * 4" +# Deny by default; the analyze job opts in to exactly what it needs. +permissions: {} + jobs: analyze: name: Analyze (${{ matrix.language }}) @@ -26,15 +29,10 @@ jobs: # Consider using larger runners or machines with greater resources for possible analysis time improvements. runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} permissions: - # required for all workflows - security-events: write - - # required to fetch internal or private CodeQL packs - packages: read - - # only required for workflows in private repositories - actions: read - contents: read + security-events: write # upload CodeQL SARIF results to the Code Scanning API + packages: read # fetch internal or private CodeQL query packs + actions: read # required by codeql-action when run from a private repo + contents: read # actions/checkout to scan the repository strategy: fail-fast: false diff --git a/.github/workflows/external-component-bot.yml b/.github/workflows/external-component-bot.yml index 3165b170780..6e2bf780b8a 100644 --- a/.github/workflows/external-component-bot.yml +++ b/.github/workflows/external-component-bot.yml @@ -5,9 +5,8 @@ on: types: [opened, synchronize] permissions: - contents: read # Needed to fetch PR details - issues: write # Needed to create and update comments (PR comments are managed via the issues REST API) - pull-requests: write # also needed? + issues: write # issues.createComment / updateComment to post the external-component usage instructions on the PR + pull-requests: read # pulls.listFiles to enumerate which components changed jobs: external-comment: diff --git a/.github/workflows/issue-codeowner-notify.yml b/.github/workflows/issue-codeowner-notify.yml index b211c13985d..bc892b64e0b 100644 --- a/.github/workflows/issue-codeowner-notify.yml +++ b/.github/workflows/issue-codeowner-notify.yml @@ -9,8 +9,8 @@ on: types: [labeled] permissions: - issues: write - contents: read + issues: write # issues.createComment to mention component codeowners on the newly labelled issue + contents: read # repos.getContent to fetch CODEOWNERS from the default branch jobs: notify-codeowners: diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index 8d1dfe857de..5e701176524 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -6,6 +6,12 @@ on: - cron: "30 0 * * *" # Run daily at 00:30 UTC workflow_dispatch: +# Deny by default; the lock job opts in to exactly what the reusable workflow needs. +permissions: {} + jobs: lock: + permissions: + issues: write # issues.lock on closed issues + pull-requests: write # issues.lock on closed pull requests uses: esphome/workflows/.github/workflows/lock.yml@025a1e6255610c498ed590403b7e510b69e474df # 2026.4.1 diff --git a/.github/workflows/pr-title-check.yml b/.github/workflows/pr-title-check.yml index 87009962719..ed0bff9664f 100644 --- a/.github/workflows/pr-title-check.yml +++ b/.github/workflows/pr-title-check.yml @@ -8,8 +8,8 @@ on: - beta permissions: - contents: read - pull-requests: read + contents: read # actions/checkout to load detect-tags.js + pull-requests: read # pulls.listFiles to map changed files to component/core/dashboard/ci tags jobs: check: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a16af92b6fb..d07c8fe6333 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ on: - cron: "0 2 * * *" permissions: - contents: read + contents: read # actions/checkout for all jobs; deploy jobs add their own scopes when they need to write jobs: init: @@ -57,8 +57,8 @@ jobs: if: github.repository == 'esphome/esphome' && github.event_name == 'release' runs-on: ubuntu-latest permissions: - contents: read - id-token: write + contents: read # actions/checkout to build the sdist/wheel + id-token: write # OIDC token for PyPI Trusted Publishing (pypa/gh-action-pypi-publish) steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: Set up Python @@ -78,8 +78,8 @@ jobs: name: Build ESPHome ${{ matrix.platform.arch }} if: github.repository == 'esphome/esphome' permissions: - contents: read - packages: write + contents: read # actions/checkout to load Dockerfile and build context + packages: write # docker/login-action + build-push-action push image digests to ghcr.io runs-on: ${{ matrix.platform.os }} needs: [init] strategy: @@ -152,8 +152,8 @@ jobs: - deploy-docker if: github.repository == 'esphome/esphome' permissions: - contents: read - packages: write + contents: read # actions/checkout to load Dockerfile and build context + packages: write # docker/login-action + build-push-action push image digests to ghcr.io strategy: fail-fast: false matrix: @@ -227,6 +227,7 @@ jobs: private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} owner: esphome repositories: home-assistant-addon + permission-actions: write # actions.createWorkflowDispatch on the target repo (only API call made with this token) - name: Trigger Workflow uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 @@ -262,6 +263,7 @@ jobs: private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} owner: esphome repositories: esphome-schema + permission-actions: write # actions.createWorkflowDispatch on the target repo (only API call made with this token) - name: Trigger Workflow uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 @@ -293,6 +295,7 @@ jobs: private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} owner: esphome repositories: version-notifier + permission-actions: write # actions.createWorkflowDispatch on the target repo (only API call made with this token) - name: Trigger Workflow uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index ba5c32e0167..2e57093bbb9 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -7,8 +7,8 @@ on: workflow_dispatch: permissions: - issues: write - pull-requests: write + issues: write # actions/stale labels, comments on, and closes stale issues + pull-requests: write # actions/stale labels, comments on, and closes stale pull requests concurrency: group: lock diff --git a/.github/workflows/status-check-labels.yml b/.github/workflows/status-check-labels.yml index 709342e5ae6..d27cc0cbec2 100644 --- a/.github/workflows/status-check-labels.yml +++ b/.github/workflows/status-check-labels.yml @@ -4,6 +4,9 @@ on: pull_request: types: [opened, reopened, labeled, unlabeled, synchronize] +permissions: + pull-requests: read # issues.listLabelsOnIssue to detect blocking labels (needs-docs, merge-after-release, chained-pr) + concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true From c82adc3892f453b09c2a7f15fd37dcc6841f83f0 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 11 May 2026 19:52:39 +1200 Subject: [PATCH 29/52] [ci] Fix external-component-bot 403 on PR comments (#16354) --- .github/workflows/external-component-bot.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/external-component-bot.yml b/.github/workflows/external-component-bot.yml index 6e2bf780b8a..2e96bec1dea 100644 --- a/.github/workflows/external-component-bot.yml +++ b/.github/workflows/external-component-bot.yml @@ -4,19 +4,29 @@ on: pull_request_target: types: [opened, synchronize] -permissions: - issues: write # issues.createComment / updateComment to post the external-component usage instructions on the PR - pull-requests: read # pulls.listFiles to enumerate which components changed +# All API calls (pulls.listFiles + issues.{list,create,update}Comment) are performed with +# the App token minted below, so the workflow's GITHUB_TOKEN does not need any scopes. +permissions: {} jobs: external-comment: name: External component comment runs-on: ubuntu-latest steps: + - name: Generate a token + id: generate-token + uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1 + with: + client-id: ${{ vars.ESPHOME_GITHUB_APP_CLIENT_ID }} + private-key: ${{ secrets.ESPHOME_GITHUB_APP_PRIVATE_KEY }} + # pulls.listFiles + issues.{list,create,update}Comment on PRs. For PR resources + # the issues.*Comment APIs require the pull-requests scope, not issues. + permission-pull-requests: write + - name: Add external component comment uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ steps.generate-token.outputs.token }} script: | // Generate external component usage instructions function generateExternalComponentInstructions(prNumber, componentNames, owner, repo) { From 267836d09886c66797062bf45a7be6e86ea93f94 Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Mon, 11 May 2026 01:27:07 -0700 Subject: [PATCH 30/52] [tuya] allow status pin that doesn't match the reported one (#16353) --- esphome/components/tuya/tuya.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index d682adffe38..b29905f9a0d 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -209,13 +209,12 @@ void Tuya::handle_command_(uint8_t command, uint8_t version, const uint8_t *buff bool is_pin_equals = this->status_pin_ != nullptr && this->status_pin_->get_pin() == this->status_pin_reported_; // Configure status pin toggling (if reported and configured) or WIFI_STATE periodic send - if (is_pin_equals) { - ESP_LOGV(TAG, "Configured status pin %i", this->status_pin_reported_); - this->set_interval("wifi", 1000, [this] { this->set_status_pin_(); }); - } else { - ESP_LOGW(TAG, "Supplied status_pin does not equals the reported pin %i. TuyaMcu will work in limited mode.", + if (!is_pin_equals) { + ESP_LOGW(TAG, "Supplied status_pin does not equals the reported pin %i. Using supplied pin anyway.", this->status_pin_reported_); } + ESP_LOGV(TAG, "Configured status pin %i", this->status_pin_->get_pin()); + this->set_interval("wifi", 1000, [this] { this->set_status_pin_(); }); } else { this->init_state_ = TuyaInitState::INIT_WIFI; ESP_LOGV(TAG, "Configured WIFI_STATE periodic send"); From e4d9786f00c0c271495a0d3cf457533eaea069e9 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Mon, 11 May 2026 05:34:47 -0400 Subject: [PATCH 31/52] [core] Move platformio files to subfolder (#16347) --- esphome/__main__.py | 68 ++++++------ esphome/analyze_memory/__init__.py | 2 +- esphome/analyze_memory/cli.py | 2 +- esphome/components/esp32/__init__.py | 4 +- esphome/components/esp8266/__init__.py | 4 +- esphome/components/nrf52/__init__.py | 4 +- esphome/components/rp2040/__init__.py | 2 +- esphome/dashboard/web_server.py | 5 +- esphome/espidf/runner.py | 2 +- esphome/espidf/{api.py => toolchain.py} | 2 +- esphome/platformio/__init__.py | 0 .../runner.py} | 2 +- .../toolchain.py} | 2 +- script/build_helpers.py | 2 +- script/ci_memory_impact_extract.py | 2 +- tests/dashboard/test_web_server.py | 4 +- tests/integration/conftest.py | 2 +- tests/unit_tests/conftest.py | 16 +-- tests/unit_tests/test_main.py | 40 +++---- ...io_api.py => test_platformio_toolchain.py} | 100 +++++++++--------- 20 files changed, 134 insertions(+), 131 deletions(-) rename esphome/espidf/{api.py => toolchain.py} (99%) create mode 100644 esphome/platformio/__init__.py rename esphome/{platformio_runner.py => platformio/runner.py} (99%) rename esphome/{platformio_api.py => platformio/toolchain.py} (99%) rename tests/unit_tests/{test_platformio_api.py => test_platformio_toolchain.py} (92%) diff --git a/esphome/__main__.py b/esphome/__main__.py index 01b33eb8acf..54d6384bfc0 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -766,24 +766,24 @@ def compile_program(args: ArgsProtocol, config: ConfigType) -> int: _LOGGER.info("Compiling app... Build path: %s", CORE.build_path) if CORE.using_toolchain_esp_idf: - from esphome.espidf import api + from esphome.espidf import toolchain - rc = api.run_compile(config, CORE.verbose) + rc = toolchain.run_compile(config, CORE.verbose) if rc != 0: return rc # Create factory.bin, ota.bin, and firmware.elf copy - api.create_factory_bin() - api.create_ota_bin() - api.create_elf_copy() + toolchain.create_factory_bin() + toolchain.create_ota_bin() + toolchain.create_elf_copy() else: - from esphome import platformio_api + from esphome.platformio import toolchain - rc = platformio_api.run_compile(config, CORE.verbose) + rc = toolchain.run_compile(config, CORE.verbose) if rc != 0: return rc - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) if idedata is None: return 1 @@ -879,13 +879,15 @@ def upload_using_esptool( if file is not None: flash_images = [FlashImage(path=file, offset="0x0")] elif CORE.using_toolchain_esp_idf: - from esphome.espidf import api + from esphome.espidf import toolchain - flash_images = [FlashImage(path=api.get_factory_firmware_path(), offset="0x0")] + flash_images = [ + FlashImage(path=toolchain.get_factory_firmware_path(), offset="0x0") + ] else: - from esphome import platformio_api + from esphome.platformio import toolchain - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) firmware_offset = "0x10000" if CORE.is_esp32 else "0x0" flash_images = [ @@ -958,13 +960,13 @@ def upload_using_esptool( def upload_using_platformio(config: ConfigType, port: str) -> int: - from esphome import platformio_api + from esphome.platformio import toolchain # RP2040 platform-raspberrypi build recipe expects firmware.bin.signed for # the upload target, but 'nobuild' skips the build phase that creates it. # Create it here so the upload doesn't fail. if CORE.data.get(KEY_CORE, {}).get(KEY_TARGET_PLATFORM) == PLATFORM_RP2040: - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) build_dir = Path(idedata.firmware_elf_path).parent firmware_bin = build_dir / "firmware.bin" signed_bin = build_dir / "firmware.bin.signed" @@ -974,15 +976,15 @@ def upload_using_platformio(config: ConfigType, port: str) -> int: upload_args = ["-t", "upload", "-t", "nobuild"] if port is not None: upload_args += ["--upload-port", port] - return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args) + return toolchain.run_platformio_cli_run(config, CORE.verbose, *upload_args) def _find_picotool() -> Path | None: """Find the picotool binary from PlatformIO packages.""" - from esphome import platformio_api + from esphome.platformio import toolchain try: - idedata = platformio_api.get_idedata(CORE.config) + idedata = toolchain.get_idedata(CORE.config) except Exception: # noqa: BLE001 # pylint: disable=broad-except return None return get_picotool_path(idedata.cc_path) @@ -995,9 +997,9 @@ def upload_using_picotool(config: ConfigType) -> int: the mass storage copy approach that causes "disk not ejected properly" warnings on macOS. """ - from esphome import platformio_api + from esphome.platformio import toolchain - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) firmware_elf = Path(idedata.firmware_elf_path) if not firmware_elf.is_file(): @@ -1457,11 +1459,11 @@ def command_compile(args: ArgsProtocol, config: ConfigType) -> int | None: return exit_code if CORE.is_host: if CORE.using_toolchain_esp_idf: - from esphome.espidf import api + from esphome.espidf import toolchain - program_path = str(api.get_elf_path()) + program_path = str(toolchain.get_elf_path()) else: - from esphome.platformio_api import get_idedata + from esphome.platformio.toolchain import get_idedata program_path = str(get_idedata(config).firmware_elf_path) _LOGGER.info("Successfully compiled program to path '%s'", program_path) @@ -1515,11 +1517,11 @@ def command_run(args: ArgsProtocol, config: ConfigType) -> int | None: _LOGGER.info("Successfully compiled program.") if CORE.is_host: if CORE.using_toolchain_esp_idf: - from esphome.espidf import api + from esphome.espidf import toolchain - program_path = str(api.get_elf_path()) + program_path = str(toolchain.get_elf_path()) else: - from esphome.platformio_api import get_idedata + from esphome.platformio.toolchain import get_idedata program_path = str(get_idedata(config).firmware_elf_path) _LOGGER.info("Running program from path '%s'", program_path) @@ -1719,12 +1721,12 @@ def command_idedata(args: ArgsProtocol, config: ConfigType) -> int: ) return 1 - from esphome import platformio_api + from esphome.platformio import toolchain logging.disable(logging.INFO) logging.disable(logging.WARNING) - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) if idedata is None: return 1 @@ -1753,16 +1755,16 @@ def command_analyze_memory(args: ArgsProtocol, config: ConfigType) -> int: # Get idedata for analysis idedata = None if CORE.using_toolchain_esp_idf: - from esphome.espidf import api + from esphome.espidf import toolchain - objdump_path = str(api.get_objdump_path()) - readelf_path = str(api.get_readelf_path()) + objdump_path = str(toolchain.get_objdump_path()) + readelf_path = str(toolchain.get_readelf_path()) - firmware_elf = api.get_elf_path() + firmware_elf = toolchain.get_elf_path() else: - from esphome import platformio_api + from esphome.platformio import toolchain - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) if idedata is None: _LOGGER.error("Failed to get IDE data for memory analysis") return 1 diff --git a/esphome/analyze_memory/__init__.py b/esphome/analyze_memory/__init__.py index 33854ac2896..1198562218d 100644 --- a/esphome/analyze_memory/__init__.py +++ b/esphome/analyze_memory/__init__.py @@ -24,7 +24,7 @@ from .helpers import ( from .toolchain import find_tool, resolve_tool_path, run_tool if TYPE_CHECKING: - from esphome.platformio_api import IDEData + from esphome.platformio.toolchain import IDEData _LOGGER = logging.getLogger(__name__) diff --git a/esphome/analyze_memory/cli.py b/esphome/analyze_memory/cli.py index b7561e8ffc0..8f1f39e1d65 100644 --- a/esphome/analyze_memory/cli.py +++ b/esphome/analyze_memory/cli.py @@ -739,7 +739,7 @@ def main(): import json from pathlib import Path - from esphome.platformio_api import IDEData + from esphome.platformio.toolchain import IDEData build_path = Path(build_dir) diff --git a/esphome/components/esp32/__init__.py b/esphome/components/esp32/__init__.py index ba32d13ab34..bb823937aa0 100644 --- a/esphome/components/esp32/__init__.py +++ b/esphome/components/esp32/__init__.py @@ -2582,9 +2582,9 @@ def copy_files(): def _decode_pc(config, addr): - from esphome import platformio_api + from esphome.platformio import toolchain - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) if not idedata.addr2line_path or not idedata.firmware_elf_path: _LOGGER.debug("decode_pc no addr2line") return diff --git a/esphome/components/esp8266/__init__.py b/esphome/components/esp8266/__init__.py index b6383653f4e..38df282fb98 100644 --- a/esphome/components/esp8266/__init__.py +++ b/esphome/components/esp8266/__init__.py @@ -463,9 +463,9 @@ ESP8266_EXCEPTION_CODES = { def _decode_pc(config, addr): - from esphome import platformio_api + from esphome.platformio import toolchain - idedata = platformio_api.get_idedata(config) + idedata = toolchain.get_idedata(config) if not idedata.addr2line_path or not idedata.firmware_elf_path: _LOGGER.debug("decode_pc no addr2line") return diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index d2ed3b15e9c..38efccab11d 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -397,11 +397,11 @@ def get_download_types(storage_json: StorageJSON) -> list[dict[str, str]]: def _upload_using_platformio( config: ConfigType, port: str, upload_args: list[str] ) -> int | str: - from esphome import platformio_api + from esphome.platformio import toolchain if port is not None: upload_args += ["--upload-port", port] - return platformio_api.run_platformio_cli_run(config, CORE.verbose, *upload_args) + return toolchain.run_platformio_cli_run(config, CORE.verbose, *upload_args) def upload_program(config: ConfigType, args, host: str) -> bool: diff --git a/esphome/components/rp2040/__init__.py b/esphome/components/rp2040/__init__.py index 7e450578cdd..81809c05519 100644 --- a/esphome/components/rp2040/__init__.py +++ b/esphome/components/rp2040/__init__.py @@ -510,7 +510,7 @@ def process_stacktrace(config, line: str, backtrace_state: bool) -> bool: if backtrace_state: if match := _CRASH_ADDR_RE.search(line): - from esphome.platformio_api import get_idedata + from esphome.platformio.toolchain import get_idedata idedata = get_idedata(config) if idedata.addr2line_path: diff --git a/esphome/dashboard/web_server.py b/esphome/dashboard/web_server.py index d67245967c5..916e937a532 100644 --- a/esphome/dashboard/web_server.py +++ b/esphome/dashboard/web_server.py @@ -40,8 +40,9 @@ import voluptuous as vol import yaml from yaml.nodes import Node -from esphome import const, platformio_api, yaml_util +from esphome import const, yaml_util from esphome.helpers import get_bool_env, mkdir_p, sort_ip_addresses +from esphome.platformio import toolchain from esphome.storage_json import ( StorageJSON, archive_storage_path, @@ -1090,7 +1091,7 @@ class DownloadBinaryRequestHandler(BaseHandler): self.send_error(404 if rc == 2 else 500) return - idedata = platformio_api.IDEData(json.loads(stdout)) + idedata = toolchain.IDEData(json.loads(stdout)) found = False for image in idedata.extra_flash_images: diff --git a/esphome/espidf/runner.py b/esphome/espidf/runner.py index e740ab72854..34e3e7694b5 100644 --- a/esphome/espidf/runner.py +++ b/esphome/espidf/runner.py @@ -190,7 +190,7 @@ def main() -> int: script_path = sys.argv[1] - # Mirror the platformio_runner behaviour: verbose mode disables the + # Mirror the platformio runner behaviour: verbose mode disables the # line filter so all output reaches the user. is_verbose = any(arg in ("-v", "--verbose") for arg in sys.argv[2:]) filter_lines = None if is_verbose else FILTER_IDF_LINES or None diff --git a/esphome/espidf/api.py b/esphome/espidf/toolchain.py similarity index 99% rename from esphome/espidf/api.py rename to esphome/espidf/toolchain.py index 847de249a7f..da6d3a8a37f 100644 --- a/esphome/espidf/api.py +++ b/esphome/espidf/toolchain.py @@ -15,7 +15,7 @@ from esphome.espidf.framework import check_esp_idf_install, get_framework_env _LOGGER = logging.getLogger(__name__) -DOMAIN = "espidf_api" +DOMAIN = "espidf_toolchain" @dataclass diff --git a/esphome/platformio/__init__.py b/esphome/platformio/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/esphome/platformio_runner.py b/esphome/platformio/runner.py similarity index 99% rename from esphome/platformio_runner.py rename to esphome/platformio/runner.py index 5b14a725577..976979dc57b 100644 --- a/esphome/platformio_runner.py +++ b/esphome/platformio/runner.py @@ -1,6 +1,6 @@ """Subprocess entry point that applies ESPHome's PlatformIO patches. -Invoked via ``python -m esphome.platformio_runner`` instead of +Invoked via ``python -m esphome.platformio.runner`` instead of ``python -m platformio`` so that the patches (incremental rebuild preservation, download retries) apply inside the subprocess. Running PlatformIO in a subprocess keeps its ``sys.path`` mutations and other diff --git a/esphome/platformio_api.py b/esphome/platformio/toolchain.py similarity index 99% rename from esphome/platformio_api.py rename to esphome/platformio/toolchain.py index 81ff01306a6..073e134ac4b 100644 --- a/esphome/platformio_api.py +++ b/esphome/platformio/toolchain.py @@ -64,7 +64,7 @@ def run_platformio_cli(*args, **kwargs) -> str | int: # a user-provided value (or the unmodified path on platforms that # don't need the strip). os.environ["PYTHONEXEPATH"] = python_exe - cmd = [python_exe, "-m", "esphome.platformio_runner"] + list(args) + cmd = [python_exe, "-m", "esphome.platformio.runner"] + list(args) return run_external_process(*cmd, **kwargs) diff --git a/script/build_helpers.py b/script/build_helpers.py index 0e0e8170a0a..fa722aa0990 100644 --- a/script/build_helpers.py +++ b/script/build_helpers.py @@ -23,7 +23,7 @@ from esphome.config import validate_config from esphome.const import CONF_PLATFORM from esphome.core import CORE from esphome.loader import get_component, get_platform -from esphome.platformio_api import get_idedata +from esphome.platformio.toolchain import get_idedata from tests.testing_helpers import ComponentManifestOverride, set_testing_manifest # This must coincide with the version in /platformio.ini diff --git a/script/ci_memory_impact_extract.py b/script/ci_memory_impact_extract.py index dd91fa861ce..2aa7394b112 100755 --- a/script/ci_memory_impact_extract.py +++ b/script/ci_memory_impact_extract.py @@ -26,7 +26,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent)) # pylint: disable=wrong-import-position from esphome.analyze_memory import MemoryAnalyzer -from esphome.platformio_api import IDEData +from esphome.platformio.toolchain import IDEData from script.ci_helpers import write_github_output # Regex patterns for extracting memory usage from PlatformIO output diff --git a/tests/dashboard/test_web_server.py b/tests/dashboard/test_web_server.py index 1a62cfda904..626aea02162 100644 --- a/tests/dashboard/test_web_server.py +++ b/tests/dashboard/test_web_server.py @@ -128,8 +128,8 @@ def mock_storage_json() -> Generator[MagicMock]: @pytest.fixture def mock_idedata() -> Generator[MagicMock]: - """Fixture to mock platformio_api.IDEData.""" - with patch("esphome.dashboard.web_server.platformio_api.IDEData") as mock: + """Fixture to mock platformio toolchain.IDEData.""" + with patch("esphome.dashboard.web_server.toolchain.IDEData") as mock: yield mock diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index f36543b7cd9..fb025ce427f 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -23,7 +23,7 @@ import pytest_asyncio import esphome.config from esphome.core import CORE -from esphome.platformio_api import get_idedata +from esphome.platformio.toolchain import get_idedata from .const import ( API_CONNECTION_TIMEOUT, diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 626f4168a60..13450b10f08 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -64,15 +64,15 @@ def mock_copy_file_if_changed() -> Generator[Mock, None, None]: @pytest.fixture def mock_run_platformio_cli() -> Generator[Mock, None, None]: - """Mock run_platformio_cli for platformio_api.""" - with patch("esphome.platformio_api.run_platformio_cli") as mock: + """Mock run_platformio_cli for platformio toolchain.""" + with patch("esphome.platformio.toolchain.run_platformio_cli") as mock: yield mock @pytest.fixture def mock_run_platformio_cli_run() -> Generator[Mock, None, None]: - """Mock run_platformio_cli_run for platformio_api.""" - with patch("esphome.platformio_api.run_platformio_cli_run") as mock: + """Mock run_platformio_cli_run for platformio toolchain.""" + with patch("esphome.platformio.toolchain.run_platformio_cli_run") as mock: yield mock @@ -92,8 +92,8 @@ def mock_esp8266_decode_pc() -> Generator[Mock, None, None]: @pytest.fixture def mock_run_external_process() -> Generator[Mock, None, None]: - """Mock run_external_process for platformio_api.""" - with patch("esphome.platformio_api.run_external_process") as mock: + """Mock run_external_process for platformio toolchain.""" + with patch("esphome.platformio.toolchain.run_external_process") as mock: yield mock @@ -113,8 +113,8 @@ def mock_subprocess_run() -> Generator[Mock, None, None]: @pytest.fixture def mock_get_idedata() -> Generator[Mock, None, None]: - """Mock get_idedata for platformio_api.""" - with patch("esphome.platformio_api.get_idedata") as mock: + """Mock get_idedata for platformio toolchain.""" + with patch("esphome.platformio.toolchain.get_idedata") as mock: yield mock diff --git a/tests/unit_tests/test_main.py b/tests/unit_tests/test_main.py index 3eb50de76b4..3648de443dc 100644 --- a/tests/unit_tests/test_main.py +++ b/tests/unit_tests/test_main.py @@ -18,7 +18,6 @@ import pytest from pytest import CaptureFixture from zeroconf import ServiceStateChange -from esphome import platformio_api from esphome.__main__ import ( Purpose, _get_configured_xtal_freq, @@ -96,6 +95,7 @@ from esphome.espota2 import ( OTA_TYPE_UPDATE_BOOTLOADER, OTA_TYPE_UPDATE_PARTITION_TABLE, ) +from esphome.platformio import toolchain from esphome.util import BootselResult, FlashImage from esphome.zeroconf import _await_discovery, discover_mdns_devices @@ -287,7 +287,7 @@ def mock_run_external_process() -> Generator[Mock]: @pytest.fixture def mock_run_external_command_main() -> Generator[Mock]: - """Mock run_external_command in __main__ module (different from platformio_api).""" + """Mock run_external_command in __main__ module (different from platformio toolchain).""" with patch("esphome.__main__.run_external_command") as mock: mock.return_value = 0 # Default to success yield mock @@ -1199,7 +1199,7 @@ def test_upload_using_esptool_path_conversion( CORE.data[KEY_ESP32] = {KEY_VARIANT: VARIANT_ESP32} # Create mock IDEData with Path objects - mock_idedata = MagicMock(spec=platformio_api.IDEData) + mock_idedata = MagicMock(spec=toolchain.IDEData) mock_idedata.firmware_bin_path = tmp_path / "firmware.bin" mock_idedata.extra_flash_images = [ FlashImage(path=tmp_path / "bootloader.bin", offset="0x1000"), @@ -1277,7 +1277,7 @@ def test_upload_using_esptool_skips_missing_extra_flash_images( missing_path = tmp_path / "variants" / "tasmota" / "tinyuf2.bin" - mock_idedata = MagicMock(spec=platformio_api.IDEData) + mock_idedata = MagicMock(spec=toolchain.IDEData) mock_idedata.firmware_bin_path = tmp_path / "firmware.bin" mock_idedata.extra_flash_images = [ FlashImage(path=tmp_path / "bootloader.bin", offset="0x1000"), @@ -1389,8 +1389,8 @@ def test_upload_using_platformio_creates_signed_bin_for_rp2040( mock_idedata.firmware_elf_path = str(firmware_elf) with ( - patch("esphome.platformio_api.get_idedata", return_value=mock_idedata), - patch("esphome.platformio_api.run_platformio_cli_run", return_value=0), + patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata), + patch("esphome.platformio.toolchain.run_platformio_cli_run", return_value=0), ): result = upload_using_platformio({}, "/dev/ttyACM0") @@ -1406,7 +1406,7 @@ def test_upload_using_platformio_skips_signed_bin_for_non_rp2040( """Test that upload_using_platformio doesn't create signed bin for non-RP2040.""" setup_core(platform=PLATFORM_ESP32) - with patch("esphome.platformio_api.run_platformio_cli_run", return_value=0): + with patch("esphome.platformio.toolchain.run_platformio_cli_run", return_value=0): result = upload_using_platformio({}, "/dev/ttyUSB0") assert result == 0 @@ -1504,7 +1504,7 @@ def test_upload_using_picotool_success(tmp_path: Path) -> None: config = {} with ( - patch("esphome.platformio_api.get_idedata", return_value=mock_idedata), + patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata), patch("subprocess.run", return_value=mock_result), ): exit_code = upload_using_picotool(config) @@ -1524,7 +1524,7 @@ def test_upload_using_picotool_no_elf(tmp_path: Path) -> None: mock_idedata.cc_path = "/fake/path/gcc" config = {} - with patch("esphome.platformio_api.get_idedata", return_value=mock_idedata): + with patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata): exit_code = upload_using_picotool(config) assert exit_code == 1 @@ -1544,7 +1544,7 @@ def test_upload_using_picotool_not_found(tmp_path: Path) -> None: mock_idedata.cc_path = "/fake/path/gcc" config = {} - with patch("esphome.platformio_api.get_idedata", return_value=mock_idedata): + with patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata): exit_code = upload_using_picotool(config) assert exit_code == 1 @@ -1578,7 +1578,7 @@ def test_upload_using_picotool_permission_error(tmp_path: Path) -> None: config = {} with ( - patch("esphome.platformio_api.get_idedata", return_value=mock_idedata), + patch("esphome.platformio.toolchain.get_idedata", return_value=mock_idedata), patch("subprocess.run", return_value=mock_result), ): exit_code = upload_using_picotool(config) @@ -4696,7 +4696,7 @@ def test_command_analyze_memory_success( firmware_elf.write_text("mock elf file") # Mock idedata - mock_idedata_obj = MagicMock(spec=platformio_api.IDEData) + mock_idedata_obj = MagicMock(spec=toolchain.IDEData) mock_idedata_obj.firmware_elf_path = str(firmware_elf) mock_idedata_obj.objdump_path = "/path/to/objdump" mock_idedata_obj.readelf_path = "/path/to/readelf" @@ -4768,7 +4768,7 @@ def test_command_analyze_memory_with_external_components( firmware_elf.write_text("mock elf file") # Mock idedata - mock_idedata_obj = MagicMock(spec=platformio_api.IDEData) + mock_idedata_obj = MagicMock(spec=toolchain.IDEData) mock_idedata_obj.firmware_elf_path = str(firmware_elf) mock_idedata_obj.objdump_path = "/path/to/objdump" mock_idedata_obj.readelf_path = "/path/to/readelf" @@ -4859,16 +4859,18 @@ def test_command_analyze_memory_no_idedata( @pytest.fixture def mock_compile_build_info_run_compile() -> Generator[Mock]: - """Mock platformio_api.run_compile for build_info tests.""" - with patch("esphome.platformio_api.run_compile", return_value=0) as mock: + """Mock toolchain.run_compile for build_info tests.""" + with patch("esphome.platformio.toolchain.run_compile", return_value=0) as mock: yield mock @pytest.fixture def mock_compile_build_info_get_idedata() -> Generator[Mock]: - """Mock platformio_api.get_idedata for build_info tests.""" + """Mock toolchain.get_idedata for build_info tests.""" mock_idedata = MagicMock() - with patch("esphome.platformio_api.get_idedata", return_value=mock_idedata) as mock: + with patch( + "esphome.platformio.toolchain.get_idedata", return_value=mock_idedata + ) as mock: yield mock @@ -5778,7 +5780,7 @@ def test_upload_using_esptool_passes_crystal_callback( sdkconfig = build_dir / "sdkconfig.test" sdkconfig.write_text("CONFIG_XTAL_FREQ=40\n") - mock_idedata = MagicMock(spec=platformio_api.IDEData) + mock_idedata = MagicMock(spec=toolchain.IDEData) mock_idedata.firmware_bin_path = tmp_path / "firmware.bin" mock_idedata.extra_flash_images = [] mock_get_idedata.return_value = mock_idedata @@ -5808,7 +5810,7 @@ def test_upload_using_esptool_subprocess_passes_crystal_callback( sdkconfig = build_dir / "sdkconfig.test" sdkconfig.write_text("CONFIG_XTAL_FREQ=40\n") - mock_idedata = MagicMock(spec=platformio_api.IDEData) + mock_idedata = MagicMock(spec=toolchain.IDEData) mock_idedata.firmware_bin_path = tmp_path / "firmware.bin" mock_idedata.extra_flash_images = [] mock_get_idedata.return_value = mock_idedata diff --git a/tests/unit_tests/test_platformio_api.py b/tests/unit_tests/test_platformio_toolchain.py similarity index 92% rename from tests/unit_tests/test_platformio_api.py rename to tests/unit_tests/test_platformio_toolchain.py index 7a88ec4d9e1..f771437dd47 100644 --- a/tests/unit_tests/test_platformio_api.py +++ b/tests/unit_tests/test_platformio_toolchain.py @@ -1,4 +1,4 @@ -"""Tests for platformio_api.py path functions.""" +"""Tests for esphome.platformio.toolchain path functions.""" # pylint: disable=protected-access @@ -11,8 +11,8 @@ from unittest.mock import MagicMock, Mock, call, patch import pytest -from esphome import platformio_api, platformio_runner from esphome.core import CORE, EsphomeError +from esphome.platformio import runner, toolchain from esphome.util import FlashImage @@ -21,7 +21,7 @@ def test_idedata_firmware_elf_path(setup_core: Path) -> None: CORE.build_path = setup_core / "build" / "test" CORE.name = "test" raw_data = {"prog_path": "/path/to/firmware.elf"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) assert idedata.firmware_elf_path == Path("/path/to/firmware.elf") @@ -32,7 +32,7 @@ def test_idedata_firmware_bin_path(setup_core: Path) -> None: CORE.name = "test" prog_path = str(Path("/path/to/firmware.elf")) raw_data = {"prog_path": prog_path} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.firmware_bin_path assert isinstance(result, Path) @@ -47,7 +47,7 @@ def test_idedata_firmware_bin_path_preserves_directory(setup_core: Path) -> None CORE.name = "test" prog_path = str(Path("/complex/path/to/build/firmware.elf")) raw_data = {"prog_path": prog_path} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.firmware_bin_path expected = Path("/complex/path/to/build/firmware.bin") @@ -67,7 +67,7 @@ def test_idedata_extra_flash_images(setup_core: Path) -> None: ] }, } - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) images = idedata.extra_flash_images assert len(images) == 2 @@ -83,7 +83,7 @@ def test_idedata_extra_flash_images_empty(setup_core: Path) -> None: CORE.build_path = setup_core / "build" / "test" CORE.name = "test" raw_data = {"prog_path": "/path/to/firmware.elf", "extra": {"flash_images": []}} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) images = idedata.extra_flash_images assert images == [] @@ -97,7 +97,7 @@ def test_idedata_cc_path(setup_core: Path) -> None: "prog_path": "/path/to/firmware.elf", "cc_path": "/Users/test/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc", } - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) assert ( idedata.cc_path @@ -132,7 +132,7 @@ def test_load_idedata_returns_dict( mock_run_platformio_cli_run.return_value = '{"prog_path": "/test/firmware.elf"}' config = {"name": "test"} - result = platformio_api._load_idedata(config) + result = toolchain._load_idedata(config) assert result is not None assert isinstance(result, dict) @@ -161,7 +161,7 @@ def test_load_idedata_uses_cache_when_valid( os.utime(idedata_path, (platformio_ini_mtime + 1, platformio_ini_mtime + 1)) config = {"name": "test"} - result = platformio_api._load_idedata(config) + result = toolchain._load_idedata(config) # Should not call _run_idedata since cache is valid mock_run_platformio_cli_run.assert_not_called() @@ -194,7 +194,7 @@ def test_load_idedata_regenerates_when_platformio_ini_newer( mock_run_platformio_cli_run.return_value = json.dumps(new_data) config = {"name": "test"} - result = platformio_api._load_idedata(config) + result = toolchain._load_idedata(config) # Should call _run_idedata since platformio.ini is newer mock_run_platformio_cli_run.assert_called_once() @@ -228,7 +228,7 @@ def test_load_idedata_regenerates_on_corrupted_cache( mock_run_platformio_cli_run.return_value = json.dumps(new_data) config = {"name": "test"} - result = platformio_api._load_idedata(config) + result = toolchain._load_idedata(config) # Should call _run_idedata since cache is corrupted mock_run_platformio_cli_run.assert_called_once() @@ -253,7 +253,7 @@ def test_run_idedata_parses_json_from_output( f"Some preamble\n{json.dumps(expected_data)}\nSome postamble" ) - result = platformio_api._run_idedata(config) + result = toolchain._run_idedata(config) assert result == expected_data @@ -267,7 +267,7 @@ def test_run_idedata_raises_on_no_json( mock_run_platformio_cli_run.return_value = "No JSON in this output" with pytest.raises(EsphomeError): - platformio_api._run_idedata(config) + toolchain._run_idedata(config) def test_run_idedata_raises_on_invalid_json( @@ -279,7 +279,7 @@ def test_run_idedata_raises_on_invalid_json( # The ValueError from json.loads is re-raised with pytest.raises(ValueError): - platformio_api._run_idedata(config) + toolchain._run_idedata(config) def test_run_platformio_cli_sets_environment_variables( @@ -290,7 +290,7 @@ def test_run_platformio_cli_sets_environment_variables( with patch.dict(os.environ, {}, clear=False): mock_run_external_process.return_value = 0 - platformio_api.run_platformio_cli("test", "arg") + toolchain.run_platformio_cli("test", "arg") # Check environment variables were set assert os.environ["PLATFORMIO_FORCE_COLOR"] == "true" @@ -303,11 +303,11 @@ def test_run_platformio_cli_sets_environment_variables( assert "PYTHONWARNINGS" in os.environ # Check command was called correctly — runs PlatformIO as a subprocess - # via the esphome.platformio_runner entry point. + # via the esphome.platformio.runner entry point. mock_run_external_process.assert_called_once() args = mock_run_external_process.call_args[0] assert "-m" in args - assert "esphome.platformio_runner" in args + assert "esphome.platformio.runner" in args assert "test" in args assert "arg" in args @@ -342,8 +342,8 @@ def test_strip_win_long_path_prefix( platform: str, input_path: str, expected: str ) -> None: r"""``\\?\`` and ``\\?\UNC\`` prefixes are stripped only on win32.""" - with patch("esphome.platformio_api.sys.platform", platform): - assert platformio_api._strip_win_long_path_prefix(input_path) == expected + with patch("esphome.platformio.toolchain.sys.platform", platform): + assert toolchain._strip_win_long_path_prefix(input_path) == expected def test_run_platformio_cli_strips_win_long_path_prefix( @@ -366,15 +366,15 @@ def test_run_platformio_cli_strips_win_long_path_prefix( with ( patch.dict(os.environ, {}, clear=False), - patch("esphome.platformio_api.sys.platform", "win32"), - patch("esphome.platformio_api.sys.executable", prefixed_exe), + patch("esphome.platformio.toolchain.sys.platform", "win32"), + patch("esphome.platformio.toolchain.sys.executable", prefixed_exe), ): # Pop any pre-existing PYTHONEXEPATH so the assertion below reflects # what run_platformio_cli set, not whatever the test runner's # environment happened to contain. os.environ.pop("PYTHONEXEPATH", None) mock_run_external_process.return_value = 0 - platformio_api.run_platformio_cli("test", "arg") + toolchain.run_platformio_cli("test", "arg") # The subprocess is invoked with the stripped executable path. mock_run_external_process.assert_called_once() @@ -398,12 +398,12 @@ def test_run_platformio_cli_does_not_set_pythonexepath_without_strip( with ( patch.dict(os.environ, {}, clear=False), - patch("esphome.platformio_api.sys.platform", "linux"), - patch("esphome.platformio_api.sys.executable", plain_exe), + patch("esphome.platformio.toolchain.sys.platform", "linux"), + patch("esphome.platformio.toolchain.sys.executable", plain_exe), ): os.environ.pop("PYTHONEXEPATH", None) mock_run_external_process.return_value = 0 - platformio_api.run_platformio_cli("test", "arg") + toolchain.run_platformio_cli("test", "arg") mock_run_external_process.assert_called_once() args = mock_run_external_process.call_args[0] @@ -419,7 +419,7 @@ def test_run_platformio_cli_run_builds_command( mock_run_platformio_cli.return_value = 0 config = {"name": "test"} - platformio_api.run_platformio_cli_run(config, True, "extra", "args") + toolchain.run_platformio_cli_run(config, True, "extra", "args") mock_run_platformio_cli.assert_called_once_with( "run", "-d", CORE.build_path, "-v", "extra", "args" @@ -434,7 +434,7 @@ def test_run_compile(setup_core: Path, mock_run_platformio_cli_run: Mock) -> Non config = {CONF_ESPHOME: {CONF_COMPILE_PROCESS_LIMIT: 4}} mock_run_platformio_cli_run.return_value = 0 - platformio_api.run_compile(config, verbose=True) + toolchain.run_compile(config, verbose=True) mock_run_platformio_cli_run.assert_called_once_with(config, True, "-j4") @@ -461,22 +461,22 @@ def test_get_idedata_caches_result( config = {"name": "test"} # First call should load and cache - result1 = platformio_api.get_idedata(config) + result1 = toolchain.get_idedata(config) mock_run_platformio_cli_run.assert_called_once() # Second call should use cache from CORE.data - result2 = platformio_api.get_idedata(config) + result2 = toolchain.get_idedata(config) mock_run_platformio_cli_run.assert_called_once() # Still only called once assert result1 is result2 - assert isinstance(result1, platformio_api.IDEData) + assert isinstance(result1, toolchain.IDEData) assert result1.firmware_elf_path == Path("/test/firmware.elf") def test_idedata_addr2line_path_windows(setup_core: Path) -> None: """Test IDEData.addr2line_path on Windows.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "C:\\tools\\gcc.exe"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.addr2line_path assert result == "C:\\tools\\addr2line.exe" @@ -485,7 +485,7 @@ def test_idedata_addr2line_path_windows(setup_core: Path) -> None: def test_idedata_addr2line_path_unix(setup_core: Path) -> None: """Test IDEData.addr2line_path on Unix.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "/usr/bin/gcc"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.addr2line_path assert result == "/usr/bin/addr2line" @@ -494,7 +494,7 @@ def test_idedata_addr2line_path_unix(setup_core: Path) -> None: def test_idedata_objdump_path_windows(setup_core: Path) -> None: """Test IDEData.objdump_path on Windows.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "C:\\tools\\gcc.exe"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.objdump_path assert result == "C:\\tools\\objdump.exe" @@ -503,7 +503,7 @@ def test_idedata_objdump_path_windows(setup_core: Path) -> None: def test_idedata_objdump_path_unix(setup_core: Path) -> None: """Test IDEData.objdump_path on Unix.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "/usr/bin/gcc"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.objdump_path assert result == "/usr/bin/objdump" @@ -512,7 +512,7 @@ def test_idedata_objdump_path_unix(setup_core: Path) -> None: def test_idedata_readelf_path_windows(setup_core: Path) -> None: """Test IDEData.readelf_path on Windows.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "C:\\tools\\gcc.exe"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.readelf_path assert result == "C:\\tools\\readelf.exe" @@ -521,7 +521,7 @@ def test_idedata_readelf_path_windows(setup_core: Path) -> None: def test_idedata_readelf_path_unix(setup_core: Path) -> None: """Test IDEData.readelf_path on Unix.""" raw_data = {"prog_path": "/path/to/firmware.elf", "cc_path": "/usr/bin/gcc"} - idedata = platformio_api.IDEData(raw_data) + idedata = toolchain.IDEData(raw_data) result = idedata.readelf_path assert result == "/usr/bin/readelf" @@ -547,7 +547,7 @@ def test_patch_structhash(setup_core: Path) -> None: }, ): # Call patch_structhash - platformio_runner.patch_structhash() + runner.patch_structhash() # Verify both modules had clean_build_dir patched # Check that clean_build_dir was set on both modules @@ -599,7 +599,7 @@ def test_patched_clean_build_dir_removes_outdated(setup_core: Path) -> None: }, ): # Call patch_structhash to install the patched function - platformio_runner.patch_structhash() + runner.patch_structhash() # Call the patched function mock_helpers.clean_build_dir(str(build_dir), []) @@ -649,7 +649,7 @@ def test_patched_clean_build_dir_keeps_updated(setup_core: Path) -> None: }, ): # Call patch_structhash to install the patched function - platformio_runner.patch_structhash() + runner.patch_structhash() # Call the patched function mock_helpers.clean_build_dir(str(build_dir), []) @@ -697,7 +697,7 @@ def test_patched_clean_build_dir_creates_missing(setup_core: Path) -> None: }, ): # Call patch_structhash to install the patched function - platformio_runner.patch_structhash() + runner.patch_structhash() # Call the patched function mock_helpers.clean_build_dir(str(build_dir), []) @@ -727,7 +727,7 @@ def test_patch_file_downloader_succeeds_first_try() -> None: ), }, ): - platformio_runner.patch_file_downloader() + runner.patch_file_downloader() from platformio.package.download import FileDownloader @@ -766,7 +766,7 @@ def test_patch_file_downloader_retries_on_failure() -> None: ), patch("time.sleep") as mock_sleep, ): - platformio_runner.patch_file_downloader() + runner.patch_file_downloader() from platformio.package.download import FileDownloader @@ -807,7 +807,7 @@ def test_patch_file_downloader_raises_after_max_retries() -> None: ), patch("time.sleep") as mock_sleep, ): - platformio_runner.patch_file_downloader() + runner.patch_file_downloader() from platformio.package.download import FileDownloader @@ -855,7 +855,7 @@ def test_patch_file_downloader_closes_session_and_response_between_retries() -> ), patch("time.sleep"), ): - platformio_runner.patch_file_downloader() + runner.patch_file_downloader() from platformio.package.download import FileDownloader @@ -890,9 +890,9 @@ def test_patch_file_downloader_idempotent() -> None: }, ): # Patch multiple times - platformio_runner.patch_file_downloader() - platformio_runner.patch_file_downloader() - platformio_runner.patch_file_downloader() + runner.patch_file_downloader() + runner.patch_file_downloader() + runner.patch_file_downloader() from platformio.package.download import FileDownloader @@ -910,9 +910,7 @@ def _filter_through_redirect(line: str) -> str: from esphome.util import RedirectText captured = io.StringIO() - redirect = RedirectText( - captured, filter_lines=platformio_runner.FILTER_PLATFORMIO_LINES - ) + redirect = RedirectText(captured, filter_lines=runner.FILTER_PLATFORMIO_LINES) redirect.write(line + "\n") return captured.getvalue() From b967adeb9d6b1ed30cbb296ad41145d55db0335f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 May 2026 08:11:36 -0500 Subject: [PATCH 32/52] [wifi] Accept lowercase variant in variant_has_wifi (#16345) --- esphome/components/wifi/__init__.py | 8 +++++- tests/unit_tests/components/test_wifi.py | 33 ++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/esphome/components/wifi/__init__.py b/esphome/components/wifi/__init__.py index 316d4321403..bad57fc4810 100644 --- a/esphome/components/wifi/__init__.py +++ b/esphome/components/wifi/__init__.py @@ -76,11 +76,17 @@ def variant_has_wifi(variant: str) -> bool: Variants without a native PHY (ESP32-H2, ESP32-P4) need the ``esp32_hosted`` co-processor to use ``wifi:``. + Case-insensitive on *variant* so external callers can pass either + the upstream uppercase form (e.g. ``"ESP32H2"`` from + ``const.VARIANT_ESP32H2``) or a lowercase form their own enum + surfaces (e.g. ``"esp32h2"`` from device-builder's + ``Esp32Variant``). Both classify identically. + Used by device-builder (esphome/device-builder) to decide whether its basic-setup wizard emits a ``wifi:`` block — please keep the signature stable. """ - return variant not in NO_WIFI_VARIANTS + return variant.upper() not in NO_WIFI_VARIANTS _WIFI_FIRST_PLATFORMS: frozenset[str] = frozenset( diff --git a/tests/unit_tests/components/test_wifi.py b/tests/unit_tests/components/test_wifi.py index e93ae4b5036..71a14d78177 100644 --- a/tests/unit_tests/components/test_wifi.py +++ b/tests/unit_tests/components/test_wifi.py @@ -10,27 +10,44 @@ from esphome.const import Platform @pytest.mark.parametrize( "variant", [ + # Upstream's canonical uppercase form. const.VARIANT_ESP32, const.VARIANT_ESP32S2, const.VARIANT_ESP32S3, const.VARIANT_ESP32C3, const.VARIANT_ESP32C6, + # Lowercase form external callers (e.g. device-builder's + # ``Esp32Variant`` StrEnum) surface. + "esp32", + "esp32s3", + "esp32c3", + # Mixed-case — defence in depth against future callers that + # pull the value off some other serialisation. + "Esp32", ], ) def test_variant_has_wifi_for_native_phy_variants(variant: str) -> None: - """Variants with a native WiFi PHY → True.""" + """Variants with a native WiFi PHY → True, case-insensitive.""" assert variant_has_wifi(variant) is True @pytest.mark.parametrize( "variant", [ + # Upstream's canonical uppercase form. const.VARIANT_ESP32H2, const.VARIANT_ESP32P4, + # Lowercase form external callers (e.g. device-builder's + # ``Esp32Variant`` StrEnum) surface. + "esp32h2", + "esp32p4", + # Mixed-case — defence in depth against future callers that + # pull the value off some other serialisation. + "Esp32H2", ], ) def test_variant_has_wifi_for_no_phy_variants(variant: str) -> None: - """Variants that need ``esp32_hosted`` → False.""" + """Variants that need ``esp32_hosted`` → False, case-insensitive.""" assert variant_has_wifi(variant) is False @@ -44,6 +61,18 @@ def test_has_native_wifi_dispatches_esp32_to_variant_check() -> None: ) +def test_has_native_wifi_esp32_variant_case_insensitive() -> None: + """has_native_wifi accepts lowercase variant input. + + External callers (device-builder's wizard, etc.) may surface + variant strings from their own enums that don't match upstream's + uppercase convention. The dispatcher should classify them + identically. + """ + assert has_native_wifi(platform=Platform.ESP32, variant="esp32h2") is False + assert has_native_wifi(platform=Platform.ESP32, variant="esp32c3") is True + + def test_has_native_wifi_dispatches_rp2040_to_board_check() -> None: """RP2040 platform routes through ``rp2040.board_id_has_wifi``.""" assert has_native_wifi(platform=Platform.RP2040, board="rpipicow") is True From 4d9d6e02e5c53dcd4db3ce84be0300a8b6fb453f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 May 2026 08:13:16 -0500 Subject: [PATCH 33/52] [core] Add stable esphome.upload_targets module for port classification (#16346) --- esphome/__main__.py | 30 +-------- esphome/components/nrf52/__init__.py | 5 +- esphome/upload_targets.py | 66 ++++++++++++++++++++ tests/unit_tests/test_upload_targets.py | 81 +++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 31 deletions(-) create mode 100644 esphome/upload_targets.py create mode 100644 tests/unit_tests/test_upload_targets.py diff --git a/esphome/__main__.py b/esphome/__main__.py index 54d6384bfc0..ce24f44b3a6 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -64,6 +64,7 @@ from esphome.enum import StrEnum from esphome.helpers import get_bool_env, indent, is_ip_address from esphome.log import AnsiFore, color, setup_log from esphome.types import ConfigType +from esphome.upload_targets import PortType, get_port_type from esphome.util import ( PICOTOOL_PACKAGE, FlashImage, @@ -194,14 +195,6 @@ class Purpose(StrEnum): LOGGING = "logging" -class PortType(StrEnum): - SERIAL = "SERIAL" - NETWORK = "NETWORK" - MQTT = "MQTT" - MQTTIP = "MQTTIP" - BOOTSEL = "BOOTSEL" - - # Magic MQTT port types that require special handling _MQTT_PORT_TYPES = frozenset({PortType.MQTT, PortType.MQTTIP}) @@ -597,27 +590,6 @@ def _resolve_network_devices( return network_devices -def get_port_type(port: str) -> PortType: - """Determine the type of port/device identifier. - - Returns: - PortType.SERIAL for serial ports (/dev/ttyUSB0, COM1, etc.) - PortType.BOOTSEL for RP2040 BOOTSEL upload via picotool - PortType.MQTT for MQTT logging - PortType.MQTTIP for MQTT IP lookup - PortType.NETWORK for IP addresses, hostnames, or mDNS names - """ - if port == "BOOTSEL": - return PortType.BOOTSEL - if port.startswith("/") or port.startswith("COM"): - return PortType.SERIAL - if port == "MQTT": - return PortType.MQTT - if port == "MQTTIP": - return PortType.MQTTIP - return PortType.NETWORK - - def run_miniterm(config: ConfigType, port: str, args) -> int: from aioesphomeapi import LogParser import serial diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index 38efccab11d..37854d4ab7f 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -405,11 +405,12 @@ def _upload_using_platformio( def upload_program(config: ConfigType, args, host: str) -> bool: - from esphome.__main__ import check_permissions, get_port_type + from esphome.__main__ import check_permissions + from esphome.upload_targets import PortType, get_port_type mcumgr_device: str | None = None - if get_port_type(host) == "SERIAL": + if get_port_type(host) == PortType.SERIAL: check_permissions(host) if zephyr_data()[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT: mcumgr_device = host diff --git a/esphome/upload_targets.py b/esphome/upload_targets.py new file mode 100644 index 00000000000..302ecf73011 --- /dev/null +++ b/esphome/upload_targets.py @@ -0,0 +1,66 @@ +"""Stable classification of ``--device`` / port strings. + +External tooling (the device-builder dashboard at +esphome/device-builder, and other consumers) needs to decide whether +a user-supplied port string names a local serial device, an OTA +network target, an MQTT magic string, or an RP2040 BOOTSEL upload. + +This module is the single stable home for that classification. The +upstream CLI (``esphome.__main__``) re-exports ``PortType`` and +``get_port_type`` from here for its own use; external callers should +import directly from ``esphome.upload_targets`` so the surface stays +stable across releases (``esphome/__main__`` is a CLI entrypoint and +not a stable import path). + +Please keep ``PortType`` member names / values and the +``get_port_type`` signature stable — see the docstrings on each for +the contract. +""" + +from __future__ import annotations + +from esphome.enum import StrEnum + + +class PortType(StrEnum): + """Port classification returned by :func:`get_port_type`. + + Used by device-builder (esphome/device-builder) and other + external tooling to route a user-supplied ``--device`` value to + the right upload / log path. Member names and string values are + part of the stable surface — adding new members is fine, but + existing names / values must not be renamed or changed. + """ + + SERIAL = "SERIAL" + NETWORK = "NETWORK" + MQTT = "MQTT" + MQTTIP = "MQTTIP" + BOOTSEL = "BOOTSEL" + + +def get_port_type(port: str) -> PortType: + """Determine the type of port/device identifier. + + Used by device-builder (esphome/device-builder)'s dashboard to + decide whether a user-supplied ``--device`` value names a local + serial port (must build / flash locally), an OTA network target + (eligible for remote builds), an MQTT magic string, or an RP2040 + BOOTSEL upload. Please keep the signature stable. + + Returns: + PortType.SERIAL for serial ports (/dev/ttyUSB0, COM1, etc.) + PortType.BOOTSEL for RP2040 BOOTSEL upload via picotool + PortType.MQTT for MQTT logging + PortType.MQTTIP for MQTT IP lookup + PortType.NETWORK for IP addresses, hostnames, or mDNS names + """ + if port == "BOOTSEL": + return PortType.BOOTSEL + if port.startswith("/") or port.startswith("COM"): + return PortType.SERIAL + if port == "MQTT": + return PortType.MQTT + if port == "MQTTIP": + return PortType.MQTTIP + return PortType.NETWORK diff --git a/tests/unit_tests/test_upload_targets.py b/tests/unit_tests/test_upload_targets.py new file mode 100644 index 00000000000..52587ca4e62 --- /dev/null +++ b/tests/unit_tests/test_upload_targets.py @@ -0,0 +1,81 @@ +"""Tests for the stable upload-targets classification helpers.""" + +import pytest + +from esphome.upload_targets import PortType, get_port_type + + +@pytest.mark.parametrize( + "port", + [ + "/dev/ttyUSB0", + "/dev/ttyACM0", + "/dev/cu.usbserial-1410", + "/dev/tty.usbmodem1101", + "COM1", + "COM23", + ], +) +def test_get_port_type_serial(port: str) -> None: + """Local serial devices classify as SERIAL.""" + assert get_port_type(port) is PortType.SERIAL + + +def test_get_port_type_bootsel() -> None: + """``BOOTSEL`` magic string classifies as BOOTSEL.""" + assert get_port_type("BOOTSEL") is PortType.BOOTSEL + + +def test_get_port_type_mqtt() -> None: + """``MQTT`` magic string classifies as MQTT.""" + assert get_port_type("MQTT") is PortType.MQTT + + +def test_get_port_type_mqttip() -> None: + """``MQTTIP`` magic string classifies as MQTTIP.""" + assert get_port_type("MQTTIP") is PortType.MQTTIP + + +@pytest.mark.parametrize( + "port", + [ + "192.168.1.10", + "fe80::1", + "device.local", + "my-esp.example.com", + ], +) +def test_get_port_type_network(port: str) -> None: + """IP addresses, mDNS, and hostnames classify as NETWORK.""" + assert get_port_type(port) is PortType.NETWORK + + +def test_port_type_values_are_stable() -> None: + """Member values are part of the stable surface. + + External tooling (device-builder, etc.) may compare against the + string values directly. Renaming or changing these breaks + downstream consumers — guard against accidental edits. + """ + assert PortType.SERIAL.value == "SERIAL" + assert PortType.NETWORK.value == "NETWORK" + assert PortType.MQTT.value == "MQTT" + assert PortType.MQTTIP.value == "MQTTIP" + assert PortType.BOOTSEL.value == "BOOTSEL" + + +def test_main_re_exports_for_backwards_compat() -> None: + """``esphome.__main__`` re-exports the stable surface. + + The CLI entry point pre-dated the stable module and existing + internal callers (and any third-party code that snuck in via + ``__main__``) still import from there. The re-export must + resolve to the same objects. + """ + from esphome.__main__ import ( + PortType as MainPortType, + get_port_type as main_get_port_type, + ) + + assert MainPortType is PortType + assert main_get_port_type is get_port_type From 105842366ebf95b982c7de6681691d5c4c662a41 Mon Sep 17 00:00:00 2001 From: rwrozelle Date: Mon, 11 May 2026 09:57:01 -0400 Subject: [PATCH 34/52] [openthread] Remove-freertos-portmacro-header-include (#16338) --- esphome/components/openthread/openthread.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/esphome/components/openthread/openthread.cpp b/esphome/components/openthread/openthread.cpp index 21dad4f8670..8557427096f 100644 --- a/esphome/components/openthread/openthread.cpp +++ b/esphome/components/openthread/openthread.cpp @@ -2,8 +2,6 @@ #ifdef USE_OPENTHREAD #include "openthread.h" -#include - #include #include #include From 68534ea24d5dae6b4d82e78c5e2cfa909afb89cb Mon Sep 17 00:00:00 2001 From: tomaszduda23 Date: Mon, 11 May 2026 16:04:48 +0200 Subject: [PATCH 35/52] [logger] fix crash on zephyr (#16330) --- esphome/components/logger/logger.cpp | 3 +++ esphome/components/logger/logger_zephyr.cpp | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index 23b69c36c60..a035525101d 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -243,6 +243,9 @@ void Logger::dump_config() { #endif #ifdef USE_ZEPHYR dump_crash_(); + if (!device_is_ready(this->uart_dev_)) { + ESP_LOGE(TAG, " %s is not ready.", LOG_STR_ARG(get_uart_selection_())); + } #endif // Warn users that VERBOSE/VERY_VERBOSE logging impacts performance. // Only the compiled log level matters — all log calls up to this level diff --git a/esphome/components/logger/logger_zephyr.cpp b/esphome/components/logger/logger_zephyr.cpp index e9caa8d9d99..240bcc57c79 100644 --- a/esphome/components/logger/logger_zephyr.cpp +++ b/esphome/components/logger/logger_zephyr.cpp @@ -74,9 +74,7 @@ void Logger::pre_setup() { break; #endif } - if (!device_is_ready(uart_dev)) { - ESP_LOGE(TAG, "%s is not ready.", LOG_STR_ARG(get_uart_selection_())); - } else { + if (device_is_ready(uart_dev)) { this->uart_dev_ = uart_dev; #if defined(USE_LOGGER_WAIT_FOR_CDC) && defined(USE_LOGGER_UART_SELECTION_USB_CDC) uint32_t dtr = 0; From 2edb7ca5c224f8f67b3189f9573a6542c2d4328d Mon Sep 17 00:00:00 2001 From: tomaszduda23 Date: Mon, 11 May 2026 16:05:41 +0200 Subject: [PATCH 36/52] [nrf52] add message that west update is running (#16321) --- .clang-tidy.hash | 2 +- esphome/components/nrf52/__init__.py | 2 +- platformio.ini | 2 +- tests/components/nrf52/test.nrf52-adafruit.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.clang-tidy.hash b/.clang-tidy.hash index 4c4b4e5c9c7..da2e8632817 100644 --- a/.clang-tidy.hash +++ b/.clang-tidy.hash @@ -1 +1 @@ -edce6cd78b33b296cef3caa5869d237061345eb346e3f9cb21e3239d2711051f +96c95feaa60831da5f43e3c6a7c7a3a237e17c5d12995a730dbc3884c8dcd11c diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index 37854d4ab7f..a9be7e56e70 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -182,7 +182,7 @@ CONFIG_SCHEMA = cv.All( default={}, ): cv.Schema( { - cv.Optional(CONF_VERSION, default="2.6.1-a"): cv.string_strict, + cv.Optional(CONF_VERSION, default="2.6.1-b"): cv.string_strict, cv.Optional(CONF_ADVANCED, default={}): cv.Schema( { cv.Optional( diff --git a/platformio.ini b/platformio.ini index 3023a157323..42b74007793 100644 --- a/platformio.ini +++ b/platformio.ini @@ -233,7 +233,7 @@ extends = common platform = https://github.com/tomaszduda23/platform-nordicnrf52/archive/refs/tags/v10.3.0-5.zip framework = zephyr platform_packages = - platformio/framework-zephyr @ https://github.com/tomaszduda23/framework-sdk-nrf/archive/refs/tags/v2.6.1-a.zip + platformio/framework-zephyr @ https://github.com/tomaszduda23/framework-sdk-nrf/archive/refs/tags/v2.6.1-b.zip build_flags = ${common.build_flags} -DUSE_ZEPHYR diff --git a/tests/components/nrf52/test.nrf52-adafruit.yaml b/tests/components/nrf52/test.nrf52-adafruit.yaml index 300cb7b5d75..3ae48b2a5f8 100644 --- a/tests/components/nrf52/test.nrf52-adafruit.yaml +++ b/tests/components/nrf52/test.nrf52-adafruit.yaml @@ -20,4 +20,4 @@ nrf52: voltage: 2.1V uicr_erase: true framework: - version: "2.6.1-a" + version: "2.6.1-b" From a7299cb95b2f8d1b4c43492554d6f4958fd1f8f3 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Mon, 11 May 2026 16:09:15 +0200 Subject: [PATCH 37/52] [esp32_camera] Downgrade esp32-camera to 2.1.5 (#16293) --- esphome/components/camera_encoder/__init__.py | 2 +- esphome/components/esp32_camera/__init__.py | 2 +- esphome/idf_component.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/camera_encoder/__init__.py b/esphome/components/camera_encoder/__init__.py index 3bbeae78356..a0c59a517a7 100644 --- a/esphome/components/camera_encoder/__init__.py +++ b/esphome/components/camera_encoder/__init__.py @@ -50,7 +50,7 @@ async def to_code(config: ConfigType) -> None: buffer = cg.new_Pvariable(config[CONF_ENCODER_BUFFER_ID]) cg.add(buffer.set_buffer_size(config[CONF_BUFFER_SIZE])) if config[CONF_TYPE] == ESP32_CAMERA_ENCODER: - add_idf_component(name="espressif/esp32-camera", ref="2.1.6") + add_idf_component(name="espressif/esp32-camera", ref="2.1.5") cg.add_define("USE_ESP32_CAMERA_JPEG_ENCODER") var = cg.new_Pvariable( config[CONF_ID], diff --git a/esphome/components/esp32_camera/__init__.py b/esphome/components/esp32_camera/__init__.py index 5165956806f..9883a0a43e0 100644 --- a/esphome/components/esp32_camera/__init__.py +++ b/esphome/components/esp32_camera/__init__.py @@ -399,7 +399,7 @@ async def to_code(config): if config[CONF_JPEG_QUALITY] != 0 and config[CONF_PIXEL_FORMAT] != "JPEG": cg.add_define("USE_ESP32_CAMERA_JPEG_CONVERSION") - add_idf_component(name="espressif/esp32-camera", ref="2.1.6") + add_idf_component(name="espressif/esp32-camera", ref="2.1.5") add_idf_sdkconfig_option("CONFIG_SCCB_HARDWARE_I2C_DRIVER_NEW", True) add_idf_sdkconfig_option("CONFIG_SCCB_HARDWARE_I2C_DRIVER_LEGACY", False) diff --git a/esphome/idf_component.yml b/esphome/idf_component.yml index 8ffcffa7051..45aaa827c87 100644 --- a/esphome/idf_component.yml +++ b/esphome/idf_component.yml @@ -20,7 +20,7 @@ dependencies: espressif/esp-tflite-micro: version: 1.3.3~1 espressif/esp32-camera: - version: 2.1.6 + version: 2.1.5 espressif/mdns: version: 1.11.0 espressif/esp_wifi_remote: From 30e2f7e8e9da26f68ff4fa24980344407c9ee81d Mon Sep 17 00:00:00 2001 From: Keith Burzinski Date: Mon, 11 May 2026 09:13:43 -0500 Subject: [PATCH 38/52] [thermostat] Fix supplemental action never firing via max run time (#16308) --- .../thermostat/thermostat_climate.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/esphome/components/thermostat/thermostat_climate.cpp b/esphome/components/thermostat/thermostat_climate.cpp index d8478d2648d..2390a96337c 100644 --- a/esphome/components/thermostat/thermostat_climate.cpp +++ b/esphome/components/thermostat/thermostat_climate.cpp @@ -506,8 +506,10 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu case climate::CLIMATE_ACTION_IDLE: if (this->idle_action_ready_()) { this->start_timer_(thermostat::THERMOSTAT_TIMER_IDLE_ON); - if (this->action == climate::CLIMATE_ACTION_COOLING) + if (this->action == climate::CLIMATE_ACTION_COOLING) { this->start_timer_(thermostat::THERMOSTAT_TIMER_COOLING_OFF); + this->cancel_timer_(thermostat::THERMOSTAT_TIMER_COOLING_MAX_RUN_TIME); + } if (this->action == climate::CLIMATE_ACTION_FAN) { if (this->supports_fan_only_action_uses_fan_mode_timer_) { this->start_timer_(thermostat::THERMOSTAT_TIMER_FAN_MODE); @@ -515,8 +517,10 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu this->start_timer_(thermostat::THERMOSTAT_TIMER_FANNING_OFF); } } - if (this->action == climate::CLIMATE_ACTION_HEATING) + if (this->action == climate::CLIMATE_ACTION_HEATING) { this->start_timer_(thermostat::THERMOSTAT_TIMER_HEATING_OFF); + this->cancel_timer_(thermostat::THERMOSTAT_TIMER_HEATING_MAX_RUN_TIME); + } // trig = this->idle_action_trigger_; ESP_LOGVV(TAG, "Switching to IDLE/OFF action"); this->cooling_max_runtime_exceeded_ = false; @@ -599,16 +603,6 @@ void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool pu } void ThermostatClimate::switch_to_supplemental_action_(climate::ClimateAction action) { - // Always cancel max-runtime timers and clear exceeded flags when transitioning to idle/off, - // even if supplemental_action_ is already idle (early-return path). This prevents a stale - // heating_max_runtime_exceeded_ flag from triggering supplemental on the next heating cycle - // when HEATING_MAX_RUN_TIME fires while the main action is already IDLE. - if (action == climate::CLIMATE_ACTION_OFF || action == climate::CLIMATE_ACTION_IDLE) { - this->cancel_timer_(thermostat::THERMOSTAT_TIMER_COOLING_MAX_RUN_TIME); - this->cancel_timer_(thermostat::THERMOSTAT_TIMER_HEATING_MAX_RUN_TIME); - this->cooling_max_runtime_exceeded_ = false; - this->heating_max_runtime_exceeded_ = false; - } // setup_complete_ helps us ensure an action is called immediately after boot if ((action == this->supplemental_action_) && this->setup_complete_) { // already in target mode From 8cf0eba0437e5eb378fa902d865228fb0d8eef65 Mon Sep 17 00:00:00 2001 From: tomaszduda23 Date: Mon, 11 May 2026 16:47:06 +0200 Subject: [PATCH 39/52] [nrf52][zephyr] prepare for native builds (#16193) Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> --- esphome/components/nrf52/__init__.py | 117 ++++++++++++++---- esphome/components/nrf52/boards.py | 8 ++ .../{zephyr => nrf52}/pre_build.py.script | 0 esphome/components/zephyr/__init__.py | 96 +++++--------- 4 files changed, 131 insertions(+), 90 deletions(-) rename esphome/components/{zephyr => nrf52}/pre_build.py.script (100%) diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index a9be7e56e70..2aba208af7e 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -9,6 +9,7 @@ import subprocess from esphome import pins import esphome.codegen as cg from esphome.components.zephyr import ( + add_extra_script, copy_files as zephyr_copy_files, zephyr_add_overlay, zephyr_add_pm_static, @@ -21,6 +22,7 @@ from esphome.components.zephyr import ( from esphome.components.zephyr.const import ( BOOTLOADER_MCUBOOT, CONF_CDC_ACM, + KEY_BOARD, KEY_BOOTLOADER, KEY_ZEPHYR, CdcAcm, @@ -36,6 +38,7 @@ from esphome.const import ( CONF_OTA, CONF_RESET_PIN, CONF_SAFE_MODE, + CONF_TOOLCHAIN, CONF_VERSION, CONF_VOLTAGE, KEY_CORE, @@ -44,10 +47,12 @@ from esphome.const import ( KEY_TARGET_PLATFORM, PLATFORM_NRF52, ThreadModel, + Toolchain, ) from esphome.core import CORE, CoroPriority, EsphomeError, coroutine_with_priority from esphome.core.config import BOARD_MAX_LENGTH import esphome.final_validate as fv +from esphome.helpers import write_file_if_changed from esphome.storage_json import StorageJSON from esphome.types import ConfigType @@ -67,8 +72,35 @@ AUTO_LOAD = ["zephyr", "preferences"] IS_TARGET_PLATFORM = True _LOGGER = logging.getLogger(__name__) +FAKE_BOARD_MANIFEST = """ +{ + "frameworks": [ + "zephyr" + ], + "name": "esphome nrf52", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200 + }, + "url": "https://esphome.io/", + "vendor": "esphome", + "build": { + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_fwid": "0x00B6" + } + } +} +""" + def set_core_data(config: ConfigType) -> ConfigType: + # Resolve toolchain: CLI (already on CORE.toolchain) > YAML > default. + if CORE.toolchain is None: + CORE.toolchain = config.get(CONF_TOOLCHAIN, Toolchain.PLATFORMIO) zephyr_set_core_data(config) CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_NRF52 CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = KEY_ZEPHYR @@ -80,10 +112,18 @@ def set_core_data(config: ConfigType) -> ConfigType: def set_framework(config: ConfigType) -> ConfigType: + if CONF_VERSION not in config[CONF_FRAMEWORK]: + default_version = "2.6.1-b" if CORE.using_toolchain_platformio else "2.9.2" + config = { + **config, + CONF_FRAMEWORK: {**config[CONF_FRAMEWORK], CONF_VERSION: default_version}, + } framework_ver = cv.Version.parse( cv.version_number(config[CONF_FRAMEWORK][CONF_VERSION]) ) CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] = framework_ver + if not CORE.using_toolchain_platformio: + return config if framework_ver < cv.Version(2, 9, 2): return cv.require_framework_version( nrf52_zephyr=cv.Version(2, 6, 1, "a"), @@ -182,7 +222,7 @@ CONFIG_SCHEMA = cv.All( default={}, ): cv.Schema( { - cv.Optional(CONF_VERSION, default="2.6.1-b"): cv.string_strict, + cv.Optional(CONF_VERSION): cv.string_strict, cv.Optional(CONF_ADVANCED, default={}): cv.Schema( { cv.Optional( @@ -238,40 +278,51 @@ FINAL_VALIDATE_SCHEMA = _final_validate @coroutine_with_priority(CoroPriority.PLATFORM) async def to_code(config: ConfigType) -> None: """Convert the configuration to code.""" - cg.add_platformio_option("board", config[CONF_BOARD]) cg.add_build_flag("-DUSE_NRF52") cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) cg.add_define("ESPHOME_VARIANT", "NRF52") # nRF52 processors are single-core cg.add_define(ThreadModel.SINGLE) - cg.add_platformio_option(CONF_FRAMEWORK, CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK]) - cg.add_platformio_option( - "platform", - "https://github.com/tomaszduda23/platform-nordicnrf52/archive/refs/tags/v10.3.0-5.zip", - ) - cg.add_platformio_option( - "platform_packages", - [ - f"platformio/framework-zephyr@https://github.com/tomaszduda23/framework-sdk-nrf/archive/refs/tags/v{CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]}.zip", - ], - ) + if CORE.using_toolchain_platformio: + cg.add_platformio_option("board", config[CONF_BOARD]) + cg.add_platformio_option( + CONF_FRAMEWORK, CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] + ) + cg.add_platformio_option( + "platform", + "https://github.com/tomaszduda23/platform-nordicnrf52/archive/refs/tags/v10.3.0-5.zip", + ) + cg.add_platformio_option( + "platform_packages", + [ + f"platformio/framework-zephyr@https://github.com/tomaszduda23/framework-sdk-nrf/archive/refs/tags/v{CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]}.zip", + ], + ) + if config[KEY_BOOTLOADER] != BOOTLOADER_MCUBOOT: + # make sure that firmware.zip is created + # for Adafruit_nRF52_Bootloader + cg.add_platformio_option("board_upload.protocol", "nrfutil") + cg.add_platformio_option("board_upload.use_1200bps_touch", "true") + cg.add_platformio_option("board_upload.require_upload_port", "true") + cg.add_platformio_option("board_upload.wait_for_upload_port", "true") + + add_extra_script( + "pre", + "pre_build.py", + Path(__file__).parent / "pre_build.py.script", + ) + # build is done by west so bypass board checking in platformio + cg.add_platformio_option("boards_dir", CORE.relative_build_path("boards")) if config[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT: cg.add_define("USE_BOOTLOADER_MCUBOOT") - else: - if "_sd" in config[KEY_BOOTLOADER]: - bootloader = config[KEY_BOOTLOADER].split("_") - sd_id = bootloader[2][2:] - cg.add_define("USE_SOFTDEVICE_ID", int(sd_id)) - if (len(bootloader)) > 3: - sd_version = bootloader[3][1:] - cg.add_define("USE_SOFTDEVICE_VERSION", int(sd_version)) - # make sure that firmware.zip is created - # for Adafruit_nRF52_Bootloader - cg.add_platformio_option("board_upload.protocol", "nrfutil") - cg.add_platformio_option("board_upload.use_1200bps_touch", "true") - cg.add_platformio_option("board_upload.require_upload_port", "true") - cg.add_platformio_option("board_upload.wait_for_upload_port", "true") + elif "_sd" in config[KEY_BOOTLOADER]: + bootloader = config[KEY_BOOTLOADER].split("_") + sd_id = bootloader[2][2:] + cg.add_define("USE_SOFTDEVICE_ID", int(sd_id)) + if (len(bootloader)) > 3: + sd_version = bootloader[3][1:] + cg.add_define("USE_SOFTDEVICE_VERSION", int(sd_version)) zephyr_setup_preferences() zephyr_to_code(config) @@ -341,6 +392,16 @@ async def _dfu_to_code(dfu_config): def copy_files() -> None: """Copy files to the build directory.""" + + if CORE.using_toolchain_platformio and ( + zephyr_data()[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT + or zephyr_data()[KEY_BOARD] == "xiao_ble" + ): + write_file_if_changed( + CORE.relative_build_path(f"boards/{zephyr_data()[KEY_BOARD]}.json"), + FAKE_BOARD_MANIFEST, + ) + zephyr_copy_files() @@ -415,6 +476,8 @@ def upload_program(config: ConfigType, args, host: str) -> bool: if zephyr_data()[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT: mcumgr_device = host else: + if not CORE.using_toolchain_platformio: + raise EsphomeError("Not implemented yet") result = _upload_using_platformio(config, host, ["-t", "upload"]) if result != 0: raise EsphomeError(f"Upload failed with result: {result}") diff --git a/esphome/components/nrf52/boards.py b/esphome/components/nrf52/boards.py index 4c33cd99399..564bf560d69 100644 --- a/esphome/components/nrf52/boards.py +++ b/esphome/components/nrf52/boards.py @@ -25,6 +25,14 @@ BOARDS_ZEPHYR = { BOOTLOADER_ADAFRUIT_NRF52_SD140_V6, ] }, + "adafruit_itsybitsy": { + KEY_BOOTLOADER: [ + BOOTLOADER_ADAFRUIT_NRF52_SD140_V6, + BOOTLOADER_ADAFRUIT, + BOOTLOADER_ADAFRUIT_NRF52_SD132, + BOOTLOADER_ADAFRUIT_NRF52_SD140_V7, + ] + }, } # https://github.com/ffenix113/zigbee_home/blob/17bb7b9e9d375e756da9e38913f53303937fb66a/types/board/known_boards.go diff --git a/esphome/components/zephyr/pre_build.py.script b/esphome/components/nrf52/pre_build.py.script similarity index 100% rename from esphome/components/zephyr/pre_build.py.script rename to esphome/components/nrf52/pre_build.py.script diff --git a/esphome/components/zephyr/__init__.py b/esphome/components/zephyr/__init__.py index 5dccecc0974..57f5778d547 100644 --- a/esphome/components/zephyr/__init__.py +++ b/esphome/components/zephyr/__init__.py @@ -10,9 +10,7 @@ from esphome.helpers import copy_file_if_changed, write_file_if_changed from esphome.types import ConfigType from .const import ( - BOOTLOADER_MCUBOOT, CONF_CDC_ACM, - KEY_BOARD, KEY_BOOTLOADER, KEY_EXTRA_BUILD_FILES, KEY_KCONFIG, @@ -50,8 +48,8 @@ class Section: class ZephyrData(TypedDict): board: str bootloader: str - prj_conf: dict[str, tuple[PrjConfValueType, bool]] - overlay: str + prj_conf: dict[str, dict[str, tuple[PrjConfValueType, bool]]] + overlay: dict[str, str] extra_build_files: dict[str, Path] pm_static: list[Section] user: dict[str, list[str]] @@ -63,7 +61,9 @@ def zephyr_set_core_data(config: ConfigType) -> None: board=config[CONF_BOARD], bootloader=config[KEY_BOOTLOADER], prj_conf={}, - overlay="", + overlay={ + "": "", + }, # set empty to make sure that overlay is cleared after config change extra_build_files={}, pm_static=[], user={}, @@ -76,12 +76,14 @@ def zephyr_data() -> ZephyrData: def zephyr_add_prj_conf( - name: str, value: PrjConfValueType, required: bool = True + name: str, value: PrjConfValueType, required: bool = True, image: str = "" ) -> None: """Set an zephyr prj conf value.""" if not name.startswith("CONFIG_"): name = "CONFIG_" + name - prj_conf = zephyr_data()[KEY_PRJ_CONF] + if image not in zephyr_data()[KEY_PRJ_CONF]: + zephyr_data()[KEY_PRJ_CONF][image] = {} + prj_conf = zephyr_data()[KEY_PRJ_CONF][image] if name not in prj_conf: prj_conf[name] = (value, required) return @@ -94,8 +96,11 @@ def zephyr_add_prj_conf( prj_conf[name] = (value, required) -def zephyr_add_overlay(content): - zephyr_data()[KEY_OVERLAY] += textwrap.dedent(content) +def zephyr_add_overlay(content: str, image: str = "") -> None: + data = zephyr_data() + if image not in data[KEY_OVERLAY]: + data[KEY_OVERLAY][image] = "" + data[KEY_OVERLAY][image] += textwrap.dedent(content) def add_extra_build_file(filename: str, path: Path) -> bool: @@ -118,8 +123,6 @@ def zephyr_to_code(config: ConfigType) -> None: cg.add_build_flag("-DUSE_ZEPHYR") cg.add_define("USE_NATIVE_64BIT_TIME") cg.set_cpp_standard("gnu++20") - # build is done by west so bypass board checking in platformio - cg.add_platformio_option("boards_dir", CORE.relative_build_path("boards")) # c++ support zephyr_add_prj_conf("NEWLIB_LIBC", True) zephyr_add_prj_conf("FPU", True) @@ -132,18 +135,12 @@ def zephyr_to_code(config: ConfigType) -> None: # os: Illegal load of EXC_RETURN into PC zephyr_add_prj_conf("MAIN_STACK_SIZE", 2048) - add_extra_script( - "pre", - "pre_build.py", - Path(__file__).parent / "pre_build.py.script", - ) - CORE.add_job(_cdc_acm_to_code, config) @coroutine_with_priority(CoroPriority.FINAL) async def _cdc_acm_to_code(config: ConfigType) -> None: - if "CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT" in zephyr_data()[KEY_PRJ_CONF]: + if "CONFIG_CDC_ACM_DTE_RATE_CALLBACK_SUPPORT" in zephyr_data()[KEY_PRJ_CONF][""]: var = cg.new_Pvariable(config[CONF_CDC_ACM]) await cg.register_component(var, {}) @@ -219,55 +216,28 @@ def copy_files(): """ ) - want_opts = zephyr_data()[KEY_PRJ_CONF] - - prj_conf = ( - "\n".join( - f"{name}={_format_prj_conf_val(value[0])}" - for name, value in sorted(want_opts.items()) + for image, want_opts in zephyr_data()[KEY_PRJ_CONF].items(): + prj_conf = ( + "\n".join( + f"{name}={_format_prj_conf_val(value[0])}" + for name, value in sorted(want_opts.items()) + ) + + "\n" ) - + "\n" - ) - write_file_if_changed(CORE.relative_build_path("zephyr/prj.conf"), prj_conf) + if image: + path = CORE.relative_build_path(f"sysbuild/{image}.conf") + else: + path = CORE.relative_build_path("zephyr/prj.conf") - write_file_if_changed( - CORE.relative_build_path("zephyr/app.overlay"), - zephyr_data()[KEY_OVERLAY], - ) + write_file_if_changed(CORE.relative_build_path(path), prj_conf) - if ( - zephyr_data()[KEY_BOOTLOADER] == BOOTLOADER_MCUBOOT - or zephyr_data()[KEY_BOARD] == "xiao_ble" - ): - fake_board_manifest = """ -{ - "frameworks": [ - "zephyr" - ], - "name": "esphome nrf52", - "upload": { - "maximum_ram_size": 248832, - "maximum_size": 815104, - "speed": 115200 - }, - "url": "https://esphome.io/", - "vendor": "esphome", - "build": { - "bsp": { - "name": "adafruit" - }, - "softdevice": { - "sd_fwid": "0x00B6" - } - } -} -""" - - write_file_if_changed( - CORE.relative_build_path(f"boards/{zephyr_data()[KEY_BOARD]}.json"), - fake_board_manifest, - ) + for image, content in zephyr_data()[KEY_OVERLAY].items(): + if image: + path = CORE.relative_build_path(f"sysbuild/{image}.overlay") + else: + path = CORE.relative_build_path("zephyr/app.overlay") + write_file_if_changed(path, content) for filename, path in zephyr_data()[KEY_EXTRA_BUILD_FILES].items(): copy_file_if_changed( From 4ac7bc46064250ca119d335d37cbc931806c931c Mon Sep 17 00:00:00 2001 From: luar123 <49960470+luar123@users.noreply.github.com> Date: Mon, 11 May 2026 16:51:47 +0200 Subject: [PATCH 40/52] [zigbee] Add sensor support on esp32 (#16026) --- esphome/components/zigbee/__init__.py | 11 +- esphome/components/zigbee/const.py | 113 ++++++++++++++++++ esphome/components/zigbee/const_esp32.py | 4 + .../zigbee/zigbee_attribute_esp32.h | 11 ++ esphome/components/zigbee/zigbee_ep_esp32.py | 29 +++++ esphome/components/zigbee/zigbee_esp32.py | 69 +++++++++-- .../components/zigbee/zigbee_helpers_esp32.c | 7 ++ esphome/components/zigbee/zigbee_zephyr.py | 66 +--------- esphome/const.py | 1 + tests/components/zigbee/common_esp32.yaml | 6 +- 10 files changed, 238 insertions(+), 79 deletions(-) diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index 8605b4fa1a3..a7e9d1096f7 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -36,6 +36,7 @@ from .const_zephyr import ( from .zigbee_esp32 import ( final_validate_esp32, validate_binary_sensor_esp32, + validate_sensor_esp32, zigbee_require_vfs_select, ) from .zigbee_zephyr import ( @@ -49,8 +50,7 @@ _LOGGER = logging.getLogger(__name__) CODEOWNERS = ["@luar123", "@tomaszduda23"] - -BINARY_SENSOR_SCHEMA = cv.Schema( +BASE_SCHEMA = cv.Schema( { cv.Optional(CONF_REPORT): cv.All( cv.requires_component("zigbee"), @@ -58,8 +58,9 @@ BINARY_SENSOR_SCHEMA = cv.Schema( cv.enum(REPORT, lower=True), ) } -).extend(zephyr_binary_sensor) -SENSOR_SCHEMA = cv.Schema({}).extend(zephyr_sensor) +) +BINARY_SENSOR_SCHEMA = cv.Schema({}).extend(BASE_SCHEMA).extend(zephyr_binary_sensor) +SENSOR_SCHEMA = cv.Schema({}).extend(BASE_SCHEMA).extend(zephyr_sensor) SWITCH_SCHEMA = cv.Schema({}).extend(zephyr_switch) NUMBER_SCHEMA = cv.Schema({}).extend(zephyr_number) @@ -227,7 +228,7 @@ def validate_sensor(config: ConfigType) -> ConfigType: if "zigbee" not in CORE.loaded_integrations or config.get(CONF_INTERNAL): return config if CORE.is_esp32: - return config + return validate_sensor_esp32(config) return consume_endpoint(config) diff --git a/esphome/components/zigbee/const.py b/esphome/components/zigbee/const.py index 26ae2cc0ec4..7d0e14c67aa 100644 --- a/esphome/components/zigbee/const.py +++ b/esphome/components/zigbee/const.py @@ -1,4 +1,47 @@ +from enum import IntEnum + import esphome.codegen as cg +from esphome.const import ( + DEVICE_CLASS_CURRENT, + DEVICE_CLASS_DURATION, + DEVICE_CLASS_ENERGY, + DEVICE_CLASS_FREQUENCY, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_POWER, + DEVICE_CLASS_PRESSURE, + DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLUME_FLOW_RATE, + UNIT_AMPERE, + UNIT_CELSIUS, + UNIT_CENTIMETER, + UNIT_DECIBEL, + UNIT_HECTOPASCAL, + UNIT_HERTZ, + UNIT_HOUR, + UNIT_KELVIN, + UNIT_KILOMETER, + UNIT_KILOWATT, + UNIT_KILOWATT_HOURS, + UNIT_LITRE_PER_SECOND, + UNIT_LUX, + UNIT_METER, + UNIT_MICROGRAMS_PER_CUBIC_METER, + UNIT_MILLIAMP, + UNIT_MILLIGRAMS_PER_CUBIC_METER, + UNIT_MILLIMETER, + UNIT_MILLISECOND, + UNIT_MILLIVOLT, + UNIT_MINUTE, + UNIT_OHM, + UNIT_PARTS_PER_BILLION, + UNIT_PARTS_PER_MILLION, + UNIT_PASCAL, + UNIT_PERCENT, + UNIT_SECOND, + UNIT_VOLT, + UNIT_WATT, + UNIT_WATT_HOURS, +) zigbee_ns = cg.esphome_ns.namespace("zigbee") ZigbeeComponent = zigbee_ns.class_("ZigbeeComponent", cg.Component) @@ -30,3 +73,73 @@ POWER_SOURCE = { } KEY_ZIGBEE = "zigbee" + +# BACnet engineering units mapping (ZCL uses BACnet unit codes) +# See: https://github.com/zigpy/zha/blob/dev/zha/application/platforms/number/bacnet.py +BACNET_UNITS = { + UNIT_CELSIUS: 62, + UNIT_KELVIN: 63, + UNIT_VOLT: 5, + UNIT_MILLIVOLT: 124, + UNIT_AMPERE: 3, + UNIT_MILLIAMP: 2, + UNIT_OHM: 4, + UNIT_WATT: 47, + UNIT_KILOWATT: 48, + UNIT_WATT_HOURS: 18, + UNIT_KILOWATT_HOURS: 19, + UNIT_PASCAL: 53, + UNIT_HECTOPASCAL: 133, + UNIT_HERTZ: 27, + UNIT_MILLIMETER: 30, + UNIT_CENTIMETER: 118, + UNIT_METER: 31, + UNIT_KILOMETER: 193, + UNIT_MILLISECOND: 159, + UNIT_SECOND: 73, + UNIT_MINUTE: 72, + UNIT_HOUR: 71, + UNIT_PARTS_PER_MILLION: 96, + UNIT_PARTS_PER_BILLION: 97, + UNIT_MICROGRAMS_PER_CUBIC_METER: 219, + UNIT_MILLIGRAMS_PER_CUBIC_METER: 218, + UNIT_LUX: 37, + UNIT_DECIBEL: 199, + UNIT_PERCENT: 98, +} +BACNET_UNIT_NO_UNITS = 95 + + +class AnalogInputType(IntEnum): + TEMP_DEGREES_C = 0x00 + RELATIVE_HUMIDITY_PERCENT = 0x01 + PRESSURE_PASCAL = 0x02 + FLOW_LITERS_PER_SEC = 0x03 + PERCENTAGE = 0x04 + PARTS_PER_MILLION = 0x05 + ROTATIONAL_SPEED_RPM = 0x06 + CURRENT_AMPS = 0x07 + FREQUENCY_HZ = 0x08 + POWER_WATTS = 0x09 + POWER_KILO_WATTS = 0x0A + ENERGY_KILO_WATT_HOURS = 0x0B + COUNT = 0x0C + ENTHALPY_KJOULES_PER_KG = 0x0D + TIME_SECONDS = 0x0E + + +ANALOG_INPUT_APPTYPE = { + (DEVICE_CLASS_TEMPERATURE, UNIT_CELSIUS): AnalogInputType.TEMP_DEGREES_C, + (DEVICE_CLASS_HUMIDITY, UNIT_PERCENT): AnalogInputType.RELATIVE_HUMIDITY_PERCENT, + (DEVICE_CLASS_PRESSURE, UNIT_PASCAL): AnalogInputType.PRESSURE_PASCAL, + ( + DEVICE_CLASS_VOLUME_FLOW_RATE, + UNIT_LITRE_PER_SECOND, + ): AnalogInputType.FLOW_LITERS_PER_SEC, + (DEVICE_CLASS_CURRENT, UNIT_AMPERE): AnalogInputType.CURRENT_AMPS, + (DEVICE_CLASS_FREQUENCY, UNIT_HERTZ): AnalogInputType.FREQUENCY_HZ, + (DEVICE_CLASS_POWER, UNIT_WATT): AnalogInputType.POWER_WATTS, + (DEVICE_CLASS_POWER, UNIT_KILOWATT): AnalogInputType.POWER_KILO_WATTS, + (DEVICE_CLASS_ENERGY, UNIT_KILOWATT_HOURS): AnalogInputType.ENERGY_KILO_WATT_HOURS, + (DEVICE_CLASS_DURATION, UNIT_SECOND): AnalogInputType.TIME_SECONDS, +} diff --git a/esphome/components/zigbee/const_esp32.py b/esphome/components/zigbee/const_esp32.py index 682638439e9..bb507320eb0 100644 --- a/esphome/components/zigbee/const_esp32.py +++ b/esphome/components/zigbee/const_esp32.py @@ -11,6 +11,7 @@ CONF_CLUSTER = "cluster" SCALE = "scale" CONF_ATTRIBUTE_ID = "attribute_id" KEY_BS_EP = "binary_sensor_ep" +KEY_SENSOR_EP = "sensor_ep" ha_standard_devices = cg.esphome_ns.enum("zb_ha_standard_devs_e") DEVICE_ID = { @@ -22,6 +23,7 @@ cluster_id = cg.esphome_ns.enum("esp_zb_zcl_cluster_id_t") CLUSTER_ID = { "BASIC": cluster_id.ESP_ZB_ZCL_CLUSTER_ID_BASIC, "BINARY_INPUT": cluster_id.ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT, + "ANALOG_INPUT": cluster_id.ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, } cluster_role = cg.esphome_ns.enum("esp_zb_zcl_cluster_role_t") CLUSTER_ROLE = { @@ -32,4 +34,6 @@ ATTR_TYPE = { "BOOL": attr_type.ESP_ZB_ZCL_ATTR_TYPE_BOOL, "8BITMAP": attr_type.ESP_ZB_ZCL_ATTR_TYPE_8BITMAP, "CHAR_STRING": attr_type.ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING, + "SINGLE": attr_type.ESP_ZB_ZCL_ATTR_TYPE_SINGLE, + "DOUBLE": attr_type.ESP_ZB_ZCL_ATTR_TYPE_DOUBLE, } diff --git a/esphome/components/zigbee/zigbee_attribute_esp32.h b/esphome/components/zigbee/zigbee_attribute_esp32.h index 5a0cfc4fbd7..90a5cf8ff9b 100644 --- a/esphome/components/zigbee/zigbee_attribute_esp32.h +++ b/esphome/components/zigbee/zigbee_attribute_esp32.h @@ -12,6 +12,9 @@ #include "esp_zigbee_core.h" #include "zigbee_esp32.h" +#ifdef USE_SENSOR +#include "esphome/components/sensor/sensor.h" +#endif #ifdef USE_BINARY_SENSOR #include "esphome/components/binary_sensor/binary_sensor.h" #endif @@ -42,6 +45,9 @@ class ZigbeeAttribute : public Component { template void set_attr(const T &value); uint8_t attr_type() { return attr_type_; } void set_report(bool force); +#ifdef USE_SENSOR + template void connect(sensor::Sensor *sensor); +#endif #ifdef USE_BINARY_SENSOR template void connect(binary_sensor::BinarySensor *sensor); #endif @@ -78,6 +84,11 @@ template void ZigbeeAttribute::set_attr(const T &value) { this->enable_loop(); } +#ifdef USE_SENSOR +template void ZigbeeAttribute::connect(sensor::Sensor *sensor) { + sensor->add_on_state_callback([this](float value) { this->set_attr((T) (this->scale_ * value)); }); +} +#endif #ifdef USE_BINARY_SENSOR template void ZigbeeAttribute::connect(binary_sensor::BinarySensor *sensor) { sensor->add_on_state_callback([this](bool value) { this->set_attr((T) (this->scale_ * value)); }); diff --git a/esphome/components/zigbee/zigbee_ep_esp32.py b/esphome/components/zigbee/zigbee_ep_esp32.py index 791232d4633..5dd76e99038 100644 --- a/esphome/components/zigbee/zigbee_ep_esp32.py +++ b/esphome/components/zigbee/zigbee_ep_esp32.py @@ -46,6 +46,35 @@ ep_configs: dict[str, dict[str, Any]] = { }, ], }, + "analog_input": { + DEVICE_TYPE: "CUSTOM_ATTR", + CONF_CLUSTERS: [ + { + CONF_ID: "ANALOG_INPUT", + ROLE: CLUSTER_ROLE["SERVER"], + CONF_ATTRIBUTES: [ + { + CONF_ATTRIBUTE_ID: 0x55, + CONF_TYPE: "SINGLE", + CONF_REPORT: REPORT["enable"], + CONF_DEVICE: None, + }, + { + CONF_ATTRIBUTE_ID: 0x51, + CONF_TYPE: "BOOL", + }, + { + CONF_ATTRIBUTE_ID: 0x6F, + CONF_TYPE: "8BITMAP", + }, + { + CONF_ATTRIBUTE_ID: 0x1C, + CONF_TYPE: "CHAR_STRING", + }, + ], + }, + ], + }, } diff --git a/esphome/components/zigbee/zigbee_esp32.py b/esphome/components/zigbee/zigbee_esp32.py index 9081582c7be..99238f758e8 100644 --- a/esphome/components/zigbee/zigbee_esp32.py +++ b/esphome/components/zigbee/zigbee_esp32.py @@ -16,11 +16,13 @@ import esphome.config_validation as cv from esphome.const import ( CONF_AP, CONF_DEVICE, + CONF_DEVICE_CLASS, CONF_ID, CONF_MAX_LENGTH, CONF_MODEL, CONF_NAME, CONF_TYPE, + CONF_UNIT_OF_MEASUREMENT, CONF_VALUE, CONF_WIFI, ) @@ -29,7 +31,16 @@ from esphome.coroutine import CoroPriority, coroutine_with_priority import esphome.final_validate as fv from esphome.types import ConfigType -from .const import CONF_REPORT, CONF_ROUTER, KEY_ZIGBEE, REPORT, ZigbeeAttribute +from .const import ( + ANALOG_INPUT_APPTYPE, + BACNET_UNIT_NO_UNITS, + BACNET_UNITS, + CONF_REPORT, + CONF_ROUTER, + KEY_ZIGBEE, + REPORT, + ZigbeeAttribute, +) from .const_esp32 import ( ATTR_TYPE, CLUSTER_ID, @@ -40,6 +51,7 @@ from .const_esp32 import ( DEVICE_ID, DEVICE_TYPE, KEY_BS_EP, + KEY_SENSOR_EP, ROLE, SCALE, ) @@ -55,6 +67,10 @@ def get_c_size(bits: str, options: list[int]) -> str: def get_c_type(attr_type: str) -> Any | None: if attr_type == "BOOL": return cg.bool_ + if attr_type == "SINGLE": + return cg.float_ + if attr_type == "DOUBLE": + return cg.double if "STRING" in attr_type: return cg.std_string test = re.match(r"(^U?)(\d{1,2})(BITMAP$|BIT$|BIT_ENUM$|$)", attr_type) @@ -66,19 +82,23 @@ def get_c_type(attr_type: str) -> Any | None: def get_cv_by_type(attr_type: str) -> Any | None: if attr_type == "BOOL": return cv.boolean + if attr_type in ["SINGLE", "DOUBLE"]: + return cv.float_ if "STRING" in attr_type: return cv.string test = re.match(r"(^U?)(\d{1,2})(BITMAP$|BIT$|BIT_ENUM$|$)", attr_type) if test and test.group(2): return cv.positive_int - return None + raise cv.Invalid(f"Zigbee: type {attr_type} not supported or implemented") -def get_default_by_type(attr_type: str) -> str | bool | int: +def get_default_by_type(attr_type: str) -> str | bool | int | float: if attr_type == "CHAR_STRING": return "" if attr_type == "BOOL": return False + if attr_type in ["SINGLE", "DOUBLE"]: + return float("nan") return 0 @@ -134,9 +154,8 @@ def final_validate_esp32(config: ConfigType) -> ConfigType: return config -def validate_binary_sensor_esp32(config: ConfigType) -> ConfigType: - ep = copy.deepcopy(ep_configs["binary_input"]) - for cl in ep.get(CONF_CLUSTERS, []): +def setup_attributes(config: ConfigType, clusters: list[dict[str, Any]]) -> None: + for cl in clusters: for attr in cl[CONF_ATTRIBUTES]: if ( attr[CONF_ATTRIBUTE_ID] == 0x1C @@ -159,6 +178,41 @@ def validate_binary_sensor_esp32(config: ConfigType) -> ConfigType: else: attr[CONF_ID] = None validate_attributes(attr) + + +def validate_sensor_esp32(config: ConfigType) -> ConfigType: + ep = copy.deepcopy(ep_configs["analog_input"]) + # get application type from device class and meas unit + # if none get BACNET unit from meas unit + dev_class = config.get(CONF_DEVICE_CLASS) + unit = config.get(CONF_UNIT_OF_MEASUREMENT) + apptype = ANALOG_INPUT_APPTYPE.get((dev_class, unit)) + bacunit = BACNET_UNITS.get(unit, BACNET_UNIT_NO_UNITS) + if apptype is not None: + ep[CONF_CLUSTERS][0][CONF_ATTRIBUTES].append( + { + CONF_ATTRIBUTE_ID: 0x100, + CONF_VALUE: (apptype << 16) | 0xFFFF, + CONF_TYPE: "U32", + }, + ) + ep[CONF_CLUSTERS][0][CONF_ATTRIBUTES].append( + { + CONF_ATTRIBUTE_ID: 0x75, + CONF_VALUE: bacunit, + CONF_TYPE: "16BIT_ENUM", + }, + ) + setup_attributes(config, ep[CONF_CLUSTERS]) + zb_data = CORE.data.setdefault(KEY_ZIGBEE, {}) + sensor_ep: list[dict] = zb_data.setdefault(KEY_SENSOR_EP, []) + sensor_ep.append(ep) + return config + + +def validate_binary_sensor_esp32(config: ConfigType) -> ConfigType: + ep = copy.deepcopy(ep_configs["binary_input"]) + setup_attributes(config, ep[CONF_CLUSTERS]) zb_data = CORE.data.setdefault(KEY_ZIGBEE, {}) binary_sensor_ep: list[dict] = zb_data.setdefault(KEY_BS_EP, []) binary_sensor_ep.append(ep) @@ -254,8 +308,9 @@ async def esp32_to_code(config: ConfigType) -> None: # create endpoints zb_data = CORE.data.get(KEY_ZIGBEE, {}) + sensor_ep: list[dict] = zb_data.get(KEY_SENSOR_EP, []) binary_sensor_ep: list[dict] = zb_data.get(KEY_BS_EP, []) - ep_list = create_ep(binary_sensor_ep, config.get(CONF_ROUTER)) + ep_list = create_ep(sensor_ep + binary_sensor_ep, config.get(CONF_ROUTER)) # setup zigbee components var = cg.new_Pvariable(config[CONF_ID]) diff --git a/esphome/components/zigbee/zigbee_helpers_esp32.c b/esphome/components/zigbee/zigbee_helpers_esp32.c index 4ba71ec6098..5254818df49 100644 --- a/esphome/components/zigbee/zigbee_helpers_esp32.c +++ b/esphome/components/zigbee/zigbee_helpers_esp32.c @@ -33,6 +33,9 @@ esp_err_t esphome_zb_cluster_list_add_or_update_cluster(uint16_t cluster_id, esp case ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY: ret = esp_zb_cluster_list_add_identify_cluster(cluster_list, attr_list, role_mask); break; + case ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT: + ret = esp_zb_cluster_list_add_analog_input_cluster(cluster_list, attr_list, role_mask); + break; case ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT: ret = esp_zb_cluster_list_add_binary_input_cluster(cluster_list, attr_list, role_mask); break; @@ -49,6 +52,8 @@ esp_zb_attribute_list_t *esphome_zb_default_attr_list_create(uint16_t cluster_id return esp_zb_basic_cluster_create(NULL); case ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY: return esp_zb_identify_cluster_create(NULL); + case ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT: + return esp_zb_analog_input_cluster_create(NULL); case ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT: return esp_zb_binary_input_cluster_create(NULL); default: @@ -63,6 +68,8 @@ esp_err_t esphome_zb_cluster_add_attr(uint16_t cluster_id, esp_zb_attribute_list return esp_zb_basic_cluster_add_attr(attr_list, attr_id, value_p); case ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY: return esp_zb_identify_cluster_add_attr(attr_list, attr_id, value_p); + case ESP_ZB_ZCL_CLUSTER_ID_ANALOG_INPUT: + return esp_zb_analog_input_cluster_add_attr(attr_list, attr_id, value_p); case ESP_ZB_ZCL_CLUSTER_ID_BINARY_INPUT: return esp_zb_binary_input_cluster_add_attr(attr_list, attr_id, value_p); default: diff --git a/esphome/components/zigbee/zigbee_zephyr.py b/esphome/components/zigbee/zigbee_zephyr.py index b74074e50f8..033511691cc 100644 --- a/esphome/components/zigbee/zigbee_zephyr.py +++ b/esphome/components/zigbee/zigbee_zephyr.py @@ -10,35 +10,6 @@ from esphome.const import ( CONF_MODEL, CONF_NAME, CONF_UNIT_OF_MEASUREMENT, - UNIT_AMPERE, - UNIT_CELSIUS, - UNIT_CENTIMETER, - UNIT_DECIBEL, - UNIT_HECTOPASCAL, - UNIT_HERTZ, - UNIT_HOUR, - UNIT_KELVIN, - UNIT_KILOMETER, - UNIT_KILOWATT, - UNIT_KILOWATT_HOURS, - UNIT_LUX, - UNIT_METER, - UNIT_MICROGRAMS_PER_CUBIC_METER, - UNIT_MILLIAMP, - UNIT_MILLIGRAMS_PER_CUBIC_METER, - UNIT_MILLIMETER, - UNIT_MILLISECOND, - UNIT_MILLIVOLT, - UNIT_MINUTE, - UNIT_OHM, - UNIT_PARTS_PER_BILLION, - UNIT_PARTS_PER_MILLION, - UNIT_PASCAL, - UNIT_PERCENT, - UNIT_SECOND, - UNIT_VOLT, - UNIT_WATT, - UNIT_WATT_HOURS, __version__, ) from esphome.core import CORE, CoroPriority, coroutine_with_priority @@ -50,6 +21,8 @@ from esphome.cpp_generator import ( from esphome.types import ConfigType from .const import ( + BACNET_UNIT_NO_UNITS, + BACNET_UNITS, CONF_ON_JOIN, CONF_POWER_SOURCE, CONF_ROUTER, @@ -86,41 +59,6 @@ ZigbeeSensor = zigbee_ns.class_("ZigbeeSensor", cg.Component) ZigbeeSwitch = zigbee_ns.class_("ZigbeeSwitch", cg.Component) ZigbeeNumber = zigbee_ns.class_("ZigbeeNumber", cg.Component) -# BACnet engineering units mapping (ZCL uses BACnet unit codes) -# See: https://github.com/zigpy/zha/blob/dev/zha/application/platforms/number/bacnet.py -BACNET_UNITS = { - UNIT_CELSIUS: 62, - UNIT_KELVIN: 63, - UNIT_VOLT: 5, - UNIT_MILLIVOLT: 124, - UNIT_AMPERE: 3, - UNIT_MILLIAMP: 2, - UNIT_OHM: 4, - UNIT_WATT: 47, - UNIT_KILOWATT: 48, - UNIT_WATT_HOURS: 18, - UNIT_KILOWATT_HOURS: 19, - UNIT_PASCAL: 53, - UNIT_HECTOPASCAL: 133, - UNIT_HERTZ: 27, - UNIT_MILLIMETER: 30, - UNIT_CENTIMETER: 118, - UNIT_METER: 31, - UNIT_KILOMETER: 193, - UNIT_MILLISECOND: 159, - UNIT_SECOND: 73, - UNIT_MINUTE: 72, - UNIT_HOUR: 71, - UNIT_PARTS_PER_MILLION: 96, - UNIT_PARTS_PER_BILLION: 97, - UNIT_MICROGRAMS_PER_CUBIC_METER: 219, - UNIT_MILLIGRAMS_PER_CUBIC_METER: 218, - UNIT_LUX: 37, - UNIT_DECIBEL: 199, - UNIT_PERCENT: 98, -} -BACNET_UNIT_NO_UNITS = 95 - zephyr_binary_sensor = cv.Schema( { cv.OnlyWith(CONF_ZIGBEE_ID, ["nrf52", "zigbee"]): cv.use_id(ZigbeeComponent), diff --git a/esphome/const.py b/esphome/const.py index c39225fdec0..a256a10e627 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1240,6 +1240,7 @@ UNIT_KILOVOLT_AMPS_REACTIVE_HOURS = "kvarh" UNIT_KILOWATT = "kW" UNIT_KILOWATT_HOURS = "kWh" UNIT_LITRE = "L" +UNIT_LITRE_PER_SECOND = "L/s" UNIT_LUX = "lx" UNIT_MEGAJOULE = "MJ" UNIT_METER = "m" diff --git a/tests/components/zigbee/common_esp32.yaml b/tests/components/zigbee/common_esp32.yaml index 4494b4081d4..94e3f3c8c04 100644 --- a/tests/components/zigbee/common_esp32.yaml +++ b/tests/components/zigbee/common_esp32.yaml @@ -1,10 +1,10 @@ +packages: + - !include common.yaml + binary_sensor: - platform: template name: "Garage Door Open 10" report: "enable" - - platform: template - name: "Garage Door Open 11" - report: "coordinator" - platform: template name: "Garage Door Open 12" report: "force" From a52ca4f80a29d234183e2a1a8de61bf86075d0e3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 May 2026 10:51:08 -0500 Subject: [PATCH 41/52] [ota] Implement host platform OTA backend with re-exec for integration testing (#16304) --- esphome/components/esphome/ota/__init__.py | 1 + .../components/esphome/ota/ota_esphome.cpp | 10 +- esphome/components/host/core.cpp | 74 +++- esphome/components/host/core.h | 22 ++ esphome/components/host/hal.cpp | 18 +- esphome/components/ota/__init__.py | 9 +- esphome/components/ota/ota_backend_host.cpp | 329 +++++++++++++++++- esphome/components/ota/ota_backend_host.h | 21 +- .../components/socket/bsd_sockets_impl.cpp | 10 +- esphome/core/__init__.py | 3 + .../fixtures/host_ota_rejects_garbage.yaml | 9 + .../fixtures/host_ota_self_update.yaml | 9 + tests/integration/test_host_ota.py | 152 ++++++++ tests/unit_tests/test_core.py | 24 ++ 14 files changed, 664 insertions(+), 27 deletions(-) create mode 100644 esphome/components/host/core.h create mode 100644 tests/integration/fixtures/host_ota_rejects_garbage.yaml create mode 100644 tests/integration/fixtures/host_ota_self_update.yaml create mode 100644 tests/integration/test_host_ota.py diff --git a/esphome/components/esphome/ota/__init__.py b/esphome/components/esphome/ota/__init__.py index ee3b7f0c20d..f7793b1493c 100644 --- a/esphome/components/esphome/ota/__init__.py +++ b/esphome/components/esphome/ota/__init__.py @@ -130,6 +130,7 @@ CONFIG_SCHEMA = cv.All( bk72xx=8892, ln882x=8820, rtl87xx=8892, + host=8082, ): cv.port, cv.Optional(CONF_ALLOW_PARTITION_ACCESS, default=False): cv.boolean, cv.Optional(CONF_PASSWORD): cv.string, diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index 843028fc974..f1857ed6642 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -68,7 +68,7 @@ void ESPHomeOTAComponent::setup() { return; } - err = this->server_->bind((struct sockaddr *) &server, sizeof(server)); + err = this->server_->bind((struct sockaddr *) &server, sl); if (err != 0) { this->server_failed_(LOG_STR("bind")); return; @@ -133,12 +133,12 @@ void ESPHomeOTAComponent::dump_config() { } void ESPHomeOTAComponent::loop() { - // Self-disabling idle loop. Runs when a wake path marks us pending-enable (fast-select - // listener filter, raw-TCP accept_fn_, or host select), finds no work, and goes back - // to sleep. cleanup_connection_() deliberately leaves the loop enabled for one more - // iteration so a connection queued mid-session is still caught here. + // Self-disable idle loop where a wake path re-enables on listener readiness + // (fast-select, raw-TCP accept_fn_). Host BSD select doesn't, so stay enabled. if (this->client_ == nullptr && !this->server_->ready()) { +#ifndef USE_HOST this->disable_loop(); +#endif return; } this->handle_handshake_(); diff --git a/esphome/components/host/core.cpp b/esphome/components/host/core.cpp index 91239758848..9292cd77f61 100644 --- a/esphome/components/host/core.cpp +++ b/esphome/components/host/core.cpp @@ -1,20 +1,92 @@ #ifdef USE_HOST +#include "core.h" + #include "esphome/core/application.h" #include "preferences.h" +#include #include +#include +#include + +#ifdef __APPLE__ +#include +#endif + +#ifdef __linux__ +#include +#endif namespace { volatile sig_atomic_t s_signal_received = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) void signal_handler(int signal) { s_signal_received = signal; } + +char **s_argv = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +std::string *s_exe_path = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) +std::string *s_reexec_path = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) + +std::string resolve_exe_path(const char *argv0) { +#ifdef __linux__ + char buf[PATH_MAX]; + ssize_t len = ::readlink("/proc/self/exe", buf, sizeof(buf) - 1); + if (len > 0) { + buf[len] = '\0'; + return std::string(buf); + } +#endif +#ifdef __APPLE__ + char buf[PATH_MAX]; + uint32_t size = sizeof(buf); + if (_NSGetExecutablePath(buf, &size) == 0) { + char real[PATH_MAX]; + if (::realpath(buf, real) != nullptr) + return std::string(real); + return std::string(buf); + } +#endif + if (argv0 == nullptr) + return {}; + char real[PATH_MAX]; + if (::realpath(argv0, real) != nullptr) + return std::string(real); + return std::string(argv0); +} } // namespace +namespace esphome::host { + +char **get_argv() { return s_argv; } + +const std::string &get_exe_path() { + static const std::string empty; + return s_exe_path != nullptr ? *s_exe_path : empty; +} + +void arm_reexec(const std::string &path) { + if (s_reexec_path != nullptr) + *s_reexec_path = path; +} + +const char *get_reexec_path() { + if (s_reexec_path == nullptr || s_reexec_path->empty()) + return nullptr; + return s_reexec_path->c_str(); +} + +} // namespace esphome::host + // HAL functions live in hal.cpp. void setup(); void loop(); -int main() { +int main(int argc, char **argv) { + s_argv = argv; + static std::string exe_path = resolve_exe_path(argc > 0 ? argv[0] : nullptr); + s_exe_path = &exe_path; + static std::string reexec_path; + s_reexec_path = &reexec_path; + // Install signal handlers for graceful shutdown (flushes preferences to disk) std::signal(SIGINT, signal_handler); std::signal(SIGTERM, signal_handler); diff --git a/esphome/components/host/core.h b/esphome/components/host/core.h new file mode 100644 index 00000000000..ab64119415b --- /dev/null +++ b/esphome/components/host/core.h @@ -0,0 +1,22 @@ +#pragma once +#ifdef USE_HOST + +#include + +namespace esphome::host { + +/// argv captured by main(); stable for process lifetime. +char **get_argv(); + +/// Absolute path to running exe (resolved at startup); empty on failure. +const std::string &get_exe_path(); + +/// Arm an execv on the next arch_restart(). Pass empty to disarm. +void arm_reexec(const std::string &path); + +/// Armed re-exec path, or nullptr. +const char *get_reexec_path(); + +} // namespace esphome::host + +#endif // USE_HOST diff --git a/esphome/components/host/hal.cpp b/esphome/components/host/hal.cpp index c7fef8d2e86..9108c1ea9d3 100644 --- a/esphome/components/host/hal.cpp +++ b/esphome/components/host/hal.cpp @@ -2,10 +2,14 @@ #include "esphome/core/hal.h" #include "esphome/core/helpers.h" +#include "esphome/core/log.h" +#include "core.h" #include +#include #include #include +#include // Empty host namespace block to satisfy ci-custom's lint_namespace check. // HAL functions live in namespace esphome (root) — they are not part of the @@ -50,7 +54,19 @@ void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { res = nanosleep(&ts, &ts); } while (res != 0 && errno == EINTR); } -void arch_restart() { exit(0); } +void arch_restart() { + // Host OTA: if a re-exec is armed, swap binaries instead of exiting. + if (const char *target = host::get_reexec_path()) { + char **argv = host::get_argv(); + if (argv != nullptr) { + execv(target, argv); + // execv only returns on failure. + ESP_LOGE("host", "execv('%s') failed: %s", target, std::strerror(errno)); + exit(1); + } + } + exit(0); +} uint32_t arch_get_cpu_cycle_count() { struct timespec spec; diff --git a/esphome/components/ota/__init__.py b/esphome/components/ota/__init__.py index 579491fe1a3..83d8c611d5e 100644 --- a/esphome/components/ota/__init__.py +++ b/esphome/components/ota/__init__.py @@ -1,5 +1,3 @@ -import logging - from esphome import automation import esphome.codegen as cg from esphome.config_helpers import filter_source_files_from_platform @@ -38,8 +36,6 @@ CONF_ON_PROGRESS = "on_progress" CONF_ON_STATE_CHANGE = "on_state_change" -_LOGGER = logging.getLogger(__name__) - ota_ns = cg.esphome_ns.namespace("ota") OTAComponent = ota_ns.class_("OTAComponent", cg.Component) OTAState = ota_ns.enum("OTAState") @@ -58,10 +54,6 @@ def _ota_final_validate(config): raise cv.Invalid( f"At least one platform must be specified for '{CONF_OTA}'; add '{CONF_PLATFORM}: {CONF_ESPHOME}' for original OTA functionality" ) - if CORE.is_host: - _LOGGER.warning( - "OTA not available for platform 'host'. OTA functionality disabled." - ) FINAL_VALIDATE_SCHEMA = _ota_final_validate @@ -172,5 +164,6 @@ FILTER_SOURCE_FILES = filter_source_files_from_platform( PlatformFramework.RTL87XX_ARDUINO, PlatformFramework.LN882X_ARDUINO, }, + "ota_backend_host.cpp": {PlatformFramework.HOST_NATIVE}, } ) diff --git a/esphome/components/ota/ota_backend_host.cpp b/esphome/components/ota/ota_backend_host.cpp index a2c9f2cc33a..ee503a49e16 100644 --- a/esphome/components/ota/ota_backend_host.cpp +++ b/esphome/components/ota/ota_backend_host.cpp @@ -1,26 +1,339 @@ #ifdef USE_HOST #include "ota_backend_host.h" -#include "esphome/core/defines.h" +#include "esphome/components/host/core.h" +#include "esphome/core/helpers.h" +#include "esphome/core/log.h" + +#include +#include +#include +#include + +#include +#include +#include + +#ifdef __linux__ +#include +#include +#endif + +#ifdef __APPLE__ +#include +#endif namespace esphome::ota { -// Stub implementation - OTA is not supported on host platform. -// All methods return error codes to allow compilation of configs with OTA triggers. +namespace { + +const char *const TAG = "ota.host"; + +constexpr size_t MAX_OTA_SIZE = 256u * 1024u * 1024u; // 256 MiB +constexpr size_t HEADER_PEEK_SIZE = 64; + +ssize_t read_header_(const char *path, uint8_t *buf, size_t len) { + int fd = ::open(path, O_RDONLY); + if (fd < 0) + return -1; + ssize_t got = ::read(fd, buf, len); + ::close(fd); + return got; +} + +#ifdef __linux__ +struct ElfIdent { + bool valid; + uint8_t ei_class; + uint8_t ei_data; + uint16_t e_machine; + uint16_t e_type; +}; + +ElfIdent parse_elf_(const uint8_t *buf, size_t len) { + ElfIdent out{}; + if (len < EI_NIDENT + 4) + return out; + if (buf[EI_MAG0] != ELFMAG0 || buf[EI_MAG1] != ELFMAG1 || buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3) + return out; + out.ei_class = buf[EI_CLASS]; + out.ei_data = buf[EI_DATA]; + // e_type @ 16, e_machine @ 18, both in EI_DATA endianness. + uint16_t e_type; + uint16_t e_machine; + std::memcpy(&e_type, buf + 16, sizeof(e_type)); + std::memcpy(&e_machine, buf + 18, sizeof(e_machine)); + if (out.ei_data == ELFDATA2LSB) { + out.e_type = le16toh(e_type); + out.e_machine = le16toh(e_machine); + } else if (out.ei_data == ELFDATA2MSB) { + out.e_type = be16toh(e_type); + out.e_machine = be16toh(e_machine); + } else { + return out; + } + out.valid = true; + return out; +} + +bool validate_elf_(const char *staging_path, const std::string &exe_path) { + uint8_t new_buf[HEADER_PEEK_SIZE]; + uint8_t cur_buf[HEADER_PEEK_SIZE]; + ssize_t new_n = read_header_(staging_path, new_buf, sizeof(new_buf)); + ssize_t cur_n = read_header_(exe_path.c_str(), cur_buf, sizeof(cur_buf)); + if (new_n < static_cast(EI_NIDENT + 4) || cur_n < static_cast(EI_NIDENT + 4)) { + ESP_LOGE(TAG, "ELF header read failed"); + return false; + } + ElfIdent new_id = parse_elf_(new_buf, new_n); + ElfIdent cur_id = parse_elf_(cur_buf, cur_n); + if (!new_id.valid) { + ESP_LOGE(TAG, "Uploaded payload is not a valid ELF"); + return false; + } + if (!cur_id.valid) { + ESP_LOGE(TAG, "Could not parse running exe ELF header"); + return false; + } + if (new_id.ei_class != cur_id.ei_class) { + ESP_LOGE(TAG, "ELF class mismatch (uploaded=%u, running=%u)", new_id.ei_class, cur_id.ei_class); + return false; + } + if (new_id.ei_data != cur_id.ei_data) { + ESP_LOGE(TAG, "ELF endianness mismatch"); + return false; + } + if (new_id.e_machine != cur_id.e_machine) { + ESP_LOGE(TAG, "ELF e_machine mismatch (uploaded=0x%04x, running=0x%04x)", new_id.e_machine, cur_id.e_machine); + return false; + } + if (new_id.e_type != ET_EXEC && new_id.e_type != ET_DYN) { + ESP_LOGE(TAG, "ELF e_type=%u is not executable", new_id.e_type); + return false; + } + return true; +} +#endif // __linux__ + +#ifdef __APPLE__ +struct MachOIdent { + bool valid; + uint32_t cputype; + uint32_t cpusubtype; +}; + +MachOIdent parse_macho_(const uint8_t *buf, size_t len) { + MachOIdent out{}; + // mach_header is the common prefix of mach_header and mach_header_64; + // cputype/cpusubtype/filetype have identical offsets in both. + if (len < sizeof(struct mach_header)) + return out; + uint32_t magic; + std::memcpy(&magic, buf, sizeof(magic)); + bool swap; + if (magic == MH_MAGIC || magic == MH_MAGIC_64) { + swap = false; + } else if (magic == MH_CIGAM || magic == MH_CIGAM_64) { + swap = true; + } else { + return out; + } + struct mach_header hdr; + std::memcpy(&hdr, buf, sizeof(hdr)); + if (swap) { + hdr.cputype = OSSwapInt32(hdr.cputype); + hdr.cpusubtype = OSSwapInt32(hdr.cpusubtype); + hdr.filetype = OSSwapInt32(hdr.filetype); + } + if (hdr.filetype != MH_EXECUTE) + return out; + out.cputype = hdr.cputype; + out.cpusubtype = hdr.cpusubtype; + out.valid = true; + return out; +} + +bool validate_macho_(const char *staging_path, const std::string &exe_path) { + uint8_t new_buf[HEADER_PEEK_SIZE]; + uint8_t cur_buf[HEADER_PEEK_SIZE]; + ssize_t new_n = read_header_(staging_path, new_buf, sizeof(new_buf)); + ssize_t cur_n = read_header_(exe_path.c_str(), cur_buf, sizeof(cur_buf)); + if (new_n < static_cast(sizeof(struct mach_header)) || + cur_n < static_cast(sizeof(struct mach_header))) { + ESP_LOGE(TAG, "Mach-O header read failed"); + return false; + } + MachOIdent new_id = parse_macho_(new_buf, new_n); + MachOIdent cur_id = parse_macho_(cur_buf, cur_n); + if (!new_id.valid) { + ESP_LOGE(TAG, "Uploaded payload is not a valid thin Mach-O executable"); + return false; + } + if (!cur_id.valid) { + ESP_LOGE(TAG, "Could not parse running exe Mach-O header"); + return false; + } + if (new_id.cputype != cur_id.cputype || new_id.cpusubtype != cur_id.cpusubtype) { + ESP_LOGE(TAG, "Mach-O arch mismatch (uploaded=0x%x/0x%x, running=0x%x/0x%x)", new_id.cputype, new_id.cpusubtype, + cur_id.cputype, cur_id.cpusubtype); + return false; + } + return true; +} +#endif // __APPLE__ + +bool validate_executable_(const char *staging_path, const std::string &exe_path) { +#ifdef __linux__ + return validate_elf_(staging_path, exe_path); +#elif defined(__APPLE__) + return validate_macho_(staging_path, exe_path); +#else + (void) staging_path; + (void) exe_path; + ESP_LOGE(TAG, "Host OTA validation not implemented for this OS"); + return false; +#endif +} + +} // namespace std::unique_ptr make_ota_backend() { return make_unique(); } OTAResponseTypes HostOTABackend::begin(size_t image_size, OTAType ota_type) { - return OTA_RESPONSE_ERROR_UPDATE_PREPARE; + if (ota_type != OTA_TYPE_UPDATE_APP) + return OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE; + // 0 = unknown size (web_server multipart); cap at MAX_OTA_SIZE. + if (image_size > MAX_OTA_SIZE) { + ESP_LOGE(TAG, "Refusing OTA of size %zu (exceeds %zu)", image_size, MAX_OTA_SIZE); + return OTA_RESPONSE_ERROR_UPDATE_PREPARE; + } + + const std::string &exe = host::get_exe_path(); + if (exe.empty()) { + ESP_LOGE(TAG, "Could not resolve running executable path; cannot stage OTA"); + return OTA_RESPONSE_ERROR_UPDATE_PREPARE; + } + this->final_path_ = exe; + this->staging_path_ = exe + ".ota.new"; + + // Clean up any leftover from a prior aborted OTA. + ::unlink(this->staging_path_.c_str()); + + this->fd_ = ::open(this->staging_path_.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755); + if (this->fd_ < 0) { + ESP_LOGE(TAG, "Open '%s' failed: %s", this->staging_path_.c_str(), std::strerror(errno)); + return OTA_RESPONSE_ERROR_UPDATE_PREPARE; + } + + this->expected_size_ = image_size; + this->bytes_written_ = 0; + this->md5_set_ = false; + this->md5_.init(); + + ESP_LOGD(TAG, "OTA begin: staging=%s, size=%zu", this->staging_path_.c_str(), image_size); + return OTA_RESPONSE_OK; } -void HostOTABackend::set_update_md5(const char *expected_md5) {} +void HostOTABackend::set_update_md5(const char *md5) { + if (parse_hex(md5, this->expected_md5_, 16)) + this->md5_set_ = true; +} -OTAResponseTypes HostOTABackend::write(uint8_t *data, size_t len) { return OTA_RESPONSE_ERROR_WRITING_FLASH; } +OTAResponseTypes HostOTABackend::write(uint8_t *data, size_t len) { + if (this->fd_ < 0) + return OTA_RESPONSE_ERROR_WRITING_FLASH; + size_t limit = this->expected_size_ != 0 ? this->expected_size_ : MAX_OTA_SIZE; + if (this->bytes_written_ + len > limit) { + ESP_LOGE(TAG, "Write past size limit (%zu)", limit); + return OTA_RESPONSE_ERROR_WRITING_FLASH; + } -OTAResponseTypes HostOTABackend::end() { return OTA_RESPONSE_ERROR_UPDATE_END; } + size_t remaining = len; + const uint8_t *p = data; + while (remaining > 0) { + ssize_t n = ::write(this->fd_, p, remaining); + if (n < 0) { + if (errno == EINTR) + continue; + ESP_LOGE(TAG, "Write failed: %s", std::strerror(errno)); + return OTA_RESPONSE_ERROR_WRITING_FLASH; + } + p += n; + remaining -= n; + } + this->md5_.add(data, len); + this->bytes_written_ += len; + return OTA_RESPONSE_OK; +} -void HostOTABackend::abort() {} +OTAResponseTypes HostOTABackend::end() { + if (this->fd_ < 0) + return OTA_RESPONSE_ERROR_UPDATE_END; + + if (this->bytes_written_ == 0) { + ESP_LOGE(TAG, "OTA ended with no data written"); + this->abort(); + return OTA_RESPONSE_ERROR_UPDATE_END; + } + if (this->expected_size_ != 0 && this->bytes_written_ != this->expected_size_) { + ESP_LOGE(TAG, "Size mismatch: got %zu, expected %zu", this->bytes_written_, this->expected_size_); + this->abort(); + return OTA_RESPONSE_ERROR_UPDATE_END; + } + + if (this->md5_set_) { + this->md5_.calculate(); + if (!this->md5_.equals_bytes(this->expected_md5_)) { + ESP_LOGE(TAG, "MD5 mismatch"); + this->abort(); + return OTA_RESPONSE_ERROR_MD5_MISMATCH; + } + } + + if (::fsync(this->fd_) != 0) { + ESP_LOGW(TAG, "fsync failed: %s", std::strerror(errno)); + } + ::close(this->fd_); + this->fd_ = -1; + + if (!validate_executable_(this->staging_path_.c_str(), this->final_path_)) { + ::unlink(this->staging_path_.c_str()); + this->staging_path_.clear(); + return OTA_RESPONSE_ERROR_UPDATE_END; + } + + if (::chmod(this->staging_path_.c_str(), 0755) != 0) { + ESP_LOGW(TAG, "chmod failed: %s", std::strerror(errno)); + } + + if (::rename(this->staging_path_.c_str(), this->final_path_.c_str()) != 0) { + ESP_LOGE(TAG, "rename '%s' -> '%s' failed: %s", this->staging_path_.c_str(), this->final_path_.c_str(), + std::strerror(errno)); + ::unlink(this->staging_path_.c_str()); + this->staging_path_.clear(); + return OTA_RESPONSE_ERROR_UPDATE_END; + } + + // arch_restart() (via App::safe_reboot) will execv this path with the original argv. + host::arm_reexec(this->final_path_); + this->staging_path_.clear(); + ESP_LOGI(TAG, "OTA staged at %s; will re-exec on reboot", this->final_path_.c_str()); + return OTA_RESPONSE_OK; +} + +void HostOTABackend::abort() { + if (this->fd_ >= 0) { + ::close(this->fd_); + this->fd_ = -1; + } + if (!this->staging_path_.empty()) { + ::unlink(this->staging_path_.c_str()); + this->staging_path_.clear(); + } + this->expected_size_ = 0; + this->bytes_written_ = 0; + this->md5_set_ = false; +} } // namespace esphome::ota #endif diff --git a/esphome/components/ota/ota_backend_host.h b/esphome/components/ota/ota_backend_host.h index 4451fdfe182..51ffdaeda3e 100644 --- a/esphome/components/ota/ota_backend_host.h +++ b/esphome/components/ota/ota_backend_host.h @@ -2,11 +2,16 @@ #ifdef USE_HOST #include "ota_backend.h" +#include "esphome/components/md5/md5.h" + +#include +#include +#include + namespace esphome::ota { -/// Stub OTA backend for host platform - allows compilation but does not implement OTA. -/// All operations return error codes immediately. This enables configurations with -/// OTA triggers to compile for host platform during development. +/// Host OTA backend: stages new binary to `.ota.new`, validates ELF/Mach-O +/// matches the running arch, renames over ``, and arms execv via arch_restart(). class HostOTABackend final { public: OTAResponseTypes begin(size_t image_size, OTAType ota_type = OTA_TYPE_UPDATE_APP); @@ -15,6 +20,16 @@ class HostOTABackend final { OTAResponseTypes end(); void abort(); bool supports_compression() { return false; } + + protected: + md5::MD5Digest md5_{}; + std::string staging_path_; + std::string final_path_; + size_t expected_size_{0}; + size_t bytes_written_{0}; + uint8_t expected_md5_[16]{}; + int fd_{-1}; + bool md5_set_{false}; }; std::unique_ptr make_ota_backend(); diff --git a/esphome/components/socket/bsd_sockets_impl.cpp b/esphome/components/socket/bsd_sockets_impl.cpp index 8e9968e05c0..ee22e4b97b2 100644 --- a/esphome/components/socket/bsd_sockets_impl.cpp +++ b/esphome/components/socket/bsd_sockets_impl.cpp @@ -14,7 +14,15 @@ namespace esphome::socket { BSDSocketImpl::BSDSocketImpl(int fd, bool monitor_loop) { this->fd_ = fd; - if (!monitor_loop || this->fd_ < 0) + if (this->fd_ < 0) + return; +#ifdef USE_HOST + // Release listening ports on OTA re-exec. + int flags = ::fcntl(this->fd_, F_GETFD, 0); + if (flags >= 0) + ::fcntl(this->fd_, F_SETFD, flags | FD_CLOEXEC); +#endif + if (!monitor_loop) return; #ifdef USE_LWIP_FAST_SELECT this->cached_sock_ = hook_fd_for_fast_select(this->fd_); diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index ef0eddc603a..e13d5668afc 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -782,6 +782,9 @@ class EsphomeCore: return self.relative_build_path("build", f"{self.name}.bin") if self.is_libretiny: return self.relative_pioenvs_path(self.name, "firmware.uf2") + if self.is_host: + # Host builds produce a native ELF/Mach-O named `program`. + return self.relative_pioenvs_path(self.name, "program") return self.relative_pioenvs_path(self.name, "firmware.bin") @property diff --git a/tests/integration/fixtures/host_ota_rejects_garbage.yaml b/tests/integration/fixtures/host_ota_rejects_garbage.yaml new file mode 100644 index 00000000000..ebf7977123d --- /dev/null +++ b/tests/integration/fixtures/host_ota_rejects_garbage.yaml @@ -0,0 +1,9 @@ +esphome: + name: host-ota-test +host: +api: +ota: + - platform: esphome + port: __OTA_PORT__ +logger: + level: DEBUG diff --git a/tests/integration/fixtures/host_ota_self_update.yaml b/tests/integration/fixtures/host_ota_self_update.yaml new file mode 100644 index 00000000000..ebf7977123d --- /dev/null +++ b/tests/integration/fixtures/host_ota_self_update.yaml @@ -0,0 +1,9 @@ +esphome: + name: host-ota-test +host: +api: +ota: + - platform: esphome + port: __OTA_PORT__ +logger: + level: DEBUG diff --git a/tests/integration/test_host_ota.py b/tests/integration/test_host_ota.py new file mode 100644 index 00000000000..e1036fdf1cf --- /dev/null +++ b/tests/integration/test_host_ota.py @@ -0,0 +1,152 @@ +"""End-to-end OTA tests on the host platform. + +Exercises the native OTA protocol against a real host binary, then asserts +pid is preserved across the post-OTA execv. A second OTA on the post-exec +instance covers the FD_CLOEXEC path. +""" + +from __future__ import annotations + +import asyncio +from collections.abc import Generator +from contextlib import contextmanager +import socket + +import pytest + +from esphome import espota2 + +from .conftest import run_binary, wait_and_connect_api_client +from .const import LOCALHOST, PORT_POLL_INTERVAL, PORT_WAIT_TIMEOUT +from .types import CompileFunction, ConfigWriter + +DEVICE_NAME = "host-ota-test" + + +@contextmanager +def _reserve_port() -> Generator[tuple[int, socket.socket]]: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(("", 0)) + try: + yield s.getsockname()[1], s + finally: + s.close() + + +async def _wait_for_port(host: str, port: int, timeout: float) -> None: + """Poll until a TCP port accepts connections, or raise TimeoutError.""" + loop = asyncio.get_running_loop() + deadline = loop.time() + timeout + while loop.time() < deadline: + try: + _, writer = await asyncio.open_connection(host, port) + except (ConnectionRefusedError, OSError): + await asyncio.sleep(PORT_POLL_INTERVAL) + continue + writer.close() + await writer.wait_closed() + return + raise TimeoutError(f"Port {port} on {host} did not open within {timeout}s") + + +@pytest.mark.asyncio +async def test_host_ota_self_update( + yaml_config: str, + write_yaml_config: ConfigWriter, + compile_esphome: CompileFunction, + reserved_tcp_port: tuple[int, socket.socket], +) -> None: + """Self-OTA: upload the running binary back to itself, expect re-exec.""" + api_port, api_socket = reserved_tcp_port + with _reserve_port() as (ota_port, ota_socket): + yaml_config = yaml_config.replace("__OTA_PORT__", str(ota_port)) + config_path = await write_yaml_config(yaml_config) + binary_path = await compile_esphome(config_path) + api_socket.close() + ota_socket.close() + + loop = asyncio.get_running_loop() + ota_staged = loop.create_future() + rebooted = loop.create_future() + + def on_log(line: str) -> None: + if not ota_staged.done() and "OTA staged at" in line: + ota_staged.set_result(True) + if not rebooted.done() and "Rebooting safely" in line: + rebooted.set_result(True) + + async with run_binary(binary_path, line_callback=on_log) as (proc, _lines): + await _wait_for_port(LOCALHOST, api_port, PORT_WAIT_TIMEOUT) + pid_before = proc.pid + async with wait_and_connect_api_client(port=api_port) as client: + info_before = await client.device_info() + assert info_before.name == DEVICE_NAME + + # espota2 is blocking; run in executor. + rc, _ = await loop.run_in_executor( + None, espota2.run_ota, LOCALHOST, ota_port, None, binary_path + ) + assert rc == 0, "espota2 reported failure" + + await asyncio.wait_for(ota_staged, timeout=10.0) + await asyncio.wait_for(rebooted, timeout=10.0) + await _wait_for_port(LOCALHOST, api_port, PORT_WAIT_TIMEOUT) + + # execv preserves pid; mismatch means external respawn. + assert proc.returncode is None, "process exited instead of execing" + assert proc.pid == pid_before + + async with wait_and_connect_api_client(port=api_port) as client: + info_after = await client.device_info() + assert info_after.name == DEVICE_NAME + assert info_after.name == info_before.name + + # Second OTA: catches FD_CLOEXEC regressions (EADDRINUSE on rebind). + rc, _ = await loop.run_in_executor( + None, espota2.run_ota, LOCALHOST, ota_port, None, binary_path + ) + assert rc == 0, "second OTA failed -- listener leaked across execv" + await _wait_for_port(LOCALHOST, api_port, PORT_WAIT_TIMEOUT) + assert proc.pid == pid_before + + +@pytest.mark.asyncio +async def test_host_ota_rejects_garbage( + yaml_config: str, + write_yaml_config: ConfigWriter, + compile_esphome: CompileFunction, + reserved_tcp_port: tuple[int, socket.socket], + integration_test_dir, +) -> None: + """Bogus payload is rejected and the device keeps running.""" + api_port, api_socket = reserved_tcp_port + with _reserve_port() as (ota_port, ota_socket): + yaml_config = yaml_config.replace("__OTA_PORT__", str(ota_port)) + config_path = await write_yaml_config(yaml_config) + binary_path = await compile_esphome(config_path) + + # 192 bytes that are neither ELF nor Mach-O. + bogus_path = integration_test_dir / "bogus.bin" + bogus_path.write_bytes(b"NOT-AN-EXECUTABLE-AT-ALL" * 8) + + api_socket.close() + ota_socket.close() + + async with run_binary(binary_path) as (proc, _lines): + await _wait_for_port(LOCALHOST, api_port, PORT_WAIT_TIMEOUT) + pid_before = proc.pid + + loop = asyncio.get_running_loop() + rc, _ = await loop.run_in_executor( + None, espota2.run_ota, LOCALHOST, ota_port, None, bogus_path + ) + assert rc == 1 + + await asyncio.sleep(0.5) + assert proc.returncode is None, "process died on rejected OTA" + assert proc.pid == pid_before + + async with wait_and_connect_api_client(port=api_port) as client: + info = await client.device_info() + assert info.name == DEVICE_NAME diff --git a/tests/unit_tests/test_core.py b/tests/unit_tests/test_core.py index 1a52e6b29ed..2322fdd014f 100644 --- a/tests/unit_tests/test_core.py +++ b/tests/unit_tests/test_core.py @@ -591,6 +591,30 @@ class TestEsphomeCore: assert target.is_esp32 is False assert target.is_esp8266 is True + def test_firmware_bin__default(self, target): + """Default platforms produce //firmware.bin.""" + target.name = "test-device" + target.data[const.KEY_CORE] = {const.KEY_TARGET_PLATFORM: "esp32"} + assert target.firmware_bin == Path( + "foo/build/.pioenvs/test-device/firmware.bin" + ) + + def test_firmware_bin__libretiny(self, target): + """The libretiny platform produces firmware.uf2.""" + target.name = "test-device" + target.data[const.KEY_CORE] = {const.KEY_TARGET_PLATFORM: "bk72xx"} + assert target.firmware_bin == Path( + "foo/build/.pioenvs/test-device/firmware.uf2" + ) + + def test_firmware_bin__host(self, target): + """Host platform produces a native ELF/Mach-O named `program`, + not firmware.bin -- needed for `esphome upload` to find the + right artifact for the host OTA backend.""" + target.name = "test-device" + target.data[const.KEY_CORE] = {const.KEY_TARGET_PLATFORM: "host"} + assert target.firmware_bin == Path("foo/build/.pioenvs/test-device/program") + @pytest.mark.skipif(os.name == "nt", reason="Unix-specific test") def test_data_dir_default_unix(self, target): """Test data_dir returns .esphome in config directory by default on Unix.""" From ee8ca2a3bf77ab3ba8dd2e7e09bfc80060d60345 Mon Sep 17 00:00:00 2001 From: luar123 <49960470+luar123@users.noreply.github.com> Date: Mon, 11 May 2026 17:54:35 +0200 Subject: [PATCH 42/52] [zigbee] add on_join trigger for esp32 (#16060) Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Co-authored-by: J. Nick Koston Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- esphome/components/zigbee/__init__.py | 17 +++++++++++------ .../zigbee/time/zigbee_time_zephyr.cpp | 2 +- esphome/components/zigbee/zigbee_esp32.cpp | 16 ++++++++++++++-- esphome/components/zigbee/zigbee_esp32.h | 10 ++++++++-- esphome/components/zigbee/zigbee_esp32.py | 4 +++- esphome/components/zigbee/zigbee_zephyr.cpp | 11 +++++------ esphome/components/zigbee/zigbee_zephyr.h | 8 +++----- esphome/components/zigbee/zigbee_zephyr.py | 9 +++------ tests/components/zigbee/common_esp32.yaml | 3 +++ 9 files changed, 51 insertions(+), 29 deletions(-) diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index a7e9d1096f7..286b395e183 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -79,10 +79,7 @@ CONFIG_SCHEMA = cv.All( cv.string, cv.Length(max=31) ), cv.Optional(CONF_ROUTER, default=False): cv.boolean, - cv.Optional(CONF_ON_JOIN): cv.All( - cv.requires_component("nrf52"), - automation.validate_automation(single=True), - ), + cv.Optional(CONF_ON_JOIN): automation.validate_automation({}), cv.OnlyWith(CONF_WIPE_ON_BOOT, "nrf52", default=False): cv.All( cv.Any( cv.boolean, @@ -146,17 +143,25 @@ FINAL_VALIDATE_SCHEMA = cv.All( ) +_CALLBACK_AUTOMATIONS = [ + automation.CallbackAutomation(CONF_ON_JOIN, "add_on_join_callback", [(bool, "x")]), +] + + @coroutine_with_priority(CoroPriority.CORE) async def to_code(config: ConfigType) -> None: cg.add_define("USE_ZIGBEE") + var = None if CORE.using_zephyr: from .zigbee_zephyr import zephyr_to_code - await zephyr_to_code(config) + var = await zephyr_to_code(config) if CORE.is_esp32: from .zigbee_esp32 import esp32_to_code - await esp32_to_code(config) + var = await esp32_to_code(config) + if var is not None: + await automation.build_callback_automations(var, config, _CALLBACK_AUTOMATIONS) async def setup_binary_sensor(entity: cg.MockObj, config: ConfigType) -> None: diff --git a/esphome/components/zigbee/time/zigbee_time_zephyr.cpp b/esphome/components/zigbee/time/zigbee_time_zephyr.cpp index 70ceb60abee..92d238629a1 100644 --- a/esphome/components/zigbee/time/zigbee_time_zephyr.cpp +++ b/esphome/components/zigbee/time/zigbee_time_zephyr.cpp @@ -26,7 +26,7 @@ void ZigbeeTime::setup() { global_time = this; this->parent_->add_callback(this->endpoint_, [this](zb_bufid_t bufid) { this->zcl_device_cb_(bufid); }); synchronize_epoch_(EPOCH_2000); - this->parent_->add_join_callback([this]() { zb_zcl_time_server_synchronize(this->endpoint_, sync_time); }); + this->parent_->add_on_join_callback([this](bool x) { zb_zcl_time_server_synchronize(this->endpoint_, sync_time); }); } void ZigbeeTime::dump_config() { diff --git a/esphome/components/zigbee/zigbee_esp32.cpp b/esphome/components/zigbee/zigbee_esp32.cpp index c16736236a4..733f45cc2ae 100644 --- a/esphome/components/zigbee/zigbee_esp32.cpp +++ b/esphome/components/zigbee/zigbee_esp32.cpp @@ -59,11 +59,13 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { ESP_LOGD(TAG, "Device started up in %sfactory-reset mode", esp_zb_bdb_is_factory_new() ? "" : "non "); global_zigbee->started = true; if (esp_zb_bdb_is_factory_new()) { + global_zigbee->factory_new = true; ESP_LOGD(TAG, "Start network steering"); esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING); } else { ESP_LOGD(TAG, "Device rebooted"); - global_zigbee->connected = true; + global_zigbee->joined = true; + global_zigbee->enable_loop_soon_any_context(); } } else { ESP_LOGE(TAG, "FIRST_START. Device started up in %sfactory-reset mode with an error %d (%s)", @@ -78,7 +80,8 @@ void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct) { steering_retry_count = 0; ESP_LOGI(TAG, "Joined network successfully (PAN ID: 0x%04hx, Channel:%d)", esp_zb_get_pan_id(), esp_zb_get_current_channel()); - global_zigbee->connected = true; + global_zigbee->joined = true; + global_zigbee->enable_loop_soon_any_context(); } else { ESP_LOGI(TAG, "Network steering was not successful (status: %s)", esp_err_to_name(err_status)); if (steering_retry_count < 10) { @@ -283,6 +286,15 @@ void ZigbeeComponent::setup() { } } xTaskCreate(esp_zb_task_, "Zigbee_main", 4096, NULL, 24, NULL); + this->disable_loop(); // loop is only needed for processing events, so disable until we join a network +} + +void ZigbeeComponent::loop() { + if (this->joined.exchange(false)) { + this->connected_ = true; + this->join_cb_.call(this->factory_new); + } + this->disable_loop(); } void ZigbeeComponent::dump_config() { diff --git a/esphome/components/zigbee/zigbee_esp32.h b/esphome/components/zigbee/zigbee_esp32.h index 80ecbfd639e..a9072f6c8d4 100644 --- a/esphome/components/zigbee/zigbee_esp32.h +++ b/esphome/components/zigbee/zigbee_esp32.h @@ -39,6 +39,7 @@ class ZigbeeAttribute; class ZigbeeComponent : public Component { public: void setup() override; + void loop() override; void dump_config() override; esp_err_t create_endpoint(uint8_t endpoint_id, zb_ha_standard_devs_e device_id, esp_zb_cluster_list_t *esp_zb_cluster_list); @@ -59,10 +60,13 @@ class ZigbeeComponent : public Component { esp_zb_lock_release(); } + template void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward(cb)); } + bool is_started() { return this->started; } - bool is_connected() { return this->connected; } - std::atomic connected = false; + bool is_connected() { return this->connected_; } std::atomic started = false; + std::atomic joined = false; + std::atomic factory_new = false; protected: struct { @@ -70,6 +74,7 @@ class ZigbeeComponent : public Component { uint8_t *manufacturer; uint8_t *date; } basic_cluster_data_; + bool connected_ = false; #ifdef ZB_ED_ROLE esp_zb_nwk_device_type_t device_role_ = ESP_ZB_DEVICE_TYPE_ED; #else @@ -89,6 +94,7 @@ class ZigbeeComponent : public Component { // key tuple could be replaced by single 64 (48) bit int with bit fields for endpoint, cluster, role and attr_id std::map, ZigbeeAttribute *> attributes_; esp_zb_ep_list_t *esp_zb_ep_list_ = esp_zb_ep_list_create(); + CallbackManager join_cb_{}; }; extern "C" void esp_zb_app_signal_handler(esp_zb_app_signal_t *signal_struct); diff --git a/esphome/components/zigbee/zigbee_esp32.py b/esphome/components/zigbee/zigbee_esp32.py index 99238f758e8..5b1808ea60d 100644 --- a/esphome/components/zigbee/zigbee_esp32.py +++ b/esphome/components/zigbee/zigbee_esp32.py @@ -28,6 +28,7 @@ from esphome.const import ( ) from esphome.core import CORE from esphome.coroutine import CoroPriority, coroutine_with_priority +from esphome.cpp_generator import MockObj import esphome.final_validate as fv from esphome.types import ConfigType @@ -289,7 +290,7 @@ async def attributes_to_code( cg.add(attr_var.connect(template_arg, device)) -async def esp32_to_code(config: ConfigType) -> None: +async def esp32_to_code(config: ConfigType) -> "MockObj": add_idf_component( name="espressif/esp-zboss-lib", ref="1.6.4", @@ -332,3 +333,4 @@ async def esp32_to_code(config: ConfigType) -> None: ) ) await attributes_to_code(var, ep[CONF_NUM], cl) + return var diff --git a/esphome/components/zigbee/zigbee_zephyr.cpp b/esphome/components/zigbee/zigbee_zephyr.cpp index 26bef8fb174..81aad7dcb17 100644 --- a/esphome/components/zigbee/zigbee_zephyr.cpp +++ b/esphome/components/zigbee/zigbee_zephyr.cpp @@ -40,7 +40,7 @@ void ZigbeeComponent::zboss_signal_handler_esphome(zb_bufid_t bufid) { case ZB_BDB_SIGNAL_DEVICE_REBOOT: ESP_LOGD(TAG, "ZB_BDB_SIGNAL_DEVICE_REBOOT, status: %d", status); if (status == RET_OK) { - on_join_(); + on_join_(false); } break; case ZB_BDB_SIGNAL_STEERING: @@ -88,7 +88,7 @@ void ZigbeeComponent::zboss_signal_handler_esphome(zb_bufid_t bufid) { for (int i = 0; i < addr_len; ++i) { if (ieee_addr_buf[i] != '0') { - on_join_(); + on_join_(true); break; } } @@ -130,11 +130,10 @@ void ZigbeeComponent::zcl_device_cb(zb_bufid_t bufid) { p_device_cb_param->status = RET_NOT_IMPLEMENTED; } -void ZigbeeComponent::on_join_() { - this->defer([this]() { +void ZigbeeComponent::on_join_(bool factory_new) { + this->defer([this, factory_new]() { ESP_LOGD(TAG, "Joined the network"); - this->join_trigger_.trigger(); - this->join_cb_.call(); + this->join_cb_.call(factory_new); }); } diff --git a/esphome/components/zigbee/zigbee_zephyr.h b/esphome/components/zigbee/zigbee_zephyr.h index 0a189ac1e04..d462d2a4031 100644 --- a/esphome/components/zigbee/zigbee_zephyr.h +++ b/esphome/components/zigbee/zigbee_zephyr.h @@ -74,25 +74,23 @@ class ZigbeeComponent : public Component { // endpoints are enumerated from 1 this->callbacks_[endpoint - 1] = std::move(cb); } - template void add_join_callback(F &&cb) { this->join_cb_.add(std::forward(cb)); } + template void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward(cb)); } void zboss_signal_handler_esphome(zb_bufid_t bufid); void after_reporting_info(zb_zcl_configure_reporting_req_t *config_rep_req, zb_zcl_attr_addr_info_t *attr_addr_info); void factory_reset(); - Trigger<> *get_join_trigger() { return &this->join_trigger_; }; void force_report(); void loop() override; void set_sleepy(bool sleepy) { this->sleepy_ = sleepy; } protected: static void zcl_device_cb(zb_bufid_t bufid); - void on_join_(); + void on_join_(bool factory_new); #ifdef USE_ZIGBEE_WIPE_ON_BOOT void erase_flash_(int area); #endif void dump_reporting_(); std::array, ZIGBEE_ENDPOINTS_COUNT> callbacks_{}; - CallbackManager join_cb_; - Trigger<> join_trigger_; + CallbackManager join_cb_; bool force_report_{false}; uint32_t sleep_time_{}; uint32_t sleep_remainder_{}; diff --git a/esphome/components/zigbee/zigbee_zephyr.py b/esphome/components/zigbee/zigbee_zephyr.py index 033511691cc..aa16bbef538 100644 --- a/esphome/components/zigbee/zigbee_zephyr.py +++ b/esphome/components/zigbee/zigbee_zephyr.py @@ -1,7 +1,6 @@ import datetime import random -from esphome import automation import esphome.codegen as cg from esphome.components.zephyr import zephyr_add_prj_conf import esphome.config_validation as cv @@ -23,7 +22,6 @@ from esphome.types import ConfigType from .const import ( BACNET_UNIT_NO_UNITS, BACNET_UNITS, - CONF_ON_JOIN, CONF_POWER_SOURCE, CONF_ROUTER, CONF_WIPE_ON_BOOT, @@ -96,7 +94,7 @@ zephyr_number = cv.Schema( ) -async def zephyr_to_code(config: ConfigType) -> None: +async def zephyr_to_code(config: ConfigType) -> "MockObj": zephyr_add_prj_conf("ZIGBEE", True) zephyr_add_prj_conf("ZIGBEE_APP_UTILS", True) if config[CONF_ROUTER]: @@ -141,15 +139,14 @@ async def zephyr_to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) - if on_join_config := config.get(CONF_ON_JOIN): - await automation.build_automation(var.get_join_trigger(), [], on_join_config) - await cg.register_component(var, config) CORE.add_job(_ctx_to_code, config) cg.add(var.set_sleepy(config[CONF_SLEEPY])) + return var + async def _attr_to_code(config: ConfigType) -> None: # Create the basic attributes structure and attribute list diff --git a/tests/components/zigbee/common_esp32.yaml b/tests/components/zigbee/common_esp32.yaml index 94e3f3c8c04..77e202b5235 100644 --- a/tests/components/zigbee/common_esp32.yaml +++ b/tests/components/zigbee/common_esp32.yaml @@ -12,3 +12,6 @@ binary_sensor: zigbee: model: zigbee_test router: true + on_join: + then: + - logger.log: "Joined network" From e479e8b6414464674c8dc0637e192fbd045b88e4 Mon Sep 17 00:00:00 2001 From: luar123 <49960470+luar123@users.noreply.github.com> Date: Mon, 11 May 2026 20:08:52 +0200 Subject: [PATCH 43/52] [zigbee] Add power_source option to esp32 (#16062) Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- esphome/components/zigbee/__init__.py | 5 ++--- esphome/components/zigbee/zigbee_esp32.cpp | 12 +++++++++--- esphome/components/zigbee/zigbee_esp32.h | 4 +++- esphome/components/zigbee/zigbee_esp32.py | 3 +++ tests/components/zigbee/common_esp32.yaml | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index 286b395e183..69e3fe9c5ae 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -87,9 +87,8 @@ CONFIG_SCHEMA = cv.All( ), cv.requires_component("nrf52"), ), - cv.OnlyWith(CONF_POWER_SOURCE, "nrf52", default="DC_SOURCE"): cv.All( - cv.enum(POWER_SOURCE, upper=True), - cv.requires_component("nrf52"), + cv.Optional(CONF_POWER_SOURCE, default="DC_SOURCE"): cv.enum( + POWER_SOURCE, upper=True ), cv.Optional(CONF_IEEE802154_VENDOR_OUI): cv.All( cv.Any( diff --git a/esphome/components/zigbee/zigbee_esp32.cpp b/esphome/components/zigbee/zigbee_esp32.cpp index 733f45cc2ae..c534a384320 100644 --- a/esphome/components/zigbee/zigbee_esp32.cpp +++ b/esphome/components/zigbee/zigbee_esp32.cpp @@ -153,7 +153,7 @@ void ZigbeeComponent::add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint this->attribute_list_[{endpoint_id, cluster_id, role}] = attr_list; } -void ZigbeeComponent::set_basic_cluster(const char *model, const char *manufacturer) { +void ZigbeeComponent::set_basic_cluster(const char *model, const char *manufacturer, uint8_t power_source) { char date_buf[16]; time_t time_val = App.get_build_time(); struct tm *timeinfo = localtime(&time_val); @@ -162,13 +162,14 @@ void ZigbeeComponent::set_basic_cluster(const char *model, const char *manufactu .model = get_zcl_string(model, 31), .manufacturer = get_zcl_string(manufacturer, 31), .date = get_zcl_string(date_buf, 15), + .power_source = power_source, }; } esp_zb_attribute_list_t *ZigbeeComponent::create_basic_cluster_() { esp_zb_basic_cluster_cfg_t basic_cluster_cfg = { .zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, - .power_source = 0, + .power_source = this->basic_cluster_data_.power_source, }; esp_zb_attribute_list_t *attr_list = esp_zb_basic_cluster_create(&basic_cluster_cfg); esp_zb_basic_cluster_add_attr(attr_list, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, @@ -192,7 +193,12 @@ static void esp_zb_task_(void *pvParameters) { ESP_LOGE(TAG, "Could not setup Zigbee"); vTaskDelete(NULL); } - esp_zb_set_node_descriptor_power_source(1); + if (global_zigbee->is_battery_powered()) { + ESP_LOGD(TAG, "Battery powered!"); + esp_zb_set_node_descriptor_power_source(0); + } else { + esp_zb_set_node_descriptor_power_source(1); + } esp_zb_stack_main_loop(); } diff --git a/esphome/components/zigbee/zigbee_esp32.h b/esphome/components/zigbee/zigbee_esp32.h index a9072f6c8d4..03d3286ab82 100644 --- a/esphome/components/zigbee/zigbee_esp32.h +++ b/esphome/components/zigbee/zigbee_esp32.h @@ -43,7 +43,7 @@ class ZigbeeComponent : public Component { void dump_config() override; esp_err_t create_endpoint(uint8_t endpoint_id, zb_ha_standard_devs_e device_id, esp_zb_cluster_list_t *esp_zb_cluster_list); - void set_basic_cluster(const char *model, const char *manufacturer); + void set_basic_cluster(const char *model, const char *manufacturer, uint8_t power_source); void add_cluster(uint8_t endpoint_id, uint16_t cluster_id, uint8_t role); void create_default_cluster(uint8_t endpoint_id, zb_ha_standard_devs_e device_id); @@ -62,6 +62,7 @@ class ZigbeeComponent : public Component { template void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward(cb)); } + bool is_battery_powered() { return this->basic_cluster_data_.power_source == ESP_ZB_ZCL_BASIC_POWER_SOURCE_BATTERY; } bool is_started() { return this->started; } bool is_connected() { return this->connected_; } std::atomic started = false; @@ -73,6 +74,7 @@ class ZigbeeComponent : public Component { uint8_t *model; uint8_t *manufacturer; uint8_t *date; + uint8_t power_source; } basic_cluster_data_; bool connected_ = false; #ifdef ZB_ED_ROLE diff --git a/esphome/components/zigbee/zigbee_esp32.py b/esphome/components/zigbee/zigbee_esp32.py index 5b1808ea60d..e446377a06b 100644 --- a/esphome/components/zigbee/zigbee_esp32.py +++ b/esphome/components/zigbee/zigbee_esp32.py @@ -36,9 +36,11 @@ from .const import ( ANALOG_INPUT_APPTYPE, BACNET_UNIT_NO_UNITS, BACNET_UNITS, + CONF_POWER_SOURCE, CONF_REPORT, CONF_ROUTER, KEY_ZIGBEE, + POWER_SOURCE, REPORT, ZigbeeAttribute, ) @@ -320,6 +322,7 @@ async def esp32_to_code(config: ConfigType) -> "MockObj": var.set_basic_cluster( config[CONF_MODEL], "esphome", + cg.RawExpression(POWER_SOURCE[config[CONF_POWER_SOURCE]]), ) ) for ep in ep_list: diff --git a/tests/components/zigbee/common_esp32.yaml b/tests/components/zigbee/common_esp32.yaml index 77e202b5235..82a523fc7c4 100644 --- a/tests/components/zigbee/common_esp32.yaml +++ b/tests/components/zigbee/common_esp32.yaml @@ -12,6 +12,7 @@ binary_sensor: zigbee: model: zigbee_test router: true + power_source: MAINS_SINGLE_PHASE on_join: then: - logger.log: "Joined network" From 55ef66cc265ceae81e9c872eb49b47ab1662c6d5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 May 2026 13:12:55 -0500 Subject: [PATCH 44/52] [helpers] Re-enable ProgressBar under --dashboard mode (#16357) --- esphome/helpers.py | 11 ++++++++- tests/unit_tests/test_helpers.py | 42 ++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 62ddc489ba2..d7ddb5c4161 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -618,10 +618,19 @@ class ProgressBar: """A simple terminal progress bar for upload operations.""" def __init__(self, header: str, stream: TextIO | None = None) -> None: + # Local import to avoid a top-level cycle with esphome.core. + from esphome.core import CORE + self.header = header self.stream = stream or sys.stderr self.last_progress: int | None = None - self.enabled = hasattr(self.stream, "isatty") and self.stream.isatty() + # Enable when writing to an interactive TTY *or* when running under + # ``--dashboard``. The dashboard captures our stderr via + # ``stdout=PIPE, stderr=STDOUT`` and parses the ``\rUploading: NN%`` + # frames to drive its own progress UI -- gating purely on ``isatty()`` + # silently disables every dashboard-side flash-progress indicator. + is_tty = hasattr(self.stream, "isatty") and self.stream.isatty() + self.enabled = is_tty or CORE.dashboard def update(self, progress: float) -> None: if not self.enabled: diff --git a/tests/unit_tests/test_helpers.py b/tests/unit_tests/test_helpers.py index f2faf3ba8f9..bb00a15beef 100644 --- a/tests/unit_tests/test_helpers.py +++ b/tests/unit_tests/test_helpers.py @@ -1,9 +1,10 @@ +import io import logging import os from pathlib import Path import socket import stat -from unittest.mock import patch +from unittest.mock import MagicMock, patch from aioesphomeapi.host_resolver import AddrInfo, IPv4Sockaddr, IPv6Sockaddr from hypothesis import given @@ -12,7 +13,8 @@ import pytest from esphome import helpers from esphome.address_cache import AddressCache -from esphome.core import EsphomeError +from esphome.core import CORE, EsphomeError +from esphome.helpers import ProgressBar @pytest.mark.parametrize( @@ -1024,3 +1026,39 @@ def test_resolve_ip_address_mixed_cached_uncached() -> None: assert "192.168.1.10" in addresses # Direct IP assert "192.168.1.50" in addresses # From cache assert "192.168.1.100" in addresses # From resolver + + +def test_progressbar_enabled_on_tty(monkeypatch) -> None: + """Interactive TTY: progress writes through (pre-existing behaviour).""" + stream = MagicMock(spec=io.TextIOWrapper) + stream.isatty.return_value = True + monkeypatch.setattr(CORE, "dashboard", False) + + bar = ProgressBar("Uploading", stream=stream) + assert bar.enabled is True + + +def test_progressbar_disabled_on_pipe_without_dashboard(monkeypatch) -> None: + """Piped output without --dashboard: progress suppressed.""" + stream = MagicMock(spec=io.TextIOWrapper) + stream.isatty.return_value = False + monkeypatch.setattr(CORE, "dashboard", False) + + bar = ProgressBar("Uploading", stream=stream) + assert bar.enabled is False + + +def test_progressbar_enabled_on_pipe_with_dashboard(monkeypatch) -> None: + r"""Piped output under --dashboard: progress writes through. + + The dashboard captures stderr through a pipe (so ``isatty()`` is False) + and parses ``\rUploading: NN%`` frames to drive its progress UI. + Gating purely on ``isatty()`` silently disables every dashboard-side + flash-progress indicator. + """ + stream = MagicMock(spec=io.TextIOWrapper) + stream.isatty.return_value = False + monkeypatch.setattr(CORE, "dashboard", True) + + bar = ProgressBar("Uploading", stream=stream) + assert bar.enabled is True From 4e31b713048d0dd9385434d2d9599baa168d506d Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Tue, 12 May 2026 08:52:33 +1000 Subject: [PATCH 45/52] [lvgl] Add new trigger `on_update` and new number option (#16312) --- esphome/components/lvgl/defines.py | 11 ++++- esphome/components/lvgl/lvcode.py | 3 +- esphome/components/lvgl/number/__init__.py | 37 ++++++++++----- esphome/components/lvgl/number/lvgl_number.h | 9 +--- esphome/components/lvgl/schemas.py | 25 +++++++++- esphome/components/lvgl/sensor/__init__.py | 18 +++---- esphome/components/lvgl/trigger.py | 8 ++++ esphome/components/lvgl/types.py | 3 +- esphome/components/lvgl/widgets/__init__.py | 13 ++--- esphome/components/lvgl/widgets/spinbox.py | 4 +- tests/components/lvgl/common.yaml | 2 +- tests/components/lvgl/lvgl-package.yaml | 50 ++++++++++++++++++++ 12 files changed, 135 insertions(+), 48 deletions(-) diff --git a/esphome/components/lvgl/defines.py b/esphome/components/lvgl/defines.py index 7bfd26bb6ec..15a24f1ad2f 100644 --- a/esphome/components/lvgl/defines.py +++ b/esphome/components/lvgl/defines.py @@ -20,7 +20,6 @@ from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor from esphome.types import Expression, SafeExpType LOGGER = logging.getLogger(__name__) -lvgl_ns = cg.esphome_ns.namespace("lvgl") DOMAIN = "lvgl" KEY_COLOR_FORMATS = "color_formats" @@ -400,6 +399,13 @@ LV_EVENT_MAP = { LV_PRESS_EVENTS = ("PRESS", "PRESSING", "RELEASE") +VALUE_ON_CHANGE = "on_change" +VALUE_ON_UPDATE = "on_update" +VALUE_ON_VALUE = "on_value" +VALUE_ON_RELEASE = "on_release" + +LV_VALUE_EVENTS = (VALUE_ON_CHANGE, VALUE_ON_UPDATE, VALUE_ON_VALUE, VALUE_ON_RELEASE) + def is_press_event(event: str) -> bool: return event.removeprefix("on_").upper() in LV_PRESS_EVENTS @@ -788,6 +794,7 @@ CONF_SKIP = "skip" CONF_SYMBOL = "symbol" CONF_TAB_ID = "tab_id" CONF_TABS = "tabs" +CONF_THEME = "theme" CONF_TICK_STYLE = "tick_style" CONF_TIME_FORMAT = "time_format" CONF_TILE = "tile" @@ -799,7 +806,7 @@ CONF_TOUCHSCREENS = "touchscreens" CONF_TRANSFORM_ROTATION = "transform_rotation" CONF_TRANSFORM_SCALE = "transform_scale" CONF_TRANSPARENCY_KEY = "transparency_key" -CONF_THEME = "theme" +CONF_TRIGGER = "trigger" CONF_UPDATE_ON_RELEASE = "update_on_release" CONF_UPDATE_WHEN_DISPLAY_IDLE = "update_when_display_idle" CONF_VISIBLE_ROW_COUNT = "visible_row_count" diff --git a/esphome/components/lvgl/lvcode.py b/esphome/components/lvgl/lvcode.py index 32fb02e3d21..de005937730 100644 --- a/esphome/components/lvgl/lvcode.py +++ b/esphome/components/lvgl/lvcode.py @@ -20,7 +20,8 @@ from esphome.cpp_generator import ( ) from esphome.yaml_util import ESPHomeDataBase -from .defines import literal, lvgl_ns +from .defines import literal +from .types import lvgl_ns LVGL_COMP = "lv_component" # used as a lambda argument in lvgl_comp() diff --git a/esphome/components/lvgl/number/__init__.py b/esphome/components/lvgl/number/__init__.py index 0c7e4b9524a..be51963ba12 100644 --- a/esphome/components/lvgl/number/__init__.py +++ b/esphome/components/lvgl/number/__init__.py @@ -1,10 +1,16 @@ import esphome.codegen as cg from esphome.components import number import esphome.config_validation as cv -from esphome.const import CONF_RESTORE_VALUE +from esphome.const import CONF_ON_RELEASE, CONF_RESTORE_VALUE from esphome.cpp_generator import MockObj -from ..defines import CONF_ANIMATED, CONF_UPDATE_ON_RELEASE, CONF_WIDGET +from ..defines import ( + CONF_ANIMATED, + CONF_TRIGGER, + CONF_UPDATE_ON_RELEASE, + CONF_WIDGET, + LOGGER, +) from ..lv_validation import animated from ..lvcode import ( EVENT_ARG, @@ -14,7 +20,8 @@ from ..lvcode import ( lv_obj, lvgl_static, ) -from ..types import LV_EVENT, LvNumber, lvgl_ns +from ..schemas import TRIGGER_EVENT_MAP, VALUE_TRIGGER_SCHEMA +from ..types import LvNumber, lvgl_ns from ..widgets import get_widgets, wait_for_widgets LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number, cg.Component) @@ -22,14 +29,22 @@ LVGLNumber = lvgl_ns.class_("LVGLNumber", number.Number, cg.Component) CONFIG_SCHEMA = number.number_schema(LVGLNumber).extend( { cv.Required(CONF_WIDGET): cv.use_id(LvNumber), + **VALUE_TRIGGER_SCHEMA, cv.Optional(CONF_ANIMATED, default=True): animated, - cv.Optional(CONF_UPDATE_ON_RELEASE, default=False): cv.boolean, + cv.Optional(CONF_UPDATE_ON_RELEASE): cv.boolean, cv.Optional(CONF_RESTORE_VALUE, default=False): cv.boolean, } ) async def to_code(config): + trigger = config[CONF_TRIGGER] + if CONF_UPDATE_ON_RELEASE in config: + LOGGER.warning( + "Option 'update_on_release' is deprecated and will be removed in 2026.11.0 - use 'trigger: on_release' instead" + ) + if config[CONF_UPDATE_ON_RELEASE]: + trigger = CONF_ON_RELEASE widget = await get_widgets(config, CONF_WIDGET) widget = widget[0] await wait_for_widgets() @@ -40,19 +55,13 @@ async def to_code(config): "value", MockObj("v") * MockObj(widget.get_scale()), config[CONF_ANIMATED] ) lv_obj.send_event(widget.obj, UPDATE_EVENT, cg.nullptr) - event_code = ( - LV_EVENT.VALUE_CHANGED - if not config[CONF_UPDATE_ON_RELEASE] - else LV_EVENT.RELEASED - ) var = await number.new_number( config, await control.get_lambda(), await value.get_lambda(), - event_code, config[CONF_RESTORE_VALUE], - max_value=widget.type.get_max(widget.config), - min_value=widget.type.get_min(widget.config), + max_value=await widget.type.get_max(widget.config), + min_value=await widget.type.get_min(widget.config), step=widget.type.get_step(widget.config), ) async with LambdaContext(EVENT_ARG) as event: @@ -60,6 +69,8 @@ async def to_code(config): await cg.register_component(var, config) cg.add( lvgl_static.add_event_cb( - widget.obj, await event.get_lambda(), UPDATE_EVENT, event_code + widget.obj, + await event.get_lambda(), + *TRIGGER_EVENT_MAP[trigger], ) ) diff --git a/esphome/components/lvgl/number/lvgl_number.h b/esphome/components/lvgl/number/lvgl_number.h index ba16b1f0b39..3fda9427c50 100644 --- a/esphome/components/lvgl/number/lvgl_number.h +++ b/esphome/components/lvgl/number/lvgl_number.h @@ -10,12 +10,8 @@ namespace esphome::lvgl { class LVGLNumber : public number::Number, public Component { public: - LVGLNumber(std::function control_lambda, std::function value_lambda, lv_event_code_t event, - bool restore) - : control_lambda_(std::move(control_lambda)), - value_lambda_(std::move(value_lambda)), - event_(event), - restore_(restore) {} + LVGLNumber(std::function control_lambda, std::function value_lambda, bool restore) + : control_lambda_(std::move(control_lambda)), value_lambda_(std::move(value_lambda)), restore_(restore) {} void setup() override { float value = this->value_lambda_(); @@ -42,7 +38,6 @@ class LVGLNumber : public number::Number, public Component { } std::function control_lambda_; std::function value_lambda_; - lv_event_code_t event_; bool restore_; ESPPreferenceObject pref_{}; }; diff --git a/esphome/components/lvgl/schemas.py b/esphome/components/lvgl/schemas.py index 6b71c2875e7..553e0f7398d 100644 --- a/esphome/components/lvgl/schemas.py +++ b/esphome/components/lvgl/schemas.py @@ -10,6 +10,7 @@ from esphome.const import ( CONF_GROUP, CONF_ID, CONF_ON_BOOT, + CONF_ON_UPDATE, CONF_ON_VALUE, CONF_STATE, CONF_TEXT, @@ -29,7 +30,13 @@ from .defines import ( CONF_SCROLL_SNAP_Y, CONF_SCROLLBAR_MODE, CONF_TIME_FORMAT, + CONF_TRIGGER, LV_GRAD_DIR, + LV_VALUE_EVENTS, + VALUE_ON_CHANGE, + VALUE_ON_RELEASE, + VALUE_ON_UPDATE, + VALUE_ON_VALUE, get_remapped_uses, is_press_event, ) @@ -41,8 +48,9 @@ from .layout import ( grid_alignments, ) from .lv_validation import lv_color, lv_font, lv_gradient, lv_image, opacity -from .lvcode import LvglComponent, lv_event_t_ptr +from .lvcode import UPDATE_EVENT, LvglComponent, lv_event_t_ptr from .types import ( + LV_EVENT, LVEncoderListener, LvType, lv_group_t, @@ -355,6 +363,19 @@ SET_STATE_SCHEMA = cv.Schema( FLAG_SCHEMA = cv.Schema({cv.Optional(flag): lvalid.lv_bool for flag in df.OBJ_FLAGS}) FLAG_LIST = cv.ensure_list(df.LV_OBJ_FLAG.one_of) +VALUE_TRIGGER_SCHEMA = { + cv.Optional(CONF_TRIGGER, default=CONF_ON_VALUE): cv.one_of( + *LV_VALUE_EVENTS, lower=True + ), +} + +TRIGGER_EVENT_MAP = { + VALUE_ON_CHANGE: (LV_EVENT.VALUE_CHANGED,), + VALUE_ON_UPDATE: (UPDATE_EVENT,), + VALUE_ON_VALUE: (LV_EVENT.VALUE_CHANGED, UPDATE_EVENT), + VALUE_ON_RELEASE: (LV_EVENT.RELEASED,), +} + def part_schema(parts): """ @@ -370,7 +391,7 @@ def part_schema(parts): def automation_schema(typ: LvType): events = df.LV_EVENT_TRIGGERS + df.SWIPE_TRIGGERS if typ.has_on_value: - events = events + (CONF_ON_VALUE,) + events = events + (CONF_ON_VALUE, CONF_ON_UPDATE) args = typ.get_arg_type() def get_trigger_args(event): diff --git a/esphome/components/lvgl/sensor/__init__.py b/esphome/components/lvgl/sensor/__init__.py index 682d84ede3e..e69ea9771a0 100644 --- a/esphome/components/lvgl/sensor/__init__.py +++ b/esphome/components/lvgl/sensor/__init__.py @@ -1,21 +1,16 @@ from esphome.components.sensor import Sensor, new_sensor, sensor_schema import esphome.config_validation as cv -from ..defines import CONF_WIDGET -from ..lvcode import ( - EVENT_ARG, - UPDATE_EVENT, - LambdaContext, - LvContext, - lv_add, - lvgl_static, -) -from ..types import LV_EVENT, LvNumber +from ..defines import CONF_TRIGGER, CONF_WIDGET +from ..lvcode import EVENT_ARG, LambdaContext, LvContext, lv_add, lvgl_static +from ..schemas import TRIGGER_EVENT_MAP, VALUE_TRIGGER_SCHEMA +from ..types import LvNumber from ..widgets import Widget, get_widgets, wait_for_widgets CONFIG_SCHEMA = sensor_schema(Sensor).extend( { cv.Required(CONF_WIDGET): cv.use_id(LvNumber), + **VALUE_TRIGGER_SCHEMA, } ) @@ -33,7 +28,6 @@ async def to_code(config): lvgl_static.add_event_cb( widget.obj, await lamb.get_lambda(), - LV_EVENT.VALUE_CHANGED, - UPDATE_EVENT, + *TRIGGER_EVENT_MAP[config[CONF_TRIGGER]], ) ) diff --git a/esphome/components/lvgl/trigger.py b/esphome/components/lvgl/trigger.py index 64590d56f61..5f524969e28 100644 --- a/esphome/components/lvgl/trigger.py +++ b/esphome/components/lvgl/trigger.py @@ -3,6 +3,7 @@ import esphome.codegen as cg from esphome.const import ( CONF_ID, CONF_ON_BOOT, + CONF_ON_UPDATE, CONF_ON_VALUE, CONF_TRIGGER_ID, CONF_X, @@ -92,6 +93,13 @@ async def generate_triggers(): UPDATE_EVENT, ) + for conf in config.get(CONF_ON_UPDATE, ()): + await add_trigger( + conf, + w, + UPDATE_EVENT, + ) + await add_on_boot_triggers(config.get(CONF_ON_BOOT, ())) diff --git a/esphome/components/lvgl/types.py b/esphome/components/lvgl/types.py index 1872ce2d32a..509d5cc7824 100644 --- a/esphome/components/lvgl/types.py +++ b/esphome/components/lvgl/types.py @@ -3,8 +3,6 @@ from esphome.const import CONF_TEXT, CONF_VALUE from esphome.cpp_generator import MockObj from esphome.cpp_types import Component, esphome_ns -from .defines import lvgl_ns - class LvType(cg.MockObjClass): def __init__(self, *args, **kwargs): @@ -47,6 +45,7 @@ PlainTrigger = esphome_ns.class_("Trigger<>", automation.Trigger.template()) DrawEndTrigger = esphome_ns.class_( "Trigger", automation.Trigger.template(cg.uint32, cg.uint32) ) +lvgl_ns = cg.esphome_ns.namespace("lvgl") IdleTrigger = lvgl_ns.class_("IdleTrigger", automation.Trigger.template()) ObjUpdateAction = lvgl_ns.class_("ObjUpdateAction", automation.Action) LvglCondition = lvgl_ns.class_("LvglCondition", automation.Condition) diff --git a/esphome/components/lvgl/widgets/__init__.py b/esphome/components/lvgl/widgets/__init__.py index 534ebe0b93d..ab1c61ff88f 100644 --- a/esphome/components/lvgl/widgets/__init__.py +++ b/esphome/components/lvgl/widgets/__init__.py @@ -48,6 +48,7 @@ from ..defines import ( join_enums, literal, ) +from ..lv_validation import lv_int from ..lvcode import ( LvConditional, add_line_marks, @@ -207,10 +208,10 @@ class WidgetType: """ return () - def get_max(self, config: dict): + async def get_max(self, config: dict): return sys.maxsize - def get_min(self, config: dict): + async def get_min(self, config: dict): return -sys.maxsize def get_step(self, config: dict): @@ -637,8 +638,8 @@ async def widget_to_code(w_cnfig, w_type: WidgetType | str, parent) -> Widget: class NumberType(WidgetType): - def get_max(self, config: dict): - return int(config.get(CONF_MAX_VALUE, 100)) + async def get_max(self, config: dict): + return await lv_int.process(config.get(CONF_MAX_VALUE, 100)) - def get_min(self, config: dict): - return int(config.get(CONF_MIN_VALUE, 0)) + async def get_min(self, config: dict): + return await lv_int.process(config.get(CONF_MIN_VALUE, 0)) diff --git a/esphome/components/lvgl/widgets/spinbox.py b/esphome/components/lvgl/widgets/spinbox.py index 58e3435c5c7..ab68a76e9cb 100644 --- a/esphome/components/lvgl/widgets/spinbox.py +++ b/esphome/components/lvgl/widgets/spinbox.py @@ -125,10 +125,10 @@ class SpinboxType(WidgetType): def get_uses(self): return CONF_TEXTAREA, CONF_LABEL - def get_max(self, config: dict): + async def get_max(self, config: dict): return config[CONF_RANGE_TO] - def get_min(self, config: dict): + async def get_min(self, config: dict): return config[CONF_RANGE_FROM] def get_step(self, config: dict): diff --git a/tests/components/lvgl/common.yaml b/tests/components/lvgl/common.yaml index 652ae7e7a13..f500002f401 100644 --- a/tests/components/lvgl/common.yaml +++ b/tests/components/lvgl/common.yaml @@ -38,7 +38,7 @@ number: - platform: lvgl widget: slider_id name: LVGL Slider Number - update_on_release: true + trigger: on_release restore_value: true - platform: lvgl widget: lv_arc diff --git a/tests/components/lvgl/lvgl-package.yaml b/tests/components/lvgl/lvgl-package.yaml index 4bf5b9d494a..53984bb006d 100644 --- a/tests/components/lvgl/lvgl-package.yaml +++ b/tests/components/lvgl/lvgl-package.yaml @@ -309,6 +309,11 @@ lvgl: - logger.log: format: "Roller changed = %d: %s" args: [x, text.c_str()] + on_update: + then: + - logger.log: + format: "Roller updated = %d: %s" + args: [x, text.c_str()] - animimg: height: 60 id: anim_img @@ -630,6 +635,10 @@ lvgl: logger.log: format: "state now %d" args: [x] + on_update: + logger.log: + format: "button updated %d" + args: [x] on_short_click: lvgl.widget.hide: hello_label on_long_press: @@ -758,6 +767,9 @@ lvgl: lambda: return tile == id(tile_1); then: - logger.log: "tile 1 is now showing" + on_update: + then: + - logger.log: "tileview updated programmatically" tiles: - id: tile_1 scroll_snap_y: center @@ -983,6 +995,11 @@ lvgl: - logger.log: format: "Arc value is %f" args: [x] + on_update: + then: + - logger.log: + format: "Arc updated to %f" + args: [x] scroll_on_focus: true value: 75 min_value: 1 @@ -1085,6 +1102,11 @@ lvgl: - logger.log: format: "slider value %f" args: [x] + on_update: + then: + - logger.log: + format: "slider updated to %f" + args: [x] on_click: then: - lvgl.slider.update: @@ -1197,6 +1219,10 @@ lvgl: logger.log: format: "Dropdown changed = %d: %s" args: [x, text.c_str()] + on_update: + logger.log: + format: "Dropdown updated = %d: %s" + args: [x, text.c_str()] on_cancel: logger.log: format: "Dropdown closed = %d" @@ -1437,6 +1463,30 @@ color: blue_int: 64 white_int: 255 +sensor: + - platform: lvgl + widget: lv_arc_1 + id: lvgl_arc1_sensor_on_change + name: LVGL Arc1 Sensor on_change + trigger: on_change + - platform: lvgl + widget: bar_id + id: lvgl_bar_sensor_on_release + name: LVGL Bar Sensor on_release + trigger: on_release + +number: + - platform: lvgl + widget: lv_arc_1 + id: lvgl_arc1_number_on_update + name: LVGL Arc1 Number on_update + trigger: on_update + - platform: lvgl + widget: spinbox_id + id: lvgl_spinbox_number_on_change + name: LVGL Spinbox Number on_change + trigger: on_change + select: - platform: lvgl id: lv_roller_select From a232aedebda88a04ef7abf27e335c27d48bdf206 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Tue, 12 May 2026 12:09:42 +1000 Subject: [PATCH 46/52] [lvgl] Check for user defined LV_USE items (#16362) --- esphome/components/lvgl/__init__.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/esphome/components/lvgl/__init__.py b/esphome/components/lvgl/__init__.py index 31131d253f9..91b101cd258 100644 --- a/esphome/components/lvgl/__init__.py +++ b/esphome/components/lvgl/__init__.py @@ -1,6 +1,7 @@ import importlib from pathlib import Path import pkgutil +import re from esphome.automation import Trigger, build_automation, validate_automation import esphome.codegen as cg @@ -30,12 +31,14 @@ import esphome.config_validation as cv from esphome.const import ( CONF_AUTO_CLEAR_ENABLED, CONF_BUFFER_SIZE, + CONF_ESPHOME, CONF_GROUP, CONF_ID, CONF_LAMBDA, CONF_LOG_LEVEL, CONF_ON_IDLE, CONF_PAGES, + CONF_PLATFORMIO_OPTIONS, CONF_ROTATION, CONF_TIMEOUT, CONF_TRIGGER_ID, @@ -51,6 +54,7 @@ from . import defines as df, lv_validation as lvalid, widgets from .automation import layers_to_code, lvgl_update from .defines import ( CONF_ALIGN_TO_LAMBDA_ID, + LOGGER, get_focused_widgets, get_lv_images_used, get_refreshed_widgets, @@ -148,9 +152,28 @@ def generate_lv_conf_h(): all_defines = set( df.LV_DEFINES + tuple(f"LV_USE_{w.upper()}" for w in WIDGET_TYPES) ) - # Get the defines that are actually used based on the config + build_flags = ( + CORE.config[CONF_ESPHOME].get(CONF_PLATFORMIO_OPTIONS).get("build_flags", []) + ) + if not isinstance(build_flags, list): + build_flags = [build_flags] + # Extract define names from build flags like '-DLV_USE_CHART=1', '-D LV_USE_CHART', + # or multiple defines in one string. + define_pattern = r'-D\s*([A-Z_][A-Z0-9_]*)(?:=[^\s\'"\]]*)?' + defines_from_flags = { + m.group(1) for flag in build_flags for m in re.finditer(define_pattern, flag) + } + + # Get the defines that are actually used based on the config, lv_defines = df.get_defines() - unused_defines = all_defines - set(lv_defines) + clashes = defines_from_flags & lv_defines.keys() + if clashes: + LOGGER.warning( + "Some defines are set both by ESPHome build flags and by LVGL configuration which may lead to unexpected behavior: %s", + sorted(list(clashes)), + ) + unused_defines = all_defines - lv_defines.keys() - defines_from_flags + # Create the content of lv_conf.h with the used defines set to their value, and the unused defines disabled definitions = [as_macro(m, v) for m, v in lv_defines.items()] + [ as_macro(m, "0") for m in unused_defines From 7dce58c58d74279ab1a81c52533d97dbde6ffa88 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 02:17:42 +0000 Subject: [PATCH 47/52] Bump requests from 2.33.1 to 2.34.0 (#16364) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 818453dc8f9..dd539d4f867 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ freetype-py==2.5.1 jinja2==3.1.6 bleak==2.1.1 smpclient==6.0.0 -requests==2.33.1 +requests==2.34.0 # esp-idf >= 5.0 requires this pyparsing >= 3.3.2 From 49df1bd30e543b870c02998d6cc3eb04d0c06f85 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 02:18:06 +0000 Subject: [PATCH 48/52] Bump actions/cache from 5.0.3 to 5.0.5 (#16365) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cb8e07afa8..bf9d474d7a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -804,7 +804,7 @@ jobs: cache-key: ${{ needs.common.outputs.cache-key }} - name: Cache ESPHome - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: ~/.esphome-idf key: ${{ runner.os }}-esphome-${{ needs.common.outputs.cache-key }} @@ -863,7 +863,7 @@ jobs: - name: Save ESPHome cache if: github.ref == 'refs/heads/dev' - uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: ~/.esphome-idf key: ${{ runner.os }}-esphome-${{ needs.common.outputs.cache-key }} From b5e50144e314dfc66da12640725c0779f399679d Mon Sep 17 00:00:00 2001 From: Mat931 <49403702+Mat931@users.noreply.github.com> Date: Tue, 12 May 2026 02:32:58 +0000 Subject: [PATCH 49/52] [ota] Improve OTA error messages (#16327) Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: J. Nick Koston --- .../components/ota/ota_backend_esp_idf.cpp | 3 + esphome/espota2.py | 29 +++++----- tests/unit_tests/test_espota2.py | 58 ++++++++++--------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/esphome/components/ota/ota_backend_esp_idf.cpp b/esphome/components/ota/ota_backend_esp_idf.cpp index f391c1791aa..ade726da1fb 100644 --- a/esphome/components/ota/ota_backend_esp_idf.cpp +++ b/esphome/components/ota/ota_backend_esp_idf.cpp @@ -68,6 +68,9 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size, ota::OTAType ota_type) return OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE; } else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) { return OTA_RESPONSE_ERROR_WRITING_FLASH; + } else if (err == ESP_ERR_OTA_PARTITION_CONFLICT) { + // This error appears with 1 factory and 1 ota partition + return OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION; } return OTA_RESPONSE_ERROR_UNKNOWN; } diff --git a/esphome/espota2.py b/esphome/espota2.py index c13c3ea207f..701a125bcdb 100644 --- a/esphome/espota2.py +++ b/esphome/espota2.py @@ -118,7 +118,8 @@ _ERROR_MESSAGES: dict[int, str] = { ), RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE: ( "The OTA partition on the ESP is too small. ESPHome needs to resize " - "this partition, please flash over USB." + "this partition. Please flash over USB or update the partition table " + "over the air." ), RESPONSE_ERROR_NO_UPDATE_PARTITION: ( "The OTA partition on the ESP couldn't be found. ESPHome needs to " @@ -202,19 +203,19 @@ def receive_exactly( try: data += recv_decode(sock, 1, decode=decode) # type: ignore[operator] except OSError as err: - raise OTAError(f"Error receiving acknowledge {msg}: {err}") from err + raise OTAError(f"receiving {msg} response: {err}") from err try: check_error(data, expect) except OTAError as err: sock.close() - raise OTAError(f"Error {msg}: {err}") from err + raise OTAError(f"receiving {msg}: {err}") from err while len(data) < amount: try: data += recv_decode(sock, amount - len(data), decode=decode) # type: ignore[operator] except OSError as err: - raise OTAError(f"Error receiving {msg}: {err}") from err + raise OTAError(f"receiving {msg}: {err}") from err return data @@ -231,14 +232,14 @@ def check_error(data: list[int] | bytes, expect: int | list[int] | None) -> None # silently passed through and surface later as cryptic decode/timeout failures. if not data: raise OTAError( - "Error: Device closed connection without responding. " + "Device closed connection without responding. " "This may indicate the device ran out of memory, " "a network issue, or the connection was interrupted." ) dat = data[0] error_msg = _ERROR_MESSAGES.get(dat) if error_msg is not None: - raise OTAError(f"Error: {error_msg}") + raise OTAError(error_msg) if expect is None: return if not isinstance(expect, (list, tuple)): @@ -267,7 +268,7 @@ def send_check( sock.sendall(data) except OSError as err: - raise OTAError(f"Error sending {msg}: {err}") from err + raise OTAError(f"sending {msg}: {err}") from err def perform_ota( @@ -376,7 +377,7 @@ def perform_ota( raise OTAError("ESP requests password, but no password given!") nonce_bytes = receive_exactly( - sock, nonce_size, f"{hash_name} authentication nonce", None, decode=False + sock, nonce_size, f"{hash_name} auth nonce", None, decode=False ) assert isinstance(nonce_bytes, bytes) nonce = nonce_bytes.decode() @@ -424,13 +425,13 @@ def perform_ota( (upload_size >> 0) & 0xFF, ] send_check(sock, upload_size_encoded, "binary size") - receive_exactly(sock, 1, "binary size", RESPONSE_UPDATE_PREPARE_OK) + receive_exactly(sock, 1, "update prepare result", RESPONSE_UPDATE_PREPARE_OK) upload_md5 = hashlib.md5(upload_contents).hexdigest() _LOGGER.debug("MD5 of upload is %s", upload_md5) send_check(sock, upload_md5, "file checksum") - receive_exactly(sock, 1, "file checksum", RESPONSE_BIN_MD5_OK) + receive_exactly(sock, 1, "file checksum result", RESPONSE_BIN_MD5_OK) # Disable nodelay for transfer sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 0) @@ -451,10 +452,10 @@ def perform_ota( try: sock.sendall(chunk) if version >= OTA_VERSION_2_0: - receive_exactly(sock, 1, "chunk OK", RESPONSE_CHUNK_OK) + receive_exactly(sock, 1, "chunk result", RESPONSE_CHUNK_OK) except OSError as err: sys.stderr.write("\n") - raise OTAError(f"Error sending data: {err}") from err + raise OTAError(f"sending data: {err}") from err progress.update(offset / upload_size) progress.done() @@ -465,8 +466,8 @@ def perform_ota( _LOGGER.info("Upload took %.2f seconds, waiting for result...", duration) - receive_exactly(sock, 1, "receive OK", RESPONSE_RECEIVE_OK) - receive_exactly(sock, 1, "Update end", RESPONSE_UPDATE_END_OK) + receive_exactly(sock, 1, "update receive result", RESPONSE_RECEIVE_OK) + receive_exactly(sock, 1, "update end result", RESPONSE_UPDATE_END_OK) send_check(sock, RESPONSE_OK, "end acknowledgement") _LOGGER.info("OTA successful") diff --git a/tests/unit_tests/test_espota2.py b/tests/unit_tests/test_espota2.py index d7fcedfd66d..9413fbcf296 100644 --- a/tests/unit_tests/test_espota2.py +++ b/tests/unit_tests/test_espota2.py @@ -135,7 +135,9 @@ def test_receive_exactly_with_error_response(mock_socket: Mock) -> None: """Test receive_exactly raises OTAError on error response.""" mock_socket.recv.return_value = bytes([espota2.RESPONSE_ERROR_AUTH_INVALID]) - with pytest.raises(espota2.OTAError, match="Error auth:.*Authentication invalid"): + with pytest.raises( + espota2.OTAError, match="receiving auth:.*Authentication invalid" + ): espota2.receive_exactly(mock_socket, 1, "auth", [espota2.RESPONSE_OK]) mock_socket.close.assert_called_once() @@ -145,69 +147,69 @@ def test_receive_exactly_socket_error(mock_socket: Mock) -> None: """Test receive_exactly handles socket errors.""" mock_socket.recv.side_effect = OSError("Connection reset") - with pytest.raises(espota2.OTAError, match="Error receiving acknowledge test"): + with pytest.raises(espota2.OTAError, match="receiving test response"): espota2.receive_exactly(mock_socket, 1, "test", espota2.RESPONSE_OK) @pytest.mark.parametrize( ("error_code", "expected_msg"), [ - (espota2.RESPONSE_ERROR_MAGIC, "Error: Invalid magic byte"), - (espota2.RESPONSE_ERROR_UPDATE_PREPARE, "Error: Couldn't prepare flash memory"), - (espota2.RESPONSE_ERROR_AUTH_INVALID, "Error: Authentication invalid"), + (espota2.RESPONSE_ERROR_MAGIC, "Invalid magic byte"), + (espota2.RESPONSE_ERROR_UPDATE_PREPARE, "Couldn't prepare flash memory"), + (espota2.RESPONSE_ERROR_AUTH_INVALID, "Authentication invalid"), ( espota2.RESPONSE_ERROR_WRITING_FLASH, - "Error: Writing OTA data to flash memory failed", + "Writing OTA data to flash memory failed", ), - (espota2.RESPONSE_ERROR_UPDATE_END, "Error: Finishing update failed"), + (espota2.RESPONSE_ERROR_UPDATE_END, "Finishing update failed"), ( espota2.RESPONSE_ERROR_INVALID_BOOTSTRAPPING, - "Error: Please press the reset button", + "Please press the reset button", ), ( espota2.RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG, - "Error: ESP has been flashed with wrong flash size", + "ESP has been flashed with wrong flash size", ), ( espota2.RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG, - "Error: ESP does not have the requested flash size", + "ESP does not have the requested flash size", ), ( espota2.RESPONSE_ERROR_ESP8266_NOT_ENOUGH_SPACE, - "Error: ESP does not have enough space", + "ESP does not have enough space", ), ( espota2.RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE, - "Error: The OTA partition on the ESP is too small", + "The OTA partition on the ESP is too small", ), ( espota2.RESPONSE_ERROR_NO_UPDATE_PARTITION, - "Error: The OTA partition on the ESP couldn't be found", + "The OTA partition on the ESP couldn't be found", ), - (espota2.RESPONSE_ERROR_MD5_MISMATCH, "Error: Application MD5 code mismatch"), + (espota2.RESPONSE_ERROR_MD5_MISMATCH, "Application MD5 code mismatch"), ( espota2.RESPONSE_ERROR_SIGNATURE_INVALID, - "Error: Firmware signature verification failed", + "Firmware signature verification failed", ), ( espota2.RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE, - "Error: The requested OTA type is not supported by the device", + "The requested OTA type is not supported by the device", ), ( espota2.RESPONSE_ERROR_PARTITION_TABLE_VERIFY, - "Error: The partition table update could not be verified", + "The partition table update could not be verified", ), ( espota2.RESPONSE_ERROR_PARTITION_TABLE_UPDATE, - "Error: An error occurred while updating the partition table", + "An error occurred while updating the partition table", ), ( espota2.RESPONSE_ERROR_BOOTLOADER_VERIFY, - "Error: The bootloader update could not be verified", + "The bootloader update could not be verified", ), ( espota2.RESPONSE_ERROR_BOOTLOADER_UPDATE, - "Error: An error occurred while updating the bootloader", + "An error occurred while updating the bootloader", ), (espota2.RESPONSE_ERROR_UNKNOWN, "Unknown error from ESP"), ], @@ -262,7 +264,7 @@ def test_send_check_socket_error(mock_socket: Mock) -> None: """Test send_check handles socket errors.""" mock_socket.sendall.side_effect = OSError("Broken pipe") - with pytest.raises(espota2.OTAError, match="Error sending test"): + with pytest.raises(espota2.OTAError, match="sending test"): espota2.send_check(mock_socket, b"data", "test") @@ -417,7 +419,9 @@ def test_perform_ota_md5_auth_wrong_password( mock_socket.recv.side_effect = recv_responses - with pytest.raises(espota2.OTAError, match="Error auth.*Authentication invalid"): + with pytest.raises( + espota2.OTAError, match="receiving auth.*Authentication invalid" + ): espota2.perform_ota(mock_socket, "wrongpassword", mock_file, "test.bin") # Verify the socket was closed after auth failure @@ -441,7 +445,9 @@ def test_perform_ota_sha256_auth_wrong_password( mock_socket.recv.side_effect = recv_responses - with pytest.raises(espota2.OTAError, match="Error auth.*Authentication invalid"): + with pytest.raises( + espota2.OTAError, match="receiving auth.*Authentication invalid" + ): espota2.perform_ota(mock_socket, "wrongpassword", mock_file, "test.bin") # Verify the socket was closed after auth failure @@ -484,7 +490,7 @@ def test_perform_ota_unexpected_auth_response(mock_socket: Mock) -> None: # This will actually raise "Unexpected response from ESP" from check_error with pytest.raises( - espota2.OTAError, match=r"Error auth: Unexpected response from ESP: 0x03" + espota2.OTAError, match=r"receiving auth: Unexpected response from ESP: 0x03" ): espota2.perform_ota(mock_socket, "password", mock_file, "test.bin") @@ -520,7 +526,7 @@ def test_perform_ota_upload_error(mock_socket: Mock, mock_file: io.BytesIO) -> N mock_socket.recv.side_effect = recv_responses - with pytest.raises(espota2.OTAError, match="Error receiving acknowledge chunk OK"): + with pytest.raises(espota2.OTAError, match="receiving chunk result response"): espota2.perform_ota(mock_socket, None, mock_file, "test.bin") @@ -1109,7 +1115,7 @@ def test_check_error_detects_errors_when_expect_is_none() -> None: during feature negotiation and nonce reads) silently passed error bytes through, turning clean device errors into confusing later failures. """ - with pytest.raises(espota2.OTAError, match="Error: Authentication invalid"): + with pytest.raises(espota2.OTAError, match="Authentication invalid"): espota2.check_error([espota2.RESPONSE_ERROR_AUTH_INVALID], None) From 4ff946ac15e8fbe040020b487dbe1a0d9c955974 Mon Sep 17 00:00:00 2001 From: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Date: Tue, 12 May 2026 21:52:07 +1000 Subject: [PATCH 50/52] [cli] Add --no-states flag to run command (#16366) --- esphome/__main__.py | 7 +++ tests/unit_tests/test_main.py | 95 +++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/esphome/__main__.py b/esphome/__main__.py index ce24f44b3a6..988f28a55fe 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -2170,6 +2170,13 @@ def parse_args(argv): parser_run.add_argument( "--no-logs", help="Disable starting logs.", action="store_true" ) + + parser_run.add_argument( + "--no-states", + action="store_true", + help="Do not show entity state changes in log output.", + ) + parser_run.add_argument( "--reset", "-r", diff --git a/tests/unit_tests/test_main.py b/tests/unit_tests/test_main.py index 3648de443dc..0104854e1f5 100644 --- a/tests/unit_tests/test_main.py +++ b/tests/unit_tests/test_main.py @@ -30,6 +30,7 @@ from esphome.__main__ import ( command_bundle, command_clean_all, command_rename, + command_run, command_update_all, command_wizard, compile_program, @@ -45,6 +46,7 @@ from esphome.__main__ import ( has_resolvable_address, has_web_server_ota, mqtt_get_ip, + parse_args, run_esphome, run_miniterm, show_logs, @@ -5823,3 +5825,96 @@ def test_upload_using_esptool_subprocess_passes_crystal_callback( call_kwargs = mock_run_external_process.call_args[1] assert "line_callbacks" in call_kwargs assert len(call_kwargs["line_callbacks"]) == 1 + + +def test_parse_args_run_no_states() -> None: + """Test that --no-states is parsed for the run command.""" + args = parse_args(["esphome", "run", "--no-states", "device.yaml"]) + assert args.no_states is True + + +def test_parse_args_run_no_states_default() -> None: + """Test that no_states defaults to False for the run command.""" + args = parse_args(["esphome", "run", "device.yaml"]) + assert args.no_states is False + + +def test_parse_args_logs_no_states() -> None: + """Test that --no-states is parsed for the logs command.""" + args = parse_args(["esphome", "logs", "--no-states", "device.yaml"]) + assert args.no_states is True + + +@patch("esphome.components.api.client.run_logs") +def test_command_run_passes_no_states_to_show_logs( + mock_run_logs: Mock, +) -> None: + """Test that command_run propagates --no-states through to run_logs.""" + setup_core( + config={ + "logger": {}, + CONF_API: {}, + CONF_MDNS: {CONF_DISABLED: False}, + }, + platform=PLATFORM_ESP32, + ) + mock_run_logs.return_value = 0 + + args = MockArgs() + args.no_states = True + args.no_logs = False + args.device = None + + with ( + patch("esphome.__main__.write_cpp", return_value=0), + patch("esphome.__main__.compile_program", return_value=0), + patch( + "esphome.__main__.choose_upload_log_host", + return_value=["192.168.1.100"], + ), + patch("esphome.__main__.upload_program", return_value=(0, "192.168.1.100")), + patch("esphome.__main__.get_serial_ports", return_value=[]), + ): + result = command_run(args, CORE.config) + + assert result == 0 + mock_run_logs.assert_called_once_with( + CORE.config, ["192.168.1.100"], subscribe_states=False + ) + + +@patch("esphome.components.api.client.run_logs") +def test_command_run_defaults_subscribe_states_true( + mock_run_logs: Mock, +) -> None: + """Test that command_run subscribes states by default (no --no-states).""" + setup_core( + config={ + "logger": {}, + CONF_API: {}, + CONF_MDNS: {CONF_DISABLED: False}, + }, + platform=PLATFORM_ESP32, + ) + mock_run_logs.return_value = 0 + + args = MockArgs() + args.no_logs = False + args.device = None + + with ( + patch("esphome.__main__.write_cpp", return_value=0), + patch("esphome.__main__.compile_program", return_value=0), + patch( + "esphome.__main__.choose_upload_log_host", + return_value=["192.168.1.100"], + ), + patch("esphome.__main__.upload_program", return_value=(0, "192.168.1.100")), + patch("esphome.__main__.get_serial_ports", return_value=[]), + ): + result = command_run(args, CORE.config) + + assert result == 0 + mock_run_logs.assert_called_once_with( + CORE.config, ["192.168.1.100"], subscribe_states=True + ) From 365ed1931920256a6d85eb0f9105516dacb49e98 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Tue, 12 May 2026 11:19:10 -0400 Subject: [PATCH 51/52] [core] Fix PROGMEM_STRING_TABLE placement on ESP8266 without flash log strings (#16373) --- esphome/core/progmem.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/esphome/core/progmem.h b/esphome/core/progmem.h index 031860e3a64..d349418d02e 100644 --- a/esphome/core/progmem.h +++ b/esphome/core/progmem.h @@ -25,6 +25,16 @@ #define ESPHOME_strncasecmp_P strncasecmp_P // Type for pointers to PROGMEM strings (for use with ESPHOME_F return values) using ProgmemStr = const __FlashStringHelper *; +// Storage class for PROGMEM_STRING_TABLE data. Mirrors the logger's choice of +// LOG_STR_ARG: when LOG_STR_ARG treats the LogString as PROGMEM (PGM_P), the +// table data must actually be in flash; when LOG_STR_ARG treats it as a plain +// const char* (assumes RAM), the table data must live in RAM or non-logger +// consumers (ArduinoJson, Print, MQTT publish) crash on unaligned flash reads. +#ifdef USE_STORE_LOG_STR_IN_FLASH +#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE PROGMEM +#else +#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE +#endif #else #define ESPHOME_F(string_literal) (string_literal) #define ESPHOME_PGM_P const char * @@ -38,6 +48,8 @@ using ProgmemStr = const __FlashStringHelper *; #define ESPHOME_strncasecmp_P strncasecmp // Type for pointers to strings (no PROGMEM on non-ESP8266 platforms) using ProgmemStr = const char *; +// No-op on non-ESP8266 platforms where PROGMEM itself is a no-op. +#define ESPHOME_PROGMEM_STRING_TABLE_STORAGE #endif namespace esphome { @@ -100,8 +112,8 @@ struct LogString; static constexpr size_t COUNT = Table::COUNT; \ static constexpr uint8_t LAST_INDEX = COUNT - 1; \ static constexpr size_t BLOB_SIZE = Table::BLOB_SIZE; \ - static constexpr auto BLOB PROGMEM = Table::make_blob(); \ - static constexpr auto OFFSETS PROGMEM = Table::make_offsets(); \ + static constexpr auto BLOB ESPHOME_PROGMEM_STRING_TABLE_STORAGE = Table::make_blob(); \ + static constexpr auto OFFSETS ESPHOME_PROGMEM_STRING_TABLE_STORAGE = Table::make_offsets(); \ static const char *get_(uint8_t idx, uint8_t fallback) { \ if (idx >= COUNT) \ idx = fallback; \ From 727c74da3f72e9df2a6a9756e4752c188fcc775d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 12 May 2026 12:17:23 -0500 Subject: [PATCH 52/52] [script] Fix array-type parameters in script.execute (#16374) --- esphome/components/script/__init__.py | 2 + tests/components/script/common.yaml | 16 +++++ .../fixtures/script_array_params.yaml | 36 ++++++++++ tests/integration/test_script_array_params.py | 71 +++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 tests/integration/fixtures/script_array_params.yaml create mode 100644 tests/integration/test_script_array_params.py diff --git a/esphome/components/script/__init__.py b/esphome/components/script/__init__.py index 51cae695b76..e92850fd63a 100644 --- a/esphome/components/script/__init__.py +++ b/esphome/components/script/__init__.py @@ -169,6 +169,8 @@ async def script_execute_action_to_code(config, action_id, template_arg, args): return value if type == "bool": return cg.RawExpression(str(value).lower()) + if isinstance(value, (list, tuple)): + return cg.ArrayInitializer(*value) return cg.RawExpression(str(value)) return converter diff --git a/tests/components/script/common.yaml b/tests/components/script/common.yaml index bfd5d0e7ffc..c1dc68513fe 100644 --- a/tests/components/script/common.yaml +++ b/tests/components/script/common.yaml @@ -7,6 +7,12 @@ esphome: prefix: "Test" param2: 0 param3: true + - script.execute: + id: my_script_with_array_params + ints: [42, 100] + floats: [1.5, 2.5] + bools: [true, false] + strings: ["a", "b"] - script.wait: my_script - script.stop: my_script - if: @@ -34,6 +40,16 @@ script: mode: restart then: - lambda: 'ESP_LOGD("main", "Hello World!");' + - id: my_script_with_array_params + parameters: + ints: int[] + floats: float[] + bools: bool[] + strings: string[] + then: + - lambda: |- + ESP_LOGD("main", "ints=%d floats=%f bools=%d strings=%s", + ints[0], floats[0], bools[0], strings[0].c_str()); - id: my_script_with_params parameters: prefix: string diff --git a/tests/integration/fixtures/script_array_params.yaml b/tests/integration/fixtures/script_array_params.yaml new file mode 100644 index 00000000000..699f00a1f39 --- /dev/null +++ b/tests/integration/fixtures/script_array_params.yaml @@ -0,0 +1,36 @@ +esphome: + name: test-script-array-params + +host: + +api: + actions: + - action: run_array_script + then: + - script.execute: + id: array_script + ints: [42, 100] + floats: [1.5, 2.5] + bools: [true, false] + strings: ["hello", "world"] + +logger: + level: DEBUG + +script: + - id: array_script + parameters: + ints: int[] + floats: float[] + bools: bool[] + strings: string[] + then: + - lambda: |- + ESP_LOGI("test", "ints size=%u [0]=%d [1]=%d", + (unsigned) ints.size(), ints[0], ints[1]); + ESP_LOGI("test", "floats size=%u [0]=%.2f [1]=%.2f", + (unsigned) floats.size(), floats[0], floats[1]); + ESP_LOGI("test", "bools size=%u [0]=%d [1]=%d", + (unsigned) bools.size(), (int) bools[0], (int) bools[1]); + ESP_LOGI("test", "strings size=%u [0]=%s [1]=%s", + (unsigned) strings.size(), strings[0].c_str(), strings[1].c_str()); diff --git a/tests/integration/test_script_array_params.py b/tests/integration/test_script_array_params.py new file mode 100644 index 00000000000..2fba8a58fe2 --- /dev/null +++ b/tests/integration/test_script_array_params.py @@ -0,0 +1,71 @@ +"""Integration test for script array parameters (issue #16367). + +Verifies that script parameters of array types (`int[]`, `float[]`, `bool[]`, +`string[]`) compile and execute correctly. Prior to the fix in +`esphome/components/script/__init__.py`, the `script.execute` codegen emitted +the Python `repr` of the list (e.g. `return [42, 100];`) instead of a C++ +braced initializer, causing compile failures. +""" + +from __future__ import annotations + +import asyncio +import re + +import pytest + +from .types import APIClientConnectedFactory, RunCompiledFunction + + +@pytest.mark.asyncio +async def test_script_array_params( + yaml_config: str, + run_compiled: RunCompiledFunction, + api_client_connected: APIClientConnectedFactory, +) -> None: + """Execute a script with int[], float[], bool[], string[] parameters.""" + loop = asyncio.get_running_loop() + seen: dict[str, str] = {} + done = loop.create_future() + + patterns = { + "ints": re.compile(r"ints size=(\d+) \[0\]=(-?\d+) \[1\]=(-?\d+)"), + "floats": re.compile( + r"floats size=(\d+) \[0\]=(-?\d+\.\d+) \[1\]=(-?\d+\.\d+)" + ), + "bools": re.compile(r"bools size=(\d+) \[0\]=(\d+) \[1\]=(\d+)"), + "strings": re.compile(r"strings size=(\d+) \[0\]=(\w+) \[1\]=(\w+)"), + } + + def check_output(line: str) -> None: + for key, pat in patterns.items(): + if (m := pat.search(line)) and key not in seen: + seen[key] = m.group(0) + if len(seen) == len(patterns) and not done.done(): + done.set_result(True) + + async with ( + run_compiled(yaml_config, line_callback=check_output), + api_client_connected() as client, + ): + _, services = await client.list_entities_services() + service = next((s for s in services if s.name == "run_array_script"), None) + assert service is not None, "run_array_script service not found" + await client.execute_service(service, {}) + + try: + await asyncio.wait_for(done, timeout=5.0) + except TimeoutError: + pytest.fail(f"Did not receive all expected log lines. Saw: {seen}") + + assert (m := patterns["ints"].search(seen["ints"])) + assert m.group(1) == "2" and m.group(2) == "42" and m.group(3) == "100" + + assert (m := patterns["floats"].search(seen["floats"])) + assert m.group(1) == "2" and m.group(2) == "1.50" and m.group(3) == "2.50" + + assert (m := patterns["bools"].search(seen["bools"])) + assert m.group(1) == "2" and m.group(2) == "1" and m.group(3) == "0" + + assert (m := patterns["strings"].search(seen["strings"])) + assert m.group(1) == "2" and m.group(2) == "hello" and m.group(3) == "world"