esphome 2024.12.4__py3-none-any.whl → 2025.2.0b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. esphome/__main__.py +16 -3
  2. esphome/components/adc/__init__.py +17 -11
  3. esphome/components/adc/adc_sensor.h +17 -0
  4. esphome/components/adc/adc_sensor_common.cpp +55 -0
  5. esphome/components/adc/adc_sensor_esp32.cpp +8 -5
  6. esphome/components/adc/adc_sensor_esp8266.cpp +10 -6
  7. esphome/components/adc/adc_sensor_libretiny.cpp +11 -6
  8. esphome/components/adc/adc_sensor_rp2040.cpp +13 -10
  9. esphome/components/adc/sensor.py +9 -3
  10. esphome/components/ads1115/ads1115.cpp +56 -7
  11. esphome/components/ads1115/ads1115.h +13 -1
  12. esphome/components/ads1115/sensor/__init__.py +16 -0
  13. esphome/components/ads1115/sensor/ads1115_sensor.cpp +2 -1
  14. esphome/components/ads1115/sensor/ads1115_sensor.h +2 -0
  15. esphome/components/animation/__init__.py +23 -261
  16. esphome/components/animation/animation.cpp +2 -2
  17. esphome/components/animation/animation.h +2 -1
  18. esphome/components/api/api_pb2.cpp +14 -0
  19. esphome/components/api/api_pb2.h +1 -0
  20. esphome/components/audio/__init__.py +112 -0
  21. esphome/components/audio/audio.cpp +67 -0
  22. esphome/components/audio/audio.h +125 -7
  23. esphome/components/audio/audio_decoder.cpp +361 -0
  24. esphome/components/audio/audio_decoder.h +135 -0
  25. esphome/components/audio/audio_reader.cpp +308 -0
  26. esphome/components/audio/audio_reader.h +85 -0
  27. esphome/components/audio/audio_resampler.cpp +159 -0
  28. esphome/components/audio/audio_resampler.h +101 -0
  29. esphome/components/audio/audio_transfer_buffer.cpp +165 -0
  30. esphome/components/audio/audio_transfer_buffer.h +139 -0
  31. esphome/components/audio_adc/__init__.py +41 -0
  32. esphome/components/audio_adc/audio_adc.h +17 -0
  33. esphome/components/audio_adc/automation.h +23 -0
  34. esphome/components/bk72xx/__init__.py +1 -0
  35. esphome/components/ble_client/ble_client.cpp +1 -2
  36. esphome/components/ble_client/sensor/__init__.py +1 -1
  37. esphome/components/ble_client/text_sensor/__init__.py +1 -1
  38. esphome/components/bluetooth_proxy/bluetooth_connection.cpp +5 -0
  39. esphome/components/bluetooth_proxy/bluetooth_connection.h +1 -0
  40. esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
  41. esphome/components/ch422g/ch422g.h +2 -0
  42. esphome/components/climate/__init__.py +1 -1
  43. esphome/components/climate_ir/climate_ir.cpp +2 -1
  44. esphome/components/coolix/coolix.cpp +2 -1
  45. esphome/components/cse7766/cse7766.cpp +8 -16
  46. esphome/components/custom/__init__.py +0 -3
  47. esphome/components/custom/binary_sensor/__init__.py +2 -28
  48. esphome/components/custom/climate/__init__.py +2 -27
  49. esphome/components/custom/cover/__init__.py +2 -27
  50. esphome/components/custom/light/__init__.py +2 -27
  51. esphome/components/custom/output/__init__.py +2 -58
  52. esphome/components/custom/sensor/__init__.py +2 -24
  53. esphome/components/custom/switch/__init__.py +2 -24
  54. esphome/components/custom/text_sensor/__init__.py +2 -29
  55. esphome/components/custom_component/__init__.py +3 -27
  56. esphome/components/daly_bms/daly_bms.cpp +6 -0
  57. esphome/components/daly_bms/daly_bms.h +2 -0
  58. esphome/components/daly_bms/sensor.py +6 -0
  59. esphome/components/debug/debug_component.cpp +4 -0
  60. esphome/components/debug/debug_component.h +14 -0
  61. esphome/components/debug/debug_esp32.cpp +154 -74
  62. esphome/components/dfplayer/dfplayer.cpp +15 -2
  63. esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +2 -1
  64. esphome/components/dht/dht.cpp +2 -1
  65. esphome/components/display/__init__.py +18 -5
  66. esphome/components/display/display.cpp +2 -1
  67. esphome/components/display/rect.cpp +2 -1
  68. esphome/components/es7210/__init__.py +0 -0
  69. esphome/components/es7210/audio_adc.py +51 -0
  70. esphome/components/es7210/es7210.cpp +228 -0
  71. esphome/components/es7210/es7210.h +62 -0
  72. esphome/components/es7210/es7210_const.h +129 -0
  73. esphome/components/es7243e/__init__.py +0 -0
  74. esphome/components/es7243e/audio_adc.py +34 -0
  75. esphome/components/es7243e/es7243e.cpp +125 -0
  76. esphome/components/es7243e/es7243e.h +37 -0
  77. esphome/components/es7243e/es7243e_const.h +54 -0
  78. esphome/components/es8156/__init__.py +0 -0
  79. esphome/components/es8156/audio_dac.py +27 -0
  80. esphome/components/es8156/es8156.cpp +87 -0
  81. esphome/components/es8156/es8156.h +51 -0
  82. esphome/components/es8156/es8156_const.h +68 -0
  83. esphome/components/es8311/audio_dac.py +1 -2
  84. esphome/components/esp32/__init__.py +1 -0
  85. esphome/components/esp32/core.cpp +5 -1
  86. esphome/components/esp32/gpio.h +2 -0
  87. esphome/components/esp32_ble/__init__.py +39 -0
  88. esphome/components/esp32_ble/queue.h +4 -4
  89. esphome/components/esp32_ble_client/ble_client_base.cpp +46 -0
  90. esphome/components/esp32_ble_client/ble_client_base.h +2 -0
  91. esphome/components/esp32_ble_server/__init__.py +582 -12
  92. esphome/components/esp32_ble_server/ble_characteristic.cpp +48 -60
  93. esphome/components/esp32_ble_server/ble_characteristic.h +24 -17
  94. esphome/components/esp32_ble_server/ble_descriptor.cpp +21 -9
  95. esphome/components/esp32_ble_server/ble_descriptor.h +17 -6
  96. esphome/components/esp32_ble_server/ble_server.cpp +62 -67
  97. esphome/components/esp32_ble_server/ble_server.h +28 -32
  98. esphome/components/esp32_ble_server/ble_server_automations.cpp +77 -0
  99. esphome/components/esp32_ble_server/ble_server_automations.h +115 -0
  100. esphome/components/esp32_ble_server/ble_service.cpp +17 -15
  101. esphome/components/esp32_ble_server/ble_service.h +10 -14
  102. esphome/components/esp32_ble_tracker/__init__.py +6 -39
  103. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +33 -10
  104. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +8 -4
  105. esphome/components/esp32_improv/__init__.py +2 -8
  106. esphome/components/esp32_improv/esp32_improv_component.cpp +21 -20
  107. esphome/components/esp32_improv/esp32_improv_component.h +3 -4
  108. esphome/components/esp32_rmt/__init__.py +28 -3
  109. esphome/components/esp32_rmt_led_strip/led_strip.cpp +73 -6
  110. esphome/components/esp32_rmt_led_strip/led_strip.h +21 -3
  111. esphome/components/esp32_rmt_led_strip/light.py +72 -7
  112. esphome/components/esp32_touch/esp32_touch.cpp +5 -0
  113. esphome/components/esp8266/__init__.py +1 -0
  114. esphome/components/esp8266/gpio.h +1 -0
  115. esphome/components/ethernet/__init__.py +10 -10
  116. esphome/components/event/event.cpp +4 -2
  117. esphome/components/event/event.h +2 -0
  118. esphome/components/event_emitter/__init__.py +5 -0
  119. esphome/components/event_emitter/event_emitter.cpp +14 -0
  120. esphome/components/event_emitter/event_emitter.h +63 -0
  121. esphome/components/gcja5/gcja5.cpp +2 -1
  122. esphome/components/graph/graph.cpp +4 -9
  123. esphome/components/haier/haier_base.cpp +2 -1
  124. esphome/components/haier/hon_climate.cpp +2 -1
  125. esphome/components/heatpumpir/heatpumpir.cpp +2 -1
  126. esphome/components/host/__init__.py +1 -0
  127. esphome/components/host/gpio.h +1 -0
  128. esphome/components/http_request/http_request.h +2 -2
  129. esphome/components/http_request/http_request_arduino.cpp +1 -1
  130. esphome/components/http_request/http_request_idf.cpp +1 -1
  131. esphome/components/i2c/i2c_bus_esp_idf.cpp +4 -0
  132. esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +7 -5
  133. esphome/components/i2s_audio/speaker/__init__.py +53 -6
  134. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +92 -46
  135. esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +8 -0
  136. esphome/components/ili9xxx/display.py +29 -11
  137. esphome/components/ili9xxx/ili9xxx_display.cpp +2 -5
  138. esphome/components/ili9xxx/ili9xxx_display.h +2 -1
  139. esphome/components/image/__init__.py +443 -255
  140. esphome/components/image/image.cpp +115 -61
  141. esphome/components/image/image.h +15 -24
  142. esphome/components/json/json_util.cpp +8 -34
  143. esphome/components/libretiny/__init__.py +1 -0
  144. esphome/components/libretiny/gpio_arduino.h +1 -0
  145. esphome/components/light/light_color_values.h +1 -1
  146. esphome/components/logger/__init__.py +43 -7
  147. esphome/components/logger/logger.cpp +16 -11
  148. esphome/components/logger/logger.h +11 -7
  149. esphome/components/logger/select/__init__.py +29 -0
  150. esphome/components/logger/select/logger_level_select.cpp +27 -0
  151. esphome/components/logger/select/logger_level_select.h +15 -0
  152. esphome/components/lvgl/__init__.py +96 -73
  153. esphome/components/lvgl/automation.py +39 -7
  154. esphome/components/lvgl/defines.py +8 -2
  155. esphome/components/lvgl/lvgl_esphome.cpp +8 -15
  156. esphome/components/lvgl/lvgl_esphome.h +20 -5
  157. esphome/components/lvgl/schemas.py +25 -14
  158. esphome/components/lvgl/trigger.py +27 -3
  159. esphome/components/lvgl/widgets/dropdown.py +1 -1
  160. esphome/components/lvgl/widgets/keyboard.py +8 -1
  161. esphome/components/lvgl/widgets/meter.py +2 -1
  162. esphome/components/lvgl/widgets/msgbox.py +1 -1
  163. esphome/components/lvgl/widgets/obj.py +1 -12
  164. esphome/components/lvgl/widgets/page.py +37 -2
  165. esphome/components/lvgl/widgets/tabview.py +1 -1
  166. esphome/components/max6956/max6956.h +2 -0
  167. esphome/components/mcp23016/mcp23016.h +2 -0
  168. esphome/components/mcp23xxx_base/mcp23xxx_base.h +2 -0
  169. esphome/components/mdns/__init__.py +1 -1
  170. esphome/components/media_player/__init__.py +37 -8
  171. esphome/components/media_player/automation.h +11 -2
  172. esphome/components/media_player/media_player.cpp +8 -0
  173. esphome/components/media_player/media_player.h +8 -4
  174. esphome/components/micronova/switch/micronova_switch.cpp +4 -2
  175. esphome/components/midea/ac_automations.h +3 -1
  176. esphome/components/midea/air_conditioner.cpp +7 -5
  177. esphome/components/midea/air_conditioner.h +1 -1
  178. esphome/components/midea/climate.py +4 -2
  179. esphome/components/midea/ir_transmitter.h +36 -5
  180. esphome/components/mixer/__init__.py +0 -0
  181. esphome/components/mixer/speaker/__init__.py +172 -0
  182. esphome/components/mixer/speaker/automation.h +19 -0
  183. esphome/components/mixer/speaker/mixer_speaker.cpp +624 -0
  184. esphome/components/mixer/speaker/mixer_speaker.h +207 -0
  185. esphome/components/modbus_controller/text_sensor/modbus_textsensor.cpp +7 -13
  186. esphome/components/mpr121/mpr121.h +2 -0
  187. esphome/components/mqtt/__init__.py +1 -1
  188. esphome/components/mqtt/mqtt_client.cpp +7 -1
  189. esphome/components/mqtt/mqtt_client.h +1 -1
  190. esphome/components/mqtt/mqtt_climate.cpp +2 -2
  191. esphome/components/network/ip_address.h +2 -0
  192. esphome/components/nextion/automation.h +17 -0
  193. esphome/components/nextion/display.py +42 -17
  194. esphome/components/nextion/nextion.cpp +4 -10
  195. esphome/components/nextion/nextion.h +89 -82
  196. esphome/components/nextion/nextion_commands.cpp +10 -10
  197. esphome/components/ntc/sensor.py +2 -4
  198. esphome/components/online_image/__init__.py +98 -46
  199. esphome/components/online_image/bmp_image.cpp +101 -0
  200. esphome/components/online_image/bmp_image.h +40 -0
  201. esphome/components/online_image/image_decoder.cpp +28 -2
  202. esphome/components/online_image/image_decoder.h +24 -15
  203. esphome/components/online_image/jpeg_image.cpp +90 -0
  204. esphome/components/online_image/jpeg_image.h +34 -0
  205. esphome/components/online_image/online_image.cpp +112 -53
  206. esphome/components/online_image/online_image.h +24 -7
  207. esphome/components/online_image/png_image.cpp +7 -3
  208. esphome/components/online_image/png_image.h +2 -1
  209. esphome/components/opentherm/__init__.py +73 -7
  210. esphome/components/opentherm/automation.h +25 -0
  211. esphome/components/opentherm/const.py +1 -0
  212. esphome/components/opentherm/generate.py +39 -6
  213. esphome/components/opentherm/hub.cpp +117 -79
  214. esphome/components/opentherm/hub.h +31 -15
  215. esphome/components/opentherm/opentherm.cpp +47 -23
  216. esphome/components/opentherm/opentherm.h +27 -6
  217. esphome/components/opentherm/opentherm_macros.h +11 -0
  218. esphome/components/opentherm/schema.py +78 -1
  219. esphome/components/opentherm/validate.py +7 -2
  220. esphome/components/pca6416a/pca6416a.h +2 -0
  221. esphome/components/pca9554/pca9554.h +2 -0
  222. esphome/components/pcf8574/pcf8574.h +2 -0
  223. esphome/components/preferences/__init__.py +2 -4
  224. esphome/components/preferences/syncer.h +10 -3
  225. esphome/components/prometheus/prometheus_handler.cpp +313 -0
  226. esphome/components/prometheus/prometheus_handler.h +48 -7
  227. esphome/components/psram/psram.cpp +8 -1
  228. esphome/components/pulse_counter/pulse_counter_sensor.cpp +14 -9
  229. esphome/components/pulse_counter/pulse_counter_sensor.h +4 -4
  230. esphome/components/pulse_meter/pulse_meter_sensor.cpp +2 -0
  231. esphome/components/qspi_dbi/__init__.py +3 -0
  232. esphome/components/qspi_dbi/display.py +74 -47
  233. esphome/components/qspi_dbi/models.py +245 -2
  234. esphome/components/qspi_dbi/qspi_dbi.cpp +9 -16
  235. esphome/components/qspi_dbi/qspi_dbi.h +2 -2
  236. esphome/components/remote_base/__init__.py +77 -25
  237. esphome/components/remote_base/remote_base.cpp +1 -1
  238. esphome/components/remote_base/remote_base.h +20 -2
  239. esphome/components/remote_base/toto_protocol.cpp +100 -0
  240. esphome/components/remote_base/toto_protocol.h +45 -0
  241. esphome/components/remote_receiver/__init__.py +55 -10
  242. esphome/components/remote_receiver/remote_receiver.h +36 -3
  243. esphome/components/remote_receiver/remote_receiver_esp32.cpp +145 -6
  244. esphome/components/remote_transmitter/__init__.py +62 -4
  245. esphome/components/remote_transmitter/remote_transmitter.h +21 -2
  246. esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +140 -4
  247. esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +3 -3
  248. esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +3 -3
  249. esphome/components/resampler/__init__.py +0 -0
  250. esphome/components/resampler/speaker/__init__.py +103 -0
  251. esphome/components/resampler/speaker/resampler_speaker.cpp +318 -0
  252. esphome/components/resampler/speaker/resampler_speaker.h +107 -0
  253. esphome/components/resistance/resistance_sensor.h +2 -3
  254. esphome/components/resistance/sensor.py +2 -9
  255. esphome/components/rotary_encoder/rotary_encoder.cpp +8 -4
  256. esphome/components/rp2040/__init__.py +1 -0
  257. esphome/components/rp2040/gpio.h +1 -0
  258. esphome/components/rtl87xx/__init__.py +2 -0
  259. esphome/components/sdl/binary_sensor.py +270 -0
  260. esphome/components/sdl/sdl_esphome.cpp +16 -0
  261. esphome/components/sdl/sdl_esphome.h +9 -0
  262. esphome/components/seeed_mr60bha2/binary_sensor.py +25 -0
  263. esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp +26 -2
  264. esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +9 -20
  265. esphome/components/seeed_mr60bha2/sensor.py +9 -1
  266. esphome/components/sn74hc165/sn74hc165.h +3 -0
  267. esphome/components/sn74hc595/sn74hc595.h +3 -0
  268. esphome/components/speaker/__init__.py +5 -4
  269. esphome/components/speaker/media_player/__init__.py +458 -0
  270. esphome/components/speaker/media_player/audio_pipeline.cpp +568 -0
  271. esphome/components/speaker/media_player/audio_pipeline.h +159 -0
  272. esphome/components/speaker/media_player/automation.h +26 -0
  273. esphome/components/speaker/media_player/speaker_media_player.cpp +577 -0
  274. esphome/components/speaker/media_player/speaker_media_player.h +160 -0
  275. esphome/components/speaker/speaker.h +20 -0
  276. esphome/components/spi/__init__.py +1 -5
  277. esphome/components/spi/spi.cpp +7 -1
  278. esphome/components/spi/spi.h +21 -2
  279. esphome/components/spi_led_strip/light.py +3 -5
  280. esphome/components/spi_led_strip/spi_led_strip.cpp +67 -0
  281. esphome/components/spi_led_strip/spi_led_strip.h +8 -60
  282. esphome/components/sprinkler/sprinkler.cpp +3 -1
  283. esphome/components/sx1509/sx1509_gpio_pin.h +2 -0
  284. esphome/components/tca9555/tca9555.h +2 -0
  285. esphome/components/toshiba/toshiba.cpp +2 -1
  286. esphome/components/tuya/light/tuya_light.cpp +4 -2
  287. esphome/components/uart/uart_component_esp32_arduino.cpp +2 -2
  288. esphome/components/uart/uart_component_esp_idf.cpp +2 -2
  289. esphome/components/udp/__init__.py +8 -2
  290. esphome/components/udp/udp_component.cpp +25 -56
  291. esphome/components/udp/udp_component.h +3 -0
  292. esphome/components/uponor_smatrix/sensor/__init__.py +14 -4
  293. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +5 -0
  294. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +1 -0
  295. esphome/components/uptime/text_sensor/__init__.py +19 -0
  296. esphome/components/uptime/text_sensor/uptime_text_sensor.cpp +63 -0
  297. esphome/components/uptime/text_sensor/uptime_text_sensor.h +25 -0
  298. esphome/components/voice_assistant/voice_assistant.cpp +24 -14
  299. esphome/components/voice_assistant/voice_assistant.h +8 -0
  300. esphome/components/waveshare_epaper/display.py +22 -1
  301. esphome/components/waveshare_epaper/waveshare_213v3.cpp +9 -3
  302. esphome/components/waveshare_epaper/waveshare_epaper.cpp +1155 -44
  303. esphome/components/waveshare_epaper/waveshare_epaper.h +208 -7
  304. esphome/components/web_server/web_server.cpp +28 -6
  305. esphome/components/weikai/weikai.h +2 -0
  306. esphome/components/wifi/__init__.py +6 -6
  307. esphome/components/wifi/wifi_component.cpp +1 -1
  308. esphome/components/wifi/wifi_component_esp32_arduino.cpp +30 -1
  309. esphome/components/wireguard/__init__.py +2 -2
  310. esphome/components/xl9535/xl9535.h +2 -0
  311. esphome/components/xxtea/__init__.py +3 -0
  312. esphome/components/xxtea/xxtea.cpp +46 -0
  313. esphome/components/xxtea/xxtea.h +26 -0
  314. esphome/components/yashima/yashima.cpp +2 -1
  315. esphome/config.py +9 -5
  316. esphome/config_validation.py +55 -17
  317. esphome/const.py +7 -10
  318. esphome/core/__init__.py +6 -13
  319. esphome/core/base_automation.h +1 -0
  320. esphome/core/config.py +59 -72
  321. esphome/core/defines.h +9 -1
  322. esphome/core/gpio.h +7 -0
  323. esphome/core/helpers.cpp +19 -15
  324. esphome/core/helpers.h +57 -8
  325. esphome/core/log.h +9 -7
  326. esphome/cpp_generator.py +2 -2
  327. esphome/espota2.py +3 -2
  328. esphome/loader.py +12 -4
  329. esphome/log.py +5 -7
  330. esphome/yaml_util.py +2 -2
  331. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/METADATA +12 -7
  332. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/RECORD +341 -292
  333. esphome/components/custom/binary_sensor/custom_binary_sensor.cpp +0 -16
  334. esphome/components/custom/binary_sensor/custom_binary_sensor.h +0 -26
  335. esphome/components/custom/climate/custom_climate.h +0 -22
  336. esphome/components/custom/cover/custom_cover.h +0 -21
  337. esphome/components/custom/light/custom_light_output.h +0 -24
  338. esphome/components/custom/output/custom_output.h +0 -37
  339. esphome/components/custom/sensor/custom_sensor.cpp +0 -16
  340. esphome/components/custom/sensor/custom_sensor.h +0 -24
  341. esphome/components/custom/switch/custom_switch.cpp +0 -16
  342. esphome/components/custom/switch/custom_switch.h +0 -24
  343. esphome/components/custom/text_sensor/custom_text_sensor.cpp +0 -16
  344. esphome/components/custom/text_sensor/custom_text_sensor.h +0 -26
  345. esphome/components/custom_component/custom_component.h +0 -28
  346. esphome/components/esp32_ble_server/ble_2901.cpp +0 -18
  347. esphome/components/esp32_ble_server/ble_2901.h +0 -19
  348. esphome/components/resistance_sampler/__init__.py +0 -6
  349. esphome/components/resistance_sampler/resistance_sampler.h +0 -10
  350. esphome/components/uptime/{sensor.py → sensor/__init__.py} +3 -3
  351. /esphome/components/uptime/{uptime_seconds_sensor.cpp → sensor/uptime_seconds_sensor.cpp} +0 -0
  352. /esphome/components/uptime/{uptime_seconds_sensor.h → sensor/uptime_seconds_sensor.h} +0 -0
  353. /esphome/components/uptime/{uptime_timestamp_sensor.cpp → sensor/uptime_timestamp_sensor.cpp} +0 -0
  354. /esphome/components/uptime/{uptime_timestamp_sensor.h → sensor/uptime_timestamp_sensor.h} +0 -0
  355. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/LICENSE +0 -0
  356. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/WHEEL +0 -0
  357. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/entry_points.txt +0 -0
  358. {esphome-2024.12.4.dist-info → esphome-2025.2.0b2.dist-info}/top_level.txt +0 -0
