esphome 2025.9.3__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 (343) 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 +166 -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 +68 -10
  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/socket/lwip_raw_tcp_impl.cpp +34 -6
  215. esphome/components/sonoff_d1/sonoff_d1.cpp +1 -1
  216. esphome/components/spi/__init__.py +0 -3
  217. esphome/components/split_buffer/__init__.py +5 -0
  218. esphome/components/split_buffer/split_buffer.cpp +133 -0
  219. esphome/components/split_buffer/split_buffer.h +40 -0
  220. esphome/components/sps30/sps30.cpp +14 -10
  221. esphome/components/sps30/sps30.h +2 -0
  222. esphome/components/st7567_i2c/st7567_i2c.cpp +3 -1
  223. esphome/components/st7789v/st7789v.cpp +3 -2
  224. esphome/components/statsd/statsd.cpp +1 -1
  225. esphome/components/substitutions/__init__.py +3 -1
  226. esphome/components/substitutions/jinja.py +13 -3
  227. esphome/components/sx126x/__init__.py +16 -0
  228. esphome/components/sx126x/sx126x.cpp +15 -1
  229. esphome/components/sx126x/sx126x.h +9 -1
  230. esphome/components/sx126x/sx126x_reg.h +2 -0
  231. esphome/components/text_sensor/text_sensor.cpp +16 -0
  232. esphome/components/text_sensor/text_sensor.h +3 -10
  233. esphome/components/tormatic/tormatic_cover.cpp +1 -1
  234. esphome/components/tuya/select/tuya_select.cpp +1 -1
  235. esphome/components/tuya/tuya.cpp +29 -4
  236. esphome/components/uart/__init__.py +36 -26
  237. esphome/components/uart/uart.h +6 -0
  238. esphome/components/uart/uart_component.cpp +8 -0
  239. esphome/components/uart/uart_component.h +28 -0
  240. esphome/components/uart/uart_component_esp_idf.cpp +64 -10
  241. esphome/components/uart/uart_component_esp_idf.h +5 -2
  242. esphome/components/uponor_smatrix/climate/uponor_smatrix_climate.cpp +1 -1
  243. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +1 -1
  244. esphome/components/uponor_smatrix/uponor_smatrix.cpp +3 -3
  245. esphome/components/usb_host/__init__.py +2 -1
  246. esphome/components/usb_host/usb_host.h +82 -13
  247. esphome/components/usb_host/usb_host_client.cpp +180 -24
  248. esphome/components/usb_host/usb_host_component.cpp +1 -1
  249. esphome/components/usb_uart/__init__.py +0 -1
  250. esphome/components/usb_uart/ch34x.cpp +4 -4
  251. esphome/components/usb_uart/cp210x.cpp +3 -3
  252. esphome/components/usb_uart/usb_uart.cpp +88 -32
  253. esphome/components/usb_uart/usb_uart.h +30 -6
  254. esphome/components/valve/valve.cpp +1 -0
  255. esphome/components/veml7700/veml7700.cpp +7 -6
  256. esphome/components/version/version_text_sensor.cpp +2 -1
  257. esphome/components/voice_assistant/voice_assistant.cpp +3 -2
  258. esphome/components/waveshare_epaper/waveshare_epaper.cpp +4 -4
  259. esphome/components/web_server/list_entities.cpp +3 -4
  260. esphome/components/web_server/list_entities.h +8 -10
  261. esphome/components/web_server/ota/__init__.py +1 -1
  262. esphome/components/web_server/ota/ota_web_server.cpp +9 -3
  263. esphome/components/web_server/web_server.cpp +509 -404
  264. esphome/components/web_server/web_server.h +5 -6
  265. esphome/components/web_server/web_server_v1.cpp +21 -19
  266. esphome/components/web_server_base/__init__.py +5 -2
  267. esphome/components/web_server_base/web_server_base.h +27 -7
  268. esphome/components/web_server_idf/__init__.py +1 -1
  269. esphome/components/web_server_idf/multipart.cpp +2 -2
  270. esphome/components/web_server_idf/multipart.h +2 -2
  271. esphome/components/web_server_idf/utils.cpp +2 -2
  272. esphome/components/web_server_idf/utils.h +2 -2
  273. esphome/components/web_server_idf/web_server_idf.cpp +118 -26
  274. esphome/components/web_server_idf/web_server_idf.h +12 -10
  275. esphome/components/wifi/__init__.py +13 -11
  276. esphome/components/wifi/wifi_component.cpp +73 -56
  277. esphome/components/wifi/wifi_component.h +4 -4
  278. esphome/components/wifi/wifi_component_esp8266.cpp +1 -1
  279. esphome/components/wifi/wifi_component_esp_idf.cpp +24 -4
  280. esphome/components/wireguard/__init__.py +1 -1
  281. esphome/components/wts01/__init__.py +0 -0
  282. esphome/components/wts01/sensor.py +41 -0
  283. esphome/components/wts01/wts01.cpp +91 -0
  284. esphome/components/wts01/wts01.h +27 -0
  285. esphome/components/zephyr/__init__.py +5 -5
  286. esphome/components/zwave_proxy/__init__.py +43 -0
  287. esphome/components/zwave_proxy/zwave_proxy.cpp +346 -0
  288. esphome/components/zwave_proxy/zwave_proxy.h +93 -0
  289. esphome/config.py +79 -24
  290. esphome/config_validation.py +13 -15
  291. esphome/const.py +9 -2
  292. esphome/core/__init__.py +31 -22
  293. esphome/core/component.cpp +28 -18
  294. esphome/core/component_iterator.h +2 -1
  295. esphome/core/config.py +15 -15
  296. esphome/core/defines.h +19 -0
  297. esphome/core/hash_base.h +56 -0
  298. esphome/core/helpers.cpp +19 -3
  299. esphome/core/helpers.h +26 -0
  300. esphome/core/scheduler.cpp +5 -21
  301. esphome/core/scheduler.h +19 -8
  302. esphome/core/string_ref.h +1 -1
  303. esphome/core/time.cpp +5 -5
  304. esphome/cpp_generator.py +4 -29
  305. esphome/dashboard/const.py +21 -4
  306. esphome/dashboard/core.py +10 -8
  307. esphome/dashboard/dns.py +15 -0
  308. esphome/dashboard/entries.py +15 -21
  309. esphome/dashboard/models.py +76 -0
  310. esphome/dashboard/settings.py +7 -7
  311. esphome/dashboard/status/mdns.py +46 -2
  312. esphome/dashboard/web_server.py +367 -93
  313. esphome/espota2.py +111 -31
  314. esphome/external_files.py +6 -7
  315. esphome/git.py +8 -0
  316. esphome/helpers.py +124 -77
  317. esphome/loader.py +8 -9
  318. esphome/platformio_api.py +25 -18
  319. esphome/storage_json.py +26 -21
  320. esphome/types.py +30 -2
  321. esphome/util.py +32 -16
  322. esphome/vscode.py +8 -8
  323. esphome/wizard.py +10 -10
  324. esphome/writer.py +50 -15
  325. esphome/yaml_util.py +37 -31
  326. esphome/zeroconf.py +12 -3
  327. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/METADATA +11 -11
  328. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/RECORD +332 -312
  329. esphome/components/event_emitter/__init__.py +0 -5
  330. esphome/components/event_emitter/event_emitter.cpp +0 -14
  331. esphome/components/event_emitter/event_emitter.h +0 -63
  332. esphome/components/remote_receiver/remote_receiver_libretiny.cpp +0 -125
  333. esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +0 -107
  334. esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +0 -110
  335. esphome/components/uart/uart_component_esp32_arduino.cpp +0 -214
  336. esphome/components/uart/uart_component_esp32_arduino.h +0 -60
  337. esphome/components/wifi/wifi_component_esp32_arduino.cpp +0 -860
  338. esphome/core/string_ref.cpp +0 -12
  339. esphome/dashboard/util/file.py +0 -63
  340. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/WHEEL +0 -0
  341. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/entry_points.txt +0 -0
  342. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/licenses/LICENSE +0 -0
  343. {esphome-2025.9.3.dist-info → esphome-2025.10.0b1.dist-info}/top_level.txt +0 -0
