esphome 2025.9.2__py3-none-any.whl → 2025.10.0b1__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.
Files changed (344) hide show
  1. esphome/__main__.py +87 -31
  2. esphome/address_cache.py +142 -0
  3. esphome/automation.py +130 -32
  4. esphome/build_gen/platformio.py +1 -3
  5. esphome/codegen.py +1 -0
  6. esphome/components/animation/animation.cpp +2 -2
  7. esphome/components/api/__init__.py +167 -3
  8. esphome/components/api/api_connection.cpp +84 -41
  9. esphome/components/api/api_connection.h +22 -16
  10. esphome/components/api/api_frame_helper.cpp +33 -19
  11. esphome/components/api/api_frame_helper.h +19 -4
  12. esphome/components/api/api_frame_helper_noise.cpp +41 -53
  13. esphome/components/api/api_frame_helper_noise.h +1 -1
  14. esphome/components/api/api_frame_helper_plaintext.cpp +22 -31
  15. esphome/components/api/api_frame_helper_plaintext.h +1 -1
  16. esphome/components/api/api_pb2.cpp +189 -15
  17. esphome/components/api/api_pb2.h +132 -20
  18. esphome/components/api/api_pb2_dump.cpp +97 -9
  19. esphome/components/api/api_pb2_service.cpp +118 -160
  20. esphome/components/api/api_pb2_service.h +31 -3
  21. esphome/components/api/api_server.cpp +78 -11
  22. esphome/components/api/api_server.h +32 -4
  23. esphome/components/api/custom_api_device.h +8 -8
  24. esphome/components/api/homeassistant_service.h +123 -6
  25. esphome/components/api/proto.h +6 -2
  26. esphome/components/api/user_services.h +2 -2
  27. esphome/components/as7341/sensor.py +1 -1
  28. esphome/components/audio/__init__.py +1 -1
  29. esphome/components/audio/audio.cpp +1 -1
  30. esphome/components/audio/audio_decoder.cpp +9 -9
  31. esphome/components/bl0906/bl0906.cpp +2 -2
  32. esphome/components/bl0942/bl0942.cpp +2 -2
  33. esphome/components/ble_client/__init__.py +1 -1
  34. esphome/components/bluetooth_proxy/__init__.py +4 -30
  35. esphome/components/bluetooth_proxy/bluetooth_connection.cpp +11 -4
  36. esphome/components/bluetooth_proxy/bluetooth_connection.h +2 -2
  37. esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +2 -2
  38. esphome/components/camera_encoder/__init__.py +2 -4
  39. esphome/components/camera_encoder/esp32_camera_jpeg_encoder.cpp +4 -2
  40. esphome/components/camera_encoder/esp32_camera_jpeg_encoder.h +3 -1
  41. esphome/components/canbus/canbus.cpp +7 -5
  42. esphome/components/canbus/canbus.h +4 -4
  43. esphome/components/captive_portal/__init__.py +18 -1
  44. esphome/components/captive_portal/captive_portal.cpp +40 -46
  45. esphome/components/captive_portal/captive_portal.h +20 -22
  46. esphome/components/captive_portal/dns_server_esp32_idf.cpp +205 -0
  47. esphome/components/captive_portal/dns_server_esp32_idf.h +27 -0
  48. esphome/components/ccs811/ccs811.cpp +1 -1
  49. esphome/components/climate/climate.cpp +10 -7
  50. esphome/components/cm1106/cm1106.cpp +1 -1
  51. esphome/components/copy/lock/copy_lock.cpp +1 -1
  52. esphome/components/cover/cover.cpp +1 -0
  53. esphome/components/daikin_arc/daikin_arc.cpp +19 -12
  54. esphome/components/deep_sleep/__init__.py +9 -2
  55. esphome/components/deep_sleep/deep_sleep_component.h +11 -9
  56. esphome/components/deep_sleep/deep_sleep_esp32.cpp +51 -27
  57. esphome/components/ektf2232/touchscreen/__init__.py +8 -5
  58. esphome/components/ektf2232/touchscreen/ektf2232.cpp +4 -4
  59. esphome/components/ektf2232/touchscreen/ektf2232.h +2 -2
  60. esphome/components/epaper_spi/__init__.py +1 -0
  61. esphome/components/epaper_spi/display.py +80 -0
  62. esphome/components/epaper_spi/epaper_spi.cpp +227 -0
  63. esphome/components/epaper_spi/epaper_spi.h +93 -0
  64. esphome/components/epaper_spi/epaper_spi_model_7p3in_spectra_e6.cpp +42 -0
  65. esphome/components/epaper_spi/epaper_spi_model_7p3in_spectra_e6.h +45 -0
  66. esphome/components/epaper_spi/epaper_spi_spectra_e6.cpp +135 -0
  67. esphome/components/epaper_spi/epaper_spi_spectra_e6.h +23 -0
  68. esphome/components/es7210/es7210.cpp +3 -3
  69. esphome/components/esp32/__init__.py +254 -339
  70. esphome/components/esp32/boards.py +81 -0
  71. esphome/components/esp32/preferences.cpp +23 -17
  72. esphome/components/esp32_ble/__init__.py +159 -44
  73. esphome/components/esp32_ble/ble.cpp +47 -3
  74. esphome/components/esp32_ble/ble.h +18 -0
  75. esphome/components/esp32_ble/ble_advertising.cpp +7 -3
  76. esphome/components/esp32_ble/ble_advertising.h +4 -0
  77. esphome/components/esp32_ble/ble_uuid.cpp +16 -42
  78. esphome/components/esp32_ble_beacon/__init__.py +3 -4
  79. esphome/components/esp32_ble_client/ble_client_base.cpp +14 -12
  80. esphome/components/esp32_ble_server/__init__.py +28 -14
  81. esphome/components/esp32_ble_server/ble_characteristic.cpp +67 -57
  82. esphome/components/esp32_ble_server/ble_characteristic.h +27 -16
  83. esphome/components/esp32_ble_server/ble_descriptor.cpp +4 -3
  84. esphome/components/esp32_ble_server/ble_descriptor.h +13 -9
  85. esphome/components/esp32_ble_server/ble_server.cpp +59 -24
  86. esphome/components/esp32_ble_server/ble_server.h +38 -20
  87. esphome/components/esp32_ble_server/ble_server_automations.cpp +49 -33
  88. esphome/components/esp32_ble_server/ble_server_automations.h +39 -24
  89. esphome/components/esp32_ble_tracker/__init__.py +25 -80
  90. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +2 -4
  91. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +0 -3
  92. esphome/components/esp32_camera/__init__.py +1 -3
  93. esphome/components/esp32_can/esp32_can.cpp +22 -4
  94. esphome/components/esp32_can/esp32_can.h +3 -0
  95. esphome/components/esp32_hosted/__init__.py +2 -1
  96. esphome/components/esp32_improv/esp32_improv_component.cpp +102 -44
  97. esphome/components/esp32_improv/esp32_improv_component.h +6 -1
  98. esphome/components/esp32_rmt_led_strip/led_strip.cpp +1 -1
  99. esphome/components/esp8266/__init__.py +3 -3
  100. esphome/components/esphome/ota/__init__.py +21 -2
  101. esphome/components/esphome/ota/ota_esphome.cpp +455 -145
  102. esphome/components/esphome/ota/ota_esphome.h +49 -2
  103. esphome/components/ethernet/__init__.py +39 -22
  104. esphome/components/ethernet/ethernet_component.cpp +28 -5
  105. esphome/components/ethernet/ethernet_component.h +5 -1
  106. esphome/components/external_components/__init__.py +8 -6
  107. esphome/components/fingerprint_grow/fingerprint_grow.cpp +1 -1
  108. esphome/components/fingerprint_grow/fingerprint_grow.h +2 -1
  109. esphome/components/font/__init__.py +5 -5
  110. esphome/components/graph/graph.cpp +1 -1
  111. esphome/components/graphical_display_menu/graphical_display_menu.cpp +3 -2
  112. esphome/components/haier/hon_climate.cpp +2 -2
  113. esphome/components/haier/hon_climate.h +1 -1
  114. esphome/components/hdc1080/hdc1080.cpp +42 -34
  115. esphome/components/hdc1080/hdc1080.h +1 -3
  116. esphome/components/homeassistant/number/homeassistant_number.cpp +2 -2
  117. esphome/components/homeassistant/switch/homeassistant_switch.cpp +2 -2
  118. esphome/components/http_request/__init__.py +3 -3
  119. esphome/components/htu21d/htu21d.cpp +13 -18
  120. esphome/components/htu21d/htu21d.h +1 -1
  121. esphome/components/i2s_audio/__init__.py +1 -2
  122. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +1 -1
  123. esphome/components/ili9xxx/ili9xxx_display.cpp +2 -2
  124. esphome/components/improv_serial/improv_serial_component.cpp +12 -15
  125. esphome/components/improv_serial/improv_serial_component.h +6 -8
  126. esphome/components/json/json_util.cpp +35 -43
  127. esphome/components/json/json_util.h +57 -0
  128. esphome/components/kamstrup_kmp/kamstrup_kmp.cpp +2 -2
  129. esphome/components/key_collector/key_collector.h +4 -4
  130. esphome/components/libretiny/__init__.py +6 -6
  131. esphome/components/libretiny/preferences.cpp +23 -16
  132. esphome/components/light/light_call.cpp +98 -120
  133. esphome/components/light/light_call.h +17 -7
  134. esphome/components/lm75b/__init__.py +0 -0
  135. esphome/components/lm75b/lm75b.cpp +39 -0
  136. esphome/components/lm75b/lm75b.h +19 -0
  137. esphome/components/lm75b/sensor.py +34 -0
  138. esphome/components/lock/lock.h +12 -6
  139. esphome/components/logger/__init__.py +15 -27
  140. esphome/components/logger/logger.cpp +10 -20
  141. esphome/components/logger/logger.h +105 -62
  142. esphome/components/logger/logger_esp32.cpp +0 -48
  143. esphome/components/logger/logger_zephyr.cpp +2 -3
  144. esphome/components/logger/select/logger_level_select.cpp +6 -7
  145. esphome/components/logger/select/logger_level_select.h +7 -0
  146. esphome/components/ltr501/ltr501.cpp +7 -6
  147. esphome/components/ltr_als_ps/ltr_als_ps.cpp +7 -6
  148. esphome/components/matrix_keypad/matrix_keypad.h +4 -4
  149. esphome/components/max7219digit/max7219digit.cpp +1 -1
  150. esphome/components/mcp2515/mcp2515.cpp +31 -3
  151. esphome/components/mcp2515/mcp2515_defs.h +3 -1
  152. esphome/components/md5/md5.cpp +0 -26
  153. esphome/components/md5/md5.h +10 -20
  154. esphome/components/mdns/__init__.py +19 -6
  155. esphome/components/mdns/mdns_component.cpp +27 -59
  156. esphome/components/mdns/mdns_component.h +23 -10
  157. esphome/components/mdns/mdns_esp32.cpp +7 -7
  158. esphome/components/mdns/mdns_esp8266.cpp +6 -6
  159. esphome/components/mdns/mdns_libretiny.cpp +3 -3
  160. esphome/components/mdns/mdns_rp2040.cpp +3 -3
  161. esphome/components/mipi/__init__.py +1 -5
  162. esphome/components/mipi_spi/display.py +24 -8
  163. esphome/components/mipi_spi/mipi_spi.h +3 -3
  164. esphome/components/mixer/speaker/mixer_speaker.cpp +3 -3
  165. esphome/components/mmc5603/mmc5603.cpp +3 -3
  166. esphome/components/modbus/modbus.cpp +27 -13
  167. esphome/components/modbus/modbus.h +5 -3
  168. esphome/components/modbus/modbus_definitions.h +86 -0
  169. esphome/components/modbus_controller/__init__.py +29 -1
  170. esphome/components/modbus_controller/const.py +4 -0
  171. esphome/components/modbus_controller/modbus_controller.cpp +38 -13
  172. esphome/components/modbus_controller/modbus_controller.h +18 -29
  173. esphome/components/mpr121/mpr121.cpp +41 -42
  174. esphome/components/mpr121/mpr121.h +0 -1
  175. esphome/components/nau7802/nau7802.cpp +2 -2
  176. esphome/components/network/__init__.py +7 -3
  177. esphome/components/nextion/display.py +4 -4
  178. esphome/components/nextion/nextion.cpp +8 -8
  179. esphome/components/number/__init__.py +2 -0
  180. esphome/components/number/number_call.cpp +23 -12
  181. esphome/components/number/number_call.h +5 -0
  182. esphome/components/online_image/bmp_image.cpp +2 -1
  183. esphome/components/online_image/jpeg_image.cpp +4 -2
  184. esphome/components/openthread/openthread.cpp +6 -7
  185. esphome/components/openthread/openthread.h +0 -1
  186. esphome/components/ota/ota_backend.h +1 -0
  187. esphome/components/packages/__init__.py +10 -8
  188. esphome/components/packet_transport/packet_transport.cpp +2 -0
  189. esphome/components/pid/pid_controller.cpp +1 -1
  190. esphome/components/prometheus/prometheus_handler.cpp +239 -239
  191. esphome/components/psram/__init__.py +30 -28
  192. esphome/components/qmc5883l/qmc5883l.cpp +15 -0
  193. esphome/components/qmc5883l/qmc5883l.h +3 -0
  194. esphome/components/qmc5883l/sensor.py +31 -12
  195. esphome/components/remote_base/gobox_protocol.cpp +3 -3
  196. esphome/components/remote_receiver/__init__.py +14 -2
  197. esphome/components/remote_receiver/{remote_receiver_esp8266.cpp → remote_receiver.cpp} +2 -2
  198. esphome/components/remote_receiver/remote_receiver.h +4 -0
  199. esphome/components/remote_receiver/remote_receiver_esp32.cpp +18 -1
  200. esphome/components/remote_transmitter/__init__.py +2 -2
  201. esphome/components/remote_transmitter/remote_transmitter.cpp +103 -0
  202. esphome/components/rp2040/__init__.py +11 -11
  203. esphome/components/rtttl/rtttl.cpp +2 -2
  204. esphome/components/scd30/sensor.py +1 -1
  205. esphome/components/script/__init__.py +1 -1
  206. esphome/components/script/script.h +7 -7
  207. esphome/components/select/select.cpp +5 -4
  208. esphome/components/select/select_call.cpp +1 -1
  209. esphome/components/sensirion_common/i2c_sensirion.cpp +2 -1
  210. esphome/components/sensor/__init__.py +2 -0
  211. esphome/components/sha256/__init__.py +22 -0
  212. esphome/components/sha256/sha256.cpp +116 -0
  213. esphome/components/sha256/sha256.h +60 -0
  214. esphome/components/sim800l/sim800l.cpp +8 -4
  215. esphome/components/socket/lwip_raw_tcp_impl.cpp +34 -6
  216. esphome/components/sonoff_d1/sonoff_d1.cpp +1 -1
  217. esphome/components/spi/__init__.py +0 -3
  218. esphome/components/split_buffer/__init__.py +5 -0
  219. esphome/components/split_buffer/split_buffer.cpp +133 -0
  220. esphome/components/split_buffer/split_buffer.h +40 -0
  221. esphome/components/sps30/sps30.cpp +14 -10
  222. esphome/components/sps30/sps30.h +2 -0
  223. esphome/components/st7567_i2c/st7567_i2c.cpp +3 -1
  224. esphome/components/st7789v/st7789v.cpp +3 -2
  225. esphome/components/statsd/statsd.cpp +1 -1
  226. esphome/components/substitutions/__init__.py +3 -1
  227. esphome/components/substitutions/jinja.py +13 -3
  228. esphome/components/sx126x/__init__.py +16 -0
  229. esphome/components/sx126x/sx126x.cpp +15 -1
  230. esphome/components/sx126x/sx126x.h +9 -1
  231. esphome/components/sx126x/sx126x_reg.h +2 -0
  232. esphome/components/text_sensor/text_sensor.cpp +16 -0
  233. esphome/components/text_sensor/text_sensor.h +3 -10
  234. esphome/components/tormatic/tormatic_cover.cpp +1 -1
  235. esphome/components/tuya/select/tuya_select.cpp +1 -1
  236. esphome/components/tuya/tuya.cpp +29 -4
  237. esphome/components/uart/__init__.py +36 -26
  238. esphome/components/uart/uart.h +6 -0
  239. esphome/components/uart/uart_component.cpp +8 -0
  240. esphome/components/uart/uart_component.h +28 -0
  241. esphome/components/uart/uart_component_esp_idf.cpp +64 -10
  242. esphome/components/uart/uart_component_esp_idf.h +5 -2
  243. esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp +1 -1
  244. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +1 -1
  245. esphome/components/uponor_smatrix/uponor_smatrix.cpp +3 -3
  246. esphome/components/usb_host/__init__.py +2 -1
  247. esphome/components/usb_host/usb_host.h +82 -13
  248. esphome/components/usb_host/usb_host_client.cpp +180 -24
  249. esphome/components/usb_host/usb_host_component.cpp +1 -1
  250. esphome/components/usb_uart/__init__.py +0 -1
  251. esphome/components/usb_uart/ch34x.cpp +4 -4
  252. esphome/components/usb_uart/cp210x.cpp +3 -3
  253. esphome/components/usb_uart/usb_uart.cpp +88 -32
  254. esphome/components/usb_uart/usb_uart.h +30 -6
  255. esphome/components/valve/valve.cpp +1 -0
  256. esphome/components/veml7700/veml7700.cpp +7 -6
  257. esphome/components/version/version_text_sensor.cpp +2 -1
  258. esphome/components/voice_assistant/voice_assistant.cpp +3 -3
  259. esphome/components/waveshare_epaper/waveshare_epaper.cpp +4 -4
  260. esphome/components/web_server/list_entities.cpp +3 -4
  261. esphome/components/web_server/list_entities.h +8 -10
  262. esphome/components/web_server/ota/__init__.py +1 -1
  263. esphome/components/web_server/ota/ota_web_server.cpp +9 -3
  264. esphome/components/web_server/web_server.cpp +509 -404
  265. esphome/components/web_server/web_server.h +5 -6
  266. esphome/components/web_server/web_server_v1.cpp +21 -19
  267. esphome/components/web_server_base/__init__.py +5 -2
  268. esphome/components/web_server_base/web_server_base.h +27 -7
  269. esphome/components/web_server_idf/__init__.py +1 -1
  270. esphome/components/web_server_idf/multipart.cpp +2 -2
  271. esphome/components/web_server_idf/multipart.h +2 -2
  272. esphome/components/web_server_idf/utils.cpp +2 -2
  273. esphome/components/web_server_idf/utils.h +2 -2
  274. esphome/components/web_server_idf/web_server_idf.cpp +118 -26
  275. esphome/components/web_server_idf/web_server_idf.h +12 -10
  276. esphome/components/wifi/__init__.py +13 -11
  277. esphome/components/wifi/wifi_component.cpp +73 -56
  278. esphome/components/wifi/wifi_component.h +4 -4
  279. esphome/components/wifi/wifi_component_esp8266.cpp +1 -1
  280. esphome/components/wifi/wifi_component_esp_idf.cpp +24 -4
  281. esphome/components/wireguard/__init__.py +1 -1
  282. esphome/components/wts01/__init__.py +0 -0
  283. esphome/components/wts01/sensor.py +41 -0
  284. esphome/components/wts01/wts01.cpp +91 -0
  285. esphome/components/wts01/wts01.h +27 -0
  286. esphome/components/zephyr/__init__.py +5 -5
  287. esphome/components/zwave_proxy/__init__.py +43 -0
  288. esphome/components/zwave_proxy/zwave_proxy.cpp +346 -0
  289. esphome/components/zwave_proxy/zwave_proxy.h +93 -0
  290. esphome/config.py +79 -24
  291. esphome/config_validation.py +13 -15
  292. esphome/const.py +9 -2
  293. esphome/core/__init__.py +31 -22
  294. esphome/core/component.cpp +28 -18
  295. esphome/core/component_iterator.h +2 -1
  296. esphome/core/config.py +15 -15
  297. esphome/core/defines.h +19 -0
  298. esphome/core/hash_base.h +56 -0
  299. esphome/core/helpers.cpp +19 -3
  300. esphome/core/helpers.h +26 -0
  301. esphome/core/scheduler.cpp +5 -21
  302. esphome/core/scheduler.h +19 -8
  303. esphome/core/string_ref.h +1 -1
  304. esphome/core/time.cpp +5 -5
  305. esphome/cpp_generator.py +4 -29
  306. esphome/dashboard/const.py +21 -4
  307. esphome/dashboard/core.py +10 -8
  308. esphome/dashboard/dns.py +15 -0
  309. esphome/dashboard/entries.py +15 -21
  310. esphome/dashboard/models.py +76 -0
  311. esphome/dashboard/settings.py +7 -7
  312. esphome/dashboard/status/mdns.py +46 -2
  313. esphome/dashboard/web_server.py +367 -93
  314. esphome/espota2.py +111 -31
  315. esphome/external_files.py +6 -7
  316. esphome/git.py +8 -0
  317. esphome/helpers.py +124 -77
  318. esphome/loader.py +8 -9
  319. esphome/platformio_api.py +25 -18
  320. esphome/storage_json.py +26 -21
  321. esphome/types.py +30 -2
  322. esphome/util.py +32 -16
  323. esphome/vscode.py +8 -8
  324. esphome/wizard.py +10 -10
  325. esphome/writer.py +50 -15
  326. esphome/yaml_util.py +37 -31
  327. esphome/zeroconf.py +12 -3
  328. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/METADATA +11 -11
  329. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/RECORD +333 -313
  330. esphome/components/event_emitter/__init__.py +0 -5
  331. esphome/components/event_emitter/event_emitter.cpp +0 -14
  332. esphome/components/event_emitter/event_emitter.h +0 -63
  333. esphome/components/remote_receiver/remote_receiver_libretiny.cpp +0 -125
  334. esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +0 -107
  335. esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +0 -110
  336. esphome/components/uart/uart_component_esp32_arduino.cpp +0 -214
  337. esphome/components/uart/uart_component_esp32_arduino.h +0 -60
  338. esphome/components/wifi/wifi_component_esp32_arduino.cpp +0 -860
  339. esphome/core/string_ref.cpp +0 -12
  340. esphome/dashboard/util/file.py +0 -63
  341. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/WHEEL +0 -0
  342. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/entry_points.txt +0 -0
  343. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/licenses/LICENSE +0 -0
  344. {esphome-2025.9.2.dist-info → esphome-2025.10.0b1.dist-info}/top_level.txt +0 -0