@@ -12,7 +12,7 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
12
12
  for (int img_y = 0; img_y < height_; img_y++) {
13
13
  if (this->get_binary_pixel_(img_x, img_y)) {
14
14
  display->draw_pixel_at(x + img_x, y + img_y, color_on);
15
- } else if (!this->transparent_) {
15
+ } else if (!this->transparency_) {
16
16
  display->draw_pixel_at(x + img_x, y + img_y, color_off);
17
17
  }
18
18
  }
@@ -22,10 +22,27 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
22
22
  case IMAGE_TYPE_GRAYSCALE:
23
23
  for (int img_x = 0; img_x < width_; img_x++) {
24
24
  for (int img_y = 0; img_y < height_; img_y++) {
25
- auto color = this->get_grayscale_pixel_(img_x, img_y);
26
- if (color.w >= 0x80) {
27
- display->draw_pixel_at(x + img_x, y + img_y, color);
25
+ const uint32_t pos = (img_x + img_y * this->width_);
26
+ const uint8_t gray = progmem_read_byte(this->data_start_ + pos);
27
+ Color color = Color(gray, gray, gray, 0xFF);
28
+ switch (this->transparency_) {
29
+ case TRANSPARENCY_CHROMA_KEY:
30
+ if (gray == 1) {
31
+ continue; // skip drawing
32
+ }
33
+ break;
34
+ case TRANSPARENCY_ALPHA_CHANNEL: {
35
+ auto on = (float) gray / 255.0f;
36
+ auto off = 1.0f - on;
37
+ // blend color_on and color_off
38
+ color = Color(color_on.r * on + color_off.r * off, color_on.g * on + color_off.g * off,
39
+ color_on.b * on + color_off.b * off, 0xFF);
40
+ break;
41
+ }
42
+ default:
43
+ break;
28
44
  }
45
+ display->draw_pixel_at(x + img_x, y + img_y, color);
29
46
  }
30
47
  }
31
48
  break;
@@ -39,20 +56,10 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
39
56
  }
