esphome 2024.12.4__py3-none-any.whl → 2025.2.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 (355) 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/custom/__init__.py +0 -3
  46. esphome/components/custom/binary_sensor/__init__.py +2 -28
  47. esphome/components/custom/climate/__init__.py +2 -27
  48. esphome/components/custom/cover/__init__.py +2 -27
  49. esphome/components/custom/light/__init__.py +2 -27
  50. esphome/components/custom/output/__init__.py +2 -58
  51. esphome/components/custom/sensor/__init__.py +2 -24
  52. esphome/components/custom/switch/__init__.py +2 -24
  53. esphome/components/custom/text_sensor/__init__.py +2 -29
  54. esphome/components/custom_component/__init__.py +3 -27
  55. esphome/components/daly_bms/daly_bms.cpp +6 -0
  56. esphome/components/daly_bms/daly_bms.h +2 -0
  57. esphome/components/daly_bms/sensor.py +6 -0
  58. esphome/components/debug/debug_component.cpp +4 -0
  59. esphome/components/debug/debug_component.h +14 -0
  60. esphome/components/debug/debug_esp32.cpp +154 -74
  61. esphome/components/dfplayer/dfplayer.cpp +15 -2
  62. esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +2 -1
  63. esphome/components/dht/dht.cpp +2 -1
  64. esphome/components/display/__init__.py +18 -5
  65. esphome/components/display/display.cpp +2 -1
  66. esphome/components/display/rect.cpp +2 -1
  67. esphome/components/es7210/__init__.py +0 -0
  68. esphome/components/es7210/audio_adc.py +51 -0
  69. esphome/components/es7210/es7210.cpp +228 -0
  70. esphome/components/es7210/es7210.h +62 -0
  71. esphome/components/es7210/es7210_const.h +129 -0
  72. esphome/components/es7243e/__init__.py +0 -0
  73. esphome/components/es7243e/audio_adc.py +34 -0
  74. esphome/components/es7243e/es7243e.cpp +125 -0
  75. esphome/components/es7243e/es7243e.h +37 -0
  76. esphome/components/es7243e/es7243e_const.h +54 -0
  77. esphome/components/es8156/__init__.py +0 -0
  78. esphome/components/es8156/audio_dac.py +27 -0
  79. esphome/components/es8156/es8156.cpp +87 -0
  80. esphome/components/es8156/es8156.h +51 -0
  81. esphome/components/es8156/es8156_const.h +68 -0
  82. esphome/components/es8311/audio_dac.py +1 -2
  83. esphome/components/esp32/__init__.py +1 -0
  84. esphome/components/esp32/core.cpp +5 -1
  85. esphome/components/esp32/gpio.h +2 -0
  86. esphome/components/esp32_ble/__init__.py +39 -0
  87. esphome/components/esp32_ble/queue.h +4 -4
  88. esphome/components/esp32_ble_client/ble_client_base.cpp +46 -0
  89. esphome/components/esp32_ble_client/ble_client_base.h +2 -0
  90. esphome/components/esp32_ble_server/__init__.py +582 -12
  91. esphome/components/esp32_ble_server/ble_characteristic.cpp +48 -60
  92. esphome/components/esp32_ble_server/ble_characteristic.h +24 -17
  93. esphome/components/esp32_ble_server/ble_descriptor.cpp +21 -9
  94. esphome/components/esp32_ble_server/ble_descriptor.h +17 -6
  95. esphome/components/esp32_ble_server/ble_server.cpp +62 -67
  96. esphome/components/esp32_ble_server/ble_server.h +28 -32
  97. esphome/components/esp32_ble_server/ble_server_automations.cpp +77 -0
  98. esphome/components/esp32_ble_server/ble_server_automations.h +115 -0
  99. esphome/components/esp32_ble_server/ble_service.cpp +17 -15
  100. esphome/components/esp32_ble_server/ble_service.h +10 -14
  101. esphome/components/esp32_ble_tracker/__init__.py +6 -39
  102. esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +33 -10
  103. esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +8 -4
  104. esphome/components/esp32_improv/__init__.py +2 -8
  105. esphome/components/esp32_improv/esp32_improv_component.cpp +21 -20
  106. esphome/components/esp32_improv/esp32_improv_component.h +3 -4
  107. esphome/components/esp32_rmt/__init__.py +28 -3
  108. esphome/components/esp32_rmt_led_strip/led_strip.cpp +73 -6
  109. esphome/components/esp32_rmt_led_strip/led_strip.h +21 -3
  110. esphome/components/esp32_rmt_led_strip/light.py +72 -7
  111. esphome/components/esp32_touch/esp32_touch.cpp +5 -0
  112. esphome/components/esp8266/__init__.py +1 -0
  113. esphome/components/esp8266/gpio.h +1 -0
  114. esphome/components/ethernet/__init__.py +10 -10
  115. esphome/components/event/event.cpp +4 -2
  116. esphome/components/event/event.h +2 -0
  117. esphome/components/event_emitter/__init__.py +5 -0
  118. esphome/components/event_emitter/event_emitter.cpp +14 -0
  119. esphome/components/event_emitter/event_emitter.h +63 -0
  120. esphome/components/gcja5/gcja5.cpp +2 -1
  121. esphome/components/haier/haier_base.cpp +2 -1
  122. esphome/components/haier/hon_climate.cpp +2 -1
  123. esphome/components/heatpumpir/heatpumpir.cpp +2 -1
  124. esphome/components/host/__init__.py +1 -0
  125. esphome/components/host/gpio.h +1 -0
  126. esphome/components/http_request/http_request.h +2 -2
  127. esphome/components/http_request/http_request_arduino.cpp +1 -1
  128. esphome/components/http_request/http_request_idf.cpp +1 -1
  129. esphome/components/i2c/i2c_bus_esp_idf.cpp +4 -0
  130. esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +7 -5
  131. esphome/components/i2s_audio/speaker/__init__.py +53 -6
  132. esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +92 -46
  133. esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +8 -0
  134. esphome/components/ili9xxx/display.py +29 -11
  135. esphome/components/ili9xxx/ili9xxx_display.cpp +2 -5
  136. esphome/components/ili9xxx/ili9xxx_display.h +2 -1
  137. esphome/components/image/__init__.py +443 -255
  138. esphome/components/image/image.cpp +115 -61
  139. esphome/components/image/image.h +15 -24
  140. esphome/components/json/json_util.cpp +8 -34
  141. esphome/components/libretiny/__init__.py +1 -0
  142. esphome/components/libretiny/gpio_arduino.h +1 -0
  143. esphome/components/light/light_color_values.h +1 -1
  144. esphome/components/logger/__init__.py +43 -7
  145. esphome/components/logger/logger.cpp +16 -11
  146. esphome/components/logger/logger.h +11 -7
  147. esphome/components/logger/select/__init__.py +29 -0
  148. esphome/components/logger/select/logger_level_select.cpp +27 -0
  149. esphome/components/logger/select/logger_level_select.h +15 -0
  150. esphome/components/lvgl/__init__.py +96 -73
  151. esphome/components/lvgl/automation.py +39 -7
  152. esphome/components/lvgl/defines.py +8 -2
  153. esphome/components/lvgl/lvgl_esphome.cpp +8 -15
  154. esphome/components/lvgl/lvgl_esphome.h +20 -5
  155. esphome/components/lvgl/schemas.py +25 -14
  156. esphome/components/lvgl/trigger.py +27 -3
  157. esphome/components/lvgl/widgets/dropdown.py +1 -1
  158. esphome/components/lvgl/widgets/keyboard.py +8 -1
  159. esphome/components/lvgl/widgets/meter.py +2 -1
  160. esphome/components/lvgl/widgets/msgbox.py +1 -1
  161. esphome/components/lvgl/widgets/obj.py +1 -12
  162. esphome/components/lvgl/widgets/page.py +37 -2
  163. esphome/components/lvgl/widgets/tabview.py +1 -1
  164. esphome/components/max6956/max6956.h +2 -0
  165. esphome/components/mcp23016/mcp23016.h +2 -0
  166. esphome/components/mcp23xxx_base/mcp23xxx_base.h +2 -0
  167. esphome/components/mdns/__init__.py +1 -1
  168. esphome/components/media_player/__init__.py +37 -8
  169. esphome/components/media_player/automation.h +11 -2
  170. esphome/components/media_player/media_player.cpp +8 -0
  171. esphome/components/media_player/media_player.h +8 -4
  172. esphome/components/micronova/switch/micronova_switch.cpp +4 -2
  173. esphome/components/midea/ac_automations.h +3 -1
  174. esphome/components/midea/air_conditioner.cpp +7 -5
  175. esphome/components/midea/air_conditioner.h +1 -1
  176. esphome/components/midea/climate.py +4 -2
  177. esphome/components/midea/ir_transmitter.h +36 -5
  178. esphome/components/mixer/__init__.py +0 -0
  179. esphome/components/mixer/speaker/__init__.py +172 -0
  180. esphome/components/mixer/speaker/automation.h +19 -0
  181. esphome/components/mixer/speaker/mixer_speaker.cpp +624 -0
  182. esphome/components/mixer/speaker/mixer_speaker.h +207 -0
  183. esphome/components/mpr121/mpr121.h +2 -0
  184. esphome/components/mqtt/__init__.py +1 -1
  185. esphome/components/mqtt/mqtt_client.cpp +7 -1
  186. esphome/components/mqtt/mqtt_client.h +1 -1
  187. esphome/components/mqtt/mqtt_climate.cpp +2 -2
  188. esphome/components/network/ip_address.h +2 -0
  189. esphome/components/nextion/automation.h +17 -0
  190. esphome/components/nextion/display.py +42 -17
  191. esphome/components/nextion/nextion.cpp +4 -10
  192. esphome/components/nextion/nextion.h +89 -82
  193. esphome/components/nextion/nextion_commands.cpp +10 -10
  194. esphome/components/ntc/sensor.py +2 -4
  195. esphome/components/online_image/__init__.py +98 -46
  196. esphome/components/online_image/bmp_image.cpp +101 -0
  197. esphome/components/online_image/bmp_image.h +40 -0
  198. esphome/components/online_image/image_decoder.cpp +28 -2
  199. esphome/components/online_image/image_decoder.h +24 -15
  200. esphome/components/online_image/jpeg_image.cpp +90 -0
  201. esphome/components/online_image/jpeg_image.h +34 -0
  202. esphome/components/online_image/online_image.cpp +112 -53
  203. esphome/components/online_image/online_image.h +24 -7
  204. esphome/components/online_image/png_image.cpp +7 -3
  205. esphome/components/online_image/png_image.h +2 -1
  206. esphome/components/opentherm/__init__.py +73 -7
  207. esphome/components/opentherm/automation.h +25 -0
  208. esphome/components/opentherm/const.py +1 -0
  209. esphome/components/opentherm/generate.py +39 -6
  210. esphome/components/opentherm/hub.cpp +117 -79
  211. esphome/components/opentherm/hub.h +31 -15
  212. esphome/components/opentherm/opentherm.cpp +47 -23
  213. esphome/components/opentherm/opentherm.h +27 -6
  214. esphome/components/opentherm/opentherm_macros.h +11 -0
  215. esphome/components/opentherm/schema.py +78 -1
  216. esphome/components/opentherm/validate.py +7 -2
  217. esphome/components/pca6416a/pca6416a.h +2 -0
  218. esphome/components/pca9554/pca9554.h +2 -0
  219. esphome/components/pcf8574/pcf8574.h +2 -0
  220. esphome/components/preferences/__init__.py +2 -4
  221. esphome/components/preferences/syncer.h +10 -3
  222. esphome/components/prometheus/prometheus_handler.cpp +313 -0
  223. esphome/components/prometheus/prometheus_handler.h +48 -7
  224. esphome/components/psram/psram.cpp +8 -1
  225. esphome/components/pulse_counter/pulse_counter_sensor.cpp +14 -9
  226. esphome/components/pulse_counter/pulse_counter_sensor.h +4 -4
  227. esphome/components/pulse_meter/pulse_meter_sensor.cpp +2 -0
  228. esphome/components/qspi_dbi/__init__.py +3 -0
  229. esphome/components/qspi_dbi/display.py +74 -47
  230. esphome/components/qspi_dbi/models.py +245 -2
  231. esphome/components/qspi_dbi/qspi_dbi.cpp +9 -16
  232. esphome/components/qspi_dbi/qspi_dbi.h +2 -2
  233. esphome/components/remote_base/__init__.py +77 -25
  234. esphome/components/remote_base/remote_base.cpp +1 -1
  235. esphome/components/remote_base/remote_base.h +20 -2
  236. esphome/components/remote_base/toto_protocol.cpp +100 -0
  237. esphome/components/remote_base/toto_protocol.h +45 -0
  238. esphome/components/remote_receiver/__init__.py +55 -10
  239. esphome/components/remote_receiver/remote_receiver.h +36 -3
  240. esphome/components/remote_receiver/remote_receiver_esp32.cpp +145 -6
  241. esphome/components/remote_transmitter/__init__.py +62 -4
  242. esphome/components/remote_transmitter/remote_transmitter.h +21 -2
  243. esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +140 -4
  244. esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +3 -3
  245. esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +3 -3
  246. esphome/components/resampler/__init__.py +0 -0
  247. esphome/components/resampler/speaker/__init__.py +103 -0
  248. esphome/components/resampler/speaker/resampler_speaker.cpp +318 -0
  249. esphome/components/resampler/speaker/resampler_speaker.h +107 -0
  250. esphome/components/resistance/resistance_sensor.h +2 -3
  251. esphome/components/resistance/sensor.py +2 -9
  252. esphome/components/rotary_encoder/rotary_encoder.cpp +8 -4
  253. esphome/components/rp2040/__init__.py +1 -0
  254. esphome/components/rp2040/gpio.h +1 -0
  255. esphome/components/rtl87xx/__init__.py +2 -0
  256. esphome/components/sdl/binary_sensor.py +270 -0
  257. esphome/components/sdl/sdl_esphome.cpp +16 -0
  258. esphome/components/sdl/sdl_esphome.h +9 -0
  259. esphome/components/seeed_mr60bha2/binary_sensor.py +25 -0
  260. esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp +26 -2
  261. esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +9 -20
  262. esphome/components/seeed_mr60bha2/sensor.py +9 -1
  263. esphome/components/sn74hc165/sn74hc165.h +3 -0
  264. esphome/components/sn74hc595/sn74hc595.h +3 -0
  265. esphome/components/speaker/__init__.py +5 -4
  266. esphome/components/speaker/media_player/__init__.py +458 -0
  267. esphome/components/speaker/media_player/audio_pipeline.cpp +568 -0
  268. esphome/components/speaker/media_player/audio_pipeline.h +159 -0
  269. esphome/components/speaker/media_player/automation.h +26 -0
  270. esphome/components/speaker/media_player/speaker_media_player.cpp +577 -0
  271. esphome/components/speaker/media_player/speaker_media_player.h +160 -0
  272. esphome/components/speaker/speaker.h +20 -0
  273. esphome/components/spi/__init__.py +1 -5
  274. esphome/components/spi/spi.cpp +7 -1
  275. esphome/components/spi/spi.h +21 -2
  276. esphome/components/spi_led_strip/light.py +3 -5
  277. esphome/components/spi_led_strip/spi_led_strip.cpp +67 -0
  278. esphome/components/spi_led_strip/spi_led_strip.h +8 -60
  279. esphome/components/sprinkler/sprinkler.cpp +3 -1
  280. esphome/components/sx1509/sx1509_gpio_pin.h +2 -0
  281. esphome/components/tca9555/tca9555.h +2 -0
  282. esphome/components/toshiba/toshiba.cpp +2 -1
  283. esphome/components/tuya/light/tuya_light.cpp +4 -2
  284. esphome/components/uart/uart_component_esp32_arduino.cpp +2 -2
  285. esphome/components/uart/uart_component_esp_idf.cpp +2 -2
  286. esphome/components/udp/__init__.py +8 -2
  287. esphome/components/udp/udp_component.cpp +25 -56
  288. esphome/components/udp/udp_component.h +3 -0
  289. esphome/components/uponor_smatrix/sensor/__init__.py +14 -4
  290. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +5 -0
  291. esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +1 -0
  292. esphome/components/uptime/text_sensor/__init__.py +19 -0
  293. esphome/components/uptime/text_sensor/uptime_text_sensor.cpp +63 -0
  294. esphome/components/uptime/text_sensor/uptime_text_sensor.h +25 -0
  295. esphome/components/voice_assistant/voice_assistant.cpp +24 -14
  296. esphome/components/voice_assistant/voice_assistant.h +8 -0
  297. esphome/components/waveshare_epaper/display.py +22 -1
  298. esphome/components/waveshare_epaper/waveshare_213v3.cpp +9 -3
  299. esphome/components/waveshare_epaper/waveshare_epaper.cpp +1155 -44
  300. esphome/components/waveshare_epaper/waveshare_epaper.h +208 -7
  301. esphome/components/web_server/web_server.cpp +28 -6
  302. esphome/components/weikai/weikai.h +2 -0
  303. esphome/components/wifi/__init__.py +6 -6
  304. esphome/components/wifi/wifi_component.cpp +1 -1
  305. esphome/components/wifi/wifi_component_esp32_arduino.cpp +30 -1
  306. esphome/components/wireguard/__init__.py +2 -2
  307. esphome/components/xl9535/xl9535.h +2 -0
  308. esphome/components/xxtea/__init__.py +3 -0
  309. esphome/components/xxtea/xxtea.cpp +46 -0
  310. esphome/components/xxtea/xxtea.h +26 -0
  311. esphome/components/yashima/yashima.cpp +2 -1
  312. esphome/config.py +9 -5
  313. esphome/config_validation.py +55 -17
  314. esphome/const.py +7 -10
  315. esphome/core/__init__.py +6 -13
  316. esphome/core/base_automation.h +1 -0
  317. esphome/core/config.py +57 -72
  318. esphome/core/defines.h +9 -1
  319. esphome/core/gpio.h +7 -0
  320. esphome/core/helpers.cpp +19 -15
  321. esphome/core/helpers.h +57 -8
  322. esphome/core/log.h +9 -7
  323. esphome/cpp_generator.py +2 -2
  324. esphome/espota2.py +3 -2
  325. esphome/loader.py +12 -4
  326. esphome/log.py +5 -7
  327. esphome/yaml_util.py +2 -2
  328. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/METADATA +12 -7
  329. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/RECORD +338 -289
  330. esphome/components/custom/binary_sensor/custom_binary_sensor.cpp +0 -16
  331. esphome/components/custom/binary_sensor/custom_binary_sensor.h +0 -26
  332. esphome/components/custom/climate/custom_climate.h +0 -22
  333. esphome/components/custom/cover/custom_cover.h +0 -21
  334. esphome/components/custom/light/custom_light_output.h +0 -24
  335. esphome/components/custom/output/custom_output.h +0 -37
  336. esphome/components/custom/sensor/custom_sensor.cpp +0 -16
  337. esphome/components/custom/sensor/custom_sensor.h +0 -24
  338. esphome/components/custom/switch/custom_switch.cpp +0 -16
  339. esphome/components/custom/switch/custom_switch.h +0 -24
  340. esphome/components/custom/text_sensor/custom_text_sensor.cpp +0 -16
  341. esphome/components/custom/text_sensor/custom_text_sensor.h +0 -26
  342. esphome/components/custom_component/custom_component.h +0 -28
  343. esphome/components/esp32_ble_server/ble_2901.cpp +0 -18
  344. esphome/components/esp32_ble_server/ble_2901.h +0 -19
  345. esphome/components/resistance_sampler/__init__.py +0 -6
  346. esphome/components/resistance_sampler/resistance_sampler.h +0 -10
  347. esphome/components/uptime/{sensor.py → sensor/__init__.py} +3 -3
  348. /esphome/components/uptime/{uptime_seconds_sensor.cpp → sensor/uptime_seconds_sensor.cpp} +0 -0
  349. /esphome/components/uptime/{uptime_seconds_sensor.h → sensor/uptime_seconds_sensor.h} +0 -0
  350. /esphome/components/uptime/{uptime_timestamp_sensor.cpp → sensor/uptime_timestamp_sensor.cpp} +0 -0
  351. /esphome/components/uptime/{uptime_timestamp_sensor.h → sensor/uptime_timestamp_sensor.h} +0 -0
  352. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/LICENSE +0 -0
  353. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/WHEEL +0 -0
  354. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/entry_points.txt +0 -0
  355. {esphome-2024.12.4.dist-info → esphome-2025.2.0b1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,77 @@
1
+ #include "ble_server_automations.h"
2
+
3
+ #ifdef USE_ESP32
4
+
5
+ namespace esphome {
6
+ namespace esp32_ble_server {
7
+ // Interface to interact with ESPHome automations and triggers
8
+ namespace esp32_ble_server_automations {
9
+
10
+ using namespace esp32_ble;
11
+
12
+ Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_write_trigger(
13
+ BLECharacteristic *characteristic) {
14
+ Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
15
+ new Trigger<std::vector<uint8_t>, uint16_t>();
16
+ characteristic->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>, uint16_t>::on(
17
+ BLECharacteristicEvt::VectorEvt::ON_WRITE,
18
+ [on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
19
+ return on_write_trigger;
20
+ }
21
+
22
+ Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_descriptor_on_write_trigger(BLEDescriptor *descriptor) {
23
+ Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
24
+ new Trigger<std::vector<uint8_t>, uint16_t>();
25
+ descriptor->on(
26
+ BLEDescriptorEvt::VectorEvt::ON_WRITE,
27
+ [on_write_trigger](const std::vector<uint8_t> &data, uint16_t id) { on_write_trigger->trigger(data, id); });
28
+ return on_write_trigger;
29
+ }
30
+
31
+ Trigger<uint16_t> *BLETriggers::create_server_on_connect_trigger(BLEServer *server) {
32
+ Trigger<uint16_t> *on_connect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
33
+ server->on(BLEServerEvt::EmptyEvt::ON_CONNECT,
34
+ [on_connect_trigger](uint16_t conn_id) { on_connect_trigger->trigger(conn_id); });
35
+ return on_connect_trigger;
36
+ }
37
+
38
+ Trigger<uint16_t> *BLETriggers::create_server_on_disconnect_trigger(BLEServer *server) {
39
+ Trigger<uint16_t> *on_disconnect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
40
+ server->on(BLEServerEvt::EmptyEvt::ON_DISCONNECT,
41
+ [on_disconnect_trigger](uint16_t conn_id) { on_disconnect_trigger->trigger(conn_id); });
42
+ return on_disconnect_trigger;
43
+ }
44
+
45
+ void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *characteristic,
46
+ EventEmitterListenerID listener_id,
47
+ const std::function<void()> &pre_notify_listener) {
48
+ // Check if there is already a listener for this characteristic
49
+ if (this->listeners_.count(characteristic) > 0) {
50
+ // Unpack the pair listener_id, pre_notify_listener_id
51
+ auto listener_pairs = this->listeners_[characteristic];
52
+ EventEmitterListenerID old_listener_id = listener_pairs.first;
53
+ EventEmitterListenerID old_pre_notify_listener_id = listener_pairs.second;
54
+ // Remove the previous listener
55
+ characteristic->EventEmitter<BLECharacteristicEvt::EmptyEvt, uint16_t>::off(BLECharacteristicEvt::EmptyEvt::ON_READ,
56
+ old_listener_id);
57
+ // Remove the pre-notify listener
58
+ this->off(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, old_pre_notify_listener_id);
59
+ }
60
+ // Create a new listener for the pre-notify event
61
+ EventEmitterListenerID pre_notify_listener_id =
62
+ this->on(BLECharacteristicSetValueActionEvt::PRE_NOTIFY,
63
+ [pre_notify_listener, characteristic](const BLECharacteristic *evt_characteristic) {
64
+ // Only call the pre-notify listener if the characteristic is the one we are interested in
65
+ if (characteristic == evt_characteristic) {
66
+ pre_notify_listener();
67
+ }
68
+ });
69
+ // Save the pair listener_id, pre_notify_listener_id to the map
70
+ this->listeners_[characteristic] = std::make_pair(listener_id, pre_notify_listener_id);
71
+ }
72
+
73
+ } // namespace esp32_ble_server_automations
74
+ } // namespace esp32_ble_server
75
+ } // namespace esphome
76
+
77
+ #endif
@@ -0,0 +1,115 @@
1
+ #pragma once
2
+
3
+ #include "ble_server.h"
4
+ #include "ble_characteristic.h"
5
+ #include "ble_descriptor.h"
6
+
7
+ #include "esphome/components/event_emitter/event_emitter.h"
8
+ #include "esphome/core/automation.h"
9
+
10
+ #include <vector>
11
+ #include <unordered_map>
12
+ #include <functional>
13
+
14
+ #ifdef USE_ESP32
15
+
16
+ namespace esphome {
17
+ namespace esp32_ble_server {
18
+ // Interface to interact with ESPHome actions and triggers
19
+ namespace esp32_ble_server_automations {
20
+
21
+ using namespace esp32_ble;
22
+ using namespace event_emitter;
23
+
24
+ class BLETriggers {
25
+ public:
26
+ static Trigger<std::vector<uint8_t>, uint16_t> *create_characteristic_on_write_trigger(
27
+ BLECharacteristic *characteristic);
28
+ static Trigger<std::vector<uint8_t>, uint16_t> *create_descriptor_on_write_trigger(BLEDescriptor *descriptor);
29
+ static Trigger<uint16_t> *create_server_on_connect_trigger(BLEServer *server);
30
+ static Trigger<uint16_t> *create_server_on_disconnect_trigger(BLEServer *server);
31
+ };
32
+
33
+ enum BLECharacteristicSetValueActionEvt {
34
+ PRE_NOTIFY,
35
+ };
36
+
37
+ // Class to make sure only one BLECharacteristicSetValueAction is active at a time for each characteristic
38
+ class BLECharacteristicSetValueActionManager
39
+ : public EventEmitter<BLECharacteristicSetValueActionEvt, BLECharacteristic *> {
40
+ public:
41
+ // Singleton pattern
42
+ static BLECharacteristicSetValueActionManager *get_instance() {
43
+ static BLECharacteristicSetValueActionManager instance;
44
+ return &instance;
45
+ }
46
+ void set_listener(BLECharacteristic *characteristic, EventEmitterListenerID listener_id,
47
+ const std::function<void()> &pre_notify_listener);
48
+ EventEmitterListenerID get_listener(BLECharacteristic *characteristic) {
49
+ return this->listeners_[characteristic].first;
50
+ }
51
+ void emit_pre_notify(BLECharacteristic *characteristic) {
52
+ this->emit_(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, characteristic);
53
+ }
54
+
55
+ private:
56
+ std::unordered_map<BLECharacteristic *, std::pair<EventEmitterListenerID, EventEmitterListenerID>> listeners_;
57
+ };
58
+
59
+ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<Ts...> {
60
+ public:
61
+ BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
62
+ TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
63
+ void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
64
+ void play(Ts... x) override {
65
+ // If the listener is already set, do nothing
66
+ if (BLECharacteristicSetValueActionManager::get_instance()->get_listener(this->parent_) == this->listener_id_)
67
+ return;
68
+ // Set initial value
69
+ this->parent_->set_value(this->buffer_.value(x...));
70
+ // Set the listener for read events
71
+ this->listener_id_ = this->parent_->EventEmitter<BLECharacteristicEvt::EmptyEvt, uint16_t>::on(
72
+ BLECharacteristicEvt::EmptyEvt::ON_READ, [this, x...](uint16_t id) {
73
+ // Set the value of the characteristic every time it is read
74
+ this->parent_->set_value(this->buffer_.value(x...));
75
+ });
76
+ // Set the listener in the global manager so only one BLECharacteristicSetValueAction is set for each characteristic
77
+ BLECharacteristicSetValueActionManager::get_instance()->set_listener(
78
+ this->parent_, this->listener_id_, [this, x...]() { this->parent_->set_value(this->buffer_.value(x...)); });
79
+ }
80
+
81
+ protected:
82
+ BLECharacteristic *parent_;
83
+ EventEmitterListenerID listener_id_;
84
+ };
85
+
86
+ template<typename... Ts> class BLECharacteristicNotifyAction : public Action<Ts...> {
87
+ public:
88
+ BLECharacteristicNotifyAction(BLECharacteristic *characteristic) : parent_(characteristic) {}
89
+ void play(Ts... x) override {
90
+ // Call the pre-notify event
91
+ BLECharacteristicSetValueActionManager::get_instance()->emit_pre_notify(this->parent_);
92
+ // Notify the characteristic
93
+ this->parent_->notify();
94
+ }
95
+
96
+ protected:
97
+ BLECharacteristic *parent_;
98
+ };
99
+
100
+ template<typename... Ts> class BLEDescriptorSetValueAction : public Action<Ts...> {
101
+ public:
102
+ BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {}
103
+ TEMPLATABLE_VALUE(std::vector<uint8_t>, buffer)
104
+ void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); }
105
+ void play(Ts... x) override { this->parent_->set_value(this->buffer_.value(x...)); }
106
+
107
+ protected:
108
+ BLEDescriptor *parent_;
109
+ };
110
+
111
+ } // namespace esp32_ble_server_automations
112
+ } // namespace esp32_ble_server
113
+ } // namespace esphome
114
+
115
+ #endif
@@ -52,18 +52,21 @@ void BLEService::do_create(BLEServer *server) {
52
52
  esp_err_t err = esp_ble_gatts_create_service(server->get_gatts_if(), &srvc_id, this->num_handles_);
53
53
  if (err != ESP_OK) {
54
54
  ESP_LOGE(TAG, "esp_ble_gatts_create_service failed: %d", err);
55
- this->init_state_ = FAILED;
55
+ this->state_ = FAILED;
56
56
  return;
57
57
  }
58
- this->init_state_ = CREATING;
58
+ this->state_ = CREATING;
59
59
  }
