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_METHOD,
CONF_TRIGGER_ID, CONF_TRIGGER_ID,
CONF_URL, CONF_URL,
CONF_ESP8266_DISABLE_SSL_SUPPORT,
) )
from esphome.core import CORE, Lambda from esphome.core import CORE, Lambda
@ -71,6 +72,9 @@ CONFIG_SCHEMA = cv.Schema(
cv.GenerateID(): cv.declare_id(HttpRequestComponent), cv.GenerateID(): cv.declare_id(HttpRequestComponent),
cv.Optional(CONF_USERAGENT, "ESPHome"): cv.string, cv.Optional(CONF_USERAGENT, "ESPHome"): cv.string,
cv.Optional(CONF_TIMEOUT, default="5s"): cv.positive_time_period_milliseconds, 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) ).extend(cv.COMPONENT_SCHEMA)
@ -98,6 +102,8 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_timeout(config[CONF_TIMEOUT])) cg.add(var.set_timeout(config[CONF_TIMEOUT]))
cg.add(var.set_useragent(config[CONF_USERAGENT])) 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) await cg.register_component(var, config)

View file

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

View file

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

View file

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

View file

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