1
0
mirror of https://github.com/esphome/esphome.git synced 2025-08-24 06:52:19 +01:00
Files
.devcontainer
.github
.vscode
docker
esphome
components
a4988
ac_dimmer
adalight
adc
adc128s102
addressable_light
ade7953
ads1115
aht10
airthings_ble
airthings_wave_mini
airthings_wave_plus
am2320
am43
analog_threshold
animation
anova
apds9960
api
as3935
as3935_i2c
as3935_spi
async_tcp
atc_mithermometer
atm90e32
b_parasite
ballu
bang_bang
bedjet
bh1750
binary
binary_sensor
binary_sensor_map
bl0939
bl0940
bl0942
ble_client
ble_presence
ble_rssi
ble_scanner
bluetooth_proxy
__init__.py
bluetooth_connection.cpp
bluetooth_connection.h
bluetooth_proxy.cpp
bluetooth_proxy.h
bme280
bme680
bme680_bsec
bmp085
bmp280
bmp3xx
button
canbus
cap1188
captive_portal
ccs811
cd74hc4067
climate
climate_ir
climate_ir_lg
color
color_temperature
coolix
copy
cover
cs5460a
cse7761
cse7766
ct_clamp
current_based
custom
custom_component
cwww
dac7678
daikin
daikin_brc
dallas
daly_bms
dashboard_import
debug
deep_sleep
delonghi
demo
dfplayer
dht
dht12
display
display_menu_base
dps310
ds1307
dsmr
duty_cycle
e131
ektf2232
endstop
ens210
esp32
esp32_ble
esp32_ble_beacon
esp32_ble_client
esp32_ble_server
esp32_ble_tracker
esp32_camera
esp32_camera_web_server
esp32_can
esp32_dac
esp32_hall
esp32_improv
esp32_touch
esp8266
esp8266_pwm
ethernet
ethernet_info
exposure_notifications
external_components
ezo
ezo_pmp
factory_reset
fan
fastled_base
fastled_clockless
fastled_spi
feedback
fingerprint_grow
font
fujitsu_general
globals
gpio
gps
graph
growatt_solar
havells_solar
hbridge
hdc1080
heatpumpir
hitachi_ac344
hitachi_ac424
hlw8012
hm3301
hmc5883l
homeassistant
honeywellabp
hrxl_maxsonar_wr
http_request
htu21d
hx711
hydreon_rgxx
i2c
i2s_audio
ili9341
image
improv_serial
ina219
ina226
ina260
ina3221
inkbird_ibsth1_mini
inkplate6
integration
interval
json
kalman_combinator
lcd_base
lcd_gpio
lcd_menu
lcd_pcf8574
ledc
light
lilygo_t5_47
lock
logger
ltr390
max31855
max31856
max31865
max44009
max6675
max7219
max7219digit
max9611
mcp23008
mcp23016
mcp23017
mcp23s08
mcp23s17
mcp23x08_base
mcp23x17_base
mcp23xxx_base
mcp2515
mcp3008
mcp3204
mcp4725
mcp4728
mcp47a1
mcp9600
mcp9808
md5
mdns
media_player
mhz19
midea
midea_ac
midea_ir
mitsubishi
mlx90393
modbus
modbus_controller
monochromatic
mopeka_ble
mopeka_pro_check
mpl3115a2
mpr121
mpu6050
mpu6886
mqtt
mqtt_subscribe
ms5611
my9231
neopixelbus
network
nextion
nfc
ntc
number
ota
output
packages
partition
pca9685
pcd8544
pcf8574
pid
pipsolar
pm1006
pmsa003i
pmsx003
pn532
pn532_i2c
pn532_spi
power_supply
preferences
prometheus
psram
pulse_counter
pulse_meter
pulse_width
pvvx_mithermometer
pzem004t
pzemac
pzemdc
qmc5883l
qmp6988
qr_code
radon_eye_ble
radon_eye_rd200
rc522
rc522_i2c
rc522_spi
rdm6300
remote_base
remote_receiver
remote_transmitter
resistance
restart
rf_bridge
rgb
rgbct
rgbw
rgbww
rotary_encoder
rp2040
rp2040_pwm
rtttl
ruuvi_ble
ruuvitag
safe_mode
scd30
scd4x
script
sdm_meter
sdp3x
sds011
selec_meter
select
sen5x
senseair
sensirion_common
sensor
servo
sgp30
sgp40
sgp4x
shelly_dimmer
sht3xd
sht4x
shtcx
shutdown
sim800l
slow_pwm
sm16716
sm2135
sm300d2
sml
smt100
sn74hc595
sntp
socket
sonoff_d1
speed
spi
sprinkler
sps30
ssd1306_base
ssd1306_i2c
ssd1306_spi
ssd1322_base
ssd1322_spi
ssd1325_base
ssd1325_spi
ssd1327_base
ssd1327_i2c
ssd1327_spi
ssd1331_base
ssd1331_spi
ssd1351_base
ssd1351_spi
st7735
st7789v
st7920
status
status_led
stepper
sts3x
substitutions
sun
switch
sx1509
t6615
tca9548a
tcl112
tcs34725
teleinfo
template
text_sensor
thermostat
time
time_based
tlc59208f
tlc5947
tm1621
tm1637
tm1638
tm1651
tmp102
tmp117
tof10120
toshiba
total_daily_energy
touchscreen
tsl2561
tsl2591
ttp229_bsf
ttp229_lsf
tuya
tx20
uart
ufire_ec
ufire_ise
uln2003
ultrasonic
uptime
version
vl53l0x
voltage_sampler
wake_on_lan
waveshare_epaper
web_server
web_server_base
whirlpool
whynter
wifi
wifi_info
wifi_signal
wl_134
wled
xiaomi_ble
xiaomi_cgd1
xiaomi_cgdk2
xiaomi_cgg1
xiaomi_cgpr1
xiaomi_gcls002
xiaomi_hhccjcy01
xiaomi_hhccpot002
xiaomi_jqjcy01ym
xiaomi_lywsd02
xiaomi_lywsd03mmc
xiaomi_lywsdcgq
xiaomi_mhoc303
xiaomi_mhoc401
xiaomi_miscale
xiaomi_miscale2
xiaomi_mjyd02yla
xiaomi_mue4094rt
xiaomi_rtcgq02lm
xiaomi_wx08zm
xpt2046
yashima
zyaura
__init__.py
core
dashboard
__init__.py
__main__.py
automation.py
codegen.py
config.py
config_helpers.py
config_validation.py
const.py
coroutine.py
cpp_generator.py
cpp_helpers.py
cpp_types.py
espota2.py
final_validate.py
git.py
helpers.py
loader.py
log.py
mqtt.py
pins.py
platformio_api.py
schema_extractors.py
storage_json.py
types.py
util.py
voluptuous_schema.py
vscode.py
wizard.py
writer.py
yaml_util.py
zeroconf.py
script
tests
.clang-format
.clang-tidy
.coveragerc
.dockerignore
.editorconfig
.gitattributes
.gitignore
.pre-commit-config.yaml
.yamllint
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
MANIFEST.in
README.md
platformio.ini
pylintrc
pyproject.toml
pytest.ini
requirements.txt
requirements_optional.txt
requirements_test.txt
sdkconfig.defaults
setup.cfg
setup.py
esphome/esphome/components/bluetooth_proxy/bluetooth_proxy.h
2022-11-02 23:02:33 +13:00

