1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-26 23:22:21 +01:00

Add trigger for http actions to receive the status code (#1599)

This commit is contained in:
Jesse Hills
2021-03-22 16:26:10 +13:00
committed by GitHub
parent 8f1eb77e05
commit af3273d930
4 changed files with 35 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ void HttpRequestComponent::set_url(std::string url) {
this->client_.setReuse(true);
}
void HttpRequestComponent::send() {
void HttpRequestComponent::send(const std::vector<HttpRequestResponseTrigger *> &response_triggers) {
bool begin_status = false;
const String url = this->url_.c_str();
#ifdef ARDUINO_ARCH_ESP32
@@ -54,6 +54,9 @@ void HttpRequestComponent::send() {
}
int http_code = this->client_.sendRequest(this->method_, this->body_.c_str());
for (auto *trigger : response_triggers)
trigger->process(http_code);
if (http_code < 0) {
ESP_LOGW(TAG, "HTTP Request failed; URL: %s; Error: %s", this->url_.c_str(),
HTTPClient::errorToString(http_code).c_str());