40
57
  }
41
58
  break;
42
- case IMAGE_TYPE_RGB24:
43
- for (int img_x = 0; img_x < width_; img_x++) {
44
- for (int img_y = 0; img_y < height_; img_y++) {
45
- auto color = this->get_rgb24_pixel_(img_x, img_y);
46
- if (color.w >= 0x80) {
47
- display->draw_pixel_at(x + img_x, y + img_y, color);
48
- }
49
- }
50
- }
51
- break;
52
- case IMAGE_TYPE_RGBA:
59
+ case IMAGE_TYPE_RGB:
53
60
  for (int img_x = 0; img_x < width_; img_x++) {
54
61
  for (int img_y = 0; img_y < height_; img_y++) {
55
- auto color = this->get_rgba_pixel_(img_x, img_y);
62
+ auto color = this->get_rgb_pixel_(img_x, img_y);
56
63
  if (color.w >= 0x80) {
57
64
  display->draw_pixel_at(x + img_x, y + img_y, color);
58
65
  }
@@ -61,20 +68,20 @@ void Image::draw(int x, int y, display::Display *display, Color color_on, Color
61
68
  break;
62
69
  }
63
70
  }
64
- Color Image::get_pixel(int x, int y, Color color_on, Color color_off) const {
71
+ Color Image::get_pixel(int x, int y, const Color color_on, const Color color_off) const {
65
72
  if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
66
73
  return color_off;
67
74
  switch (this->type_) {
68
75
  case IMAGE_TYPE_BINARY:
69
- return this->get_binary_pixel_(x, y) ? color_on : color_off;
76
+ if (this->get_binary_pixel_(x, y))
77
+ return color_on;
78
+ return color_off;
70
79
  case IMAGE_TYPE_GRAYSCALE:
71
80
  return this->get_grayscale_pixel_(x, y);
72
81
  case IMAGE_TYPE_RGB565:
73
82
  return this->get_rgb565_pixel_(x, y);
74
- case IMAGE_TYPE_RGB24:
75
- return this->get_rgb24_pixel_(x, y);
76
- case IMAGE_TYPE_RGBA:
77
- return this->get_rgba_pixel_(x, y);
83
+ case IMAGE_TYPE_RGB:
84
+ return this->get_rgb_pixel_(x, y);
78
85
  default:
79
86
  return color_off;
80
87
  }
@@ -98,23 +105,40 @@ lv_img_dsc_t *Image::get_lv_img_dsc() {
98
105
  this->dsc_.header.cf = LV_IMG_CF_ALPHA_8BIT;
99
106
  break;
100
107
 
101
- case IMAGE_TYPE_RGB24:
102
- this->dsc_.header.cf = LV_IMG_CF_RGB888;
103
- break;
104
-
105
- case IMAGE_TYPE_RGB565:
106
- #if LV_COLOR_DEPTH == 16
107
- this->dsc_.header.cf = this->has_transparency() ? LV_IMG_CF_TRUE_COLOR_ALPHA : LV_IMG_CF_TRUE_COLOR;
108
+ case IMAGE_TYPE_RGB:
109
+ #if LV_COLOR_DEPTH == 32
110
+ switch (this->transparent_) {
111
+ case TRANSPARENCY_ALPHA_CHANNEL:
112
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
113
+ break;
114
+ case TRANSPARENCY_CHROMA_KEY:
115
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
116
+ break;
117
+ default:
118
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR;
119
+ break;
120
+ }
108
121
  #else
109
- this->dsc_.header.cf = LV_IMG_CF_RGB565;
122
+ this->dsc_.header.cf =
123
+ this->transparency_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGBA8888 : LV_IMG_CF_RGB888;
110
124
  #endif
111
125
  break;
112
126
 
113
- case IMAGE_TYPE_RGBA:
114
- #if LV_COLOR_DEPTH == 32
115
- this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR;
127
+ case IMAGE_TYPE_RGB565:
128
+ #if LV_COLOR_DEPTH == 16
129
+ switch (this->transparency_) {
130
+ case TRANSPARENCY_ALPHA_CHANNEL:
131
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
132
+ break;
133
+ case TRANSPARENCY_CHROMA_KEY:
134
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
135
+ break;
136
+ default:
137
+ this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR;
138
+ break;
139
+ }
116
140
  #else
117
- this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
141
+ this->dsc_.header.cf = this->transparent_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGB565A8 : LV_IMG_CF_RGB565;
118
142
  #endif
119
143
  break;
120
144
  }
@@ -128,51 +152,81 @@ bool Image::get_binary_pixel_(int x, int y) const {
128
152
  const uint32_t pos = x + y * width_8;
129
153
  return progmem_read_byte(this->data_start_ + (pos / 8u)) & (0x80 >> (pos % 8u));
130
154
  }
131
- Color Image::get_rgba_pixel_(int x, int y) const {
132
- const uint32_t pos = (x + y * this->width_) * 4;
133
- return Color(progmem_read_byte(this->data_start_ + pos + 0), progmem_read_byte(this->data_start_ + pos + 1),
134
- progmem_read_byte(this->data_start_ + pos + 2), progmem_read_byte(this->data_start_ + pos + 3));
135
- }
136
- Color Image::get_rgb24_pixel_(int x, int y) const {
137
- const uint32_t pos = (x + y * this->width_) * 3;
155
+ Color Image::get_rgb_pixel_(int x, int y) const {
156
+ const uint32_t pos = (x + y * this->width_) * this->bpp_ / 8;
138
157
  Color color = Color(progmem_read_byte(this->data_start_ + pos + 0), progmem_read_byte(this->data_start_ + pos + 1),
139
- progmem_read_byte(this->data_start_ + pos + 2));
140
- if (color.b == 1 && color.r == 0 && color.g == 0 && transparent_) {
141
- // (0, 0, 1) has been defined as transparent color for non-alpha images.
142
- // putting blue == 1 as a first condition for performance reasons (least likely value to short-cut the if)
143
- color.w = 0;
144
- } else {
145
- color.w = 0xFF;
158
+ progmem_read_byte(this->data_start_ + pos + 2), 0xFF);
159
+
160
+ switch (this->transparency_) {
161
+ case TRANSPARENCY_CHROMA_KEY:
162
+ if (color.g == 1 && color.r == 0 && color.b == 0) {
163
+ // (0, 1, 0) has been defined as transparent color for non-alpha images.
164
+ color.w = 0;
165
+ }
166
+ break;
167
+ case TRANSPARENCY_ALPHA_CHANNEL:
168
+ color.w = progmem_read_byte(this->data_start_ + (pos + 3));
169
+ break;
170
+ default:
171
+ break;
146
172
  }
147
173
  return color;
148
174
  }
149
175
  Color Image::get_rgb565_pixel_(int x, int y) const {
150
- const uint8_t *pos = this->data_start_;
151
- if (this->transparent_) {
152
- pos += (x + y * this->width_) * 3;
153
- } else {
154
- pos += (x + y * this->width_) * 2;
155
- }
176
+ const uint8_t *pos = this->data_start_ + (x + y * this->width_) * this->bpp_ / 8;
156
177
  uint16_t rgb565 = encode_uint16(progmem_read_byte(pos), progmem_read_byte(pos + 1));
157
178
  auto r = (rgb565 & 0xF800) >> 11;
158
179
  auto g = (rgb565 & 0x07E0) >> 5;
159
180
  auto b = rgb565 & 0x001F;
160
- auto a = this->transparent_ ? progmem_read_byte(pos + 2) : 0xFF;
161
- Color color = Color((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), a);
162
- return color;
181
+ auto a = 0xFF;
182
+ switch (this->transparency_) {
183
+ case TRANSPARENCY_ALPHA_CHANNEL:
184
+ a = progmem_read_byte(pos + 2);
185
+ break;
186
+ case TRANSPARENCY_CHROMA_KEY:
187
+ if (rgb565 == 0x0020)
188
+ a = 0;
189
+ break;
190
+ default:
191
+ break;
192
+ }
193
+ return Color((r << 3) | (r >> 2), (g << 2) | (g >> 4), (b << 3) | (b >> 2), a);
163
194
  }
164
195
 
165
196
  Color Image::get_grayscale_pixel_(int x, int y) const {
166
197
  const uint32_t pos = (x + y * this->width_);
167
198
  const uint8_t gray = progmem_read_byte(this->data_start_ + pos);
168
- uint8_t alpha = (gray == 1 && transparent_) ? 0 : 0xFF;
169
- return Color(gray, gray, gray, alpha);
199
+ switch (this->transparency_) {
200
+ case TRANSPARENCY_CHROMA_KEY:
201
+ if (gray == 1)
202
+ return Color(0, 0, 0, 0);
203
+ return Color(gray, gray, gray, 0xFF);
204
+ case TRANSPARENCY_ALPHA_CHANNEL:
205
+ return Color(0, 0, 0, gray);
206
+ default:
207
+ return Color(gray, gray, gray, 0xFF);
208
+ }
170
209
  }
171
210
  int Image::get_width() const { return this->width_; }
172
211
  int Image::get_height() const { return this->height_; }
173
212
  ImageType Image::get_type() const { return this->type_; }
174
- Image::Image(const uint8_t *data_start, int width, int height, ImageType type)
175
- : width_(width), height_(height), type_(type), data_start_(data_start) {}
213
+ Image::Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency)
214
+ : width_(width), height_(height), type_(type), data_start_(data_start), transparency_(transparency) {
215
+ switch (this->type_) {
216
+ case IMAGE_TYPE_BINARY:
217
+ this->bpp_ = 1;
218
+ break;
219
+ case IMAGE_TYPE_GRAYSCALE:
220
+ this->bpp_ = 8;
221
+ break;
222
+ case IMAGE_TYPE_RGB565:
223
+ this->bpp_ = transparency == TRANSPARENCY_ALPHA_CHANNEL ? 24 : 16;
224
+ break;
225
+ case IMAGE_TYPE_RGB:
226
+ this->bpp_ = this->transparency_ == TRANSPARENCY_ALPHA_CHANNEL ? 32 : 24;
227
+ break;
228
+ }
229
+ }
176
230
 
177
231
  } // namespace image
178
232
  } // namespace esphome
@@ -12,51 +12,40 @@ namespace image {
12
12
  enum ImageType {
13
13
  IMAGE_TYPE_BINARY = 0,
14
14
  IMAGE_TYPE_GRAYSCALE = 1,
15
- IMAGE_TYPE_RGB24 = 2,
15
+ IMAGE_TYPE_RGB = 2,
16
16
  IMAGE_TYPE_RGB565 = 3,
17
- IMAGE_TYPE_RGBA = 4,
17
+ };
18
+
19
+ enum Transparency {
20
+ TRANSPARENCY_OPAQUE = 0,
21
+ TRANSPARENCY_CHROMA_KEY = 1,
22
+ TRANSPARENCY_ALPHA_CHANNEL = 2,
18
23
  };
19
24
 
20
25
  class Image : public display::BaseImage {
21
26
  public:
22
- Image(const uint8_t *data_start, int width, int height, ImageType type);
27
+ Image(const uint8_t *data_start, int width, int height, ImageType type, Transparency transparency);
23
28
  Color get_pixel(int x, int y, Color color_on = display::COLOR_ON, Color color_off = display::COLOR_OFF) const;
24
29
  int get_width() const override;
25
30
  int get_height() const override;
26
31
  const uint8_t *get_data_start() const { return this->data_start_; }
27
32
  ImageType get_type() const;
28
33
 
29
- int get_bpp() const {
30
- switch (this->type_) {
31
- case IMAGE_TYPE_BINARY:
32
- return 1;
33
- case IMAGE_TYPE_GRAYSCALE:
34
- return 8;
35
- case IMAGE_TYPE_RGB565:
36
- return this->transparent_ ? 24 : 16;
37
- case IMAGE_TYPE_RGB24:
38
- return 24;
39
- case IMAGE_TYPE_RGBA:
40
- return 32;
41
- }
42
- return 0;
43
- }
34
+ int get_bpp() const { return this->bpp_; }
44
35
 
45
36
  /// Return the stride of the image in bytes, that is, the distance in bytes
46
37
  /// between two consecutive rows of pixels.
47
- uint32_t get_width_stride() const { return (this->width_ * this->get_bpp() + 7u) / 8u; }
38
+ size_t get_width_stride() const { return (this->width_ * this->get_bpp() + 7u) / 8u; }
48
39
  void draw(int x, int y, display::Display *display, Color color_on, Color color_off) override;
49
40
 
50
- void set_transparency(bool transparent) { transparent_ = transparent; }
51
- bool has_transparency() const { return transparent_; }
41
+ bool has_transparency() const { return this->transparency_ != TRANSPARENCY_OPAQUE; }
52
42
 
53
43
  #ifdef USE_LVGL
54
44
  lv_img_dsc_t *get_lv_img_dsc();
55
45
  #endif
56
46
  protected:
57
47
  bool get_binary_pixel_(int x, int y) const;
58
- Color get_rgb24_pixel_(int x, int y) const;
59
- Color get_rgba_pixel_(int x, int y) const;
48
+ Color get_rgb_pixel_(int x, int y) const;
60
49
  Color get_rgb565_pixel_(int x, int y) const;
61
50
  Color get_grayscale_pixel_(int x, int y) const;
62
51
 
@@ -64,7 +53,9 @@ class Image : public display::BaseImage {
64
53
  int height_;
65
54
  ImageType type_;
66
55
  const uint8_t *data_start_;
67
- bool transparent_;
56
+ Transparency transparency_;
57
+ size_t bpp_{};
58
+ size_t stride_{};
68
59
  #ifdef USE_LVGL
69
60
  lv_img_dsc_t dsc_{};
70
61
  #endif
@@ -1,45 +1,27 @@
1
1
  #include "json_util.h"
2
2
  #include "esphome/core/log.h"
3
3
 
4
- #ifdef USE_ESP8266
5
- #include <Esp.h>
6
- #endif
7
- #ifdef USE_ESP32
8
- #include <esp_heap_caps.h>
9
- #endif
10
- #ifdef USE_RP2040
11
- #include <Arduino.h>
12
- #endif
13
-
14
4
  namespace esphome {
15
5
  namespace json {
16
6
 
17
7
  static const char *const TAG = "json";
18
8
 
19
9
  static std::vector<char> global_json_build_buffer; // NOLINT
10
+ static const auto ALLOCATOR = RAMAllocator<uint8_t>(RAMAllocator<uint8_t>::ALLOC_INTERNAL);
20
11
 
21
12
  std::string build_json(const json_build_t &f) {
22
13
  // Here we are allocating up to 5kb of memory,
23
14
  // with the heap size minus 2kb to be safe if less than 5kb
24
15
  // as we can not have a true dynamic sized document.
25
16
  // The excess memory is freed below with `shrinkToFit()`
26
- #ifdef USE_ESP8266
27
- const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance)
28
- #elif defined(USE_ESP32)
29
- const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
30
- #elif defined(USE_RP2040)
31
- const size_t free_heap = rp2040.getFreeHeap();
32
- #elif defined(USE_LIBRETINY)
33
- const size_t free_heap = lt_heap_get_free();
34
- #endif
35
-
17
+ auto free_heap = ALLOCATOR.get_max_free_block_size();
36
18
  size_t request_size = std::min(free_heap, (size_t) 512);
37
19
  while (true) {
38
- ESP_LOGV(TAG, "Attempting to allocate %u bytes for JSON serialization", request_size);
20
+ ESP_LOGV(TAG, "Attempting to allocate %zu bytes for JSON serialization", request_size);
39
21
  DynamicJsonDocument json_document(request_size);
40
22
  if (json_document.capacity() == 0) {
41
23
  ESP_LOGE(TAG,
42
- "Could not allocate memory for JSON document! Requested %u bytes, largest free heap block: %u bytes",
24
+ "Could not allocate memory for JSON document! Requested %zu bytes, largest free heap block: %zu bytes",
43
25
  request_size, free_heap);
44
26
  return "{}";
45
27
  }
@@ -47,7 +29,7 @@ std::string build_json(const json_build_t &f) {
47
29
  f(root);
48
30
  if (json_document.overflowed()) {
49
31
  if (request_size == free_heap) {
50
- ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %u bytes",
32
+ ESP_LOGE(TAG, "Could not allocate memory for JSON document! Overflowed largest free heap block: %zu bytes",
51
33
  free_heap);
52
34
  return "{}";
53
35
  }
@@ -55,7 +37,7 @@ std::string build_json(const json_build_t &f) {
55
37
  continue;
56
38
  }
57
39
  json_document.shrinkToFit();
58
- ESP_LOGV(TAG, "Size after shrink %u bytes", json_document.capacity());
40
+ ESP_LOGV(TAG, "Size after shrink %zu bytes", json_document.capacity());
59
41
  std::string output;
60
42
  serializeJson(json_document, output);
61
43
  return output;
@@ -67,20 +49,12 @@ bool parse_json(const std::string &data, const json_parse_t &f) {
67
49
  // with the heap size minus 2kb to be safe if less than that
68
50
  // as we can not have a true dynamic sized document.
69
51
  // The excess memory is freed below with `shrinkToFit()`
70
- #ifdef USE_ESP8266
71
- const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance)
72
- #elif defined(USE_ESP32)
73
- const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
74
- #elif defined(USE_RP2040)
75
- const size_t free_heap = rp2040.getFreeHeap();
76
- #elif defined(USE_LIBRETINY)
77
- const size_t free_heap = lt_heap_get_free();
78
- #endif
52
+ auto free_heap = ALLOCATOR.get_max_free_block_size();
79
53
  size_t request_size = std::min(free_heap, (size_t) (data.size() * 1.5));
80
54
  while (true) {
81
55
  DynamicJsonDocument json_document(request_size);
82
56
  if (json_document.capacity() == 0) {
83
- ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %u bytes, free heap: %u", request_size,
57
+ ESP_LOGE(TAG, "Could not allocate memory for JSON document! Requested %zu bytes, free heap: %zu", request_size,
84
58
  free_heap);
85
59
  return false;
86
60
  }
@@ -47,6 +47,7 @@ from .const import (
47
47
  _LOGGER = logging.getLogger(__name__)
48
48
  CODEOWNERS = ["@kuba2k2"]
49
49
  AUTO_LOAD = ["preferences"]
50
+ IS_TARGET_PLATFORM = True
50
51
 
51
52
 
52
53
  def _detect_variant(value):
@@ -20,6 +20,7 @@ class ArduinoInternalGPIOPin : public InternalGPIOPin {
20
20
  void detach_interrupt() const override;
21
21
  ISRInternalGPIOPin to_isr() const override;
22
22
  uint8_t get_pin() const override { return pin_; }
23
+ gpio::Flags get_flags() const override { return flags_; }
23
24
  bool is_inverted() const override { return inverted_; }
24
25
 
25
26
  protected:
@@ -36,7 +36,7 @@ inline static uint8_t to_uint8_scale(float x) { return static_cast<uint8_t>(roun
36
36
  * range as set in the traits, so the output needs to do this.
37
37
  *
38
38
  * For COLD_WARM_WHITE capability:
39
- * - cold_white, warm_white: The brightness of the cald and warm white channels of the light.
39
+ * - cold_white, warm_white: The brightness of the light's cold and warm white channels.
40
40
  *
41
41
  * All values (except color temperature) are represented using floats in the range 0.0 (off) to 1.0 (on), and are
42
42
  * automatically clamped to this range. Properties not used in the current color mode can still have (invalid) values
@@ -35,7 +35,7 @@ from esphome.const import (
35
35
  PLATFORM_RP2040,
36
36
  PLATFORM_RTL87XX,
37
37
  )
38
- from esphome.core import CORE, EsphomeError, Lambda, coroutine_with_priority
38
+ from esphome.core import CORE, Lambda, coroutine_with_priority
39
39
 
40
40
  CODEOWNERS = ["@esphome/core"]
41
41
  logger_ns = cg.esphome_ns.namespace("logger")
@@ -77,6 +77,9 @@ USB_SERIAL_JTAG = "USB_SERIAL_JTAG"
77
77
  USB_CDC = "USB_CDC"
78
78
  DEFAULT = "DEFAULT"
79
79
 
80
+ CONF_INITIAL_LEVEL = "initial_level"
81
+ CONF_LOGGER_ID = "logger_id"
82
+
80
83
  UART_SELECTION_ESP32 = {
81
84
  VARIANT_ESP32: [UART0, UART1, UART2],
82
85
  VARIANT_ESP32S2: [UART0, UART1, USB_CDC],
@@ -154,11 +157,11 @@ def uart_selection(value):
154
157
 
155
158
 
156
159
  def validate_local_no_higher_than_global(value):
157
- global_level = value.get(CONF_LEVEL, "DEBUG")
160
+ global_level = LOG_LEVEL_SEVERITY.index(value[CONF_LEVEL])
158
161
  for tag, level in value.get(CONF_LOGS, {}).items():
159
- if LOG_LEVEL_SEVERITY.index(level) > LOG_LEVEL_SEVERITY.index(global_level):
160
- raise EsphomeError(
161
- f"The local log level {level} for {tag} must be less severe than the global log level {global_level}."
162
+ if LOG_LEVEL_SEVERITY.index(level) > global_level:
163
+ raise cv.Invalid(
164
+ f"The configured log level for {tag} ({level}) must be no more severe than the global log level {value[CONF_LEVEL]}."
162
165
  )
163
166
  return value
164
167
 
@@ -186,6 +189,8 @@ CONFIG_SCHEMA = cv.All(
186
189
  esp32_s3_idf=USB_SERIAL_JTAG,
187
190
  esp32_c3_arduino=USB_CDC,
188
191
  esp32_c3_idf=USB_SERIAL_JTAG,
192
+ esp32_c6_arduino=USB_CDC,
193
+ esp32_c6_idf=USB_SERIAL_JTAG,
189
194
  rp2040=USB_CDC,
190
195
  bk72xx=DEFAULT,
191
196
  rtl87xx=DEFAULT,
@@ -207,6 +212,7 @@ CONFIG_SCHEMA = cv.All(
207
212
  cv.string: is_log_level,
208
213
  }
209
214
  ),
215
+ cv.Optional(CONF_INITIAL_LEVEL): is_log_level,
210
216
  cv.Optional(CONF_ON_MESSAGE): automation.validate_automation(
211
217
  {
212
218
  cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoggerMessageTrigger),
@@ -225,7 +231,14 @@ CONFIG_SCHEMA = cv.All(
225
231
  @coroutine_with_priority(90.0)
226
232
  async def to_code(config):
227
233
  baud_rate = config[CONF_BAUD_RATE]
228
- log = cg.new_Pvariable(config[CONF_ID], baud_rate, config[CONF_TX_BUFFER_SIZE])
234
+ level = config[CONF_LEVEL]
235
+ initial_level = LOG_LEVELS[config.get(CONF_INITIAL_LEVEL, level)]
236
+ log = cg.new_Pvariable(
237
+ config[CONF_ID],
238
+ baud_rate,
239
+ config[CONF_TX_BUFFER_SIZE],
240
+ )
241
+ cg.add(log.set_log_level(initial_level))
229
242
  if CONF_HARDWARE_UART in config:
230
243
  cg.add(
231
244
  log.set_uart_selection(
@@ -237,7 +250,6 @@ async def to_code(config):
237
250
  for tag, level in config[CONF_LOGS].items():
238
251
  cg.add(log.set_log_level(tag, LOG_LEVELS[level]))
239
252
 
240
- level = config[CONF_LEVEL]
241
253
  cg.add_define("USE_LOGGER")
242
254
  this_severity = LOG_LEVEL_SEVERITY.index(level)
243
255
  cg.add_build_flag(f"-DESPHOME_LOG_LEVEL={LOG_LEVELS[level]}")
@@ -365,3 +377,27 @@ async def logger_log_action_to_code(config, action_id, template_arg, args):
365
377
 
366
378
  lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
367
379
  return cg.new_Pvariable(action_id, template_arg, lambda_)
380
+
381
+
382
+ @automation.register_action(
383
+ "logger.set_level",
384
+ LambdaAction,
385
+ cv.maybe_simple_value(
386
+ {
387
+ cv.GenerateID(CONF_LOGGER_ID): cv.use_id(Logger),
388
+ cv.Required(CONF_LEVEL): is_log_level,
389
+ cv.Optional(CONF_TAG): cv.string,
390
+ },
391
+ key=CONF_LEVEL,
392
+ ),
393
+ )
394
+ async def logger_set_level_to_code(config, action_id, template_arg, args):
395
+ level = LOG_LEVELS[config[CONF_LEVEL]]
396
+ logger = await cg.get_variable(config[CONF_LOGGER_ID])
397
+ if tag := config.get(CONF_TAG):
398
+ text = str(cg.statement(logger.set_log_level(tag, level)))
399
+ else:
400
+ text = str(cg.statement(logger.set_log_level(level)))
401
+
402
+ lambda_ = await cg.process_lambda(Lambda(text), args, return_type=cg.void)
403
+ return cg.new_Pvariable(action_id, template_arg, lambda_)
@@ -105,12 +105,9 @@ int HOT Logger::level_for(const char *tag) {
105
105
  // Uses std::vector<> for low memory footprint, though the vector
106
106
  // could be sorted to minimize lookup times. This feature isn't used that
107
107
  // much anyway so it doesn't matter too much.
108
- for (auto &it : this->log_levels_) {
109
- if (it.tag == tag) {
110
- return it.level;
111
- }
112
- }
113
- return ESPHOME_LOG_LEVEL;
108
+ if (this->log_levels_.count(tag) != 0)
109
+ return this->log_levels_[tag];
110
+ return this->current_level_;
114
111
  }
115
112
 
116
113
  void HOT Logger::log_message_(int level, const char *tag, int offset) {
@@ -167,9 +164,7 @@ void Logger::loop() {
167
164
  #endif
168
165
 
169
166
  void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
170
- void Logger::set_log_level(const std::string &tag, int log_level) {
171
- this->log_levels_.push_back(LogLevelOverride{tag, log_level});
172
- }
167
+ void Logger::set_log_level(const std::string &tag, int log_level) { this->log_levels_[tag] = log_level; }
173
168
 
174
169
  #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY)
175
170
  UARTSelection Logger::get_uart() const { return this->uart_; }
@@ -183,18 +178,28 @@ const char *const LOG_LEVELS[] = {"NONE", "ERROR", "WARN", "INFO", "CONFIG", "DE
183
178
 
184
179
  void Logger::dump_config() {
185
180
  ESP_LOGCONFIG(TAG, "Logger:");
186
- ESP_LOGCONFIG(TAG, " Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
181
+ ESP_LOGCONFIG(TAG, " Max Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
182
+ ESP_LOGCONFIG(TAG, " Initial Level: %s", LOG_LEVELS[this->current_level_]);
187
183
  #ifndef USE_HOST
188
184
  ESP_LOGCONFIG(TAG, " Log Baud Rate: %" PRIu32, this->baud_rate_);
189
185
  ESP_LOGCONFIG(TAG, " Hardware UART: %s", get_uart_selection_());
190
186
  #endif
191
187
 
192
188
  for (auto &it : this->log_levels_) {
193
- ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.tag.c_str(), LOG_LEVELS[it.level]);
189
+ ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.first.c_str(), LOG_LEVELS[it.second]);
194
190
  }
195
191
  }
196
192
  void Logger::write_footer_() { this->write_to_buffer_(ESPHOME_LOG_RESET_COLOR, strlen(ESPHOME_LOG_RESET_COLOR)); }
197
193
 
194
+ void Logger::set_log_level(int level) {
195
+ if (level > ESPHOME_LOG_LEVEL) {
196
+ level = ESPHOME_LOG_LEVEL;
197
+ ESP_LOGW(TAG, "Cannot set log level higher than pre-compiled %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
198
+ }
199
+ this->current_level_ = level;
200
+ this->level_callback_.call(level);
201
+ }
202
+
198
203
  Logger *global_logger = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
199
204
 
200
205
  } // namespace logger
@@ -1,11 +1,12 @@
1
1
  #pragma once
2
2
 
3
3
  #include <cstdarg>
4
- #include <vector>
4
+ #include <map>
5
5
  #include "esphome/core/automation.h"
6
6
  #include "esphome/core/component.h"
7
7
  #include "esphome/core/defines.h"
8
8
  #include "esphome/core/helpers.h"
9
+ #include "esphome/core/log.h"
9
10
 
10
11
  #ifdef USE_ARDUINO
11
12
  #if defined(USE_ESP8266) || defined(USE_ESP32)
@@ -74,8 +75,11 @@ class Logger : public Component {
74
75
  UARTSelection get_uart() const;
75
76
  #endif
76
77
 
78
+ /// Set the default log level for this logger.
79
+ void set_log_level(int level);
77
80
  /// Set the log level of the specified tag.
78
81
  void set_log_level(const std::string &tag, int log_level);
82
+ int get_log_level() { return this->current_level_; }
79
83
 
80
84
  // ========== INTERNAL METHODS ==========
81
85
  // (In most use cases you won't need these)
@@ -88,6 +92,9 @@ class Logger : public Component {
88
92
  /// Register a callback that will be called for every log message sent
89
93
  void add_on_log_callback(std::function<void(int, const char *, const char *)> &&callback);
90
94
 
95
+ // add a listener for log level changes
96
+ void add_listener(std::function<void(int)> &&callback) { this->level_callback_.add(std::move(callback)); }
97
+
91
98
  float get_setup_priority() const override;
92
99
 
93
100
  void log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT
@@ -159,17 +166,14 @@ class Logger : public Component {
159
166
  #ifdef USE_ESP_IDF
160
167
  uart_port_t uart_num_;
161
168
  #endif
162
- struct LogLevelOverride {
163
- std::string tag;
164
- int level;
165
- };
166
- std::vector<LogLevelOverride> log_levels_;
169
+ std::map<std::string, int> log_levels_{};
167
170
  CallbackManager<void(int, const char *, const char *)> log_callback_{};
171
+ int current_level_{ESPHOME_LOG_LEVEL_VERY_VERBOSE};
168
172
  /// Prevents recursive log calls, if true a log message is already being processed.
169
173
  bool recursion_guard_ = false;
170
174
  void *main_task_ = nullptr;
175
+ CallbackManager<void(int)> level_callback_{};
171
176
  };
172
-
173
177
  extern Logger *global_logger; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
174
178
 
175
179
  class LoggerMessageTrigger : public Trigger<int, const char *, const char *> {