diff --git a/esphome/components/ota/ota_backend.h b/esphome/components/ota/ota_backend.h index 7348a0ce90..ed2718f980 100644 --- a/esphome/components/ota/ota_backend.h +++ b/esphome/components/ota/ota_backend.h @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef USE_OTA_STATE_LISTENER #include @@ -102,6 +103,9 @@ enum OTAType : uint8_t { // - set_update_md5: expected digest of the incoming image, hex string. // - write: consume the next chunk; end: finalize and mark bootable. // - abort: safe to call in any state, including after end(). +// - supports_compression: static constexpr, whether a gzip image can be stored +// as is and inflated at reboot; the esphome platform asserts it at compile +// time when it builds its own inflater. template concept OTABackendContract = requires(T backend, size_t image_size, uint8_t *data, size_t len, const char *md5) { { backend.begin(image_size, OTA_TYPE_UPDATE_APP) } -> std::same_as; @@ -110,7 +114,8 @@ concept OTABackendContract = requires(T backend, size_t image_size, uint8_t *dat { backend.write(data, len) } -> std::same_as; { backend.end() } -> std::same_as; backend.abort(); - { backend.supports_compression() } -> std::same_as; + { T::supports_compression() } -> std::same_as; + requires std::bool_constant::value || true; }; /** Listener interface for OTA state changes. diff --git a/tests/components/ota/test_backend_contract.cpp b/tests/components/ota/test_backend_contract.cpp index 1b4fbbc32d..36b7a793c3 100644 --- a/tests/components/ota/test_backend_contract.cpp +++ b/tests/components/ota/test_backend_contract.cpp @@ -14,7 +14,7 @@ struct MinimalBackend { OTAResponseTypes write(uint8_t *data, size_t len) { return OTA_RESPONSE_OK; } OTAResponseTypes end() { return OTA_RESPONSE_OK; } void abort() {} - bool supports_compression() { return false; } + static constexpr bool supports_compression() { return false; } }; static_assert(OTABackendContract);