diff --git a/esphome/components/online_image/online_image.cpp b/esphome/components/online_image/online_image.cpp index 797ae4dc9e..5caf5deb63 100644 --- a/esphome/components/online_image/online_image.cpp +++ b/esphome/components/online_image/online_image.cpp @@ -104,10 +104,12 @@ void OnlineImage::update() { } std::list headers; - for (const auto &[key, value_template] : this->headers_) { - auto val = value_template(); - if (val.has_value()) { - headers.push_back(http_request::Header{key, *val}); + for (const auto &item : this->headers_) { + auto header_name = item.first; + auto header_value_template = item.second; + auto header_value = header_value_template(); + if (header_value.has_value()) { + headers.push_back(http_request::Header{header_name, *header_value}); } }