60
60
 
61
61
  void BLEService::do_delete() {
62
- if (this->init_state_ == DELETING || this->init_state_ == DELETED)
62
+ if (this->state_ == DELETING || this->state_ == DELETED)
63
63
  return;
64
- this->init_state_ = DELETING;
64
+ this->state_ = DELETING;
65
65
  this->created_characteristic_count_ = 0;
66
66
  this->last_created_characteristic_ = nullptr;
67
+ // Call all characteristics to delete
68
+ for (auto *characteristic : this->characteristics_)
69
+ characteristic->do_delete();
67
70
  this->stop_();
68
71
  esp_err_t err = esp_ble_gatts_delete_service(this->handle_);
69
72
  if (err != ESP_OK) {
@@ -91,6 +94,7 @@ void BLEService::start() {
91
94
  return;
92
95
  should_start_ = true;
93
96
 
97
+ this->state_ = STARTING;
94
98
  esp_err_t err = esp_ble_gatts_start_service(this->handle_);
95
99
  if (err != ESP_OK) {
96
100
  ESP_LOGE(TAG, "esp_ble_gatts_start_service failed: %d", err);
@@ -98,7 +102,6 @@ void BLEService::start() {
98
102
  }
99
103
  if (this->advertise_)
100
104
  esp32_ble::global_ble->advertising_add_service_uuid(this->uuid_);
101
- this->running_state_ = STARTING;
102
105
  }
103
106
 
104
107
  void BLEService::stop() {
@@ -107,9 +110,9 @@ void BLEService::stop() {
107
110
  }
108
111
 
109
112
  void BLEService::stop_() {
110
- if (this->running_state_ == STOPPING || this->running_state_ == STOPPED)
113
+ if (this->state_ == STOPPING || this->state_ == STOPPED)
111
114
  return;
112
- this->running_state_ = STOPPING;
115
+ this->state_ = STOPPING;
113
116
  esp_err_t err = esp_ble_gatts_stop_service(this->handle_);
114
117
  if (err != ESP_OK) {
115
118
  ESP_LOGE(TAG, "esp_ble_gatts_stop_service failed: %d", err);
@@ -119,17 +122,16 @@ void BLEService::stop_() {
119
122
  esp32_ble::global_ble->advertising_remove_service_uuid(this->uuid_);
120
123
  }
121
124
 
122
- bool BLEService::is_created() { return this->init_state_ == CREATED; }
123
125
  bool BLEService::is_failed() {
124
- if (this->init_state_ == FAILED)
126
+ if (this->state_ == FAILED)
125
127
  return true;
126
128
  bool failed = false;
127
129
  for (auto *characteristic : this->characteristics_)
128
130
  failed |= characteristic->is_failed();
129
131
 
130
132
  if (failed)
131
- this->init_state_ = FAILED;
132
- return this->init_state_ == FAILED;
133
+ this->state_ = FAILED;
134
+ return this->state_ == FAILED;
133
135
  }
134
136
 
135
137
  void BLEService::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if,
@@ -139,7 +141,7 @@ void BLEService::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t g
139
141
  if (this->uuid_ == ESPBTUUID::from_uuid(param->create.service_id.id.uuid) &&
140
142
  this->inst_id_ == param->create.service_id.id.inst_id) {
141
143
  this->handle_ = param->create.service_handle;
142
- this->init_state_ = CREATED;
144
+ this->state_ = CREATED;
143
145
  if (this->should_start_)
144
146
  this->start();
145
147
  }
@@ -147,18 +149,18 @@ void BLEService::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t g
147
149
  }
148
150
  case ESP_GATTS_DELETE_EVT:
149
151
  if (param->del.service_handle == this->handle_) {
150
- this->init_state_ = DELETED;
152
+ this->state_ = DELETED;
151
153
  }
152
154
  break;
153
155
  case ESP_GATTS_START_EVT: {
154
156
  if (param->start.service_handle == this->handle_) {
155
- this->running_state_ = RUNNING;
157
+ this->state_ = RUNNING;
156
158
  }
157
159
  break;
158
160
  }
159
161
  case ESP_GATTS_STOP_EVT: {
160
162
  if (param->start.service_handle == this->handle_) {
161
- this->running_state_ = STOPPED;
163
+ this->state_ = STOPPED;
162
164
  }
163
165
  break;
164
166
  }
@@ -32,6 +32,7 @@ class BLEService {
32
32
  BLECharacteristic *create_characteristic(ESPBTUUID uuid, esp_gatt_char_prop_t properties);
33
33
 
34
34
  ESPBTUUID get_uuid() { return this->uuid_; }
35
+ uint8_t get_inst_id() { return this->inst_id_; }
35
36
  BLECharacteristic *get_last_created_characteristic() { return this->last_created_characteristic_; }
36
37
  uint16_t get_handle() { return this->handle_; }
37
38
 
@@ -44,18 +45,17 @@ class BLEService {
44
45
  void start();
45
46
  void stop();
46
47
 
47
- bool is_created();
48
48
  bool is_failed();
49
-
50
- bool is_running() { return this->running_state_ == RUNNING; }
51
- bool is_starting() { return this->running_state_ == STARTING; }
52
- bool is_deleted() { return this->init_state_ == DELETED; }
49
+ bool is_created() { return this->state_ == CREATED; }
50
+ bool is_running() { return this->state_ == RUNNING; }
51
+ bool is_starting() { return this->state_ == STARTING; }
52
+ bool is_deleted() { return this->state_ == DELETED; }
53
53
 
54
54
  protected:
55
55
  std::vector<BLECharacteristic *> characteristics_;
56
56
  BLECharacteristic *last_created_characteristic_{nullptr};
57
57
  uint32_t created_characteristic_count_{0};
58
- BLEServer *server_;
58
+ BLEServer *server_ = nullptr;
59
59
  ESPBTUUID uuid_;
60
60
  uint16_t num_handles_;
61
61
  uint16_t handle_{0xFFFF};
@@ -66,22 +66,18 @@ class BLEService {
66
66
  bool do_create_characteristics_();
67
67
  void stop_();
68
68
 
69
- enum InitState : uint8_t {
69
+ enum State : uint8_t {
70
70
  FAILED = 0x00,
71
71
  INIT,
72
72
  CREATING,
73
- CREATING_DEPENDENTS,
74
73
  CREATED,
75
- DELETING,
76
- DELETED,
77
- } init_state_{INIT};
78
-
79
- enum RunningState : uint8_t {
80
74
  STARTING,
81
75
  RUNNING,
82
76
  STOPPING,
83
77
  STOPPED,
84
- } running_state_{STOPPED};
78
+ DELETING,
79
+ DELETED,
80
+ } state_{INIT};
85
81
  };
86
82
 
87
83
  } // namespace esp32_ble_server
@@ -1,9 +1,13 @@
1
- import re
2
-
3
1
  from esphome import automation
4
2
  import esphome.codegen as cg
5
3
  from esphome.components import esp32_ble
6
4
  from esphome.components.esp32 import add_idf_sdkconfig_option
5
+ from esphome.components.esp32_ble import (
6
+ bt_uuid,
7
+ bt_uuid16_format,
8
+ bt_uuid32_format,
9
+ bt_uuid128_format,
10
+ )
7
11
  import esphome.config_validation as cv
8
12
  from esphome.const import (
9
13
  CONF_ACTIVE,
@@ -86,43 +90,6 @@ def validate_scan_parameters(config):
86
90
  return config
87
91
 
88
92
 
89
- bt_uuid16_format = "XXXX"
90
- bt_uuid32_format = "XXXXXXXX"
91
- bt_uuid128_format = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
92
-
93
-
94
- def bt_uuid(value):
95
- in_value = cv.string_strict(value)
96
- value = in_value.upper()
97
-
98
- if len(value) == len(bt_uuid16_format):
99
- pattern = re.compile("^[A-F|0-9]{4,}$")
100
- if not pattern.match(value):
101
- raise cv.Invalid(
102
- f"Invalid hexadecimal value for 16 bit UUID format: '{in_value}'"
103
- )
104
- return value
105
- if len(value) == len(bt_uuid32_format):
106
- pattern = re.compile("^[A-F|0-9]{8,}$")
107
- if not pattern.match(value):
108
- raise cv.Invalid(
109
- f"Invalid hexadecimal value for 32 bit UUID format: '{in_value}'"
110
- )
111
- return value
112
- if len(value) == len(bt_uuid128_format):
113
- pattern = re.compile(
114
- "^[A-F|0-9]{8,}-[A-F|0-9]{4,}-[A-F|0-9]{4,}-[A-F|0-9]{4,}-[A-F|0-9]{12,}$"
115
- )
116
- if not pattern.match(value):
117
- raise cv.Invalid(
118
- f"Invalid hexadecimal value for 128 UUID format: '{in_value}'"
119
- )
120
- return value
121
- raise cv.Invalid(
122
- f"Service UUID must be in 16 bit '{bt_uuid16_format}', 32 bit '{bt_uuid32_format}', or 128 bit '{bt_uuid128_format}' format"
123
- )
124
-
125
-
126
93
  def as_hex(value):
127
94
  return cg.RawExpression(f"0x{value}ULL")
128
95
 
@@ -58,7 +58,6 @@ void ESP32BLETracker::setup() {
58
58
  global_esp32_ble_tracker = this;
59
59
  this->scan_result_lock_ = xSemaphoreCreateMutex();
60
60
  this->scan_end_lock_ = xSemaphoreCreateMutex();
61
- this->scanner_idle_ = true;
62
61
 
63
62
  #ifdef USE_OTA
64
63
  ota::get_global_ota_callback()->add_on_state_callback(
@@ -107,6 +106,15 @@ void ESP32BLETracker::loop() {
107
106
  break;
108
107
  }
109
108
  }
109
+ if (connecting != connecting_ || discovered != discovered_ || searching != searching_ ||
110
+ disconnecting != disconnecting_) {
111
+ connecting_ = connecting;
112
+ discovered_ = discovered;
113
+ searching_ = searching;
114
+ disconnecting_ = disconnecting;
115
+ ESP_LOGD(TAG, "connecting: %d, discovered: %d, searching: %d, disconnecting: %d", connecting_, discovered_,
116
+ searching_, disconnecting_);
117
+ }
110
118
  bool promote_to_connecting = discovered && !searching && !connecting;
111
119
 
112
120
  if (!this->scanner_idle_) {
@@ -183,8 +191,9 @@ void ESP32BLETracker::loop() {
183
191
  }
184
192
 
185
193
  if (this->scan_start_failed_ || this->scan_set_param_failed_) {
186
- if (this->scan_start_fail_count_ == 255) {
187
- ESP_LOGE(TAG, "ESP-IDF BLE scan could not restart after 255 attempts, rebooting to restore BLE stack...");
194
+ if (this->scan_start_fail_count_ == std::numeric_limits<uint8_t>::max()) {
195
+ ESP_LOGE(TAG, "ESP-IDF BLE scan could not restart after %d attempts, rebooting to restore BLE stack...",
196
+ std::numeric_limits<uint8_t>::max());
188
197
  App.reboot();
189
198
  }
190
199
  if (xSemaphoreTake(this->scan_end_lock_, 0L)) {
@@ -282,6 +291,12 @@ void ESP32BLETracker::start_scan_(bool first) {
282
291
  this->scan_params_.scan_interval = this->scan_interval_;
283
292
  this->scan_params_.scan_window = this->scan_window_;
284
293
 
294
+ // Start timeout before scan is started. Otherwise scan never starts if any error.
295
+ this->set_timeout("scan", this->scan_duration_ * 2000, []() {
296
+ ESP_LOGE(TAG, "ESP-IDF BLE scan never terminated, rebooting to restore BLE stack...");
297
+ App.reboot();
298
+ });
299
+
285
300
  esp_err_t err = esp_ble_gap_set_scan_params(&this->scan_params_);
286
301
  if (err != ESP_OK) {
287
302
  ESP_LOGE(TAG, "esp_ble_gap_set_scan_params failed: %d", err);
@@ -293,11 +308,6 @@ void ESP32BLETracker::start_scan_(bool first) {
293
308
  return;
294
309
  }
295
310
  this->scanner_idle_ = false;
296
-
297
- this->set_timeout("scan", this->scan_duration_ * 2000, []() {
298
- ESP_LOGE(TAG, "ESP-IDF BLE scan never terminated, rebooting to restore BLE stack...");
299
- App.reboot();
300
- });
301
311
  }
302
312
 
303
313
  void ESP32BLETracker::end_of_scan_() {
@@ -371,6 +381,7 @@ void ESP32BLETracker::gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_ga
371
381
  }
372
382
 
373
383
  void ESP32BLETracker::gap_scan_set_param_complete_(const esp_ble_gap_cb_param_t::ble_scan_param_cmpl_evt_param &param) {
384
+ ESP_LOGV(TAG, "gap_scan_set_param_complete - status %d", param.status);
374
385
  if (param.status == ESP_BT_STATUS_DONE) {
375
386
  this->scan_set_param_failed_ = ESP_BT_STATUS_SUCCESS;
376
387
  } else {
@@ -379,20 +390,25 @@ void ESP32BLETracker::gap_scan_set_param_complete_(const esp_ble_gap_cb_param_t:
379
390
  }
380
391
 
381
392
  void ESP32BLETracker::gap_scan_start_complete_(const esp_ble_gap_cb_param_t::ble_scan_start_cmpl_evt_param &param) {
393
+ ESP_LOGV(TAG, "gap_scan_start_complete - status %d", param.status);
382
394
  this->scan_start_failed_ = param.status;
383
395
  if (param.status == ESP_BT_STATUS_SUCCESS) {
384
396
  this->scan_start_fail_count_ = 0;
385
397
  } else {
386
- this->scan_start_fail_count_++;
398
+ if (this->scan_start_fail_count_ != std::numeric_limits<uint8_t>::max()) {
399
+ this->scan_start_fail_count_++;
400
+ }
387
401
  xSemaphoreGive(this->scan_end_lock_);
388
402
  }
389
403
  }
390
404
 
391
405
  void ESP32BLETracker::gap_scan_stop_complete_(const esp_ble_gap_cb_param_t::ble_scan_stop_cmpl_evt_param &param) {
406
+ ESP_LOGV(TAG, "gap_scan_stop_complete - status %d", param.status);
392
407
  xSemaphoreGive(this->scan_end_lock_);
393
408
  }
394
409
 
395
410
  void ESP32BLETracker::gap_scan_result_(const esp_ble_gap_cb_param_t::ble_scan_result_evt_param &param) {
411
+ ESP_LOGV(TAG, "gap_scan_result - event %d", param.search_evt);
396
412
  if (param.search_evt == ESP_GAP_SEARCH_INQ_RES_EVT) {
397
413
  if (xSemaphoreTake(this->scan_result_lock_, 0L)) {
398
414
  if (this->scan_result_index_ < ESP32BLETracker::SCAN_RESULT_BUFFER_SIZE) {
@@ -663,7 +679,14 @@ void ESP32BLETracker::dump_config() {
663
679
  ESP_LOGCONFIG(TAG, " Scan Interval: %.1f ms", this->scan_interval_ * 0.625f);
664
680
  ESP_LOGCONFIG(TAG, " Scan Window: %.1f ms", this->scan_window_ * 0.625f);
665
681
  ESP_LOGCONFIG(TAG, " Scan Type: %s", this->scan_active_ ? "ACTIVE" : "PASSIVE");
666
- ESP_LOGCONFIG(TAG, " Continuous Scanning: %s", this->scan_continuous_ ? "True" : "False");
682
+ ESP_LOGCONFIG(TAG, " Continuous Scanning: %s", YESNO(this->scan_continuous_));
683
+ ESP_LOGCONFIG(TAG, " Scanner Idle: %s", YESNO(this->scanner_idle_));
684
+ ESP_LOGCONFIG(TAG, " Scan End: %s", YESNO(xSemaphoreGetMutexHolder(this->scan_end_lock_) == nullptr));
685
+ ESP_LOGCONFIG(TAG, " Connecting: %d, discovered: %d, searching: %d, disconnecting: %d", connecting_, discovered_,
686
+ searching_, disconnecting_);
687
+ if (this->scan_start_fail_count_) {
688
+ ESP_LOGCONFIG(TAG, " Scan Start Fail Count: %d", this->scan_start_fail_count_);
689
+ }
667
690
  }
668
691
 
669
692
  void ESP32BLETracker::print_bt_device_info(const ESPBTDevice &device) {
@@ -178,7 +178,7 @@ class ESPBTClient : public ESPBTDeviceListener {
178
178
  int app_id;
179
179
 
180
180
  protected:
181
- ClientState state_;
181
+ ClientState state_{ClientState::INIT};
182
182
  };
183
183
 
184
184
  class ESP32BLETracker : public Component,
@@ -229,7 +229,7 @@ class ESP32BLETracker : public Component,
229
229
  /// Called when a `ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT` event is received.
230
230
  void gap_scan_stop_complete_(const esp_ble_gap_cb_param_t::ble_scan_stop_cmpl_evt_param &param);
231
231
 
232
- int app_id_;
232
+ int app_id_{0};
233
233
 
234
234
  /// Vector of addresses that have already been printed in print_bt_device_info
235
235
  std::vector<uint64_t> already_discovered_;
@@ -242,10 +242,10 @@ class ESP32BLETracker : public Component,
242
242
  uint32_t scan_duration_;
243
243
  uint32_t scan_interval_;
244
244
  uint32_t scan_window_;
245
- uint8_t scan_start_fail_count_;
245
+ uint8_t scan_start_fail_count_{0};
246
246
  bool scan_continuous_;
247
247
  bool scan_active_;
248
- bool scanner_idle_;
248
+ bool scanner_idle_{true};
249
249
  bool ble_was_disabled_{true};
250
250
  bool raw_advertisements_{false};
251
251
  bool parse_advertisements_{false};
@@ -260,6 +260,10 @@ class ESP32BLETracker : public Component,
260
260
  esp_ble_gap_cb_param_t::ble_scan_result_evt_param *scan_result_buffer_;
261
261
  esp_bt_status_t scan_start_failed_{ESP_BT_STATUS_SUCCESS};
262
262
  esp_bt_status_t scan_set_param_failed_{ESP_BT_STATUS_SUCCESS};
263
+ int connecting_{0};
264
+ int discovered_{0};
265
+ int searching_{0};
266
+ int disconnecting_{0};
263
267
  };
264
268
 
265
269
  // NOLINTNEXTLINE
@@ -1,6 +1,6 @@
1
1
  from esphome import automation
2
2
  import esphome.codegen as cg
3
- from esphome.components import binary_sensor, esp32_ble_server, output
3
+ from esphome.components import binary_sensor, output
4
4
  import esphome.config_validation as cv
5
5
  from esphome.const import CONF_ID, CONF_ON_STATE, CONF_TRIGGER_ID
6
6
 
@@ -24,9 +24,7 @@ Error = improv_ns.enum("Error")
24
24
  State = improv_ns.enum("State")
25
25
 
26
26
  esp32_improv_ns = cg.esphome_ns.namespace("esp32_improv")
27
- ESP32ImprovComponent = esp32_improv_ns.class_(
28
- "ESP32ImprovComponent", cg.Component, esp32_ble_server.BLEServiceComponent
29
- )
27
+ ESP32ImprovComponent = esp32_improv_ns.class_("ESP32ImprovComponent", cg.Component)
30
28
  ESP32ImprovProvisionedTrigger = esp32_improv_ns.class_(
31
29
  "ESP32ImprovProvisionedTrigger", automation.Trigger.template()
32
30
  )
@@ -47,7 +45,6 @@ ESP32ImprovStoppedTrigger = esp32_improv_ns.class_(
47
45
  CONFIG_SCHEMA = cv.Schema(
48
46
  {
49
47
  cv.GenerateID(): cv.declare_id(ESP32ImprovComponent),
50
- cv.GenerateID(CONF_BLE_SERVER_ID): cv.use_id(esp32_ble_server.BLEServer),
51
48
  cv.Required(CONF_AUTHORIZER): cv.Any(
52
49
  cv.none, cv.use_id(binary_sensor.BinarySensor)
53
50
  ),
@@ -100,9 +97,6 @@ async def to_code(config):
100
97
  var = cg.new_Pvariable(config[CONF_ID])
101
98
  await cg.register_component(var, config)
102
99
 
103
- ble_server = await cg.get_variable(config[CONF_BLE_SERVER_ID])
104
- cg.add(ble_server.register_service_component(var))
105
-
106
100
  cg.add_define("USE_IMPROV")
107
101
  cg.add_library("improv/Improv", "1.2.4")
108
102