@@ -148,9 +148,11 @@ void Logger::log_vprintf_(uint8_t level, const char *tag, int line, const __Flas
148
148
  #endif // USE_STORE_LOG_STR_IN_FLASH
149
149
 
150
150
  inline uint8_t Logger::level_for(const char *tag) {
151
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
151
152
  auto it = this->log_levels_.find(tag);
152
153
  if (it != this->log_levels_.end())
153
154
  return it->second;
155
+ #endif
154
156
  return this->current_level_;
155
157
  }
156
158
 
@@ -173,24 +175,8 @@ void Logger::init_log_buffer(size_t total_buffer_size) {
173
175
  }
174
176
  #endif
175
177
 
176
- #ifndef USE_ZEPHYR
177
- #if defined(USE_LOGGER_USB_CDC) || defined(USE_ESP32)
178
- void Logger::loop() {
179
- #if defined(USE_LOGGER_USB_CDC) && defined(USE_ARDUINO)
180
- if (this->uart_ == UART_SELECTION_USB_CDC) {
181
- static bool opened = false;
182
- if (opened == Serial) {
183
- return;
184
- }
185
- if (false == opened) {
186
- App.schedule_dump_config();
187
- }
188
- opened = !opened;
189
- }
190
- #endif
191
- this->process_messages_();
192
- }
193
- #endif
178
+ #ifdef USE_ESPHOME_TASK_LOG_BUFFER
179
+ void Logger::loop() { this->process_messages_(); }
194
180
  #endif
195
181
 
196
182
  void Logger::process_messages_() {
@@ -236,7 +222,9 @@ void Logger::process_messages_() {
236
222
  }
237
223
 
238
224
  void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
239
- void Logger::set_log_level(const std::string &tag, uint8_t log_level) { this->log_levels_[tag] = log_level; }
225
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
226
+ void Logger::set_log_level(const char *tag, uint8_t log_level) { this->log_levels_[tag] = log_level; }
227
+ #endif
240
228
 
241
229
  #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
242
230
  UARTSelection Logger::get_uart() const { return this->uart_; }
@@ -287,9 +275,11 @@ void Logger::dump_config() {
287
275
  }
288
276
  #endif
289
277
 
278
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
290
279
  for (auto &it : this->log_levels_) {
291
- ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.first.c_str(), LOG_STR_ARG(LOG_LEVELS[it.second]));
280
+ ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.first, LOG_STR_ARG(LOG_LEVELS[it.second]));
292
281
  }
