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
@@ -5,10 +5,12 @@ from esphome.components.const import CONF_REQUEST_HEADERS
5
5
  from esphome.config_helpers import filter_source_files_from_platform
6
6
  import esphome.config_validation as cv
7
7
  from esphome.const import (
8
+ CONF_CAPTURE_RESPONSE,
8
9
  CONF_ESP8266_DISABLE_SSL_SUPPORT,
9
10
  CONF_ID,
10
11
  CONF_METHOD,
11
12
  CONF_ON_ERROR,
13
+ CONF_ON_RESPONSE,
12
14
  CONF_TIMEOUT,
13
15
  CONF_TRIGGER_ID,
14
16
  CONF_URL,
@@ -52,12 +54,10 @@ CONF_BUFFER_SIZE_TX = "buffer_size_tx"
52
54
  CONF_CA_CERTIFICATE_PATH = "ca_certificate_path"
53
55
 
54
56
  CONF_MAX_RESPONSE_BUFFER_SIZE = "max_response_buffer_size"
55
- CONF_ON_RESPONSE = "on_response"
56
57
  CONF_HEADERS = "headers"
57
58
  CONF_COLLECT_HEADERS = "collect_headers"
58
59
  CONF_BODY = "body"
59
60
  CONF_JSON = "json"
60
- CONF_CAPTURE_RESPONSE = "capture_response"
61
61
 
62
62
 
63
63
  def validate_url(value):
@@ -194,7 +194,7 @@ async def to_code(config):
194
194
  cg.add_define("CPPHTTPLIB_OPENSSL_SUPPORT")
195
195
  elif path := config.get(CONF_CA_CERTIFICATE_PATH):
196
196
  cg.add_define("CPPHTTPLIB_OPENSSL_SUPPORT")
197
- cg.add(var.set_ca_path(path))
197
+ cg.add(var.set_ca_path(str(path)))
198
198
  cg.add_build_flag("-lssl")
199
199
  cg.add_build_flag("-lcrypto")
200
200
 
@@ -9,8 +9,8 @@ static const char *const TAG = "htu21d";
9
9
 
10
10
  static const uint8_t HTU21D_ADDRESS = 0x40;
11
11
  static const uint8_t HTU21D_REGISTER_RESET = 0xFE;
12
- static const uint8_t HTU21D_REGISTER_TEMPERATURE = 0xF3;
13
- static const uint8_t HTU21D_REGISTER_HUMIDITY = 0xF5;
12
+ static const uint8_t HTU21D_REGISTER_TEMPERATURE = 0xE3;
13
+ static const uint8_t HTU21D_REGISTER_HUMIDITY = 0xE5;
14
14
  static const uint8_t HTU21D_WRITERHT_REG_CMD = 0xE6; /**< Write RH/T User Register 1 */
15
15
  static const uint8_t HTU21D_REGISTER_STATUS = 0xE7;
16
16
  static const uint8_t HTU21D_WRITEHEATER_REG_CMD = 0x51; /**< Write Heater Control Register */
@@ -57,7 +57,6 @@ void HTU21DComponent::update() {
57
57
 
58
58
  if (this->temperature_ != nullptr)
59
59
  this->temperature_->publish_state(temperature);
60
- this->status_clear_warning();
61
60
 
62
61
  if (this->write(&HTU21D_REGISTER_HUMIDITY, 1) != i2c::ERROR_OK) {
63
62
  this->status_set_warning();
@@ -79,10 +78,11 @@ void HTU21DComponent::update() {
79
78
  if (this->humidity_ != nullptr)
80
79
  this->humidity_->publish_state(humidity);
81
80
 
82
- int8_t heater_level;
81
+ this->status_clear_warning();
83
82
 
84
83
  // HTU21D does have a heater module but does not have heater level
85
84
  // Setting heater level to 1 in case the heater is ON
85
+ uint8_t heater_level = 0;
86
86
  if (this->sensor_model_ == HTU21D_SENSOR_MODEL_HTU21D) {
87
87
  if (this->is_heater_enabled()) {
88
88
  heater_level = 1;
@@ -97,34 +97,30 @@ void HTU21DComponent::update() {
97
97
 
98
98
  if (this->heater_ != nullptr)
99
99
  this->heater_->publish_state(heater_level);
100
- this->status_clear_warning();
101
100
  });
102
101
  });
103
102
  }
104
103
 
105
104
  bool HTU21DComponent::is_heater_enabled() {
106
105
  uint8_t raw_heater;
107
- if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
106
+ if (this->read_register(HTU21D_REGISTER_STATUS, &raw_heater, 1) != i2c::ERROR_OK) {
108
107
  this->status_set_warning();
109
108
  return false;
110
109
  }
111
- raw_heater = i2c::i2ctohs(raw_heater);
112
- return (bool) (((raw_heater) >> (HTU21D_REG_HTRE_BIT)) & 0x01);
110
+ return (bool) ((raw_heater >> HTU21D_REG_HTRE_BIT) & 0x01);
113
111
  }
114
112
 
115
113
  void HTU21DComponent::set_heater(bool status) {
116
114
  uint8_t raw_heater;
117
- if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
115
+ if (this->read_register(HTU21D_REGISTER_STATUS, &raw_heater, 1) != i2c::ERROR_OK) {
118
116
  this->status_set_warning();
119
117
  return;
120
118
  }
121
- raw_heater = i2c::i2ctohs(raw_heater);
122
119
  if (status) {
123
- raw_heater |= (1 << (HTU21D_REG_HTRE_BIT));
120
+ raw_heater |= (1 << HTU21D_REG_HTRE_BIT);
124
121
  } else {
125
- raw_heater &= ~(1 << (HTU21D_REG_HTRE_BIT));
122
+ raw_heater &= ~(1 << HTU21D_REG_HTRE_BIT);
126
123
  }
127
-
128
124
  if (this->write_register(HTU21D_WRITERHT_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
129
125
  this->status_set_warning();
130
126
  return;
@@ -138,14 +134,13 @@ void HTU21DComponent::set_heater_level(uint8_t level) {
138
134
  }
139
135
  }
140
136
 
141
- int8_t HTU21DComponent::get_heater_level() {
142
- int8_t raw_heater;
143
- if (this->read_register(HTU21D_READHEATER_REG_CMD, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) {
137
+ uint8_t HTU21DComponent::get_heater_level() {
138
+ uint8_t raw_heater;
139
+ if (this->read_register(HTU21D_READHEATER_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
144
140
  this->status_set_warning();
145
141
  return 0;
146
142
  }
147
- raw_heater = i2c::i2ctohs(raw_heater);
148
- return raw_heater;
143
+ return raw_heater & 0xF;
149
144
  }
150
145
 
151
146
  float HTU21DComponent::get_setup_priority() const { return setup_priority::DATA; }
@@ -26,7 +26,7 @@ class HTU21DComponent : public PollingComponent, public i2c::I2CDevice {
26
26
  bool is_heater_enabled();
27
27
  void set_heater(bool status);
28
28
  void set_heater_level(uint8_t level);
29
- int8_t get_heater_level();
29
+ uint8_t get_heater_level();
30
30
 
31
31
  float get_setup_priority() const override;
32
32
 
@@ -262,8 +262,7 @@ async def to_code(config):
262
262
  cg.add_define("USE_I2S_LEGACY")
263
263
 
264
264
  # Helps avoid callbacks being skipped due to processor load
265
- if CORE.using_esp_idf:
266
- add_idf_sdkconfig_option("CONFIG_I2S_ISR_IRAM_SAFE", True)
265
+ add_idf_sdkconfig_option("CONFIG_I2S_ISR_IRAM_SAFE", True)
267
266
 
268
267
  cg.add(var.set_lrclk_pin(config[CONF_I2S_LRCLK_PIN]))
269
268
  if CONF_I2S_BCLK_PIN in config:
@@ -377,7 +377,7 @@ void I2SAudioSpeaker::speaker_task(void *params) {
377
377
  this_speaker->current_stream_info_.get_bits_per_sample() <= 16) {
378
378
  size_t len = bytes_read / sizeof(int16_t);
379
379
  int16_t *tmp_buf = (int16_t *) new_data;
380
- for (int i = 0; i < len; i += 2) {
380
+ for (size_t i = 0; i < len; i += 2) {
381
381
  int16_t tmp = tmp_buf[i];
382
382
  tmp_buf[i] = tmp_buf[i + 1];
383
383
  tmp_buf[i + 1] = tmp;
@@ -325,7 +325,7 @@ void ILI9XXXDisplay::draw_pixels_at(int x_start, int y_start, int w, int h, cons
325
325
  // we could deal here with a non-zero y_offset, but if x_offset is zero, y_offset probably will be so don't bother
326
326
  this->write_array(ptr, w * h * 2);
327
327
  } else {
328
- for (size_t y = 0; y != h; y++) {
328
+ for (size_t y = 0; y != static_cast<size_t>(h); y++) {
329
329
  this->write_array(ptr + (y + y_offset) * stride + x_offset, w * 2);
330
330
  }
331
331
  }
@@ -349,7 +349,7 @@ void ILI9XXXDisplay::draw_pixels_at(int x_start, int y_start, int w, int h, cons
349
349
  App.feed_wdt();
350
350
  }
351
351
  // end of line? Skip to the next.
352
- if (++pixel == w) {
352
+ if (++pixel == static_cast<size_t>(w)) {
353
353
  pixel = 0;
354
354
  ptr += (x_pad + x_offset) * 2;
355
355
  }
@@ -15,11 +15,10 @@ static const char *const TAG = "improv_serial";
15
15
 
16
16
  void ImprovSerialComponent::setup() {
17
17
  global_improv_serial_component = this;
18
- #ifdef USE_ARDUINO
19
- this->hw_serial_ = logger::global_logger->get_hw_serial();
20
- #endif
21
- #ifdef USE_ESP_IDF
18
+ #ifdef USE_ESP32
22
19
  this->uart_num_ = logger::global_logger->get_uart_num();
20
+ #elif defined(USE_ARDUINO)
21
+ this->hw_serial_ = logger::global_logger->get_hw_serial();
23
22
  #endif
24
23
 
25
24
  if (wifi::global_wifi_component->has_sta()) {
@@ -34,13 +33,7 @@ void ImprovSerialComponent::dump_config() { ESP_LOGCONFIG(TAG, "Improv Serial:")
34
33
  optional<uint8_t> ImprovSerialComponent::read_byte_() {
35
34
  optional<uint8_t> byte;
36
35
  uint8_t data = 0;
37
- #ifdef USE_ARDUINO
38
- if (this->hw_serial_->available()) {
39
- this->hw_serial_->readBytes(&data, 1);
40
- byte = data;
41
- }
42
- #endif
43
- #ifdef USE_ESP_IDF
36
+ #ifdef USE_ESP32
44
37
  switch (logger::global_logger->get_uart()) {
45
38
  case logger::UART_SELECTION_UART0:
46
39
  case logger::UART_SELECTION_UART1:
@@ -76,16 +69,18 @@ optional<uint8_t> ImprovSerialComponent::read_byte_() {
76
69
  default:
77
70
  break;
78
71
  }
72
+ #elif defined(USE_ARDUINO)
73
+ if (this->hw_serial_->available()) {
74
+ this->hw_serial_->readBytes(&data, 1);
75
+ byte = data;
76
+ }
79
77
  #endif
80
78
  return byte;
81
79
  }
82
80
 
83
81
  void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
84
82
  data.push_back('\n');
85
- #ifdef USE_ARDUINO
86
- this->hw_serial_->write(data.data(), data.size());
87
- #endif
88
- #ifdef USE_ESP_IDF
83
+ #ifdef USE_ESP32
89
84
  switch (logger::global_logger->get_uart()) {
90
85
  case logger::UART_SELECTION_UART0:
91
86
  case logger::UART_SELECTION_UART1:
@@ -112,6 +107,8 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
112
107
  default:
113
108
  break;
114
109
  }
110
+ #elif defined(USE_ARDUINO)
111
+ this->hw_serial_->write(data.data(), data.size());
115
112
  #endif
116
113
  }
117
114
 
@@ -9,10 +9,7 @@
9
9
  #include <improv.h>
10
10
  #include <vector>
11
11
 
12
- #ifdef USE_ARDUINO
13
- #include <HardwareSerial.h>
14
- #endif
15
- #ifdef USE_ESP_IDF
12
+ #ifdef USE_ESP32
16
13
  #include <driver/uart.h>
17
14
  #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
18
15
  defined(USE_ESP32_VARIANT_ESP32H2)
@@ -22,6 +19,8 @@
22
19
  #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
23
20
  #include <esp_private/usb_console.h>
24
21
  #endif
22
+ #elif defined(USE_ARDUINO)
23
+ #include <HardwareSerial.h>
25
24
  #endif
26
25
 
27
26
  namespace esphome {
@@ -60,11 +59,10 @@ class ImprovSerialComponent : public Component, public improv_base::ImprovBase {
60
59
  optional<uint8_t> read_byte_();
61
60
  void write_data_(std::vector<uint8_t> &data);
62
61
 
63
- #ifdef USE_ARDUINO
64
- Stream *hw_serial_{nullptr};
65
- #endif
66
- #ifdef USE_ESP_IDF
62
+ #ifdef USE_ESP32
67
63
  uart_port_t uart_num_;
64
+ #elif defined(USE_ARDUINO)
65
+ Stream *hw_serial_{nullptr};
68
66
  #endif
69
67
 
70
68
  std::vector<uint8_t> rx_buffer_;
@@ -8,70 +8,62 @@ namespace json {
8
8
 
9
9
  static const char *const TAG = "json";
10
10
 
11
- // Build an allocator for the JSON Library using the RAMAllocator class
12
- struct SpiRamAllocator : ArduinoJson::Allocator {
13
- void *allocate(size_t size) override { return this->allocator_.allocate(size); }
14
-
15
- void deallocate(void *pointer) override {
16
- // ArduinoJson's Allocator interface doesn't provide the size parameter in deallocate.
17
- // RAMAllocator::deallocate() requires the size, which we don't have access to here.
18
- // RAMAllocator::deallocate implementation just calls free() regardless of whether
19
- // the memory was allocated with heap_caps_malloc or malloc.
20
- // This is safe because ESP-IDF's heap implementation internally tracks the memory region
21
- // and routes free() to the appropriate heap.
22
- free(pointer); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc)
23
- }
24
-
25
- void *reallocate(void *ptr, size_t new_size) override {
26
- return this->allocator_.reallocate(static_cast<uint8_t *>(ptr), new_size);
27
- }
28
-
29
- protected:
30
- RAMAllocator<uint8_t> allocator_{RAMAllocator<uint8_t>(RAMAllocator<uint8_t>::NONE)};
31
- };
32
-
33
11
  std::string build_json(const json_build_t &f) {
34
12
  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
35
- auto doc_allocator = SpiRamAllocator();
36
- JsonDocument json_document(&doc_allocator);
37
- if (json_document.overflowed()) {
38
- ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
39
- return "{}";
40
- }
41
- JsonObject root = json_document.to<JsonObject>();
13
+ JsonBuilder builder;
14
+ JsonObject root = builder.root();
42
15
  f(root);
43
- if (json_document.overflowed()) {
44
- ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
45
- return "{}";
46
- }
47
- std::string output;
48
- serializeJson(json_document, output);
49
- return output;
16
+ return builder.serialize();
50
17
  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
51
18
  }
52
19
 
53
20
  bool parse_json(const std::string &data, const json_parse_t &f) {
54
21
  // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
22
+ JsonDocument doc = parse_json(reinterpret_cast<const uint8_t *>(data.c_str()), data.size());
23
+ if (doc.overflowed() || doc.isNull())
24
+ return false;
25
+ return f(doc.as<JsonObject>());
26
+ // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
27
+ }
28
+
29
+ JsonDocument parse_json(const uint8_t *data, size_t len) {
30
+ // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
31
+ if (data == nullptr || len == 0) {
32
+ ESP_LOGE(TAG, "No data to parse");
33
+ return JsonObject(); // return unbound object
34
+ }
35
+ #ifdef USE_PSRAM
55
36
  auto doc_allocator = SpiRamAllocator();
56
37
  JsonDocument json_document(&doc_allocator);
38
+ #else
39
+ JsonDocument json_document;
40
+ #endif
57
41
  if (json_document.overflowed()) {
58
42
  ESP_LOGE(TAG, "Could not allocate memory for JSON document!");
59
- return false;
43
+ return JsonObject(); // return unbound object
60
44
  }
61
- DeserializationError err = deserializeJson(json_document, data);
62
-
63
- JsonObject root = json_document.as<JsonObject>();
45
+ DeserializationError err = deserializeJson(json_document, data, len);
64
46
 
65
47
  if (err == DeserializationError::Ok) {
66
- return f(root);
48
+ return json_document;
67
49
  } else if (err == DeserializationError::NoMemory) {
68
50
  ESP_LOGE(TAG, "Can not allocate more memory for deserialization. Consider making source string smaller");
69
- return false;
51
+ return JsonObject(); // return unbound object
70
52
  }
71
53
  ESP_LOGE(TAG, "Parse error: %s", err.c_str());
72
- return false;
54
+ return JsonObject(); // return unbound object
73
55
  // NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
74
56
  }
75
57
 
58
+ std::string JsonBuilder::serialize() {
59
+ if (doc_.overflowed()) {
60
+ ESP_LOGE(TAG, "JSON document overflow");
61
+ return "{}";
62
+ }
63
+ std::string output;
64
+ serializeJson(doc_, output);
65
+ return output;
66
+ }
67
+
76
68
  } // namespace json
77
69
  } // namespace esphome
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include <vector>
4
4
 
5
+ #include "esphome/core/defines.h"
5
6
  #include "esphome/core/helpers.h"
6
7
 
7
8
  #define ARDUINOJSON_ENABLE_STD_STRING 1 // NOLINT
@@ -13,6 +14,31 @@
13
14
  namespace esphome {
14
15
  namespace json {
15
16
 
17
+ #ifdef USE_PSRAM
18
+ // Build an allocator for the JSON Library using the RAMAllocator class
19
+ // This is only compiled when PSRAM is enabled
20
+ struct SpiRamAllocator : ArduinoJson::Allocator {
21
+ void *allocate(size_t size) override { return allocator_.allocate(size); }
22
+
23
+ void deallocate(void *ptr) override {
24
+ // ArduinoJson's Allocator interface doesn't provide the size parameter in deallocate.
25
+ // RAMAllocator::deallocate() requires the size, which we don't have access to here.
26
+ // RAMAllocator::deallocate implementation just calls free() regardless of whether
27
+ // the memory was allocated with heap_caps_malloc or malloc.
28
+ // This is safe because ESP-IDF's heap implementation internally tracks the memory region
29
+ // and routes free() to the appropriate heap.
30
+ free(ptr); // NOLINT(cppcoreguidelines-owning-memory,cppcoreguidelines-no-malloc)
31
+ }
32
+
33
+ void *reallocate(void *ptr, size_t new_size) override {
34
+ return allocator_.reallocate(static_cast<uint8_t *>(ptr), new_size);
35
+ }
36
+
37
+ protected:
38
+ RAMAllocator<uint8_t> allocator_{RAMAllocator<uint8_t>::NONE};
39
+ };
40
+ #endif
41
+
16
42
  /// Callback function typedef for parsing JsonObjects.
17
43
  using json_parse_t = std::function<bool(JsonObject)>;
18
44
 
@@ -25,5 +51,36 @@ std::string build_json(const json_build_t &f);
25
51
  /// Parse a JSON string and run the provided json parse function if it's valid.
26
52
  bool parse_json(const std::string &data, const json_parse_t &f);
27
53
 
54
+ /// Parse a JSON string and return the root JsonDocument (or an unbound object on error)
55
+ JsonDocument parse_json(const uint8_t *data, size_t len);
56
+ /// Parse a JSON string and return the root JsonDocument (or an unbound object on error)
57
+ inline JsonDocument parse_json(const std::string &data) {
58
+ return parse_json(reinterpret_cast<const uint8_t *>(data.c_str()), data.size());
59
+ }
60
+
61
+ /// Builder class for creating JSON documents without lambdas
62
+ class JsonBuilder {
63
+ public:
64
+ JsonObject root() {
65
+ if (!root_created_) {
66
+ root_ = doc_.to<JsonObject>();
67
+ root_created_ = true;
68
+ }
69
+ return root_;
70
+ }
71
+
72
+ std::string serialize();
73
+
74
+ private:
75
+ #ifdef USE_PSRAM
76
+ SpiRamAllocator allocator_;
77
+ JsonDocument doc_{&allocator_};
78
+ #else
79
+ JsonDocument doc_;
80
+ #endif
81
+ JsonObject root_;
82
+ bool root_created_{false};
83
+ };
84
+
28
85
  } // namespace json
29
86
  } // namespace esphome
@@ -22,7 +22,7 @@ void KamstrupKMPComponent::dump_config() {
22
22
  LOG_SENSOR(" ", "Flow", this->flow_sensor_);
23
23
  LOG_SENSOR(" ", "Volume", this->volume_sensor_);
24
24
 
25
- for (int i = 0; i < this->custom_sensors_.size(); i++) {
25
+ for (size_t i = 0; i < this->custom_sensors_.size(); i++) {
26
26
  LOG_SENSOR(" ", "Custom Sensor", this->custom_sensors_[i]);
27
27
  ESP_LOGCONFIG(TAG, " Command: 0x%04X", this->custom_commands_[i]);
28
28
  }
@@ -268,7 +268,7 @@ void KamstrupKMPComponent::set_sensor_value_(uint16_t command, float value, uint
268
268
  }
269
269
 
270
270
  // Custom sensors
271
- for (int i = 0; i < this->custom_commands_.size(); i++) {
271
+ for (size_t i = 0; i < this->custom_commands_.size(); i++) {
272
272
  if (command == this->custom_commands_[i]) {
273
273
  this->custom_sensors_[i]->publish_state(value);
274
274
  }
@@ -13,8 +13,8 @@ class KeyCollector : public Component {
13
13
  void loop() override;
14
14
  void dump_config() override;
15
15
  void set_provider(key_provider::KeyProvider *provider);
16
- void set_min_length(int min_length) { this->min_length_ = min_length; };
17
- void set_max_length(int max_length) { this->max_length_ = max_length; };
16
+ void set_min_length(uint32_t min_length) { this->min_length_ = min_length; };
17
+ void set_max_length(uint32_t max_length) { this->max_length_ = max_length; };
18
18
  void set_start_keys(std::string start_keys) { this->start_keys_ = std::move(start_keys); };
19
19
  void set_end_keys(std::string end_keys) { this->end_keys_ = std::move(end_keys); };
20
20
  void set_end_key_required(bool end_key_required) { this->end_key_required_ = end_key_required; };
@@ -33,8 +33,8 @@ class KeyCollector : public Component {
33
33
  protected:
34
34
  void key_pressed_(uint8_t key);
35
35
 
36
- int min_length_{0};
37
- int max_length_{0};
36
+ uint32_t min_length_{0};
37
+ uint32_t max_length_{0};
38
38
  std::string start_keys_;
39
39
  std::string end_keys_;
40
40
  bool end_key_required_{false};
@@ -1,6 +1,5 @@
1
1
  import json
2
2
  import logging
3
- from os.path import dirname, isfile, join
4
3
 
5
4
  import esphome.codegen as cg
6
5
  import esphome.config_validation as cv
@@ -24,6 +23,7 @@ from esphome.const import (
24
23
  __version__,
25
24
  )
26
25
  from esphome.core import CORE
26
+ from esphome.storage_json import StorageJSON
27
27
 
28
28
  from . import gpio # noqa
29
29
  from .const import (
@@ -129,7 +129,7 @@ def only_on_family(*, supported=None, unsupported=None):
129
129
  return validator_
130
130
 
131
131
 
132
- def get_download_types(storage_json=None):
132
+ def get_download_types(storage_json: StorageJSON = None):
133
133
  types = [
134
134
  {
135
135
  "title": "UF2 package (recommended)",
@@ -139,11 +139,11 @@ def get_download_types(storage_json=None):
139
139
  },
140
140
  ]
141
141
 
142
- build_dir = dirname(storage_json.firmware_bin_path)
143
- outputs = join(build_dir, "firmware.json")
144
- if not isfile(outputs):
142
+ build_dir = storage_json.firmware_bin_path.parent
143
+ outputs = build_dir / "firmware.json"
144
+ if not outputs.is_file():
145
145
  return types
146
- with open(outputs, encoding="utf-8") as f:
146
+ with outputs.open(encoding="utf-8") as f:
147
147
  outputs = json.load(f)
148
148
  for output in outputs:
149
149
  if not output["public"]:
@@ -15,7 +15,14 @@ static const char *const TAG = "lt.preferences";
15
15
 
16
16
  struct NVSData {
17
17
  std::string key;
18
- std::vector<uint8_t> data;
18
+ std::unique_ptr<uint8_t[]> data;
19
+ size_t len;
20
+
21
+ void set_data(const uint8_t *src, size_t size) {
22
+ data = std::make_unique<uint8_t[]>(size);
23
+ memcpy(data.get(), src, size);
24
+ len = size;
25
+ }
19
26
  };
20
27
 
21
28
  static std::vector<NVSData> s_pending_save; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
@@ -30,15 +37,15 @@ class LibreTinyPreferenceBackend : public ESPPreferenceBackend {
30
37
  // try find in pending saves and update that
31
38
  for (auto &obj : s_pending_save) {
32
39
  if (obj.key == key) {
33
- obj.data.assign(data, data + len);
40
+ obj.set_data(data, len);
34
41
  return true;
35
42
  }
36
43
  }
37
44
  NVSData save{};
38
45
  save.key = key;
39
- save.data.assign(data, data + len);
40
- s_pending_save.emplace_back(save);
41
- ESP_LOGVV(TAG, "s_pending_save: key: %s, len: %d", key.c_str(), len);
46
+ save.set_data(data, len);
47
+ s_pending_save.emplace_back(std::move(save));
48
+ ESP_LOGVV(TAG, "s_pending_save: key: %s, len: %zu", key.c_str(), len);
42
49
  return true;
43
50
  }
44
51
 
@@ -46,11 +53,11 @@ class LibreTinyPreferenceBackend : public ESPPreferenceBackend {
46
53
  // try find in pending saves and load from that
47
54
  for (auto &obj : s_pending_save) {
48
55
  if (obj.key == key) {
49
- if (obj.data.size() != len) {
56
+ if (obj.len != len) {
50
57
  // size mismatch
51
58
  return false;
52
59
  }
53
- memcpy(data, obj.data.data(), len);
60
+ memcpy(data, obj.data.get(), len);
54
61
  return true;
55
62
  }
56
63
  }
@@ -58,10 +65,10 @@ class LibreTinyPreferenceBackend : public ESPPreferenceBackend {
58
65
  fdb_blob_make(blob, data, len);
59
66
  size_t actual_len = fdb_kv_get_blob(db, key.c_str(), blob);
60
67
  if (actual_len != len) {
61
- ESP_LOGVV(TAG, "NVS length does not match (%u!=%u)", actual_len, len);
68
+ ESP_LOGVV(TAG, "NVS length does not match (%zu!=%zu)", actual_len, len);
62
69
  return false;
63
70
  } else {
64
- ESP_LOGVV(TAG, "fdb_kv_get_blob: key: %s, len: %d", key.c_str(), len);
71
+ ESP_LOGVV(TAG, "fdb_kv_get_blob: key: %s, len: %zu", key.c_str(), len);
65
72
  }
66
73
  return true;
67
74
  }
@@ -101,7 +108,7 @@ class LibreTinyPreferences : public ESPPreferences {
101
108
  if (s_pending_save.empty())
102
109
  return true;
103
110
 
104
- ESP_LOGV(TAG, "Saving %d items...", s_pending_save.size());
111
+ ESP_LOGV(TAG, "Saving %zu items...", s_pending_save.size());
105
112
  // goal try write all pending saves even if one fails
106
113
  int cached = 0, written = 0, failed = 0;
107
114
  fdb_err_t last_err = FDB_NO_ERR;
@@ -112,11 +119,11 @@ class LibreTinyPreferences : public ESPPreferences {
112
119
  const auto &save = s_pending_save[i];
113
120
  ESP_LOGVV(TAG, "Checking if FDB data %s has changed", save.key.c_str());
114
121
  if (is_changed(&db, save)) {
115
- ESP_LOGV(TAG, "sync: key: %s, len: %d", save.key.c_str(), save.data.size());
116
- fdb_blob_make(&blob, save.data.data(), save.data.size());
122
+ ESP_LOGV(TAG, "sync: key: %s, len: %zu", save.key.c_str(), save.len);
123
+ fdb_blob_make(&blob, save.data.get(), save.len);
117
124
  fdb_err_t err = fdb_kv_set_blob(&db, save.key.c_str(), &blob);
118
125
  if (err != FDB_NO_ERR) {
119
- ESP_LOGV(TAG, "fdb_kv_set_blob('%s', len=%u) failed: %d", save.key.c_str(), save.data.size(), err);
126
+ ESP_LOGV(TAG, "fdb_kv_set_blob('%s', len=%zu) failed: %d", save.key.c_str(), save.len, err);
120
127
  failed++;
121
128
  last_err = err;
122
129
  last_key = save.key;
@@ -124,7 +131,7 @@ class LibreTinyPreferences : public ESPPreferences {
124
131
  }
125
132
  written++;
126
133
  } else {
127
- ESP_LOGD(TAG, "FDB data not changed; skipping %s len=%u", save.key.c_str(), save.data.size());
134
+ ESP_LOGD(TAG, "FDB data not changed; skipping %s len=%zu", save.key.c_str(), save.len);
128
135
  cached++;
129
136
  }
130
137
  s_pending_save.erase(s_pending_save.begin() + i);
@@ -147,7 +154,7 @@ class LibreTinyPreferences : public ESPPreferences {
147
154
  }
148
155
 
149
156
  // Check size first - if different, data has changed
150
- if (kv.value_len != to_save.data.size()) {
157
+ if (kv.value_len != to_save.len) {
151
158
  return true;
152
159
  }
153
160
 
@@ -161,7 +168,7 @@ class LibreTinyPreferences : public ESPPreferences {
161
168
  }
162
169
 
163
170
  // Compare the actual data
164
- return memcmp(to_save.data.data(), stored_data.get(), kv.value_len) != 0;
171
+ return memcmp(to_save.data.get(), stored_data.get(), kv.value_len) != 0;
165
172
  }
166
173
 
167
174
  bool reset() override {