esphome 2025.8.4__py3-none-any.whl → 2025.9.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/__main__.py +177 -105
- esphome/components/absolute_humidity/absolute_humidity.cpp +3 -5
- esphome/components/adc/__init__.py +1 -26
- esphome/components/adc/adc_sensor_esp32.cpp +29 -6
- esphome/components/adc/sensor.py +20 -0
- esphome/components/ags10/ags10.cpp +3 -18
- esphome/components/ags10/ags10.h +2 -12
- esphome/components/aht10/aht10.cpp +3 -3
- esphome/components/airthings_ble/__init__.py +2 -2
- esphome/components/alarm_control_panel/__init__.py +2 -2
- esphome/components/am2315c/am2315c.cpp +1 -17
- esphome/components/am2315c/am2315c.h +2 -3
- esphome/components/api/__init__.py +2 -2
- esphome/components/api/api_connection.cpp +38 -34
- esphome/components/api/api_connection.h +20 -40
- esphome/components/api/api_frame_helper.cpp +25 -25
- esphome/components/api/api_frame_helper.h +3 -3
- esphome/components/api/api_frame_helper_noise.cpp +75 -40
- esphome/components/api/api_frame_helper_noise.h +3 -7
- esphome/components/api/api_frame_helper_plaintext.cpp +17 -4
- esphome/components/api/api_frame_helper_plaintext.h +1 -4
- esphome/components/api/api_pb2.cpp +12 -2
- esphome/components/api/api_pb2.h +144 -143
- esphome/components/api/api_pb2_dump.cpp +6 -1
- esphome/components/api/api_pb2_service.cpp +0 -14
- esphome/components/api/api_pb2_service.h +1 -3
- esphome/components/api/client.py +5 -3
- esphome/components/api/proto.cpp +33 -37
- esphome/components/async_tcp/__init__.py +2 -2
- esphome/components/atm90e26/sensor.py +2 -0
- esphome/components/atm90e32/sensor.py +4 -2
- esphome/components/audio_adc/__init__.py +2 -2
- esphome/components/audio_dac/__init__.py +2 -2
- esphome/components/axs15231/touchscreen/axs15231_touchscreen.cpp +1 -1
- esphome/components/bedjet/bedjet_hub.cpp +1 -1
- esphome/components/binary_sensor/__init__.py +2 -2
- esphome/components/binary_sensor/binary_sensor.cpp +13 -0
- esphome/components/binary_sensor/binary_sensor.h +4 -7
- esphome/components/bl0940/__init__.py +6 -1
- esphome/components/bl0940/bl0940.cpp +178 -41
- esphome/components/bl0940/bl0940.h +121 -76
- esphome/components/bl0940/button/__init__.py +27 -0
- esphome/components/bl0940/button/calibration_reset_button.cpp +20 -0
- esphome/components/bl0940/button/calibration_reset_button.h +19 -0
- esphome/components/bl0940/number/__init__.py +94 -0
- esphome/components/bl0940/number/calibration_number.cpp +29 -0
- esphome/components/bl0940/number/calibration_number.h +26 -0
- esphome/components/bl0940/sensor.py +151 -2
- esphome/components/bl0942/bl0942.cpp +1 -1
- esphome/components/ble_client/output/__init__.py +4 -4
- esphome/components/bluetooth_proxy/__init__.py +1 -1
- esphome/components/bluetooth_proxy/bluetooth_connection.h +1 -1
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +15 -7
- esphome/components/bluetooth_proxy/bluetooth_proxy.h +6 -3
- esphome/components/button/__init__.py +2 -2
- esphome/components/button/button.cpp +13 -0
- esphome/components/button/button.h +4 -7
- esphome/components/camera/buffer.h +18 -0
- esphome/components/camera/buffer_impl.cpp +20 -0
- esphome/components/camera/buffer_impl.h +26 -0
- esphome/components/camera/camera.h +43 -0
- esphome/components/camera/encoder.h +69 -0
- esphome/components/camera_encoder/__init__.py +62 -0
- esphome/components/camera_encoder/encoder_buffer_impl.cpp +23 -0
- esphome/components/camera_encoder/encoder_buffer_impl.h +25 -0
- esphome/components/camera_encoder/esp32_camera_jpeg_encoder.cpp +82 -0
- esphome/components/camera_encoder/esp32_camera_jpeg_encoder.h +39 -0
- esphome/components/captive_portal/__init__.py +2 -2
- esphome/components/captive_portal/captive_index.h +77 -97
- esphome/components/captive_portal/captive_portal.cpp +35 -12
- esphome/components/captive_portal/captive_portal.h +3 -3
- esphome/components/ccs811/ccs811.cpp +3 -3
- esphome/components/climate/__init__.py +2 -2
- esphome/components/climate/climate.cpp +1 -1
- esphome/components/cover/__init__.py +5 -5
- esphome/components/cover/cover.cpp +1 -1
- esphome/components/cover/cover.h +2 -2
- esphome/components/dallas_temp/dallas_temp.cpp +2 -2
- esphome/components/datetime/__init__.py +2 -2
- esphome/components/datetime/date_entity.h +2 -2
- esphome/components/datetime/datetime_entity.h +2 -2
- esphome/components/datetime/time_entity.h +2 -2
- esphome/components/debug/debug_esp32.cpp +1 -1
- esphome/components/display/__init__.py +4 -4
- esphome/components/duty_time/duty_time_sensor.cpp +1 -1
- esphome/components/esp32/__init__.py +0 -5
- esphome/components/esp32/gpio.cpp +27 -23
- esphome/components/esp32/gpio.h +26 -11
- esphome/components/esp32/preferences.cpp +8 -4
- esphome/components/esp32_ble/__init__.py +7 -2
- esphome/components/esp32_ble/ble_uuid.cpp +30 -9
- esphome/components/esp32_ble_beacon/esp32_ble_beacon.cpp +4 -3
- esphome/components/esp32_ble_client/ble_client_base.cpp +7 -3
- esphome/components/esp32_ble_client/ble_client_base.h +8 -5
- esphome/components/esp32_ble_tracker/__init__.py +2 -2
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +11 -47
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +2 -14
- esphome/components/esp8266/__init__.py +2 -2
- esphome/components/esp8266/core.cpp +2 -2
- esphome/components/esp8266/gpio.py +4 -4
- esphome/components/esp8266/preferences.cpp +30 -28
- esphome/components/esphome/ota/__init__.py +2 -2
- esphome/components/esphome/ota/ota_esphome.cpp +21 -19
- esphome/components/esphome/ota/ota_esphome.h +6 -5
- esphome/components/ethernet/__init__.py +7 -2
- esphome/components/ethernet/ethernet_component.cpp +49 -3
- esphome/components/ethernet/ethernet_component.h +2 -0
- esphome/components/event/__init__.py +2 -2
- esphome/components/event/event.h +4 -4
- esphome/components/factory_reset/button/factory_reset_button.cpp +18 -1
- esphome/components/factory_reset/button/factory_reset_button.h +6 -1
- esphome/components/factory_reset/switch/factory_reset_switch.cpp +18 -1
- esphome/components/factory_reset/switch/factory_reset_switch.h +5 -1
- esphome/components/fan/__init__.py +2 -2
- esphome/components/fan/fan.cpp +2 -1
- esphome/components/gdk101/gdk101.cpp +4 -4
- esphome/components/globals/__init__.py +2 -2
- esphome/components/gpio/binary_sensor/gpio_binary_sensor.cpp +19 -18
- esphome/components/gpio_expander/cached_gpio.h +36 -16
- esphome/components/grove_gas_mc_v2/grove_gas_mc_v2.cpp +5 -5
- esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +1 -1
- esphome/components/haier/haier_base.cpp +1 -1
- esphome/components/haier/hon_climate.cpp +1 -1
- esphome/components/hlw8012/hlw8012.cpp +5 -5
- esphome/components/honeywellabp2_i2c/honeywellabp2.cpp +4 -4
- esphome/components/host/preferences.h +3 -2
- esphome/components/hte501/hte501.cpp +3 -21
- esphome/components/hte501/hte501.h +2 -3
- esphome/components/http_request/ota/__init__.py +2 -2
- esphome/components/i2c/__init__.py +2 -2
- esphome/components/i2c/i2c.cpp +13 -9
- esphome/components/i2c/i2c_bus.h +36 -6
- esphome/components/i2s_audio/__init__.py +8 -2
- esphome/components/i2s_audio/media_player/__init__.py +1 -1
- esphome/components/i2s_audio/microphone/__init__.py +1 -1
- esphome/components/i2s_audio/speaker/__init__.py +1 -1
- esphome/components/ina2xx_base/__init__.py +4 -2
- esphome/components/inkplate/__init__.py +1 -0
- esphome/components/inkplate/const.py +105 -0
- esphome/components/inkplate/display.py +238 -0
- esphome/components/{inkplate6 → inkplate}/inkplate.cpp +156 -74
- esphome/components/{inkplate6 → inkplate}/inkplate.h +28 -68
- esphome/components/inkplate6/__init__.py +0 -1
- esphome/components/inkplate6/display.py +2 -211
- esphome/components/integration/integration_sensor.cpp +1 -1
- esphome/components/json/__init__.py +2 -2
- esphome/components/lc709203f/lc709203f.cpp +4 -17
- esphome/components/lc709203f/lc709203f.h +2 -3
- esphome/components/ld2420/text_sensor/{text_sensor.cpp → ld2420_text_sensor.cpp} +1 -1
- esphome/components/ld2450/ld2450.cpp +1 -1
- esphome/components/libretiny/preferences.cpp +13 -5
- esphome/components/light/__init__.py +2 -2
- esphome/components/light/addressable_light_effect.h +7 -0
- esphome/components/light/base_light_effects.h +8 -0
- esphome/components/light/light_call.cpp +22 -20
- esphome/components/light/light_effect.cpp +36 -0
- esphome/components/light/light_effect.h +14 -0
- esphome/components/light/light_json_schema.cpp +9 -1
- esphome/components/light/light_state.cpp +2 -2
- esphome/components/light/light_state.h +38 -0
- esphome/components/lock/__init__.py +2 -2
- esphome/components/lock/lock.h +2 -2
- esphome/components/logger/__init__.py +2 -2
- esphome/components/logger/logger.cpp +25 -4
- esphome/components/logger/logger.h +1 -1
- esphome/components/logger/logger_esp32.cpp +16 -8
- esphome/components/logger/logger_esp8266.cpp +11 -3
- esphome/components/logger/logger_libretiny.cpp +13 -3
- esphome/components/logger/logger_rp2040.cpp +14 -3
- esphome/components/logger/logger_zephyr.cpp +15 -4
- esphome/components/lvgl/defines.py +1 -0
- esphome/components/lvgl/hello_world.py +96 -33
- esphome/components/lvgl/number/lvgl_number.h +1 -1
- esphome/components/lvgl/select/lvgl_select.h +1 -1
- esphome/components/lvgl/widgets/__init__.py +0 -1
- esphome/components/lvgl/widgets/spinbox.py +20 -11
- esphome/components/m5stack_8angle/binary_sensor/m5stack_8angle_binary_sensor.cpp +1 -1
- esphome/components/m5stack_8angle/sensor/m5stack_8angle_sensor.cpp +1 -1
- esphome/components/mapping/__init__.py +13 -5
- esphome/components/mapping/mapping.h +69 -0
- esphome/components/max17043/max17043.cpp +2 -2
- esphome/components/mcp23016/__init__.py +1 -0
- esphome/components/mcp23016/mcp23016.cpp +20 -5
- esphome/components/mcp23016/mcp23016.h +10 -4
- esphome/components/mcp23x08_base/mcp23x08_base.cpp +1 -1
- esphome/components/mcp23x17_base/mcp23x17_base.cpp +2 -2
- esphome/components/md5/md5.cpp +3 -2
- esphome/components/mdns/__init__.py +2 -2
- esphome/components/mdns/mdns_component.cpp +145 -54
- esphome/components/media_player/__init__.py +2 -2
- esphome/components/micro_wake_word/__init__.py +2 -2
- esphome/components/microphone/__init__.py +2 -2
- esphome/components/mipi/__init__.py +77 -33
- esphome/components/mipi_rgb/__init__.py +2 -0
- esphome/components/mipi_rgb/display.py +321 -0
- esphome/components/mipi_rgb/mipi_rgb.cpp +388 -0
- esphome/components/mipi_rgb/mipi_rgb.h +127 -0
- esphome/components/mipi_rgb/models/guition.py +24 -0
- esphome/components/mipi_rgb/models/lilygo.py +228 -0
- esphome/components/mipi_rgb/models/rpi.py +9 -0
- esphome/components/mipi_rgb/models/st7701s.py +214 -0
- esphome/components/mipi_rgb/models/waveshare.py +64 -0
- esphome/components/mipi_spi/models/jc.py +229 -0
- esphome/components/mlx90614/mlx90614.cpp +1 -16
- esphome/components/mlx90614/mlx90614.h +0 -1
- esphome/components/mqtt/__init__.py +2 -2
- esphome/components/mqtt/mqtt_sensor.cpp +7 -2
- esphome/components/ms5611/ms5611.cpp +7 -6
- esphome/components/network/__init__.py +2 -2
- esphome/components/nextion/nextion_upload.cpp +4 -1
- esphome/components/nrf52/__init__.py +49 -6
- esphome/components/nrf52/const.py +1 -0
- esphome/components/nrf52/dfu.cpp +51 -0
- esphome/components/nrf52/dfu.h +24 -0
- esphome/components/ntc/ntc.cpp +1 -1
- esphome/components/number/__init__.py +2 -2
- esphome/components/number/automation.cpp +1 -1
- esphome/components/number/number.cpp +21 -0
- esphome/components/number/number.h +4 -13
- esphome/components/opentherm/hub.h +6 -6
- esphome/components/opentherm/number/{number.cpp → opentherm_number.cpp} +2 -2
- esphome/components/opentherm/output/{output.cpp → opentherm_output.cpp} +1 -1
- esphome/components/opentherm/switch/{switch.cpp → opentherm_switch.cpp} +1 -1
- esphome/components/openthread/openthread.cpp +41 -7
- esphome/components/openthread/openthread.h +11 -0
- esphome/components/ota/__init__.py +2 -2
- esphome/components/pca6416a/__init__.py +1 -0
- esphome/components/pca6416a/pca6416a.cpp +20 -5
- esphome/components/pca6416a/pca6416a.h +12 -5
- esphome/components/pca9554/__init__.py +2 -1
- esphome/components/pca9554/pca9554.cpp +12 -18
- esphome/components/pca9554/pca9554.h +10 -9
- esphome/components/pcf8574/__init__.py +1 -0
- esphome/components/pcf8574/pcf8574.cpp +14 -5
- esphome/components/pcf8574/pcf8574.h +13 -6
- esphome/components/pi4ioe5v6408/pi4ioe5v6408.cpp +7 -7
- esphome/components/pipsolar/__init__.py +3 -3
- esphome/components/pipsolar/output/__init__.py +4 -4
- esphome/components/pulse_width/pulse_width.cpp +2 -2
- esphome/components/qmp6988/qmp6988.cpp +81 -126
- esphome/components/qmp6988/qmp6988.h +31 -37
- esphome/components/radon_eye_ble/__init__.py +2 -2
- esphome/components/remote_base/__init__.py +6 -8
- esphome/components/rotary_encoder/rotary_encoder.cpp +1 -1
- esphome/components/rp2040/__init__.py +2 -2
- esphome/components/runtime_stats/runtime_stats.cpp +10 -23
- esphome/components/runtime_stats/runtime_stats.h +4 -10
- esphome/components/safe_mode/__init__.py +2 -2
- esphome/components/safe_mode/safe_mode.cpp +33 -31
- esphome/components/script/script.cpp +6 -0
- esphome/components/script/script.h +19 -5
- esphome/components/sdm_meter/sensor.py +3 -1
- esphome/components/select/__init__.py +2 -2
- esphome/components/select/select.h +2 -2
- esphome/components/sen5x/sen5x.cpp +57 -55
- esphome/components/sen5x/sen5x.h +21 -15
- esphome/components/sen5x/sensor.py +67 -44
- esphome/components/sensirion_common/i2c_sensirion.cpp +18 -47
- esphome/components/sensirion_common/i2c_sensirion.h +39 -55
- esphome/components/sensor/__init__.py +2 -2
- esphome/components/sensor/automation.h +1 -1
- esphome/components/sensor/sensor.cpp +34 -6
- esphome/components/sensor/sensor.h +4 -21
- esphome/components/sgp30/sgp30.cpp +34 -35
- esphome/components/sgp30/sgp30.h +11 -10
- esphome/components/sgp4x/sgp4x.cpp +2 -2
- esphome/components/shelly_dimmer/light.py +7 -7
- esphome/components/sht4x/sht4x.cpp +1 -1
- esphome/components/sntp/sntp_component.cpp +36 -9
- esphome/components/sntp/sntp_component.h +7 -0
- esphome/components/sound_level/sound_level.cpp +1 -1
- esphome/components/speaker/__init__.py +2 -2
- esphome/components/speaker/media_player/__init__.py +2 -2
- esphome/components/speaker/media_player/speaker_media_player.cpp +1 -1
- esphome/components/spi/__init__.py +2 -2
- esphome/components/sprinkler/sprinkler.cpp +1 -1
- esphome/components/sps30/sps30.cpp +18 -23
- esphome/components/sps30/sps30.h +3 -3
- esphome/components/status_led/__init__.py +2 -2
- esphome/components/stepper/__init__.py +2 -2
- esphome/components/switch/__init__.py +2 -2
- esphome/components/switch/switch.cpp +5 -5
- esphome/components/sx1509/__init__.py +1 -1
- esphome/components/sx1509/sx1509.cpp +12 -7
- esphome/components/sx1509/sx1509.h +11 -4
- esphome/components/tca9555/tca9555.cpp +5 -5
- esphome/components/tee501/tee501.cpp +2 -21
- esphome/components/tee501/tee501.h +2 -4
- esphome/components/template/alarm_control_panel/template_alarm_control_panel.cpp +1 -1
- esphome/components/template/datetime/template_date.cpp +1 -1
- esphome/components/template/datetime/template_datetime.cpp +2 -2
- esphome/components/template/datetime/template_time.cpp +1 -1
- esphome/components/template/number/template_number.cpp +1 -1
- esphome/components/template/select/template_select.cpp +1 -1
- esphome/components/template/text/template_text.cpp +1 -1
- esphome/components/text/__init__.py +2 -2
- esphome/components/text/text.h +2 -2
- esphome/components/text_sensor/__init__.py +2 -2
- esphome/components/text_sensor/text_sensor.h +4 -4
- esphome/components/thermostat/climate.py +11 -7
- esphome/components/thermostat/thermostat_climate.cpp +237 -206
- esphome/components/thermostat/thermostat_climate.h +52 -41
- esphome/components/time/__init__.py +2 -2
- esphome/components/tmp1075/tmp1075.cpp +1 -1
- esphome/components/total_daily_energy/total_daily_energy.cpp +1 -1
- esphome/components/touchscreen/__init__.py +2 -2
- esphome/components/tuya/number/tuya_number.cpp +1 -1
- esphome/components/udp/udp_component.cpp +3 -3
- esphome/components/ufire_ec/ufire_ec.cpp +4 -4
- esphome/components/ufire_ise/ufire_ise.cpp +4 -4
- esphome/components/update/__init__.py +2 -2
- esphome/components/usb_uart/usb_uart.cpp +1 -1
- esphome/components/valve/__init__.py +5 -5
- esphome/components/valve/valve.cpp +1 -1
- esphome/components/valve/valve.h +2 -2
- esphome/components/wake_on_lan/wake_on_lan.cpp +2 -2
- esphome/components/waveshare_epaper/waveshare_213v3.cpp +1 -1
- esphome/components/web_server/__init__.py +2 -2
- esphome/components/web_server/ota/__init__.py +2 -2
- esphome/components/web_server/ota/ota_web_server.cpp +11 -0
- esphome/components/web_server/server_index_v2.h +149 -149
- esphome/components/web_server/web_server.cpp +58 -12
- esphome/components/web_server_base/__init__.py +2 -2
- esphome/components/wifi/__init__.py +5 -5
- esphome/components/wifi/wifi_component.cpp +4 -4
- esphome/components/wifi/wifi_component_esp_idf.cpp +2 -0
- esphome/components/wifi_info/wifi_info_text_sensor.h +3 -2
- esphome/config_validation.py +2 -2
- esphome/const.py +3 -1
- esphome/core/__init__.py +1 -0
- esphome/core/application.cpp +89 -51
- esphome/core/application.h +1 -0
- esphome/core/component.cpp +41 -19
- esphome/core/component.h +17 -13
- esphome/core/config.py +7 -7
- esphome/core/defines.h +4 -0
- esphome/core/entity_base.cpp +22 -8
- esphome/core/entity_base.h +43 -0
- esphome/core/helpers.cpp +34 -20
- esphome/core/helpers.h +33 -3
- esphome/core/ring_buffer.cpp +6 -2
- esphome/core/ring_buffer.h +2 -1
- esphome/core/scheduler.cpp +178 -97
- esphome/core/scheduler.h +67 -36
- esphome/core/time.cpp +6 -20
- esphome/coroutine.py +80 -3
- esphome/cpp_generator.py +13 -0
- esphome/cpp_helpers.py +2 -2
- esphome/dashboard/web_server.py +67 -10
- esphome/espota2.py +13 -6
- esphome/helpers.py +68 -83
- esphome/resolver.py +67 -0
- esphome/util.py +9 -6
- esphome/wizard.py +39 -26
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/METADATA +9 -9
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/RECORD +364 -333
- /esphome/components/ld2420/text_sensor/{text_sensor.h → ld2420_text_sensor.h} +0 -0
- /esphome/components/opentherm/number/{number.h → opentherm_number.h} +0 -0
- /esphome/components/opentherm/output/{output.h → opentherm_output.h} +0 -0
- /esphome/components/opentherm/switch/{switch.h → opentherm_switch.h} +0 -0
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/WHEEL +0 -0
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/entry_points.txt +0 -0
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/licenses/LICENSE +0 -0
- {esphome-2025.8.4.dist-info → esphome-2025.9.0b2.dist-info}/top_level.txt +0 -0
@@ -31,12 +31,13 @@ void ESP32BLEBeacon::dump_config() {
|
|
31
31
|
char uuid[37];
|
32
32
|
char *bpos = uuid;
|
33
33
|
for (int8_t ii = 0; ii < 16; ++ii) {
|
34
|
-
bpos
|
34
|
+
*bpos++ = format_hex_pretty_char(this->uuid_[ii] >> 4);
|
35
|
+
*bpos++ = format_hex_pretty_char(this->uuid_[ii] & 0x0F);
|
35
36
|
if (ii == 3 || ii == 5 || ii == 7 || ii == 9) {
|
36
|
-
bpos
|
37
|
+
*bpos++ = '-';
|
37
38
|
}
|
38
39
|
}
|
39
|
-
|
40
|
+
*bpos = '\0';
|
40
41
|
ESP_LOGCONFIG(TAG,
|
41
42
|
" UUID: %s, Major: %u, Minor: %u, Min Interval: %ums, Max Interval: %ums, Measured Power: %d"
|
42
43
|
", TX Power: %ddBm",
|
@@ -93,7 +93,7 @@ bool BLEClientBase::parse_device(const espbt::ESPBTDevice &device) {
|
|
93
93
|
return false;
|
94
94
|
if (this->address_ == 0 || device.address_uint64() != this->address_)
|
95
95
|
return false;
|
96
|
-
if (this->state_ != espbt::ClientState::IDLE
|
96
|
+
if (this->state_ != espbt::ClientState::IDLE)
|
97
97
|
return false;
|
98
98
|
|
99
99
|
this->log_event_("Found device");
|
@@ -168,8 +168,7 @@ void BLEClientBase::unconditional_disconnect() {
|
|
168
168
|
this->log_gattc_warning_("esp_ble_gattc_close", err);
|
169
169
|
}
|
170
170
|
|
171
|
-
if (this->state_ == espbt::ClientState::
|
172
|
-
this->state_ == espbt::ClientState::DISCOVERED) {
|
171
|
+
if (this->state_ == espbt::ClientState::READY_TO_CONNECT || this->state_ == espbt::ClientState::DISCOVERED) {
|
173
172
|
this->set_address(0);
|
174
173
|
this->set_state(espbt::ClientState::IDLE);
|
175
174
|
} else {
|
@@ -495,6 +494,11 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
|
|
495
494
|
break;
|
496
495
|
}
|
497
496
|
|
497
|
+
case ESP_GATTC_UNREG_FOR_NOTIFY_EVT: {
|
498
|
+
this->log_gattc_event_("UNREG_FOR_NOTIFY");
|
499
|
+
break;
|
500
|
+
}
|
501
|
+
|
498
502
|
default:
|
499
503
|
// ideally would check all other events for matching conn_id
|
500
504
|
ESP_LOGD(TAG, "[%d] [%s] Event %d", this->connection_index_, this->address_str_.c_str(), event);
|
@@ -60,11 +60,14 @@ class BLEClientBase : public espbt::ESPBTClient, public Component {
|
|
60
60
|
if (address == 0) {
|
61
61
|
this->address_str_ = "";
|
62
62
|
} else {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
char buf[18];
|
64
|
+
uint8_t mac[6] = {
|
65
|
+
(uint8_t) ((this->address_ >> 40) & 0xff), (uint8_t) ((this->address_ >> 32) & 0xff),
|
66
|
+
(uint8_t) ((this->address_ >> 24) & 0xff), (uint8_t) ((this->address_ >> 16) & 0xff),
|
67
|
+
(uint8_t) ((this->address_ >> 8) & 0xff), (uint8_t) ((this->address_ >> 0) & 0xff),
|
68
|
+
};
|
69
|
+
format_mac_addr_upper(mac, buf);
|
70
|
+
this->address_str_ = buf;
|
68
71
|
}
|
69
72
|
}
|
70
73
|
const std::string &address_str() const { return this->address_str_; }
|
@@ -30,7 +30,7 @@ from esphome.const import (
|
|
30
30
|
CONF_SERVICE_UUID,
|
31
31
|
CONF_TRIGGER_ID,
|
32
32
|
)
|
33
|
-
from esphome.core import CORE, coroutine_with_priority
|
33
|
+
from esphome.core import CORE, CoroPriority, coroutine_with_priority
|
34
34
|
from esphome.enum import StrEnum
|
35
35
|
from esphome.types import ConfigType
|
36
36
|
|
@@ -368,7 +368,7 @@ async def to_code(config):
|
|
368
368
|
# This needs to be run as a job with very low priority so that all components have
|
369
369
|
# chance to call register_ble_tracker and register_client before the list is checked
|
370
370
|
# and added to the global defines list.
|
371
|
-
@coroutine_with_priority(
|
371
|
+
@coroutine_with_priority(CoroPriority.FINAL)
|
372
372
|
async def _add_ble_features():
|
373
373
|
# Add feature-specific defines based on what's needed
|
374
374
|
if BLEFeatures.ESP_BT_DEVICE in _required_features:
|
@@ -49,8 +49,6 @@ const char *client_state_to_string(ClientState state) {
|
|
49
49
|
return "DISCONNECTING";
|
50
50
|
case ClientState::IDLE:
|
51
51
|
return "IDLE";
|
52
|
-
case ClientState::SEARCHING:
|
53
|
-
return "SEARCHING";
|
54
52
|
case ClientState::DISCOVERED:
|
55
53
|
return "DISCOVERED";
|
56
54
|
case ClientState::READY_TO_CONNECT:
|
@@ -136,9 +134,8 @@ void ESP32BLETracker::loop() {
|
|
136
134
|
ClientStateCounts counts = this->count_client_states_();
|
137
135
|
if (counts != this->client_state_counts_) {
|
138
136
|
this->client_state_counts_ = counts;
|
139
|
-
ESP_LOGD(TAG, "connecting: %d, discovered: %d,
|
140
|
-
this->client_state_counts_.
|
141
|
-
this->client_state_counts_.searching, this->client_state_counts_.disconnecting);
|
137
|
+
ESP_LOGD(TAG, "connecting: %d, discovered: %d, disconnecting: %d", this->client_state_counts_.connecting,
|
138
|
+
this->client_state_counts_.discovered, this->client_state_counts_.disconnecting);
|
142
139
|
}
|
143
140
|
|
144
141
|
if (this->scanner_state_ == ScannerState::FAILED ||
|
@@ -158,10 +155,8 @@ void ESP32BLETracker::loop() {
|
|
158
155
|
https://github.com/espressif/esp-idf/issues/6688
|
159
156
|
|
160
157
|
*/
|
161
|
-
bool promote_to_connecting = counts.discovered && !counts.searching && !counts.connecting;
|
162
158
|
|
163
|
-
if (this->scanner_state_ == ScannerState::IDLE && !counts.connecting && !counts.disconnecting &&
|
164
|
-
!promote_to_connecting) {
|
159
|
+
if (this->scanner_state_ == ScannerState::IDLE && !counts.connecting && !counts.disconnecting && !counts.discovered) {
|
165
160
|
#ifdef USE_ESP32_BLE_SOFTWARE_COEXISTENCE
|
166
161
|
this->update_coex_preference_(false);
|
167
162
|
#endif
|
@@ -170,12 +165,11 @@ void ESP32BLETracker::loop() {
|
|
170
165
|
}
|
171
166
|
}
|
172
167
|
// If there is a discovered client and no connecting
|
173
|
-
// clients
|
174
|
-
// devices, then promote the discovered client to ready to connect.
|
168
|
+
// clients, then promote the discovered client to ready to connect.
|
175
169
|
// We check both RUNNING and IDLE states because:
|
176
170
|
// - RUNNING: gap_scan_event_handler initiates stop_scan_() but promotion can happen immediately
|
177
171
|
// - IDLE: Scanner has already stopped (naturally or by gap_scan_event_handler)
|
178
|
-
if (
|
172
|
+
if (counts.discovered && !counts.connecting &&
|
179
173
|
(this->scanner_state_ == ScannerState::RUNNING || this->scanner_state_ == ScannerState::IDLE)) {
|
180
174
|
this->try_promote_discovered_clients_();
|
181
175
|
}
|
@@ -307,14 +301,7 @@ void ESP32BLETracker::gap_scan_event_handler(const BLEScanResult &scan_result) {
|
|
307
301
|
|
308
302
|
if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) {
|
309
303
|
// Process the scan result immediately
|
310
|
-
|
311
|
-
|
312
|
-
// If we found a discovered client that needs promotion, stop scanning
|
313
|
-
// This replaces the promote_to_connecting logic from loop()
|
314
|
-
if (found_discovered_client && this->scanner_state_ == ScannerState::RUNNING) {
|
315
|
-
ESP_LOGD(TAG, "Found discovered client, stopping scan for connection");
|
316
|
-
this->stop_scan_();
|
317
|
-
}
|
304
|
+
this->process_scan_result_(scan_result);
|
318
305
|
} else if (scan_result.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) {
|
319
306
|
// Scan finished on its own
|
320
307
|
if (this->scanner_state_ != ScannerState::RUNNING) {
|
@@ -620,9 +607,8 @@ void ESPBTDevice::parse_adv_(const uint8_t *payload, uint8_t len) {
|
|
620
607
|
}
|
621
608
|
|
622
609
|
std::string ESPBTDevice::address_str() const {
|
623
|
-
char mac[
|
624
|
-
|
625
|
-
this->address_[3], this->address_[4], this->address_[5]);
|
610
|
+
char mac[18];
|
611
|
+
format_mac_addr_upper(this->address_, mac);
|
626
612
|
return mac;
|
627
613
|
}
|
628
614
|
|
@@ -640,9 +626,8 @@ void ESP32BLETracker::dump_config() {
|
|
640
626
|
this->scan_duration_, this->scan_interval_ * 0.625f, this->scan_window_ * 0.625f,
|
641
627
|
this->scan_active_ ? "ACTIVE" : "PASSIVE", YESNO(this->scan_continuous_));
|
642
628
|
ESP_LOGCONFIG(TAG, " Scanner State: %s", this->scanner_state_to_string_(this->scanner_state_));
|
643
|
-
ESP_LOGCONFIG(TAG, " Connecting: %d, discovered: %d,
|
644
|
-
this->client_state_counts_.
|
645
|
-
this->client_state_counts_.searching, this->client_state_counts_.disconnecting);
|
629
|
+
ESP_LOGCONFIG(TAG, " Connecting: %d, discovered: %d, disconnecting: %d", this->client_state_counts_.connecting,
|
630
|
+
this->client_state_counts_.discovered, this->client_state_counts_.disconnecting);
|
646
631
|
if (this->scan_start_fail_count_) {
|
647
632
|
ESP_LOGCONFIG(TAG, " Scan Start Fail Count: %d", this->scan_start_fail_count_);
|
648
633
|
}
|
@@ -720,20 +705,9 @@ bool ESPBTDevice::resolve_irk(const uint8_t *irk) const {
|
|
720
705
|
ecb_ciphertext[13] == ((addr64 >> 16) & 0xff);
|
721
706
|
}
|
722
707
|
|
723
|
-
bool ESP32BLETracker::has_connecting_clients_() const {
|
724
|
-
for (auto *client : this->clients_) {
|
725
|
-
auto state = client->state();
|
726
|
-
if (state == ClientState::CONNECTING || state == ClientState::READY_TO_CONNECT) {
|
727
|
-
return true;
|
728
|
-
}
|
729
|
-
}
|
730
|
-
return false;
|
731
|
-
}
|
732
708
|
#endif // USE_ESP32_BLE_DEVICE
|
733
709
|
|
734
|
-
|
735
|
-
bool found_discovered_client = false;
|
736
|
-
|
710
|
+
void ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) {
|
737
711
|
// Process raw advertisements
|
738
712
|
if (this->raw_advertisements_) {
|
739
713
|
for (auto *listener : this->listeners_) {
|
@@ -759,14 +733,6 @@ bool ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) {
|
|
759
733
|
for (auto *client : this->clients_) {
|
760
734
|
if (client->parse_device(device)) {
|
761
735
|
found = true;
|
762
|
-
// Check if this client is discovered and needs promotion
|
763
|
-
if (client->state() == ClientState::DISCOVERED) {
|
764
|
-
// Only check for connecting clients if we found a discovered client
|
765
|
-
// This matches the original logic: !connecting && client->state() == DISCOVERED
|
766
|
-
if (!this->has_connecting_clients_()) {
|
767
|
-
found_discovered_client = true;
|
768
|
-
}
|
769
|
-
}
|
770
736
|
}
|
771
737
|
}
|
772
738
|
|
@@ -775,8 +741,6 @@ bool ESP32BLETracker::process_scan_result_(const BLEScanResult &scan_result) {
|
|
775
741
|
}
|
776
742
|
#endif // USE_ESP32_BLE_DEVICE
|
777
743
|
}
|
778
|
-
|
779
|
-
return found_discovered_client;
|
780
744
|
}
|
781
745
|
|
782
746
|
void ESP32BLETracker::cleanup_scan_state_(bool is_stop_complete) {
|
@@ -141,12 +141,10 @@ class ESPBTDeviceListener {
|
|
141
141
|
struct ClientStateCounts {
|
142
142
|
uint8_t connecting = 0;
|
143
143
|
uint8_t discovered = 0;
|
144
|
-
uint8_t searching = 0;
|
145
144
|
uint8_t disconnecting = 0;
|
146
145
|
|
147
146
|
bool operator==(const ClientStateCounts &other) const {
|
148
|
-
return connecting == other.connecting && discovered == other.discovered &&
|
149
|
-
disconnecting == other.disconnecting;
|
147
|
+
return connecting == other.connecting && discovered == other.discovered && disconnecting == other.disconnecting;
|
150
148
|
}
|
151
149
|
|
152
150
|
bool operator!=(const ClientStateCounts &other) const { return !(*this == other); }
|
@@ -159,8 +157,6 @@ enum class ClientState : uint8_t {
|
|
159
157
|
DISCONNECTING,
|
160
158
|
// Connection is idle, no device detected.
|
161
159
|
IDLE,
|
162
|
-
// Searching for device.
|
163
|
-
SEARCHING,
|
164
160
|
// Device advertisement found.
|
165
161
|
DISCOVERED,
|
166
162
|
// Device is discovered and the scanner is stopped
|
@@ -292,12 +288,7 @@ class ESP32BLETracker : public Component,
|
|
292
288
|
/// Common cleanup logic when transitioning scanner to IDLE state
|
293
289
|
void cleanup_scan_state_(bool is_stop_complete);
|
294
290
|
/// Process a single scan result immediately
|
295
|
-
|
296
|
-
bool process_scan_result_(const BLEScanResult &scan_result);
|
297
|
-
#ifdef USE_ESP32_BLE_DEVICE
|
298
|
-
/// Check if any clients are in connecting or ready to connect state
|
299
|
-
bool has_connecting_clients_() const;
|
300
|
-
#endif
|
291
|
+
void process_scan_result_(const BLEScanResult &scan_result);
|
301
292
|
/// Handle scanner failure states
|
302
293
|
void handle_scanner_failure_();
|
303
294
|
/// Try to promote discovered clients to ready to connect
|
@@ -321,9 +312,6 @@ class ESP32BLETracker : public Component,
|
|
321
312
|
case ClientState::DISCOVERED:
|
322
313
|
counts.discovered++;
|
323
314
|
break;
|
324
|
-
case ClientState::SEARCHING:
|
325
|
-
counts.searching++;
|
326
|
-
break;
|
327
315
|
case ClientState::CONNECTING:
|
328
316
|
case ClientState::READY_TO_CONNECT:
|
329
317
|
counts.connecting++;
|
@@ -17,7 +17,7 @@ from esphome.const import (
|
|
17
17
|
PLATFORM_ESP8266,
|
18
18
|
ThreadModel,
|
19
19
|
)
|
20
|
-
from esphome.core import CORE, coroutine_with_priority
|
20
|
+
from esphome.core import CORE, CoroPriority, coroutine_with_priority
|
21
21
|
from esphome.helpers import copy_file_if_changed
|
22
22
|
|
23
23
|
from .boards import BOARDS, ESP8266_LD_SCRIPTS
|
@@ -176,7 +176,7 @@ CONFIG_SCHEMA = cv.All(
|
|
176
176
|
)
|
177
177
|
|
178
178
|
|
179
|
-
@coroutine_with_priority(
|
179
|
+
@coroutine_with_priority(CoroPriority.PLATFORM)
|
180
180
|
async def to_code(config):
|
181
181
|
cg.add(esp8266_ns.setup_preferences())
|
182
182
|
|
@@ -58,8 +58,8 @@ extern "C" void resetPins() { // NOLINT
|
|
58
58
|
|
59
59
|
#ifdef USE_ESP8266_EARLY_PIN_INIT
|
60
60
|
for (int i = 0; i < 16; i++) {
|
61
|
-
uint8_t mode = ESPHOME_ESP8266_GPIO_INITIAL_MODE[i];
|
62
|
-
uint8_t level = ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i];
|
61
|
+
uint8_t mode = progmem_read_byte(&ESPHOME_ESP8266_GPIO_INITIAL_MODE[i]);
|
62
|
+
uint8_t level = progmem_read_byte(&ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i]);
|
63
63
|
if (mode != 255)
|
64
64
|
pinMode(i, mode); // NOLINT
|
65
65
|
if (level != 255)
|
@@ -17,7 +17,7 @@ from esphome.const import (
|
|
17
17
|
CONF_PULLUP,
|
18
18
|
PLATFORM_ESP8266,
|
19
19
|
)
|
20
|
-
from esphome.core import CORE, coroutine_with_priority
|
20
|
+
from esphome.core import CORE, CoroPriority, coroutine_with_priority
|
21
21
|
|
22
22
|
from . import boards
|
23
23
|
from .const import KEY_BOARD, KEY_ESP8266, KEY_PIN_INITIAL_STATES, esp8266_ns
|
@@ -188,7 +188,7 @@ async def esp8266_pin_to_code(config):
|
|
188
188
|
return var
|
189
189
|
|
190
190
|
|
191
|
-
@coroutine_with_priority(
|
191
|
+
@coroutine_with_priority(CoroPriority.WORKAROUNDS)
|
192
192
|
async def add_pin_initial_states_array():
|
193
193
|
# Add includes at the very end, so that they override everything
|
194
194
|
initial_states: list[PinInitialState] = CORE.data[KEY_ESP8266][
|
@@ -199,11 +199,11 @@ async def add_pin_initial_states_array():
|
|
199
199
|
|
200
200
|
cg.add_global(
|
201
201
|
cg.RawExpression(
|
202
|
-
f"const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_MODE[16] = {{{initial_modes_s}}}"
|
202
|
+
f"const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_MODE[16] PROGMEM = {{{initial_modes_s}}}"
|
203
203
|
)
|
204
204
|
)
|
205
205
|
cg.add_global(
|
206
206
|
cg.RawExpression(
|
207
|
-
f"const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[16] = {{{initial_levels_s}}}"
|
207
|
+
f"const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[16] PROGMEM = {{{initial_levels_s}}}"
|
208
208
|
)
|
209
209
|
)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#ifdef USE_ESP8266
|
2
2
|
|
3
3
|
#include <c_types.h>
|
4
|
+
#include <cinttypes>
|
4
5
|
extern "C" {
|
5
6
|
#include "spi_flash.h"
|
6
7
|
}
|
@@ -12,7 +13,7 @@ extern "C" {
|
|
12
13
|
#include "preferences.h"
|
13
14
|
|
14
15
|
#include <cstring>
|
15
|
-
#include <
|
16
|
+
#include <memory>
|
16
17
|
|
17
18
|
namespace esphome {
|
18
19
|
namespace esp8266 {
|
@@ -67,6 +68,8 @@ static uint32_t get_esp8266_flash_sector() {
|
|
67
68
|
}
|
68
69
|
static uint32_t get_esp8266_flash_address() { return get_esp8266_flash_sector() * SPI_FLASH_SEC_SIZE; }
|
69
70
|
|
71
|
+
static inline size_t bytes_to_words(size_t bytes) { return (bytes + 3) / 4; }
|
72
|
+
|
70
73
|
template<class It> uint32_t calculate_crc(It first, It last, uint32_t type) {
|
71
74
|
uint32_t crc = type;
|
72
75
|
while (first != last) {
|
@@ -117,47 +120,42 @@ static bool load_from_rtc(size_t offset, uint32_t *data, size_t len) {
|
|
117
120
|
|
118
121
|
class ESP8266PreferenceBackend : public ESPPreferenceBackend {
|
119
122
|
public:
|
120
|
-
size_t offset = 0;
|
121
123
|
uint32_t type = 0;
|
124
|
+
uint16_t offset = 0;
|
125
|
+
uint8_t length_words = 0; // Max 255 words (1020 bytes of data)
|
122
126
|
bool in_flash = false;
|
123
|
-
size_t length_words = 0;
|
124
127
|
|
125
128
|
bool save(const uint8_t *data, size_t len) override {
|
126
|
-
if ((len
|
129
|
+
if (bytes_to_words(len) != length_words) {
|
127
130
|
return false;
|
128
131
|
}
|
129
|
-
|
130
|
-
buffer
|
131
|
-
memcpy(buffer.
|
132
|
-
buffer[
|
132
|
+
size_t buffer_size = static_cast<size_t>(length_words) + 1;
|
133
|
+
std::unique_ptr<uint32_t[]> buffer(new uint32_t[buffer_size]()); // Note the () for zero-initialization
|
134
|
+
memcpy(buffer.get(), data, len);
|
135
|
+
buffer[length_words] = calculate_crc(buffer.get(), buffer.get() + length_words, type);
|
133
136
|
|
134
137
|
if (in_flash) {
|
135
|
-
return save_to_flash(offset, buffer.
|
136
|
-
} else {
|
137
|
-
return save_to_rtc(offset, buffer.data(), buffer.size());
|
138
|
+
return save_to_flash(offset, buffer.get(), buffer_size);
|
138
139
|
}
|
140
|
+
return save_to_rtc(offset, buffer.get(), buffer_size);
|
139
141
|
}
|
140
142
|
bool load(uint8_t *data, size_t len) override {
|
141
|
-
if ((len
|
143
|
+
if (bytes_to_words(len) != length_words) {
|
142
144
|
return false;
|
143
145
|
}
|
144
|
-
|
145
|
-
buffer
|
146
|
-
bool ret
|
147
|
-
|
148
|
-
ret = load_from_flash(offset, buffer.data(), buffer.size());
|
149
|
-
} else {
|
150
|
-
ret = load_from_rtc(offset, buffer.data(), buffer.size());
|
151
|
-
}
|
146
|
+
size_t buffer_size = static_cast<size_t>(length_words) + 1;
|
147
|
+
std::unique_ptr<uint32_t[]> buffer(new uint32_t[buffer_size]());
|
148
|
+
bool ret = in_flash ? load_from_flash(offset, buffer.get(), buffer_size)
|
149
|
+
: load_from_rtc(offset, buffer.get(), buffer_size);
|
152
150
|
if (!ret)
|
153
151
|
return false;
|
154
152
|
|
155
|
-
uint32_t crc = calculate_crc(buffer.
|
156
|
-
if (buffer[
|
153
|
+
uint32_t crc = calculate_crc(buffer.get(), buffer.get() + length_words, type);
|
154
|
+
if (buffer[length_words] != crc) {
|
157
155
|
return false;
|
158
156
|
}
|
159
157
|
|
160
|
-
memcpy(data, buffer.
|
158
|
+
memcpy(data, buffer.get(), len);
|
161
159
|
return true;
|
162
160
|
}
|
163
161
|
};
|
@@ -178,16 +176,20 @@ class ESP8266Preferences : public ESPPreferences {
|
|
178
176
|
}
|
179
177
|
|
180
178
|
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override {
|
181
|
-
uint32_t length_words = (length
|
179
|
+
uint32_t length_words = bytes_to_words(length);
|
180
|
+
if (length_words > 255) {
|
181
|
+
ESP_LOGE(TAG, "Preference too large: %" PRIu32 " words > 255", length_words);
|
182
|
+
return {};
|
183
|
+
}
|
182
184
|
if (in_flash) {
|
183
185
|
uint32_t start = current_flash_offset;
|
184
186
|
uint32_t end = start + length_words + 1;
|
185
187
|
if (end > ESP8266_FLASH_STORAGE_SIZE)
|
186
188
|
return {};
|
187
189
|
auto *pref = new ESP8266PreferenceBackend(); // NOLINT(cppcoreguidelines-owning-memory)
|
188
|
-
pref->offset = start;
|
190
|
+
pref->offset = static_cast<uint16_t>(start);
|
189
191
|
pref->type = type;
|
190
|
-
pref->length_words = length_words;
|
192
|
+
pref->length_words = static_cast<uint8_t>(length_words);
|
191
193
|
pref->in_flash = true;
|
192
194
|
current_flash_offset = end;
|
193
195
|
return {pref};
|
@@ -213,9 +215,9 @@ class ESP8266Preferences : public ESPPreferences {
|
|
213
215
|
uint32_t rtc_offset = in_normal ? start + 32 : start - 96;
|
214
216
|
|
215
217
|
auto *pref = new ESP8266PreferenceBackend(); // NOLINT(cppcoreguidelines-owning-memory)
|
216
|
-
pref->offset = rtc_offset;
|
218
|
+
pref->offset = static_cast<uint16_t>(rtc_offset);
|
217
219
|
pref->type = type;
|
218
|
-
pref->length_words = length_words;
|
220
|
+
pref->length_words = static_cast<uint8_t>(length_words);
|
219
221
|
pref->in_flash = false;
|
220
222
|
current_offset += length_words + 1;
|
221
223
|
return pref;
|
@@ -16,7 +16,7 @@ from esphome.const import (
|
|
16
16
|
CONF_SAFE_MODE,
|
17
17
|
CONF_VERSION,
|
18
18
|
)
|
19
|
-
from esphome.core import coroutine_with_priority
|
19
|
+
from esphome.core import CoroPriority, coroutine_with_priority
|
20
20
|
import esphome.final_validate as fv
|
21
21
|
|
22
22
|
_LOGGER = logging.getLogger(__name__)
|
@@ -121,7 +121,7 @@ CONFIG_SCHEMA = (
|
|
121
121
|
FINAL_VALIDATE_SCHEMA = ota_esphome_final_validate
|
122
122
|
|
123
123
|
|
124
|
-
@coroutine_with_priority(
|
124
|
+
@coroutine_with_priority(CoroPriority.COMMUNICATION)
|
125
125
|
async def to_code(config):
|
126
126
|
var = cg.new_Pvariable(config[CONF_ID])
|
127
127
|
cg.add(var.set_port(config[CONF_PORT]))
|
@@ -30,19 +30,19 @@ void ESPHomeOTAComponent::setup() {
|
|
30
30
|
|
31
31
|
this->server_ = socket::socket_ip_loop_monitored(SOCK_STREAM, 0); // monitored for incoming connections
|
32
32
|
if (this->server_ == nullptr) {
|
33
|
-
this->log_socket_error_("creation");
|
33
|
+
this->log_socket_error_(LOG_STR("creation"));
|
34
34
|
this->mark_failed();
|
35
35
|
return;
|
36
36
|
}
|
37
37
|
int enable = 1;
|
38
38
|
int err = this->server_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
|
39
39
|
if (err != 0) {
|
40
|
-
this->log_socket_error_("reuseaddr");
|
40
|
+
this->log_socket_error_(LOG_STR("reuseaddr"));
|
41
41
|
// we can still continue
|
42
42
|
}
|
43
43
|
err = this->server_->setblocking(false);
|
44
44
|
if (err != 0) {
|
45
|
-
this->log_socket_error_("non-blocking");
|
45
|
+
this->log_socket_error_(LOG_STR("non-blocking"));
|
46
46
|
this->mark_failed();
|
47
47
|
return;
|
48
48
|
}
|
@@ -51,21 +51,21 @@ void ESPHomeOTAComponent::setup() {
|
|
51
51
|
|
52
52
|
socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), this->port_);
|
53
53
|
if (sl == 0) {
|
54
|
-
this->log_socket_error_("set sockaddr");
|
54
|
+
this->log_socket_error_(LOG_STR("set sockaddr"));
|
55
55
|
this->mark_failed();
|
56
56
|
return;
|
57
57
|
}
|
58
58
|
|
59
59
|
err = this->server_->bind((struct sockaddr *) &server, sizeof(server));
|
60
60
|
if (err != 0) {
|
61
|
-
this->log_socket_error_("bind");
|
61
|
+
this->log_socket_error_(LOG_STR("bind"));
|
62
62
|
this->mark_failed();
|
63
63
|
return;
|
64
64
|
}
|
65
65
|
|
66
66
|
err = this->server_->listen(4);
|
67
67
|
if (err != 0) {
|
68
|
-
this->log_socket_error_("listen");
|
68
|
+
this->log_socket_error_(LOG_STR("listen"));
|
69
69
|
this->mark_failed();
|
70
70
|
return;
|
71
71
|
}
|
@@ -114,17 +114,17 @@ void ESPHomeOTAComponent::handle_handshake_() {
|
|
114
114
|
return;
|
115
115
|
int err = this->client_->setsockopt(IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(int));
|
116
116
|
if (err != 0) {
|
117
|
-
this->log_socket_error_("nodelay");
|
117
|
+
this->log_socket_error_(LOG_STR("nodelay"));
|
118
118
|
this->cleanup_connection_();
|
119
119
|
return;
|
120
120
|
}
|
121
121
|
err = this->client_->setblocking(false);
|
122
122
|
if (err != 0) {
|
123
|
-
this->log_socket_error_("non-blocking");
|
123
|
+
this->log_socket_error_(LOG_STR("non-blocking"));
|
124
124
|
this->cleanup_connection_();
|
125
125
|
return;
|
126
126
|
}
|
127
|
-
this->log_start_("handshake");
|
127
|
+
this->log_start_(LOG_STR("handshake"));
|
128
128
|
this->client_connect_time_ = App.get_loop_component_start_time();
|
129
129
|
this->magic_buf_pos_ = 0; // Reset magic buffer position
|
130
130
|
}
|
@@ -150,7 +150,7 @@ void ESPHomeOTAComponent::handle_handshake_() {
|
|
150
150
|
if (read <= 0) {
|
151
151
|
// Error or connection closed
|
152
152
|
if (read == -1) {
|
153
|
-
this->log_socket_error_("reading magic bytes");
|
153
|
+
this->log_socket_error_(LOG_STR("reading magic bytes"));
|
154
154
|
} else {
|
155
155
|
ESP_LOGW(TAG, "Remote closed during handshake");
|
156
156
|
}
|
@@ -209,7 +209,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|
209
209
|
|
210
210
|
// Read features - 1 byte
|
211
211
|
if (!this->readall_(buf, 1)) {
|
212
|
-
this->log_read_error_("features");
|
212
|
+
this->log_read_error_(LOG_STR("features"));
|
213
213
|
goto error; // NOLINT(cppcoreguidelines-avoid-goto)
|
214
214
|
}
|
215
215
|
ota_features = buf[0]; // NOLINT
|
@@ -288,7 +288,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|
288
288
|
|
289
289
|
// Read size, 4 bytes MSB first
|
290
290
|
if (!this->readall_(buf, 4)) {
|
291
|
-
this->log_read_error_("size");
|
291
|
+
this->log_read_error_(LOG_STR("size"));
|
292
292
|
goto error; // NOLINT(cppcoreguidelines-avoid-goto)
|
293
293
|
}
|
294
294
|
ota_size = 0;
|
@@ -302,7 +302,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|
302
302
|
// starting the update, set the warning status and notify
|
303
303
|
// listeners. This ensures that port scanners do not
|
304
304
|
// accidentally trigger the update process.
|
305
|
-
this->log_start_("update");
|
305
|
+
this->log_start_(LOG_STR("update"));
|
306
306
|
this->status_set_warning();
|
307
307
|
#ifdef USE_OTA_STATE_CALLBACK
|
308
308
|
this->state_callback_.call(ota::OTA_STARTED, 0.0f, 0);
|
@@ -320,7 +320,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|
320
320
|
|
321
321
|
// Read binary MD5, 32 bytes
|
322
322
|
if (!this->readall_(buf, 32)) {
|
323
|
-
this->log_read_error_("MD5 checksum");
|
323
|
+
this->log_read_error_(LOG_STR("MD5 checksum"));
|
324
324
|
goto error; // NOLINT(cppcoreguidelines-avoid-goto)
|
325
325
|
}
|
326
326
|
sbuf[32] = '\0';
|
@@ -393,7 +393,7 @@ void ESPHomeOTAComponent::handle_data_() {
|
|
393
393
|
|
394
394
|
// Read ACK
|
395
395
|
if (!this->readall_(buf, 1) || buf[0] != ota::OTA_RESPONSE_OK) {
|
396
|
-
this->log_read_error_("ack");
|
396
|
+
this->log_read_error_(LOG_STR("ack"));
|
397
397
|
// do not go to error, this is not fatal
|
398
398
|
}
|
399
399
|
|
@@ -477,12 +477,14 @@ float ESPHomeOTAComponent::get_setup_priority() const { return setup_priority::A
|
|
477
477
|
uint16_t ESPHomeOTAComponent::get_port() const { return this->port_; }
|
478
478
|
void ESPHomeOTAComponent::set_port(uint16_t port) { this->port_ = port; }
|
479
479
|
|
480
|
-
void ESPHomeOTAComponent::log_socket_error_(const
|
480
|
+
void ESPHomeOTAComponent::log_socket_error_(const LogString *msg) {
|
481
|
+
ESP_LOGW(TAG, "Socket %s: errno %d", LOG_STR_ARG(msg), errno);
|
482
|
+
}
|
481
483
|
|
482
|
-
void ESPHomeOTAComponent::log_read_error_(const
|
484
|
+
void ESPHomeOTAComponent::log_read_error_(const LogString *what) { ESP_LOGW(TAG, "Read %s failed", LOG_STR_ARG(what)); }
|
483
485
|
|
484
|
-
void ESPHomeOTAComponent::log_start_(const
|
485
|
-
ESP_LOGD(TAG, "Starting %s from %s", phase, this->client_->getpeername().c_str());
|
486
|
+
void ESPHomeOTAComponent::log_start_(const LogString *phase) {
|
487
|
+
ESP_LOGD(TAG, "Starting %s from %s", LOG_STR_ARG(phase), this->client_->getpeername().c_str());
|
486
488
|
}
|
487
489
|
|
488
490
|
void ESPHomeOTAComponent::cleanup_connection_() {
|
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
#include "esphome/core/defines.h"
|
4
4
|
#ifdef USE_OTA
|
5
|
-
#include "esphome/core/helpers.h"
|
6
|
-
#include "esphome/core/preferences.h"
|
7
5
|
#include "esphome/components/ota/ota_backend.h"
|
8
6
|
#include "esphome/components/socket/socket.h"
|
7
|
+
#include "esphome/core/helpers.h"
|
8
|
+
#include "esphome/core/log.h"
|
9
|
+
#include "esphome/core/preferences.h"
|
9
10
|
|
10
11
|
namespace esphome {
|
11
12
|
|
@@ -31,9 +32,9 @@ class ESPHomeOTAComponent : public ota::OTAComponent {
|
|
31
32
|
void handle_data_();
|
32
33
|
bool readall_(uint8_t *buf, size_t len);
|
33
34
|
bool writeall_(const uint8_t *buf, size_t len);
|
34
|
-
void log_socket_error_(const
|
35
|
-
void log_read_error_(const
|
36
|
-
void log_start_(const
|
35
|
+
void log_socket_error_(const LogString *msg);
|
36
|
+
void log_read_error_(const LogString *what);
|
37
|
+
void log_start_(const LogString *phase);
|
37
38
|
void cleanup_connection_();
|
38
39
|
void yield_and_feed_watchdog_();
|
39
40
|
|
@@ -38,7 +38,12 @@ from esphome.const import (
|
|
38
38
|
KEY_CORE,
|
39
39
|
KEY_FRAMEWORK_VERSION,
|
40
40
|
)
|
41
|
-
from esphome.core import
|
41
|
+
from esphome.core import (
|
42
|
+
CORE,
|
43
|
+
CoroPriority,
|
44
|
+
TimePeriodMilliseconds,
|
45
|
+
coroutine_with_priority,
|
46
|
+
)
|
42
47
|
import esphome.final_validate as fv
|
43
48
|
|
44
49
|
CONFLICTS_WITH = ["wifi"]
|
@@ -289,7 +294,7 @@ def phy_register(address: int, value: int, page: int):
|
|
289
294
|
)
|
290
295
|
|
291
296
|
|
292
|
-
@coroutine_with_priority(
|
297
|
+
@coroutine_with_priority(CoroPriority.COMMUNICATION)
|
293
298
|
async def to_code(config):
|
294
299
|
var = cg.new_Pvariable(config[CONF_ID])
|
295
300
|
await cg.register_component(var, config)
|