74 lines
2.2 KiB
C++

#pragma once
#ifdef USE_ESP32
#include <map>
#include "esphome/components/api/api_pb2.h"
#include "esphome/components/esp32_ble_client/ble_client_base.h"
#include "esphome/components/esp32_ble_tracker/esp32_ble_tracker.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "bluetooth_connection.h"
namespace esphome {
namespace bluetooth_proxy {
static const esp_err_t ESP_GATT_NOT_CONNECTED = -1;
using namespace esp32_ble_client;
class BluetoothProxy : public esp32_ble_tracker::ESPBTDeviceListener, public Component {
public:
BluetoothProxy();
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
void dump_config() override;
void loop() override;
void register_connection(BluetoothConnection *connection) {
this->connections_.push_back(connection);
connection->proxy_ = this;
}
void bluetooth_device_request(const api::BluetoothDeviceRequest &msg);
void bluetooth_gatt_read(const api::BluetoothGATTReadRequest &msg);
void bluetooth_gatt_write(const api::BluetoothGATTWriteRequest &msg);
void bluetooth_gatt_read_descriptor(const api::BluetoothGATTReadDescriptorRequest &msg);
void bluetooth_gatt_write_descriptor(const api::BluetoothGATTWriteDescriptorRequest &msg);
void bluetooth_gatt_send_services(const api::BluetoothGATTGetServicesRequest &msg);
void bluetooth_gatt_notify(const api::BluetoothGATTNotifyRequest &msg);
int get_bluetooth_connections_free() {
int free = 0;
for (auto *connection : this->connections_) {
if (connection->address_ == 0) {
free++;
}
}
return free;
}
int get_bluetooth_connections_limit() { return this->connections_.size(); }
void set_active(bool active) { this->active_ = active; }
bool has_active() { return this->active_; }
protected:
void send_api_packet_(const esp32_ble_tracker::ESPBTDevice &device);
BluetoothConnection *get_connection_(uint64_t address, bool reserve);
int16_t send_service_{-1};
bool active_;
std::vector<BluetoothConnection *> connections_{};
};
extern BluetoothProxy *global_bluetooth_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace bluetooth_proxy
} // namespace esphome
#endif // USE_ESP32