esphome 2024.12.3__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.
- esphome/__main__.py +16 -3
- esphome/components/adc/__init__.py +17 -11
- esphome/components/adc/adc_sensor.h +17 -0
- esphome/components/adc/adc_sensor_common.cpp +55 -0
- esphome/components/adc/adc_sensor_esp32.cpp +8 -5
- esphome/components/adc/adc_sensor_esp8266.cpp +10 -6
- esphome/components/adc/adc_sensor_libretiny.cpp +11 -6
- esphome/components/adc/adc_sensor_rp2040.cpp +13 -10
- esphome/components/adc/sensor.py +9 -3
- esphome/components/ads1115/ads1115.cpp +56 -7
- esphome/components/ads1115/ads1115.h +13 -1
- esphome/components/ads1115/sensor/__init__.py +16 -0
- esphome/components/ads1115/sensor/ads1115_sensor.cpp +2 -1
- esphome/components/ads1115/sensor/ads1115_sensor.h +2 -0
- esphome/components/animation/__init__.py +23 -261
- esphome/components/animation/animation.cpp +2 -2
- esphome/components/animation/animation.h +2 -1
- esphome/components/api/api_pb2.cpp +14 -0
- esphome/components/api/api_pb2.h +1 -0
- esphome/components/audio/__init__.py +112 -0
- esphome/components/audio/audio.cpp +67 -0
- esphome/components/audio/audio.h +125 -7
- esphome/components/audio/audio_decoder.cpp +361 -0
- esphome/components/audio/audio_decoder.h +135 -0
- esphome/components/audio/audio_reader.cpp +308 -0
- esphome/components/audio/audio_reader.h +85 -0
- esphome/components/audio/audio_resampler.cpp +159 -0
- esphome/components/audio/audio_resampler.h +101 -0
- esphome/components/audio/audio_transfer_buffer.cpp +165 -0
- esphome/components/audio/audio_transfer_buffer.h +139 -0
- esphome/components/audio_adc/__init__.py +41 -0
- esphome/components/audio_adc/audio_adc.h +17 -0
- esphome/components/audio_adc/automation.h +23 -0
- esphome/components/bk72xx/__init__.py +1 -0
- esphome/components/ble_client/ble_client.cpp +1 -2
- esphome/components/ble_client/sensor/__init__.py +1 -1
- esphome/components/ble_client/text_sensor/__init__.py +1 -1
- esphome/components/bluetooth_proxy/bluetooth_connection.cpp +5 -0
- esphome/components/bluetooth_proxy/bluetooth_connection.h +1 -0
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
- esphome/components/ch422g/ch422g.h +2 -0
- esphome/components/climate/__init__.py +1 -1
- esphome/components/climate_ir/climate_ir.cpp +2 -1
- esphome/components/coolix/coolix.cpp +2 -1
- esphome/components/custom/__init__.py +0 -3
- esphome/components/custom/binary_sensor/__init__.py +2 -28
- esphome/components/custom/climate/__init__.py +2 -27
- esphome/components/custom/cover/__init__.py +2 -27
- esphome/components/custom/light/__init__.py +2 -27
- esphome/components/custom/output/__init__.py +2 -58
- esphome/components/custom/sensor/__init__.py +2 -24
- esphome/components/custom/switch/__init__.py +2 -24
- esphome/components/custom/text_sensor/__init__.py +2 -29
- esphome/components/custom_component/__init__.py +3 -27
- esphome/components/daly_bms/daly_bms.cpp +6 -0
- esphome/components/daly_bms/daly_bms.h +2 -0
- esphome/components/daly_bms/sensor.py +6 -0
- esphome/components/debug/debug_component.cpp +4 -0
- esphome/components/debug/debug_component.h +14 -0
- esphome/components/debug/debug_esp32.cpp +154 -74
- esphome/components/dfplayer/dfplayer.cpp +15 -2
- esphome/components/dfrobot_sen0395/dfrobot_sen0395.cpp +2 -1
- esphome/components/dht/dht.cpp +2 -1
- esphome/components/display/__init__.py +18 -5
- esphome/components/display/display.cpp +2 -1
- esphome/components/display/rect.cpp +2 -1
- esphome/components/es7210/__init__.py +0 -0
- esphome/components/es7210/audio_adc.py +51 -0
- esphome/components/es7210/es7210.cpp +228 -0
- esphome/components/es7210/es7210.h +62 -0
- esphome/components/es7210/es7210_const.h +129 -0
- esphome/components/es7243e/__init__.py +0 -0
- esphome/components/es7243e/audio_adc.py +34 -0
- esphome/components/es7243e/es7243e.cpp +125 -0
- esphome/components/es7243e/es7243e.h +37 -0
- esphome/components/es7243e/es7243e_const.h +54 -0
- esphome/components/es8156/__init__.py +0 -0
- esphome/components/es8156/audio_dac.py +27 -0
- esphome/components/es8156/es8156.cpp +87 -0
- esphome/components/es8156/es8156.h +51 -0
- esphome/components/es8156/es8156_const.h +68 -0
- esphome/components/es8311/audio_dac.py +1 -2
- esphome/components/esp32/__init__.py +1 -0
- esphome/components/esp32/core.cpp +5 -1
- esphome/components/esp32/gpio.h +2 -0
- esphome/components/esp32_ble/__init__.py +39 -0
- esphome/components/esp32_ble/queue.h +4 -4
- esphome/components/esp32_ble_client/ble_client_base.cpp +46 -0
- esphome/components/esp32_ble_client/ble_client_base.h +2 -0
- esphome/components/esp32_ble_server/__init__.py +582 -12
- esphome/components/esp32_ble_server/ble_characteristic.cpp +48 -60
- esphome/components/esp32_ble_server/ble_characteristic.h +24 -17
- esphome/components/esp32_ble_server/ble_descriptor.cpp +21 -9
- esphome/components/esp32_ble_server/ble_descriptor.h +17 -6
- esphome/components/esp32_ble_server/ble_server.cpp +62 -67
- esphome/components/esp32_ble_server/ble_server.h +28 -32
- esphome/components/esp32_ble_server/ble_server_automations.cpp +77 -0
- esphome/components/esp32_ble_server/ble_server_automations.h +115 -0
- esphome/components/esp32_ble_server/ble_service.cpp +17 -15
- esphome/components/esp32_ble_server/ble_service.h +10 -14
- esphome/components/esp32_ble_tracker/__init__.py +6 -39
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp +33 -10
- esphome/components/esp32_ble_tracker/esp32_ble_tracker.h +8 -4
- esphome/components/esp32_improv/__init__.py +2 -8
- esphome/components/esp32_improv/esp32_improv_component.cpp +21 -20
- esphome/components/esp32_improv/esp32_improv_component.h +3 -4
- esphome/components/esp32_rmt/__init__.py +28 -3
- esphome/components/esp32_rmt_led_strip/led_strip.cpp +73 -6
- esphome/components/esp32_rmt_led_strip/led_strip.h +21 -3
- esphome/components/esp32_rmt_led_strip/light.py +72 -7
- esphome/components/esp32_touch/esp32_touch.cpp +5 -0
- esphome/components/esp8266/__init__.py +1 -0
- esphome/components/esp8266/gpio.h +1 -0
- esphome/components/ethernet/__init__.py +10 -10
- esphome/components/event/event.cpp +4 -2
- esphome/components/event/event.h +2 -0
- esphome/components/event_emitter/__init__.py +5 -0
- esphome/components/event_emitter/event_emitter.cpp +14 -0
- esphome/components/event_emitter/event_emitter.h +63 -0
- esphome/components/gcja5/gcja5.cpp +2 -1
- esphome/components/haier/haier_base.cpp +2 -1
- esphome/components/haier/hon_climate.cpp +2 -1
- esphome/components/heatpumpir/heatpumpir.cpp +2 -1
- esphome/components/host/__init__.py +1 -0
- esphome/components/host/gpio.h +1 -0
- esphome/components/http_request/http_request.h +2 -2
- esphome/components/http_request/http_request_arduino.cpp +1 -1
- esphome/components/http_request/http_request_idf.cpp +1 -1
- esphome/components/i2c/i2c_bus_esp_idf.cpp +4 -0
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +7 -5
- esphome/components/i2s_audio/speaker/__init__.py +53 -6
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +92 -46
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +8 -0
- esphome/components/ili9xxx/display.py +29 -11
- esphome/components/ili9xxx/ili9xxx_display.cpp +2 -5
- esphome/components/ili9xxx/ili9xxx_display.h +2 -1
- esphome/components/image/__init__.py +443 -255
- esphome/components/image/image.cpp +115 -61
- esphome/components/image/image.h +15 -24
- esphome/components/json/json_util.cpp +8 -34
- esphome/components/libretiny/__init__.py +1 -0
- esphome/components/libretiny/gpio_arduino.h +1 -0
- esphome/components/light/light_color_values.h +1 -1
- esphome/components/logger/__init__.py +43 -7
- esphome/components/logger/logger.cpp +16 -11
- esphome/components/logger/logger.h +11 -7
- esphome/components/logger/select/__init__.py +29 -0
- esphome/components/logger/select/logger_level_select.cpp +27 -0
- esphome/components/logger/select/logger_level_select.h +15 -0
- esphome/components/lvgl/__init__.py +96 -73
- esphome/components/lvgl/automation.py +39 -7
- esphome/components/lvgl/defines.py +8 -2
- esphome/components/lvgl/lvgl_esphome.cpp +8 -15
- esphome/components/lvgl/lvgl_esphome.h +20 -5
- esphome/components/lvgl/schemas.py +25 -14
- esphome/components/lvgl/trigger.py +27 -3
- esphome/components/lvgl/widgets/dropdown.py +1 -1
- esphome/components/lvgl/widgets/keyboard.py +8 -1
- esphome/components/lvgl/widgets/meter.py +2 -1
- esphome/components/lvgl/widgets/msgbox.py +1 -1
- esphome/components/lvgl/widgets/obj.py +1 -12
- esphome/components/lvgl/widgets/page.py +37 -2
- esphome/components/lvgl/widgets/tabview.py +1 -1
- esphome/components/max6956/max6956.h +2 -0
- esphome/components/mcp23016/mcp23016.h +2 -0
- esphome/components/mcp23xxx_base/mcp23xxx_base.h +2 -0
- esphome/components/mdns/__init__.py +1 -1
- esphome/components/media_player/__init__.py +37 -8
- esphome/components/media_player/automation.h +11 -2
- esphome/components/media_player/media_player.cpp +8 -0
- esphome/components/media_player/media_player.h +8 -4
- esphome/components/micronova/switch/micronova_switch.cpp +4 -2
- esphome/components/midea/ac_automations.h +3 -1
- esphome/components/midea/air_conditioner.cpp +7 -5
- esphome/components/midea/air_conditioner.h +1 -1
- esphome/components/midea/climate.py +4 -2
- esphome/components/midea/ir_transmitter.h +36 -5
- esphome/components/mixer/__init__.py +0 -0
- esphome/components/mixer/speaker/__init__.py +172 -0
- esphome/components/mixer/speaker/automation.h +19 -0
- esphome/components/mixer/speaker/mixer_speaker.cpp +624 -0
- esphome/components/mixer/speaker/mixer_speaker.h +207 -0
- esphome/components/mpr121/mpr121.h +2 -0
- esphome/components/mqtt/__init__.py +1 -1
- esphome/components/mqtt/mqtt_client.cpp +7 -1
- esphome/components/mqtt/mqtt_client.h +1 -1
- esphome/components/mqtt/mqtt_climate.cpp +2 -2
- esphome/components/network/ip_address.h +2 -0
- esphome/components/nextion/automation.h +17 -0
- esphome/components/nextion/display.py +42 -17
- esphome/components/nextion/nextion.cpp +4 -10
- esphome/components/nextion/nextion.h +89 -82
- esphome/components/nextion/nextion_commands.cpp +10 -10
- esphome/components/ntc/sensor.py +2 -4
- esphome/components/online_image/__init__.py +98 -46
- esphome/components/online_image/bmp_image.cpp +101 -0
- esphome/components/online_image/bmp_image.h +40 -0
- esphome/components/online_image/image_decoder.cpp +28 -2
- esphome/components/online_image/image_decoder.h +24 -15
- esphome/components/online_image/jpeg_image.cpp +90 -0
- esphome/components/online_image/jpeg_image.h +34 -0
- esphome/components/online_image/online_image.cpp +112 -53
- esphome/components/online_image/online_image.h +24 -7
- esphome/components/online_image/png_image.cpp +7 -3
- esphome/components/online_image/png_image.h +2 -1
- esphome/components/opentherm/__init__.py +73 -7
- esphome/components/opentherm/automation.h +25 -0
- esphome/components/opentherm/const.py +1 -0
- esphome/components/opentherm/generate.py +39 -6
- esphome/components/opentherm/hub.cpp +117 -79
- esphome/components/opentherm/hub.h +31 -15
- esphome/components/opentherm/opentherm.cpp +47 -23
- esphome/components/opentherm/opentherm.h +27 -6
- esphome/components/opentherm/opentherm_macros.h +11 -0
- esphome/components/opentherm/schema.py +78 -1
- esphome/components/opentherm/validate.py +7 -2
- esphome/components/pca6416a/pca6416a.h +2 -0
- esphome/components/pca9554/pca9554.h +2 -0
- esphome/components/pcf8574/pcf8574.h +2 -0
- esphome/components/preferences/__init__.py +2 -4
- esphome/components/preferences/syncer.h +10 -3
- esphome/components/prometheus/prometheus_handler.cpp +313 -0
- esphome/components/prometheus/prometheus_handler.h +48 -7
- esphome/components/psram/psram.cpp +8 -1
- esphome/components/pulse_counter/pulse_counter_sensor.cpp +14 -9
- esphome/components/pulse_counter/pulse_counter_sensor.h +4 -4
- esphome/components/pulse_meter/pulse_meter_sensor.cpp +2 -0
- esphome/components/qspi_dbi/__init__.py +3 -0
- esphome/components/qspi_dbi/display.py +74 -47
- esphome/components/qspi_dbi/models.py +245 -2
- esphome/components/qspi_dbi/qspi_dbi.cpp +9 -16
- esphome/components/qspi_dbi/qspi_dbi.h +2 -2
- esphome/components/remote_base/__init__.py +77 -25
- esphome/components/remote_base/remote_base.cpp +1 -1
- esphome/components/remote_base/remote_base.h +20 -2
- esphome/components/remote_base/toto_protocol.cpp +100 -0
- esphome/components/remote_base/toto_protocol.h +45 -0
- esphome/components/remote_receiver/__init__.py +55 -10
- esphome/components/remote_receiver/remote_receiver.h +36 -3
- esphome/components/remote_receiver/remote_receiver_esp32.cpp +145 -6
- esphome/components/remote_transmitter/__init__.py +62 -4
- esphome/components/remote_transmitter/remote_transmitter.h +21 -2
- esphome/components/remote_transmitter/remote_transmitter_esp32.cpp +140 -4
- esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp +3 -3
- esphome/components/remote_transmitter/remote_transmitter_libretiny.cpp +3 -3
- esphome/components/resampler/__init__.py +0 -0
- esphome/components/resampler/speaker/__init__.py +103 -0
- esphome/components/resampler/speaker/resampler_speaker.cpp +318 -0
- esphome/components/resampler/speaker/resampler_speaker.h +107 -0
- esphome/components/resistance/resistance_sensor.h +2 -3
- esphome/components/resistance/sensor.py +2 -9
- esphome/components/rotary_encoder/rotary_encoder.cpp +8 -4
- esphome/components/rp2040/__init__.py +1 -0
- esphome/components/rp2040/gpio.h +1 -0
- esphome/components/rtl87xx/__init__.py +2 -0
- esphome/components/sdl/binary_sensor.py +270 -0
- esphome/components/sdl/sdl_esphome.cpp +16 -0
- esphome/components/sdl/sdl_esphome.h +9 -0
- esphome/components/seeed_mr60bha2/binary_sensor.py +25 -0
- esphome/components/seeed_mr60bha2/seeed_mr60bha2.cpp +26 -2
- esphome/components/seeed_mr60bha2/seeed_mr60bha2.h +9 -20
- esphome/components/seeed_mr60bha2/sensor.py +9 -1
- esphome/components/sn74hc165/sn74hc165.h +3 -0
- esphome/components/sn74hc595/sn74hc595.h +3 -0
- esphome/components/speaker/__init__.py +5 -4
- esphome/components/speaker/media_player/__init__.py +458 -0
- esphome/components/speaker/media_player/audio_pipeline.cpp +568 -0
- esphome/components/speaker/media_player/audio_pipeline.h +159 -0
- esphome/components/speaker/media_player/automation.h +26 -0
- esphome/components/speaker/media_player/speaker_media_player.cpp +577 -0
- esphome/components/speaker/media_player/speaker_media_player.h +160 -0
- esphome/components/speaker/speaker.h +20 -0
- esphome/components/spi/__init__.py +1 -5
- esphome/components/spi/spi.cpp +7 -1
- esphome/components/spi/spi.h +21 -2
- esphome/components/spi_led_strip/light.py +3 -5
- esphome/components/spi_led_strip/spi_led_strip.cpp +67 -0
- esphome/components/spi_led_strip/spi_led_strip.h +8 -60
- esphome/components/sprinkler/sprinkler.cpp +3 -1
- esphome/components/sx1509/sx1509_gpio_pin.h +2 -0
- esphome/components/tca9555/tca9555.h +2 -0
- esphome/components/toshiba/toshiba.cpp +2 -1
- esphome/components/tuya/light/tuya_light.cpp +4 -2
- esphome/components/uart/uart_component_esp32_arduino.cpp +2 -2
- esphome/components/uart/uart_component_esp_idf.cpp +2 -2
- esphome/components/udp/__init__.py +8 -2
- esphome/components/udp/udp_component.cpp +25 -56
- esphome/components/udp/udp_component.h +3 -0
- esphome/components/uponor_smatrix/sensor/__init__.py +14 -4
- esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.cpp +5 -0
- esphome/components/uponor_smatrix/sensor/uponor_smatrix_sensor.h +1 -0
- esphome/components/uptime/text_sensor/__init__.py +19 -0
- esphome/components/uptime/text_sensor/uptime_text_sensor.cpp +63 -0
- esphome/components/uptime/text_sensor/uptime_text_sensor.h +25 -0
- esphome/components/voice_assistant/voice_assistant.cpp +24 -14
- esphome/components/voice_assistant/voice_assistant.h +8 -0
- esphome/components/waveshare_epaper/display.py +22 -1
- esphome/components/waveshare_epaper/waveshare_213v3.cpp +9 -3
- esphome/components/waveshare_epaper/waveshare_epaper.cpp +1155 -44
- esphome/components/waveshare_epaper/waveshare_epaper.h +208 -7
- esphome/components/web_server/web_server.cpp +28 -6
- esphome/components/weikai/weikai.h +2 -0
- esphome/components/wifi/__init__.py +6 -6
- esphome/components/wifi/wifi_component.cpp +1 -1
- esphome/components/wifi/wifi_component_esp32_arduino.cpp +30 -1
- esphome/components/wireguard/__init__.py +2 -2
- esphome/components/xl9535/xl9535.h +2 -0
- esphome/components/xxtea/__init__.py +3 -0
- esphome/components/xxtea/xxtea.cpp +46 -0
- esphome/components/xxtea/xxtea.h +26 -0
- esphome/components/yashima/yashima.cpp +2 -1
- esphome/config.py +9 -5
- esphome/config_validation.py +55 -17
- esphome/const.py +7 -10
- esphome/core/__init__.py +6 -13
- esphome/core/base_automation.h +1 -0
- esphome/core/config.py +57 -72
- esphome/core/defines.h +9 -1
- esphome/core/gpio.h +7 -0
- esphome/core/helpers.cpp +19 -15
- esphome/core/helpers.h +57 -8
- esphome/core/log.h +9 -7
- esphome/cpp_generator.py +2 -2
- esphome/espota2.py +3 -2
- esphome/loader.py +12 -4
- esphome/log.py +5 -7
- esphome/yaml_util.py +2 -2
- {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/METADATA +12 -7
- {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/RECORD +338 -289
- esphome/components/custom/binary_sensor/custom_binary_sensor.cpp +0 -16
- esphome/components/custom/binary_sensor/custom_binary_sensor.h +0 -26
- esphome/components/custom/climate/custom_climate.h +0 -22
- esphome/components/custom/cover/custom_cover.h +0 -21
- esphome/components/custom/light/custom_light_output.h +0 -24
- esphome/components/custom/output/custom_output.h +0 -37
- esphome/components/custom/sensor/custom_sensor.cpp +0 -16
- esphome/components/custom/sensor/custom_sensor.h +0 -24
- esphome/components/custom/switch/custom_switch.cpp +0 -16
- esphome/components/custom/switch/custom_switch.h +0 -24
- esphome/components/custom/text_sensor/custom_text_sensor.cpp +0 -16
- esphome/components/custom/text_sensor/custom_text_sensor.h +0 -26
- esphome/components/custom_component/custom_component.h +0 -28
- esphome/components/esp32_ble_server/ble_2901.cpp +0 -18
- esphome/components/esp32_ble_server/ble_2901.h +0 -19
- esphome/components/resistance_sampler/__init__.py +0 -6
- esphome/components/resistance_sampler/resistance_sampler.h +0 -10
- esphome/components/uptime/{sensor.py → sensor/__init__.py} +3 -3
- /esphome/components/uptime/{uptime_seconds_sensor.cpp → sensor/uptime_seconds_sensor.cpp} +0 -0
- /esphome/components/uptime/{uptime_seconds_sensor.h → sensor/uptime_seconds_sensor.h} +0 -0
- /esphome/components/uptime/{uptime_timestamp_sensor.cpp → sensor/uptime_timestamp_sensor.cpp} +0 -0
- /esphome/components/uptime/{uptime_timestamp_sensor.h → sensor/uptime_timestamp_sensor.h} +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/LICENSE +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/WHEEL +0 -0
- {esphome-2024.12.3.dist-info → esphome-2025.2.0b1.dist-info}/entry_points.txt +0 -0
- {esphome-2024.12.3.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->
|
55
|
+
this->state_ = FAILED;
|
56
56
|
return;
|
57
57
|
}
|
58
|
-
this->
|
58
|
+
this->state_ = CREATING;
|
59
59
|
}
|
60
60
|
|
61
61
|
void BLEService::do_delete() {
|
62
|
-
if (this->
|
62
|
+
if (this->state_ == DELETING || this->state_ == DELETED)
|
63
63
|
return;
|
64
|
-
this->
|
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->
|
113
|
+
if (this->state_ == STOPPING || this->state_ == STOPPED)
|
111
114
|
return;
|
112
|
-
this->
|
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->
|
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->
|
132
|
-
return this->
|
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->
|
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->
|
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->
|
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->
|
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->
|
51
|
-
bool is_starting() { return this->
|
52
|
-
bool is_deleted() { return this->
|
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
|
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
|
-
|
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_ ==
|
187
|
-
ESP_LOGE(TAG, "ESP-IDF BLE scan could not restart after
|
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 ¶m) {
|
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 ¶m) {
|
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 ¶m) {
|
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 ¶m) {
|
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_
|
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 ¶m);
|
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,
|
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
|
|