1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 11:52:20 +01:00

Initial bluetooth_proxy support (#3736)

This commit is contained in:
Jesse Hills
2022-08-25 07:13:44 +12:00
committed by GitHub
parent 5dec9d88f6
commit b854e17995
16 changed files with 394 additions and 1 deletions

View File

@@ -7,6 +7,10 @@
#include "api_server.h"
#include "api_frame_helper.h"
#ifdef USE_BLUETOOTH_PROXY
#include "esphome/components/bluetooth_proxy/bluetooth_proxy.h"
#endif
namespace esphome {
namespace api {
@@ -94,6 +98,13 @@ class APIConnection : public APIServerConnection {
return;
this->send_homeassistant_service_response(call);
}
#ifdef USE_BLUETOOTH_PROXY
bool send_bluetooth_le_advertisement(const BluetoothLEAdvertisementResponse &call) {
if (!this->bluetooth_le_advertisement_subscription_)
return false;
return this->send_bluetooth_le_advertisement_response(call);
}
#endif
#ifdef USE_HOMEASSISTANT_TIME
void send_time_request() {
GetTimeRequest req;
@@ -134,6 +145,9 @@ class APIConnection : public APIServerConnection {
return {};
}
void execute_service(const ExecuteServiceRequest &msg) override;
void subscribe_bluetooth_le_advertisements(const SubscribeBluetoothLEAdvertisementsRequest &msg) override {
this->bluetooth_le_advertisement_subscription_ = true;
}
bool is_authenticated() override { return this->connection_state_ == ConnectionState::AUTHENTICATED; }
bool is_connection_setup() override {
return this->connection_state_ == ConnectionState ::CONNECTED || this->is_authenticated();
@@ -176,6 +190,7 @@ class APIConnection : public APIServerConnection {
uint32_t last_traffic_;
bool sent_ping_{false};
bool service_call_subscription_{false};
bool bluetooth_le_advertisement_subscription_{true};
bool next_close_ = false;
APIServer *parent_;
InitialStateIterator initial_state_iterator_;