[online_image] Allow suppressing update on url change (#8885)

This commit is contained in:
Gustavo Ambrozio 2025-06-23 00:40:07 -10:00 committed by GitHub
parent 1a47164876
commit 2ad266582f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -34,6 +34,7 @@ MULTI_CONF = True
CONF_ON_DOWNLOAD_FINISHED = "on_download_finished"
CONF_PLACEHOLDER = "placeholder"
CONF_UPDATE = "update"
_LOGGER = logging.getLogger(__name__)
@ -167,6 +168,7 @@ SET_URL_SCHEMA = cv.Schema(
{
cv.GenerateID(): cv.use_id(OnlineImage),
cv.Required(CONF_URL): cv.templatable(cv.url),
cv.Optional(CONF_UPDATE, default=True): cv.templatable(bool),
}
)
@ -188,6 +190,9 @@ async def online_image_action_to_code(config, action_id, template_arg, args):
if CONF_URL in config:
template_ = await cg.templatable(config[CONF_URL], args, cg.std_string)
cg.add(var.set_url(template_))
if CONF_UPDATE in config:
template_ = await cg.templatable(config[CONF_UPDATE], args, bool)
cg.add(var.set_update(template_))
return var

View File

@ -201,9 +201,12 @@ template<typename... Ts> class OnlineImageSetUrlAction : public Action<Ts...> {
public:
OnlineImageSetUrlAction(OnlineImage *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(std::string, url)
TEMPLATABLE_VALUE(bool, update)
void play(Ts... x) override {
this->parent_->set_url(this->url_.value(x...));
this->parent_->update();
if (this->update_.value(x...)) {
this->parent_->update();
}
}
protected: