online_image: nicer code style for http_request_headers

This commit is contained in:
Kjell Braden 2024-11-14 11:03:33 +01:00
parent 01c1894849
commit dad61299b8
3 changed files with 8 additions and 7 deletions

View file

@ -160,7 +160,9 @@ async def to_code(config):
for key in config.get(CONF_HTTP_REQUEST_HEADERS, []): for key in config.get(CONF_HTTP_REQUEST_HEADERS, []):
template_ = await cg.templatable( template_ = await cg.templatable(
config[CONF_HTTP_REQUEST_HEADERS][key], [], cg.optional.template(cg.const_char_ptr) config[CONF_HTTP_REQUEST_HEADERS][key],
[],
cg.optional.template(cg.const_char_ptr),
) )
cg.add(var.add_header(key, template_)) cg.add(var.add_header(key, template_))

View file

@ -103,12 +103,11 @@ void OnlineImage::update() {
ESP_LOGI(TAG, "Updating image"); ESP_LOGI(TAG, "Updating image");
} }
std::list<http_request::Header> headers; std::list<http_request::Header> headers;
for (const auto &item : this->headers_) { for (const auto &[key, value_template] : this->headers_) {
auto val = item.second(); auto val = value_template();
if (val.has_value()) { if (val.has_value()) {
headers.push_back(http_request::Header{item.first, *val}); headers.push_back(http_request::Header{key, *val});
} }
} }