@@ -9,12 +9,16 @@
9
9
  #include "esphome/core/log.h"
10
10
  #include "esphome/core/util.h"
11
11
  #include "esphome/core/version.h"
12
+ #ifdef USE_API_HOMEASSISTANT_SERVICES
13
+ #include "homeassistant_service.h"
14
+ #endif
12
15
 
13
16
  #ifdef USE_LOGGER
14
17
  #include "esphome/components/logger/logger.h"
15
18
  #endif
16
19
 
17
20
  #include <algorithm>
21
+ #include <utility>
18
22
 
19
23
  namespace esphome::api {
20
24
 
@@ -37,12 +41,14 @@ void APIServer::setup() {
37
41
 
38
42
  this->noise_pref_ = global_preferences->make_preference<SavedNoisePsk>(hash, true);
39
43
 
44
+ #ifndef USE_API_NOISE_PSK_FROM_YAML
45
+ // Only load saved PSK if not set from YAML
40
46
  SavedNoisePsk noise_pref_saved{};
41
47
  if (this->noise_pref_.load(&noise_pref_saved)) {
42
48
  ESP_LOGD(TAG, "Loaded saved Noise PSK");
43
-
44
49
  this->set_noise_psk(noise_pref_saved.psk);
45
50
  }
51
+ #endif
46
52
  #endif
47
53
 
48
54
  // Schedule reboot if no clients connect within timeout
@@ -85,7 +91,7 @@ void APIServer::setup() {
85
91
  return;
86
92
  }
87
93
 
88
- err = this->socket_->listen(4);
94
+ err = this->socket_->listen(this->listen_backlog_);
89
95
  if (err != 0) {
90
96
  ESP_LOGW(TAG, "Socket unable to listen: errno %d", errno);
91
97
  this->mark_failed();
@@ -138,9 +144,19 @@ void APIServer::loop() {
138
144
  while (true) {
139
145
  struct sockaddr_storage source_addr;
140
146
  socklen_t addr_len = sizeof(source_addr);
147
+
141
148
  auto sock = this->socket_->accept_loop_monitored((struct sockaddr *) &source_addr, &addr_len);
142
149
  if (!sock)
143
150
  break;
151
+
152
+ // Check if we're at the connection limit
153
+ if (this->clients_.size() >= this->max_connections_) {
154
+ ESP_LOGW(TAG, "Max connections (%d), rejecting %s", this->max_connections_, sock->getpeername().c_str());
155
+ // Immediately close - socket destructor will handle cleanup
156
+ sock.reset();
157
+ continue;
158
+ }
159
+
144
160
  ESP_LOGD(TAG, "Accept %s", sock->getpeername().c_str());
145
161
 
146
162
  auto *conn = new APIConnection(std::move(sock), this);
@@ -165,7 +181,8 @@ void APIServer::loop() {
165
181
  // Network is down - disconnect all clients
166
182
  for (auto &client : this->clients_) {
167
183
  client->on_fatal_error();
168
- ESP_LOGW(TAG, "%s: Network down; disconnect", client->get_client_combined_info().c_str());
184
+ ESP_LOGW(TAG, "%s (%s): Network down; disconnect", client->client_info_.name.c_str(),
185
+ client->client_info_.peername.c_str());
169
186
  }
170
187
  // Continue to process and clean up the clients below
171
188
  }
@@ -204,8 +221,10 @@ void APIServer::loop() {
204
221
  void APIServer::dump_config() {
205
222
  ESP_LOGCONFIG(TAG,
206
223
  "Server:\n"
207
- " Address: %s:%u",
208
- network::get_use_address().c_str(), this->port_);
224
+ " Address: %s:%u\n"
225
+ " Listen backlog: %u\n"
226
+ " Max connections: %u",
227
+ network::get_use_address().c_str(), this->port_, this->listen_backlog_, this->max_connections_);
209
228
  #ifdef USE_API_NOISE
210
229
  ESP_LOGCONFIG(TAG, " Noise encryption: %s", YESNO(this->noise_ctx_->has_psk()));
211
230
  if (!this->noise_ctx_->has_psk()) {
@@ -217,12 +236,12 @@ void APIServer::dump_config() {
217
236
  }
218
237
 
219
238
  #ifdef USE_API_PASSWORD
220
- bool APIServer::check_password(const std::string &password) const {
239
+ bool APIServer::check_password(const uint8_t *password_data, size_t password_len) const {
221
240
  // depend only on input password length
222
241
  const char *a = this->password_.c_str();
223
242
  uint32_t len_a = this->password_.length();
224
- const char *b = password.c_str();
225
- uint32_t len_b = password.length();
243
+ const char *b = reinterpret_cast<const char *>(password_data);
244
+ uint32_t len_b = password_len;
226
245
 
227
246
  // disable optimization with volatile
228
247
  volatile uint32_t length = len_b;
@@ -245,6 +264,7 @@ bool APIServer::check_password(const std::string &password) const {
245
264
 
246
265
  return result == 0;
247
266
  }
267
+
248
268
  #endif
249
269
 
250
270
  void APIServer::handle_disconnect(APIConnection *conn) {}
@@ -355,6 +375,15 @@ void APIServer::on_update(update::UpdateEntity *obj) {
355
375
  }
356
376
  #endif
357
377
 
378
+ #ifdef USE_ZWAVE_PROXY
379
+ void APIServer::on_zwave_proxy_request(const esphome::api::ProtoMessage &msg) {
380
+ // We could add code to manage a second subscription type, but, since this message type is
381
+ // very infrequent and small, we simply send it to all clients
382
+ for (auto &c : this->clients_)
383
+ c->send_message(msg, api::ZWaveProxyRequest::MESSAGE_TYPE);
384
+ }
385
+ #endif
386
+
358
387
  #ifdef USE_ALARM_CONTROL_PANEL
359
388
  API_DISPATCH_UPDATE(alarm_control_panel::AlarmControlPanel, alarm_control_panel)
360
389
  #endif
@@ -370,12 +399,43 @@ void APIServer::set_password(const std::string &password) { this->password_ = pa
370
399
  void APIServer::set_batch_delay(uint16_t batch_delay) { this->batch_delay_ = batch_delay; }
371
400
 
372
401
  #ifdef USE_API_HOMEASSISTANT_SERVICES
373
- void APIServer::send_homeassistant_service_call(const HomeassistantServiceResponse &call) {
402
+ void APIServer::send_homeassistant_action(const HomeassistantActionRequest &call) {
374
403
  for (auto &client : this->clients_) {
375
- client->send_homeassistant_service_call(call);
404
+ client->send_homeassistant_action(call);
376
405
  }
377
406
  }
378
- #endif
407
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
408
+ void APIServer::register_action_response_callback(uint32_t call_id, ActionResponseCallback callback) {
409
+ this->action_response_callbacks_.push_back({call_id, std::move(callback)});
410
+ }
411
+
412
+ void APIServer::handle_action_response(uint32_t call_id, bool success, const std::string &error_message) {
413
+ for (auto it = this->action_response_callbacks_.begin(); it != this->action_response_callbacks_.end(); ++it) {
414
+ if (it->call_id == call_id) {
415
+ auto callback = std::move(it->callback);
416
+ this->action_response_callbacks_.erase(it);
417
+ ActionResponse response(success, error_message);
418
+ callback(response);
419
+ return;
420
+ }
421
+ }
422
+ }
423
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
424
+ void APIServer::handle_action_response(uint32_t call_id, bool success, const std::string &error_message,
425
+ const uint8_t *response_data, size_t response_data_len) {
426
+ for (auto it = this->action_response_callbacks_.begin(); it != this->action_response_callbacks_.end(); ++it) {
427
+ if (it->call_id == call_id) {
428
+ auto callback = std::move(it->callback);
429
+ this->action_response_callbacks_.erase(it);
430
+ ActionResponse response(success, error_message, response_data, response_data_len);
431
+ callback(response);
432
+ return;
433
+ }
434
+ }
435
+ }
436
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
437
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
438
+ #endif // USE_API_HOMEASSISTANT_SERVICES
379
439
 
380
440
  #ifdef USE_API_HOMEASSISTANT_STATES
381
441
  void APIServer::subscribe_home_assistant_state(std::string entity_id, optional<std::string> attribute,
@@ -409,6 +469,12 @@ void APIServer::set_reboot_timeout(uint32_t reboot_timeout) { this->reboot_timeo
409
469
 
410
470
  #ifdef USE_API_NOISE
411
471
  bool APIServer::save_noise_psk(psk_t psk, bool make_active) {
472
+ #ifdef USE_API_NOISE_PSK_FROM_YAML
473
+ // When PSK is set from YAML, this function should never be called
474
+ // but if it is, reject the change
475
+ ESP_LOGW(TAG, "Key set in YAML");
476
+ return false;
477
+ #else
412
478
  auto &old_psk = this->noise_ctx_->get_psk();
413
479
  if (std::equal(old_psk.begin(), old_psk.end(), psk.begin())) {
414
480
  ESP_LOGW(TAG, "New PSK matches old");
@@ -437,6 +503,7 @@ bool APIServer::save_noise_psk(psk_t psk, bool make_active) {
437
503
  });
438
504
  }
439
505
  return true;
506
+ #endif
440
507
  }
441
508
  #endif
442
509
 
@@ -16,6 +16,7 @@
16
16
  #include "user_services.h"
17
17
  #endif
18
18
 
19
+ #include <map>
19
20
  #include <vector>
20
21
 
21
22
  namespace esphome::api {
@@ -37,13 +38,15 @@ class APIServer : public Component, public Controller {
37
38
  void on_shutdown() override;
38
39
  bool teardown() override;
39
40
  #ifdef USE_API_PASSWORD
40
- bool check_password(const std::string &password) const;
41
+ bool check_password(const uint8_t *password_data, size_t password_len) const;
41
42
  void set_password(const std::string &password);
42
43
  #endif
43
44
  void set_port(uint16_t port);
44
45
  void set_reboot_timeout(uint32_t reboot_timeout);
45
46
  void set_batch_delay(uint16_t batch_delay);
46
47
  uint16_t get_batch_delay() const { return batch_delay_; }
48
+ void set_listen_backlog(uint8_t listen_backlog) { this->listen_backlog_ = listen_backlog; }
49
+ void set_max_connections(uint8_t max_connections) { this->max_connections_ = max_connections; }
47
50
 
48
51
  // Get reference to shared buffer for API connections
49
52
  std::vector<uint8_t> &get_shared_buffer_ref() { return shared_write_buffer_; }
@@ -107,8 +110,19 @@ class APIServer : public Component, public Controller {
107
110
  void on_media_player_update(media_player::MediaPlayer *obj) override;
108
111
  #endif
109
112
  #ifdef USE_API_HOMEASSISTANT_SERVICES
110
- void send_homeassistant_service_call(const HomeassistantServiceResponse &call);
111
- #endif
113
+ void send_homeassistant_action(const HomeassistantActionRequest &call);
114
+
115
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
116
+ // Action response handling
117
+ using ActionResponseCallback = std::function<void(const class ActionResponse &)>;
118
+ void register_action_response_callback(uint32_t call_id, ActionResponseCallback callback);
119
+ void handle_action_response(uint32_t call_id, bool success, const std::string &error_message);
120
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
121
+ void handle_action_response(uint32_t call_id, bool success, const std::string &error_message,
122
+ const uint8_t *response_data, size_t response_data_len);
123
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
124
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
125
+ #endif // USE_API_HOMEASSISTANT_SERVICES
112
126
  #ifdef USE_API_SERVICES
113
127
  void register_user_service(UserServiceDescriptor *descriptor) { this->user_services_.push_back(descriptor); }
114
128
  #endif
@@ -125,6 +139,9 @@ class APIServer : public Component, public Controller {
125
139
  #ifdef USE_UPDATE
126
140
  void on_update(update::UpdateEntity *obj) override;
127
141
  #endif
142
+ #ifdef USE_ZWAVE_PROXY
143
+ void on_zwave_proxy_request(const esphome::api::ProtoMessage &msg);
144
+ #endif
128
145
 
129
146
  bool is_connected() const;
130
147
 
@@ -181,12 +198,23 @@ class APIServer : public Component, public Controller {
181
198
  #ifdef USE_API_SERVICES
182
199
  std::vector<UserServiceDescriptor *> user_services_;
183
200
  #endif
201
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
202
+ struct PendingActionResponse {
203
+ uint32_t call_id;
204
+ ActionResponseCallback callback;
205
+ };
206
+ std::vector<PendingActionResponse> action_response_callbacks_;
207
+ #endif
184
208
 
185
209
  // Group smaller types together
186
210
  uint16_t port_{6053};
187
211
  uint16_t batch_delay_{100};
212
+ // Connection limits - these defaults will be overridden by config values
213
+ // from cv.SplitDefault in __init__.py which sets platform-specific defaults
214
+ uint8_t listen_backlog_{4};
215
+ uint8_t max_connections_{8};
188
216
  bool shutting_down_ = false;
189
- // 5 bytes used, 3 bytes padding
217
+ // 7 bytes used, 1 byte padding
190
218
 
191
219
  #ifdef USE_API_NOISE
192
220
  std::shared_ptr<APINoiseContext> noise_ctx_ = std::make_shared<APINoiseContext>();
@@ -179,9 +179,9 @@ class CustomAPIDevice {
179
179
  * @param service_name The service to call.
180
180
  */
181
181
  void call_homeassistant_service(const std::string &service_name) {
182
- HomeassistantServiceResponse resp;
182
+ HomeassistantActionRequest resp;
183
183
  resp.set_service(StringRef(service_name));
184
- global_api_server->send_homeassistant_service_call(resp);
184
+ global_api_server->send_homeassistant_action(resp);
185
185
  }
186
186
 
187
187
  /** Call a Home Assistant service from ESPHome.
@@ -199,7 +199,7 @@ class CustomAPIDevice {
199
199
  * @param data The data for the service call, mapping from string to string.
200
200
  */
201
201
  void call_homeassistant_service(const std::string &service_name, const std::map<std::string, std::string> &data) {
202
- HomeassistantServiceResponse resp;
202
+ HomeassistantActionRequest resp;
203
203
  resp.set_service(StringRef(service_name));
204
204
  for (auto &it : data) {
205
205
  resp.data.emplace_back();
@@ -207,7 +207,7 @@ class CustomAPIDevice {
207
207
  kv.set_key(StringRef(it.first));
208
208
  kv.value = it.second;
209
209
  }
210
- global_api_server->send_homeassistant_service_call(resp);
210
+ global_api_server->send_homeassistant_action(resp);
211
211
  }
212
212
 
213
213
  /** Fire an ESPHome event in Home Assistant.
@@ -221,10 +221,10 @@ class CustomAPIDevice {
221
221
  * @param event_name The event to fire.
222
222
  */
223
223
  void fire_homeassistant_event(const std::string &event_name) {
224
- HomeassistantServiceResponse resp;
224
+ HomeassistantActionRequest resp;
225
225
  resp.set_service(StringRef(event_name));
226
226
  resp.is_event = true;
227
- global_api_server->send_homeassistant_service_call(resp);
227
+ global_api_server->send_homeassistant_action(resp);
228
228
  }
229
229
 
230
230
  /** Fire an ESPHome event in Home Assistant.
@@ -241,7 +241,7 @@ class CustomAPIDevice {
241
241
  * @param data The data for the event, mapping from string to string.
242
242
  */
243
243
  void fire_homeassistant_event(const std::string &service_name, const std::map<std::string, std::string> &data) {
244
- HomeassistantServiceResponse resp;
244
+ HomeassistantActionRequest resp;
245
245
  resp.set_service(StringRef(service_name));
246
246
  resp.is_event = true;
247
247
  for (auto &it : data) {
@@ -250,7 +250,7 @@ class CustomAPIDevice {
250
250
  kv.set_key(StringRef(it.first));
251
251
  kv.value = it.second;
252
252
  }
253
- global_api_server->send_homeassistant_service_call(resp);
253
+ global_api_server->send_homeassistant_action(resp);
254
254
  }
255
255
  #else
256
256
  template<typename T = void> void call_homeassistant_service(const std::string &service_name) {
@@ -3,10 +3,15 @@
3
3
  #include "api_server.h"
4
4
  #ifdef USE_API
5
5
  #ifdef USE_API_HOMEASSISTANT_SERVICES
6
+ #include <functional>
7
+ #include <utility>
8
+ #include <vector>
6
9
  #include "api_pb2.h"
10
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
11
+ #include "esphome/components/json/json_util.h"
12
+ #endif
7
13
  #include "esphome/core/automation.h"
8
14
  #include "esphome/core/helpers.h"
9
- #include <vector>
10
15
 
11
16
  namespace esphome::api {
12
17
 
@@ -44,9 +49,47 @@ template<typename... Ts> class TemplatableKeyValuePair {
44
49
  TemplatableStringValue<Ts...> value;
45
50
  };
46
51
 
52
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
53
+ // Represents the response data from a Home Assistant action
54
+ class ActionResponse {
55
+ public:
56
+ ActionResponse(bool success, std::string error_message = "")
57
+ : success_(success), error_message_(std::move(error_message)) {}
58
+
59
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
60
+ ActionResponse(bool success, std::string error_message, const uint8_t *data, size_t data_len)
61
+ : success_(success), error_message_(std::move(error_message)) {
62
+ if (data == nullptr || data_len == 0)
63
+ return;
64
+ this->json_document_ = json::parse_json(data, data_len);
65
+ }
66
+ #endif
67
+
68
+ bool is_success() const { return this->success_; }
69
+ const std::string &get_error_message() const { return this->error_message_; }
70
+
71
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
72
+ // Get data as parsed JSON object (const version returns read-only view)
73
+ JsonObjectConst get_json() const { return this->json_document_.as<JsonObjectConst>(); }
74
+ #endif
75
+
76
+ protected:
77
+ bool success_;
78
+ std::string error_message_;
79
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
80
+ JsonDocument json_document_;
81
+ #endif
82
+ };
83
+
84
+ // Callback type for action responses
85
+ template<typename... Ts> using ActionResponseCallback = std::function<void(const ActionResponse &, Ts...)>;
86
+ #endif
87
+
47
88
  template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts...> {
48
89
  public:
49
- explicit HomeAssistantServiceCallAction(APIServer *parent, bool is_event) : parent_(parent), is_event_(is_event) {}
90
+ explicit HomeAssistantServiceCallAction(APIServer *parent, bool is_event) : parent_(parent) {
91
+ this->flags_.is_event = is_event;
92
+ }
50
93
 
51
94
  template<typename T> void set_service(T service) { this->service_ = service; }
52
95
 
@@ -61,11 +104,29 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
61
104
  this->variables_.emplace_back(std::move(key), value);
62
105
  }
63
106
 
107
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
108
+ template<typename T> void set_response_template(T response_template) {
109
+ this->response_template_ = response_template;
110
+ this->flags_.has_response_template = true;
111
+ }
112
+
113
+ void set_wants_status() { this->flags_.wants_status = true; }
114
+ void set_wants_response() { this->flags_.wants_response = true; }
115
+
116
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
117
+ Trigger<JsonObjectConst, Ts...> *get_success_trigger_with_response() const {
118
+ return this->success_trigger_with_response_;
119
+ }
120
+ #endif
121
+ Trigger<Ts...> *get_success_trigger() const { return this->success_trigger_; }
122
+ Trigger<std::string, Ts...> *get_error_trigger() const { return this->error_trigger_; }
123
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
124
+
64
125
  void play(Ts... x) override {
65
- HomeassistantServiceResponse resp;
126
+ HomeassistantActionRequest resp;
66
127
  std::string service_value = this->service_.value(x...);
67
128
  resp.set_service(StringRef(service_value));
68
- resp.is_event = this->is_event_;
129
+ resp.is_event = this->flags_.is_event;
69
130
  for (auto &it : this->data_) {
70
131
  resp.data.emplace_back();
71
132
  auto &kv = resp.data.back();
@@ -84,18 +145,74 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
84
145
  kv.set_key(StringRef(it.key));
85
146
  kv.value = it.value.value(x...);
86
147
  }
87
- this->parent_->send_homeassistant_service_call(resp);
148
+
149
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
150
+ if (this->flags_.wants_status) {
151
+ // Generate a unique call ID for this service call
152
+ static uint32_t call_id_counter = 1;
153
+ uint32_t call_id = call_id_counter++;
154
+ resp.call_id = call_id;
155
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
156
+ if (this->flags_.wants_response) {
157
+ resp.wants_response = true;
158
+ // Set response template if provided
159
+ if (this->flags_.has_response_template) {
160
+ std::string response_template_value = this->response_template_.value(x...);
161
+ resp.response_template = response_template_value;
162
+ }
163
+ }
164
+ #endif
165
+
166
+ auto captured_args = std::make_tuple(x...);
167
+ this->parent_->register_action_response_callback(call_id, [this, captured_args](const ActionResponse &response) {
168
+ std::apply(
169
+ [this, &response](auto &&...args) {
170
+ if (response.is_success()) {
171
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
172
+ if (this->flags_.wants_response) {
173
+ this->success_trigger_with_response_->trigger(response.get_json(), args...);
174
+ } else
175
+ #endif
176
+ {
177
+ this->success_trigger_->trigger(args...);
178
+ }
179
+ } else {
180
+ this->error_trigger_->trigger(response.get_error_message(), args...);
181
+ }
182
+ },
183
+ captured_args);
184
+ });
185
+ }
186
+ #endif
187
+
188
+ this->parent_->send_homeassistant_action(resp);
88
189
  }
89
190
 
90
191
  protected:
91
192
  APIServer *parent_;
92
- bool is_event_;
93
193
  TemplatableStringValue<Ts...> service_{};
94
194
  std::vector<TemplatableKeyValuePair<Ts...>> data_;
95
195
  std::vector<TemplatableKeyValuePair<Ts...>> data_template_;
96
196
  std::vector<TemplatableKeyValuePair<Ts...>> variables_;
197
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
198
+ #ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
199
+ TemplatableStringValue<Ts...> response_template_{""};
200
+ Trigger<JsonObjectConst, Ts...> *success_trigger_with_response_ = new Trigger<JsonObjectConst, Ts...>();
201
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
202
+ Trigger<Ts...> *success_trigger_ = new Trigger<Ts...>();
203
+ Trigger<std::string, Ts...> *error_trigger_ = new Trigger<std::string, Ts...>();
204
+ #endif // USE_API_HOMEASSISTANT_ACTION_RESPONSES
205
+
206
+ struct Flags {
207
+ uint8_t is_event : 1;
208
+ uint8_t wants_status : 1;
209
+ uint8_t wants_response : 1;
210
+ uint8_t has_response_template : 1;
211
+ uint8_t reserved : 5;
212
+ } flags_{0};
97
213
  };
98
214
 
99
215
  } // namespace esphome::api
216
+
100
217
  #endif
101
218
  #endif
@@ -182,6 +182,10 @@ class ProtoLengthDelimited {
182
182
  explicit ProtoLengthDelimited(const uint8_t *value, size_t length) : value_(value), length_(length) {}
183
183
  std::string as_string() const { return std::string(reinterpret_cast<const char *>(this->value_), this->length_); }
184
184
 
185
+ // Direct access to raw data without string allocation
186
+ const uint8_t *data() const { return this->value_; }
187
+ size_t size() const { return this->length_; }
188
+
185
189
  /**
186
190
  * Decode the length-delimited data into an existing ProtoDecodableMessage instance.
187
191
  *
@@ -827,7 +831,7 @@ class ProtoService {
827
831
  }
828
832
 
829
833
  // Authentication helper methods
830
- bool check_connection_setup_() {
834
+ inline bool check_connection_setup_() {
831
835
  if (!this->is_connection_setup()) {
832
836
  this->on_no_setup_connection();
833
837
  return false;
@@ -835,7 +839,7 @@ class ProtoService {
835
839
  return true;
836
840
  }
837
841
 
838
- bool check_authenticated_() {
842
+ inline bool check_authenticated_() {
839
843
  #ifdef USE_API_PASSWORD
840
844
  if (!this->check_connection_setup_()) {
841
845
  return false;
@@ -35,7 +35,7 @@ template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
35
35
  msg.set_name(StringRef(this->name_));
36
36
  msg.key = this->key_;
37
37
  std::array<enums::ServiceArgType, sizeof...(Ts)> arg_types = {to_service_arg_type<Ts>()...};
38
- for (int i = 0; i < sizeof...(Ts); i++) {
38
+ for (size_t i = 0; i < sizeof...(Ts); i++) {
39
39
  msg.args.emplace_back();
40
40
  auto &arg = msg.args.back();
41
41
  arg.type = arg_types[i];
@@ -55,7 +55,7 @@ template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
55
55
 
56
56
  protected:
57
57
  virtual void execute(Ts... x) = 0;
58
- template<int... S> void execute_(std::vector<ExecuteServiceArgument> args, seq<S...> type) {
58
+ template<int... S> void execute_(const std::vector<ExecuteServiceArgument> &args, seq<S...> type) {
59
59
  this->execute((get_execute_arg_value<Ts>(args[S]))...);
60
60
  }
61
61
 
@@ -2,6 +2,7 @@ import esphome.codegen as cg
2
2
  from esphome.components import i2c, sensor
3
3
  import esphome.config_validation as cv
4
4
  from esphome.const import (
5
+ CONF_CLEAR,
5
6
  CONF_GAIN,
6
7
  CONF_ID,
7
8
  DEVICE_CLASS_ILLUMINANCE,
@@ -29,7 +30,6 @@ CONF_F5 = "f5"
29
30
  CONF_F6 = "f6"
30
31
  CONF_F7 = "f7"
31
32
  CONF_F8 = "f8"
32
- CONF_CLEAR = "clear"
33
33
  CONF_NIR = "nir"
34
34
 
35
35
  UNIT_COUNTS = "#"
@@ -165,4 +165,4 @@ def final_validate_audio_schema(
165
165
 
166
166
 
167
167
  async def to_code(config):
168
- cg.add_library("esphome/esp-audio-libs", "1.1.4")
168
+ cg.add_library("esphome/esp-audio-libs", "2.0.1")
@@ -57,7 +57,7 @@ const char *audio_file_type_to_string(AudioFileType file_type) {
57
57
  void scale_audio_samples(const int16_t *audio_samples, int16_t *output_buffer, int16_t scale_factor,
58
58
  size_t samples_to_scale) {
59
59
  // Note the assembly dsps_mulc function has audio glitches if the input and output buffers are the same.
60
- for (int i = 0; i < samples_to_scale; i++) {
60
+ for (size_t i = 0; i < samples_to_scale; i++) {
61
61
  int32_t acc = (int32_t) audio_samples[i] * (int32_t) scale_factor;
62
62
  output_buffer[i] = (int16_t) (acc >> 15);
63
63
  }
@@ -229,18 +229,18 @@ FileDecoderState AudioDecoder::decode_flac_() {
229
229
  auto result = this->flac_decoder_->read_header(this->input_transfer_buffer_->get_buffer_start(),
230
230
  this->input_transfer_buffer_->available());
231
231
 
232
- if (result == esp_audio_libs::flac::FLAC_DECODER_HEADER_OUT_OF_DATA) {
233
- return FileDecoderState::POTENTIALLY_FAILED;
234
- }
235
-
236
- if (result != esp_audio_libs::flac::FLAC_DECODER_SUCCESS) {
237
- // Couldn't read FLAC header
232
+ if (result > esp_audio_libs::flac::FLAC_DECODER_HEADER_OUT_OF_DATA) {
233
+ // Serrious error reading FLAC header, there is no recovery
238
234
  return FileDecoderState::FAILED;
239
235
  }
240
236
 
241
237
  size_t bytes_consumed = this->flac_decoder_->get_bytes_index();
242
238
  this->input_transfer_buffer_->decrease_buffer_length(bytes_consumed);
243
239
 
240
+ if (result == esp_audio_libs::flac::FLAC_DECODER_HEADER_OUT_OF_DATA) {
241
+ return FileDecoderState::MORE_TO_PROCESS;
242
+ }
243
+
244
244
  // Reallocate the output transfer buffer to the smallest necessary size
245
245
  this->free_buffer_required_ = flac_decoder_->get_output_buffer_size_bytes();
246
246
  if (!this->output_transfer_buffer_->reallocate(this->free_buffer_required_)) {
@@ -256,9 +256,9 @@ FileDecoderState AudioDecoder::decode_flac_() {
256
256
  }
257
257
 
258
258
  uint32_t output_samples = 0;
259
- auto result = this->flac_decoder_->decode_frame(
260
- this->input_transfer_buffer_->get_buffer_start(), this->input_transfer_buffer_->available(),
261
- reinterpret_cast<int16_t *>(this->output_transfer_buffer_->get_buffer_end()), &output_samples);
259
+ auto result = this->flac_decoder_->decode_frame(this->input_transfer_buffer_->get_buffer_start(),
260
+ this->input_transfer_buffer_->available(),
261
+ this->output_transfer_buffer_->get_buffer_end(), &output_samples);
262
262
 
263
263
  if (result == esp_audio_libs::flac::FLAC_DECODER_ERROR_OUT_OF_DATA) {
264
264
  // Not an issue, just needs more data that we'll get next time.
@@ -97,10 +97,10 @@ void BL0906::handle_actions_() {
97
97
  return;
98
98
  }
99
99
  ActionCallbackFuncPtr ptr_func = nullptr;
100
- for (int i = 0; i < this->action_queue_.size(); i++) {
100
+ for (size_t i = 0; i < this->action_queue_.size(); i++) {
101
101
  ptr_func = this->action_queue_[i];
102
102
  if (ptr_func) {
103
- ESP_LOGI(TAG, "HandleActionCallback[%d]", i);
103
+ ESP_LOGI(TAG, "HandleActionCallback[%zu]", i);
104
104
  (this->*ptr_func)();
105
105
  }
106
106
  }
@@ -51,7 +51,7 @@ void BL0942::loop() {
51
51
  if (!avail) {
52
52
  return;
53
53
  }
54
- if (avail < sizeof(buffer)) {
54
+ if (static_cast<size_t>(avail) < sizeof(buffer)) {
55
55
  if (!this->rx_start_) {
56
56
  this->rx_start_ = millis();
57
57
  } else if (millis() > this->rx_start_ + PKT_TIMEOUT_MS) {
@@ -148,7 +148,7 @@ void BL0942::setup() {
148
148
 
149
149
  this->write_reg_(BL0942_REG_USR_WRPROT, 0);
150
150
 
151
- if (this->read_reg_(BL0942_REG_MODE) != mode)
151
+ if (static_cast<uint32_t>(this->read_reg_(BL0942_REG_MODE)) != mode)
152
152
  this->status_set_warning(LOG_STR("BL0942 setup failed!"));
153
153
 
154
154
  this->flush();
@@ -116,7 +116,7 @@ CONFIG_SCHEMA = cv.All(
116
116
  )
117
117
  .extend(cv.COMPONENT_SCHEMA)
118
118
  .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA),
119
- esp32_ble_tracker.consume_connection_slots(1, "ble_client"),
119
+ esp32_ble.consume_connection_slots(1, "ble_client"),
120
120
  )
121
121
 
122
122
  CONF_BLE_CLIENT_ID = "ble_client_id"