282
+ #endif
293
283
  }
294
284
 
295
285
  void Logger::set_log_level(uint8_t level) {
@@ -16,18 +16,18 @@
16
16
  #endif
17
17
 
18
18
  #ifdef USE_ARDUINO
19
- #if defined(USE_ESP8266) || defined(USE_ESP32)
19
+ #if defined(USE_ESP8266)
20
20
  #include <HardwareSerial.h>
21
- #endif // USE_ESP8266 || USE_ESP32
21
+ #endif // USE_ESP8266
22
22
  #ifdef USE_RP2040
23
23
  #include <HardwareSerial.h>
24
24
  #include <SerialUSB.h>
25
25
  #endif // USE_RP2040
26
26
  #endif // USE_ARDUINO
27
27
 
28
- #ifdef USE_ESP_IDF
28
+ #ifdef USE_ESP32
29
29
  #include <driver/uart.h>
30
- #endif // USE_ESP_IDF
30
+ #endif // USE_ESP32
31
31
 
32
32
  #ifdef USE_ZEPHYR
33
33
  #include <zephyr/kernel.h>
@@ -36,29 +36,38 @@ struct device;
36
36
 
37
37
  namespace esphome::logger {
38
38
 
39
- // Color and letter constants for log levels
40
- static const char *const LOG_LEVEL_COLORS[] = {
41
- "", // NONE
42
- ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), // ERROR
43
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_YELLOW), // WARNING
44
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GREEN), // INFO
45
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_MAGENTA), // CONFIG
46
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_CYAN), // DEBUG
47
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GRAY), // VERBOSE
48
- ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_WHITE), // VERY_VERBOSE
39
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
40
+ // Comparison function for const char* keys in log_levels_ map
41
+ struct CStrCompare {
42
+ bool operator()(const char *a, const char *b) const { return strcmp(a, b) < 0; }
43
+ };
44
+ #endif
45
+
46
+ // ANSI color code last digit (30-38 range, store only last digit to save RAM)
47
+ static constexpr char LOG_LEVEL_COLOR_DIGIT[] = {
48
+ '\0', // NONE
49
+ '1', // ERROR (31 = red)
50
+ '3', // WARNING (33 = yellow)
51
+ '2', // INFO (32 = green)
52
+ '5', // CONFIG (35 = magenta)
53
+ '6', // DEBUG (36 = cyan)
54
+ '7', // VERBOSE (37 = gray)
55
+ '8', // VERY_VERBOSE (38 = white)
49
56
  };
50
57
 
