Add esp8266_disable_ssl_support: config option (#2236)

This commit is contained in:
Kamil Trzciński 2021-09-19 18:46:17 +02:00 committed by GitHub
parent f76685fccf
commit 30eca885c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from esphome.const import (
CONF_METHOD,
CONF_TRIGGER_ID,
CONF_URL,
CONF_ESP8266_DISABLE_SSL_SUPPORT,
)
from esphome.core import CORE, Lambda
@ -71,6 +72,9 @@ CONFIG_SCHEMA = cv.Schema(
cv.GenerateID(): cv.declare_id(HttpRequestComponent),
cv.Optional(CONF_USERAGENT, "ESPHome"): cv.string,
cv.Optional(CONF_TIMEOUT, default="5s"): cv.positive_time_period_milliseconds,
cv.SplitDefault(CONF_ESP8266_DISABLE_SSL_SUPPORT, esp8266=False): cv.All(
cv.only_on_esp8266, cv.boolean
),
}
).extend(cv.COMPONENT_SCHEMA)
@ -98,6 +102,8 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_timeout(config[CONF_TIMEOUT]))
cg.add(var.set_useragent(config[CONF_USERAGENT]))
if CORE.is_esp8266 and not config[CONF_ESP8266_DISABLE_SSL_SUPPORT]:
cg.add_define("USE_HTTP_REQUEST_ESP8266_HTTPS")
await cg.register_component(var, config)

View File

@ -81,6 +81,7 @@ void HttpRequestComponent::send(const std::vector<HttpRequestResponseTrigger *>
#ifdef ARDUINO_ARCH_ESP8266
std::shared_ptr<WiFiClient> HttpRequestComponent::get_wifi_client_() {
#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS
if (this->secure_) {
if (this->wifi_client_secure_ == nullptr) {
this->wifi_client_secure_ = std::make_shared<BearSSL::WiFiClientSecure>();
@ -89,6 +90,7 @@ std::shared_ptr<WiFiClient> HttpRequestComponent::get_wifi_client_() {
}
return this->wifi_client_secure_;
}
#endif
if (this->wifi_client_ == nullptr) {
this->wifi_client_ = std::make_shared<WiFiClient>();

View File

@ -3,6 +3,7 @@
#include "esphome/components/json/json_util.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include <list>
#include <map>
#include <utility>
@ -13,8 +14,10 @@
#endif
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266HTTPClient.h>
#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS
#include <WiFiClientSecure.h>
#endif
#endif
namespace esphome {
namespace http_request {
@ -53,7 +56,9 @@ class HttpRequestComponent : public Component {
std::list<Header> headers_;
#ifdef ARDUINO_ARCH_ESP8266
std::shared_ptr<WiFiClient> wifi_client_;
#ifdef USE_HTTP_REQUEST_ESP8266_HTTPS
std::shared_ptr<BearSSL::WiFiClientSecure> wifi_client_secure_;
#endif
std::shared_ptr<WiFiClient> get_wifi_client_();
#endif
};

View File

@ -208,6 +208,7 @@ CONF_ENABLE_PIN = "enable_pin"
CONF_ENABLE_TIME = "enable_time"
CONF_ENERGY = "energy"
CONF_ENTITY_ID = "entity_id"
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
CONF_ESP8266_RESTORE_FROM_FLASH = "esp8266_restore_from_flash"
CONF_ESPHOME = "esphome"
CONF_ETHERNET = "ethernet"

View File

@ -20,6 +20,7 @@
#define USE_ESP8266_PREFERENCES_FLASH
#define USE_FAN
#define USE_HOMEASSISTANT_TIME
#define USE_HTTP_REQUEST_ESP8266_HTTPS
#define USE_I2C_MULTIPLEXER
#define USE_JSON
#define USE_LIGHT