1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 22:53:59 +00:00

Allow ble tracker to subscribe to ota start and stop the scanning (#3800)

This commit is contained in:
Jesse Hills
2022-09-14 16:49:20 +12:00
committed by GitHub
parent a5e3cd1a42
commit f4b0917239
6 changed files with 36 additions and 12 deletions

View File

@@ -78,6 +78,7 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_port(config[CONF_PORT]))
cg.add_define("USE_OTA")
if CONF_PASSWORD in config:
cg.add(var.set_auth_password(config[CONF_PASSWORD]))
cg.add_define("USE_OTA_PASSWORD")

View File

@@ -21,6 +21,8 @@ static const char *const TAG = "ota";
static const uint8_t OTA_VERSION_1_0 = 1;
OTAComponent *global_ota_component = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
std::unique_ptr<OTABackend> make_ota_backend() {
#ifdef USE_ARDUINO
#ifdef USE_ESP8266
@@ -35,6 +37,8 @@ std::unique_ptr<OTABackend> make_ota_backend() {
#endif // USE_ESP_IDF
}
OTAComponent::OTAComponent() { global_ota_component = this; }
void OTAComponent::setup() {
server_ = socket::socket_ip(SOCK_STREAM, 0);
if (server_ == nullptr) {

View File

@@ -41,6 +41,7 @@ enum OTAState { OTA_COMPLETED = 0, OTA_STARTED, OTA_IN_PROGRESS, OTA_ERROR };
/// OTAComponent provides a simple way to integrate Over-the-Air updates into your app using ArduinoOTA.
class OTAComponent : public Component {
public:
OTAComponent();
#ifdef USE_OTA_PASSWORD
void set_auth_password(const std::string &password) { password_ = password; }
#endif // USE_OTA_PASSWORD
@@ -103,5 +104,7 @@ class OTAComponent : public Component {
#endif
};
extern OTAComponent *global_ota_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace ota
} // namespace esphome