51
- static const char *const LOG_LEVEL_LETTERS[] = {
52
- "", // NONE
53
- "E", // ERROR
54
- "W", // WARNING
55
- "I", // INFO
56
- "C", // CONFIG
57
- "D", // DEBUG
58
- "V", // VERBOSE
59
- "VV", // VERY_VERBOSE
58
+ static constexpr char LOG_LEVEL_LETTER_CHARS[] = {
59
+ '\0', // NONE
60
+ 'E', // ERROR
61
+ 'W', // WARNING
62
+ 'I', // INFO
63
+ 'C', // CONFIG
64
+ 'D', // DEBUG
65
+ 'V', // VERBOSE (VERY_VERBOSE uses two 'V's)
60
66
  };
61
67
 
68
+ // Maximum header size: 35 bytes fixed + 32 bytes tag + 16 bytes thread name = 83 bytes (45 byte safety margin)
69
+ static constexpr uint16_t MAX_HEADER_SIZE = 128;
70
+
62
71
  #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
63
72
  /** Enum for logging UART selection
64
73
  *
@@ -110,19 +119,17 @@ class Logger : public Component {
110
119
  #ifdef USE_ESPHOME_TASK_LOG_BUFFER
111
120
  void init_log_buffer(size_t total_buffer_size);
112
121
  #endif
113
- #if defined(USE_LOGGER_USB_CDC) || defined(USE_ESP32) || defined(USE_ZEPHYR)
122
+ #if defined(USE_ESPHOME_TASK_LOG_BUFFER) || (defined(USE_ZEPHYR) && defined(USE_LOGGER_USB_CDC))
114
123
  void loop() override;
115
124
  #endif
116
125
  /// Manually set the baud rate for serial, set to 0 to disable.
117
126
  void set_baud_rate(uint32_t baud_rate);
118
127
  uint32_t get_baud_rate() const { return baud_rate_; }
119
- #ifdef USE_ARDUINO
128
+ #if defined(USE_ARDUINO) && !defined(USE_ESP32)
120
129
  Stream *get_hw_serial() const { return hw_serial_; }
121
130
  #endif
122
- #ifdef USE_ESP_IDF
123
- uart_port_t get_uart_num() const { return uart_num_; }
124
- #endif
125
131
  #ifdef USE_ESP32
132
+ uart_port_t get_uart_num() const { return uart_num_; }
126
133
  void create_pthread_key() { pthread_key_create(&log_recursion_key_, nullptr); }
127
134
  #endif
128
135
  #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
@@ -133,8 +140,10 @@ class Logger : public Component {
133
140
 
134
141
  /// Set the default log level for this logger.
135
142
  void set_log_level(uint8_t level);
143
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
136
144
  /// Set the log level of the specified tag.
137
- void set_log_level(const std::string &tag, uint8_t log_level);
145
+ void set_log_level(const char *tag, uint8_t log_level);
146
+ #endif
138
147
  uint8_t get_log_level() { return this->current_level_; }
139
148
 
140
149
  // ========== INTERNAL METHODS ==========
@@ -217,14 +226,6 @@ class Logger : public Component {
217
226
  }
218
227
  }
219
228
 
220
- // Format string to explicit buffer with varargs
221
- inline void printf_to_buffer_(char *buffer, uint16_t *buffer_at, uint16_t buffer_size, const char *format, ...) {
222
- va_list arg;
223
- va_start(arg, format);
224
- this->format_body_to_buffer_(buffer, buffer_at, buffer_size, format, arg);
225
- va_end(arg);
226
- }
227
-
228
229
  #ifndef USE_HOST
229
230
  const LogString *get_uart_selection_();
230
231
  #endif
@@ -232,7 +233,7 @@ class Logger : public Component {
232
233
  // Group 4-byte aligned members first
233
234
  uint32_t baud_rate_;
234
235
  char *tx_buffer_{nullptr};
235
- #ifdef USE_ARDUINO
236
+ #if defined(USE_ARDUINO) && !defined(USE_ESP32)
236
237
  Stream *hw_serial_{nullptr};
237
238
  #endif
238
239
  #if defined(USE_ZEPHYR)
@@ -246,13 +247,13 @@ class Logger : public Component {
246
247
  // - Main task uses a dedicated member variable for efficiency
247
248
  // - Other tasks use pthread TLS with a dynamically created key via pthread_key_create
248
249
  pthread_key_t log_recursion_key_; // 4 bytes
249
- #endif
250
- #ifdef USE_ESP_IDF
251
- uart_port_t uart_num_; // 4 bytes (enum defaults to int size)
250
+ uart_port_t uart_num_; // 4 bytes (enum defaults to int size)
252
251
  #endif
253
252
 
254
253
  // Large objects (internally aligned)
255
- std::map<std::string, uint8_t> log_levels_{};
254
+ #ifdef USE_LOGGER_RUNTIME_TAG_LEVELS
255
+ std::map<const char *, uint8_t, CStrCompare> log_levels_{};
256
+ #endif
256
257
  CallbackManager<void(uint8_t, const char *, const char *, size_t)> log_callback_{};
257
258
  CallbackManager<void(uint8_t)> level_callback_{};
258
259
  #ifdef USE_ESPHOME_TASK_LOG_BUFFER
@@ -322,26 +323,76 @@ class Logger : public Component {
322
323
  }
323
324
  #endif
324
325
 
326
+ static inline void copy_string(char *buffer, uint16_t &pos, const char *str) {
327
+ const size_t len = strlen(str);
328
+ // Intentionally no null terminator, building larger string
329
+ memcpy(buffer + pos, str, len); // NOLINT(bugprone-not-null-terminated-result)
330
+ pos += len;
331
+ }
332
+
333
+ static inline void write_ansi_color_for_level(char *buffer, uint16_t &pos, uint8_t level) {
334
+ if (level == 0)
335
+ return;
336
+ // Construct ANSI escape sequence: "\033[{bold};3{color}m"
337
+ // Example: "\033[1;31m" for ERROR (bold red)
338
+ buffer[pos++] = '\033';
339
+ buffer[pos++] = '[';
340
+ buffer[pos++] = (level == 1) ? '1' : '0'; // Only ERROR is bold
341
+ buffer[pos++] = ';';
342
+ buffer[pos++] = '3';
343
+ buffer[pos++] = LOG_LEVEL_COLOR_DIGIT[level];
344
+ buffer[pos++] = 'm';
345
+ }
346
+
325
347
  inline void HOT write_header_to_buffer_(uint8_t level, const char *tag, int line, const char *thread_name,
326
348
  char *buffer, uint16_t *buffer_at, uint16_t buffer_size) {
327
- // Format header
328
- // uint8_t level is already bounded 0-255, just ensure it's <= 7
329
- if (level > 7)
330
- level = 7;
349
+ uint16_t pos = *buffer_at;
350
+ // Early return if insufficient space - intentionally don't update buffer_at to prevent partial writes
351
+ if (pos + MAX_HEADER_SIZE > buffer_size)
352
+ return;
331
353
 
332
- const char *color = esphome::logger::LOG_LEVEL_COLORS[level];
333
- const char *letter = esphome::logger::LOG_LEVEL_LETTERS[level];
354
+ // Construct: <color>[LEVEL][tag:line]:
355
+ write_ansi_color_for_level(buffer, pos, level);
356
+ buffer[pos++] = '[';
357
+ if (level != 0) {
358
+ if (level >= 7) {
359
+ buffer[pos++] = 'V'; // VERY_VERBOSE = "VV"
360
+ buffer[pos++] = 'V';
361
+ } else {
362
+ buffer[pos++] = LOG_LEVEL_LETTER_CHARS[level];
363
+ }
364
+ }
365
+ buffer[pos++] = ']';
366
+ buffer[pos++] = '[';
367
+ copy_string(buffer, pos, tag);
368
+ buffer[pos++] = ':';
369
+ // Format line number without modulo operations (passed by value, safe to mutate)
370
+ if (line > 999) [[unlikely]] {
371
+ int thousands = line / 1000;
372
+ buffer[pos++] = '0' + thousands;
373
+ line -= thousands * 1000;
374
+ }
375
+ int hundreds = line / 100;
376
+ int remainder = line - hundreds * 100;
377
+ int tens = remainder / 10;
378
+ buffer[pos++] = '0' + hundreds;
379
+ buffer[pos++] = '0' + tens;
380
+ buffer[pos++] = '0' + (remainder - tens * 10);
381
+ buffer[pos++] = ']';
334
382
 
335
383
  #if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
336
384
  if (thread_name != nullptr) {
337
- // Non-main task with thread name
338
- this->printf_to_buffer_(buffer, buffer_at, buffer_size, "%s[%s][%s:%03u]%s[%s]%s: ", color, letter, tag, line,
339
- ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), thread_name, color);
340
- return;
385
+ write_ansi_color_for_level(buffer, pos, 1); // Always use bold red for thread name
386
+ buffer[pos++] = '[';
387
+ copy_string(buffer, pos, thread_name);
388
+ buffer[pos++] = ']';
389
+ write_ansi_color_for_level(buffer, pos, level); // Restore original color
341
390
  }
342
391
  #endif
343
- // Main task or non ESP32/LibreTiny platform
344
- this->printf_to_buffer_(buffer, buffer_at, buffer_size, "%s[%s][%s:%03u]: ", color, letter, tag, line);
392
+
393
+ buffer[pos++] = ':';
394
+ buffer[pos++] = ' ';
395
+ *buffer_at = pos;
345
396
  }
346
397
 
347
398
  inline void HOT format_body_to_buffer_(char *buffer, uint16_t *buffer_at, uint16_t buffer_size, const char *format,
@@ -380,15 +431,7 @@ class Logger : public Component {
380
431
  // will be processed on the next main loop iteration since:
381
432
  // - disable_loop() takes effect immediately
382
433
  // - enable_loop_soon_any_context() sets a pending flag that's checked at loop start
383
- #if defined(USE_LOGGER_USB_CDC) && defined(USE_ARDUINO)
384
- // Only disable if not using USB CDC (which needs loop for connection detection)
385
- if (this->uart_ != UART_SELECTION_USB_CDC) {
386
- this->disable_loop();
387
- }
388
- #else
389
- // No USB CDC support, always safe to disable
390
434
  this->disable_loop();
391
- #endif
392
435
  }
393
436
  #endif
394
437
  };
@@ -1,11 +1,8 @@
1
1
  #ifdef USE_ESP32
2
2
  #include "logger.h"
3
3
 
4
- #if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_ESP_IDF)
5
4
  #include <esp_log.h>
6
- #endif // USE_ESP32_FRAMEWORK_ARDUINO || USE_ESP_IDF
7
5
 
8
- #ifdef USE_ESP_IDF
9
6
  #include <driver/uart.h>
10
7
 
11
8
  #ifdef USE_LOGGER_USB_SERIAL_JTAG
@@ -25,16 +22,12 @@
25
22
  #include <cstdint>
26
23
  #include <cstdio>
27
24
 
28
- #endif // USE_ESP_IDF
29
-
30
25
  #include "esphome/core/log.h"
31
26
 
32
27
  namespace esphome::logger {
33
28
 
34
29
  static const char *const TAG = "logger";
35
30
 
36
- #ifdef USE_ESP_IDF
37
-
38
31
  #ifdef USE_LOGGER_USB_SERIAL_JTAG
39
32
  static void init_usb_serial_jtag_() {
40
33
  setvbuf(stdin, NULL, _IONBF, 0); // Disable buffering on stdin
@@ -89,42 +82,8 @@ void init_uart(uart_port_t uart_num, uint32_t baud_rate, int tx_buffer_size) {
89
82
  uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10, nullptr, 0);
90
83
  }
91
84
 
92
- #endif // USE_ESP_IDF
93
-
94
85
  void Logger::pre_setup() {
95
86
  if (this->baud_rate_ > 0) {
96
- #ifdef USE_ARDUINO
97
- switch (this->uart_) {
98
- case UART_SELECTION_UART0:
99
- #if ARDUINO_USB_CDC_ON_BOOT
100
- this->hw_serial_ = &Serial0;
101
- Serial0.begin(this->baud_rate_);
102
- #else
103
- this->hw_serial_ = &Serial;
104
- Serial.begin(this->baud_rate_);
105
- #endif
106
- break;
107
- case UART_SELECTION_UART1:
108
- this->hw_serial_ = &Serial1;
109
- Serial1.begin(this->baud_rate_);
110
- break;
111
- #ifdef USE_ESP32_VARIANT_ESP32
112
- case UART_SELECTION_UART2:
113
- this->hw_serial_ = &Serial2;
114
- Serial2.begin(this->baud_rate_);
115
- break;
116
- #endif
117
-
118
- #ifdef USE_LOGGER_USB_CDC
119
- case UART_SELECTION_USB_CDC:
120
- this->hw_serial_ = &Serial;
121
- Serial.begin(this->baud_rate_);
122
- break;
123
- #endif
124
- }
125
- #endif // USE_ARDUINO
126
-
127
- #ifdef USE_ESP_IDF
128
87
  this->uart_num_ = UART_NUM_0;
129
88
  switch (this->uart_) {
130
89
  case UART_SELECTION_UART0:
@@ -151,21 +110,17 @@ void Logger::pre_setup() {
151
110
  break;
152
111
  #endif
153
112
  }
154
- #endif // USE_ESP_IDF
155
113
  }
156
114
 
157
115
  global_logger = this;
158
- #if defined(USE_ESP_IDF) || defined(USE_ESP32_FRAMEWORK_ARDUINO)
159
116
  esp_log_set_vprintf(esp_idf_log_vprintf_);
160
117
  if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE) {
161
118
  esp_log_level_set("*", ESP_LOG_VERBOSE);
162
119
  }
163
- #endif // USE_ESP_IDF || USE_ESP32_FRAMEWORK_ARDUINO
164
120
 
165
121
  ESP_LOGI(TAG, "Log initialized");
166
122
  }
167
123
 
168
- #ifdef USE_ESP_IDF
169
124
  void HOT Logger::write_msg_(const char *msg) {
170
125
  if (
171
126
  #if defined(USE_LOGGER_USB_CDC) && !defined(USE_LOGGER_USB_SERIAL_JTAG)
@@ -186,9 +141,6 @@ void HOT Logger::write_msg_(const char *msg) {
186
141
  uart_write_bytes(this->uart_num_, "\n", 1);
187
142
  }
188
143
  }
189
- #else
190
- void HOT Logger::write_msg_(const char *msg) { this->hw_serial_->println(msg); }
191
- #endif
192
144
 
193
145
  const LogString *Logger::get_uart_selection_() {
194
146
  switch (this->uart_) {
@@ -12,8 +12,8 @@ namespace esphome::logger {
12
12
 
13
13
  static const char *const TAG = "logger";
14
14
 
15
- void Logger::loop() {
16
15
  #ifdef USE_LOGGER_USB_CDC
16
+ void Logger::loop() {
17
17
  if (this->uart_ != UART_SELECTION_USB_CDC || nullptr == this->uart_dev_) {
18
18
  return;
19
19
  }
@@ -30,9 +30,8 @@ void Logger::loop() {
30
30
  App.schedule_dump_config();
31
31
  }
32
32
  opened = !opened;
33
- #endif
34
- this->process_messages_();
35
33
  }
34
+ #endif
36
35
 
37
36
  void Logger::pre_setup() {
38
37
  if (this->baud_rate_ > 0) {
@@ -3,11 +3,10 @@
3
3
  namespace esphome::logger {
4
4
 
5
5
  void LoggerLevelSelect::publish_state(int level) {
6
- auto value = this->at(level);
7
- if (!value) {
6
+ const auto &option = this->at(level_to_index(level));
7
+ if (!option)
8
8
  return;
9
- }
10
- Select::publish_state(value.value());
9
+ Select::publish_state(option.value());
11
10
  }
12
11
 
13
12
  void LoggerLevelSelect::setup() {
@@ -16,10 +15,10 @@ void LoggerLevelSelect::setup() {
16
15
  }
17
16
 
18
17
  void LoggerLevelSelect::control(const std::string &value) {
19
- auto level = this->index_of(value);
20
- if (!level)
18
+ const auto index = this->index_of(value);
19
+ if (!index)
21
20
  return;
22
- this->parent_->set_log_level(level.value());
21
+ this->parent_->set_log_level(index_to_level(index.value()));
23
22
  }
24
23
 
25
24
  } // namespace esphome::logger
@@ -3,11 +3,18 @@
3
3
  #include "esphome/components/select/select.h"
4
4
  #include "esphome/core/component.h"
5
5
  #include "esphome/components/logger/logger.h"
6
+
6
7
  namespace esphome::logger {
7
8
  class LoggerLevelSelect : public Component, public select::Select, public Parented<Logger> {
8
9
  public:
9
10
  void publish_state(int level);
10
11
  void setup() override;
11
12
  void control(const std::string &value) override;
13
+
14
+ protected:
15
+ // Convert log level to option index (skip CONFIG at level 4)
16
+ static uint8_t level_to_index(uint8_t level) { return (level > ESPHOME_LOG_LEVEL_CONFIG) ? level - 1 : level; }
17
+ // Convert option index to log level (skip CONFIG at level 4)
18
+ static uint8_t index_to_level(uint8_t index) { return (index >= ESPHOME_LOG_LEVEL_CONFIG) ? index + 1 : index; }
12
19
  };
13
20
  } // namespace esphome::logger
@@ -2,6 +2,7 @@
2
2
  #include "esphome/core/application.h"
3
3
  #include "esphome/core/helpers.h"
4
4
  #include "esphome/core/log.h"
5
+ #include <limits>
5
6
 
6
7
  using esphome::i2c::ErrorCode;
7
8
 
@@ -28,30 +29,30 @@ bool operator!=(const GainTimePair &lhs, const GainTimePair &rhs) {
28
29
 
29
30
  template<typename T, size_t size> T get_next(const T (&array)[size], const T val) {
30
31
  size_t i = 0;
31
- size_t idx = -1;
32
- while (idx == -1 && i < size) {
32
+ size_t idx = std::numeric_limits<size_t>::max();
33
+ while (idx == std::numeric_limits<size_t>::max() && i < size) {
33
34
  if (array[i] == val) {
34
35
  idx = i;
35
36
  break;
36
37
  }
37
38
  i++;
38
39
  }
39
- if (idx == -1 || i + 1 >= size)
40
+ if (idx == std::numeric_limits<size_t>::max() || i + 1 >= size)
40
41
  return val;
41
42
  return array[i + 1];
42
43
  }
43
44
 
44
45
  template<typename T, size_t size> T get_prev(const T (&array)[size], const T val) {
45
46
  size_t i = size - 1;
46
- size_t idx = -1;
47
- while (idx == -1 && i > 0) {
47
+ size_t idx = std::numeric_limits<size_t>::max();
48
+ while (idx == std::numeric_limits<size_t>::max() && i > 0) {
48
49
  if (array[i] == val) {
49
50
  idx = i;
50
51
  break;
51
52
  }
52
53
  i--;
53
54
  }
54
- if (idx == -1 || i == 0)
55
+ if (idx == std::numeric_limits<size_t>::max() || i == 0)
55
56
  return val;
56
57
  return array[i - 1];
57
58
  }
@@ -2,6 +2,7 @@
2
2
  #include "esphome/core/application.h"
3
3
  #include "esphome/core/helpers.h"
4
4
  #include "esphome/core/log.h"
5
+ #include <limits>
5
6
 
6
7
  using esphome::i2c::ErrorCode;
7
8
 
@@ -14,30 +15,30 @@ static const uint8_t MAX_TRIES = 5;
14
15
 
15
16
  template<typename T, size_t size> T get_next(const T (&array)[size], const T val) {
16
17
  size_t i = 0;
17
- size_t idx = -1;
18
- while (idx == -1 && i < size) {
18
+ size_t idx = std::numeric_limits<size_t>::max();
19
+ while (idx == std::numeric_limits<size_t>::max() && i < size) {
19
20
  if (array[i] == val) {
20
21
  idx = i;
21
22
  break;
22
23
  }
23
24
  i++;
24
25
  }
25
- if (idx == -1 || i + 1 >= size)
26
+ if (idx == std::numeric_limits<size_t>::max() || i + 1 >= size)
26
27
  return val;
27
28
  return array[i + 1];
28
29
  }
29
30
 
30
31
  template<typename T, size_t size> T get_prev(const T (&array)[size], const T val) {
31
32
  size_t i = size - 1;
32
- size_t idx = -1;
33
- while (idx == -1 && i > 0) {
33
+ size_t idx = std::numeric_limits<size_t>::max();
34
+ while (idx == std::numeric_limits<size_t>::max() && i > 0) {
34
35
  if (array[i] == val) {
35
36
  idx = i;
36
37
  break;
37
38
  }
38
39
  i--;
39
40
  }
40
- if (idx == -1 || i == 0)
41
+ if (idx == std::numeric_limits<size_t>::max() || i == 0)
41
42
  return val;
42
43
  return array[i - 1];
43
44
  }
@@ -29,9 +29,9 @@ class MatrixKeypad : public key_provider::KeyProvider, public Component {
29
29
  void set_columns(std::vector<GPIOPin *> pins) { columns_ = std::move(pins); };
30
30
  void set_rows(std::vector<GPIOPin *> pins) { rows_ = std::move(pins); };
31
31
  void set_keys(std::string keys) { keys_ = std::move(keys); };
32
- void set_debounce_time(int debounce_time) { debounce_time_ = debounce_time; };
33
- void set_has_diodes(int has_diodes) { has_diodes_ = has_diodes; };
34
- void set_has_pulldowns(int has_pulldowns) { has_pulldowns_ = has_pulldowns; };
32
+ void set_debounce_time(uint32_t debounce_time) { debounce_time_ = debounce_time; };
33
+ void set_has_diodes(bool has_diodes) { has_diodes_ = has_diodes; };
34
+ void set_has_pulldowns(bool has_pulldowns) { has_pulldowns_ = has_pulldowns; };
35
35
 
36
36
  void register_listener(MatrixKeypadListener *listener);
37
37
  void register_key_trigger(MatrixKeyTrigger *trig);
@@ -40,7 +40,7 @@ class MatrixKeypad : public key_provider::KeyProvider, public Component {
40
40
  std::vector<GPIOPin *> rows_;
41
41
  std::vector<GPIOPin *> columns_;
42
42
  std::string keys_;
43
- int debounce_time_ = 0;
43
+ uint32_t debounce_time_ = 0;
44
44
  bool has_diodes_{false};
45
45
  bool has_pulldowns_{false};
46
46
  int pressed_key_ = -1;
@@ -90,7 +90,7 @@ void MAX7219Component::loop() {
90
90
  }
91
91
 
92
92
  if (this->scroll_mode_ == ScrollMode::STOP) {
93
- if (this->stepsleft_ + get_width_internal() == first_line_size + 1) {
93
+ if (static_cast<size_t>(this->stepsleft_ + get_width_internal()) == first_line_size + 1) {
94
94
  if (millis_since_last_scroll < this->scroll_dwell_) {
95
95
  ESP_LOGVV(TAG, "Dwell time at end of string in case of stop at end. Step %d, since last scroll %d, dwell %d.",
96
96
  this->stepsleft_, millis_since_last_scroll, this->scroll_dwell_);