mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[esp32_hosted] Fire on_update_available trigger when update is detected (#18591)
This commit is contained in:
@@ -135,6 +135,10 @@ void Esp32HostedUpdate::setup() {
|
|||||||
// Publish state
|
// Publish state
|
||||||
this->status_clear_error();
|
this->status_clear_error();
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
|
// Defer so the automation runs on the main loop after setup, not during App.setup()
|
||||||
|
if (this->state_ == update::UPDATE_STATE_AVAILABLE && this->update_available_trigger_) {
|
||||||
|
this->defer([this]() { this->update_available_trigger_->trigger(this->update_info_); });
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// HTTP mode: check every 10s until network is ready (max 6 attempts)
|
// HTTP mode: check every 10s until network is ready (max 6 attempts)
|
||||||
// Only if update interval is > 1 minute to avoid redundant checks
|
// Only if update interval is > 1 minute to avoid redundant checks
|
||||||
@@ -185,6 +189,8 @@ void Esp32HostedUpdate::check() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool was_available = this->state_ == update::UPDATE_STATE_AVAILABLE;
|
||||||
|
|
||||||
// Compare versions
|
// Compare versions
|
||||||
if (this->update_info_.latest_version.empty() ||
|
if (this->update_info_.latest_version.empty() ||
|
||||||
this->update_info_.latest_version == this->update_info_.current_version) {
|
this->update_info_.latest_version == this->update_info_.current_version) {
|
||||||
@@ -197,6 +203,9 @@ void Esp32HostedUpdate::check() {
|
|||||||
this->update_info_.progress = 0.0f;
|
this->update_info_.progress = 0.0f;
|
||||||
this->status_clear_error();
|
this->status_clear_error();
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
|
if (this->state_ == update::UPDATE_STATE_AVAILABLE && !was_available && this->update_available_trigger_) {
|
||||||
|
this->update_available_trigger_->trigger(this->update_info_);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,6 @@ update:
|
|||||||
type: embedded
|
type: embedded
|
||||||
path: $component_dir/test_firmware.bin
|
path: $component_dir/test_firmware.bin
|
||||||
sha256: de2f256064a0af797747c2b97505dc0b9f3df0de4f489eac731c23ae9ca9cc31
|
sha256: de2f256064a0af797747c2b97505dc0b9f3df0de4f489eac731c23ae9ca9cc31
|
||||||
|
on_update_available:
|
||||||
|
then:
|
||||||
|
- logger.log: "Coprocessor update available"
|
||||||
|
|||||||
@@ -8,3 +8,6 @@ update:
|
|||||||
type: http
|
type: http
|
||||||
source: https://esphome.github.io/esp-hosted-firmware/manifest/esp32c6.json
|
source: https://esphome.github.io/esp-hosted-firmware/manifest/esp32c6.json
|
||||||
update_interval: 6h
|
update_interval: 6h
|
||||||
|
on_update_available:
|
||||||
|
then:
|
||||||
|
- logger.log: "Coprocessor update available"
|
||||||
|
|||||||
Reference in New Issue
Block a user