From 1065fe05687a8c1e242a1f58fd0fcfca144cc4e7 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:54:48 +0200 Subject: [PATCH] Ignore different patch versions Change the versioning control to major and minor only, ignoring differences on the patch version. So components with different patch versions should be able to work with each other as soon the major and minor versions are the same. This same logic was implemented on the blueprint before the 4.0 release. --- nspanel_esphome.yaml | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 79522bc..703d34d 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -8,7 +8,7 @@ substitutions: ##### DON'T CHANGE THIS ##### - version: "4.0" + version: "4.0.1dev" ############################# ##### WIFI SETUP ##### @@ -2202,15 +2202,37 @@ script: then: - wait_until: condition: - - lambda: !lambda 'return (id(version_tft) == "${version}");' - - lambda: !lambda 'return (id(version_blueprint) == "${version}");' + - lambda: |- + auto compareVersions = [](const char* version1, const char* version2) -> bool + { + int major1 = 0, minor1 = 0; + int major2 = 0, minor2 = 0; + + sscanf(version1, "%d.%d", &major1, &minor1); + sscanf(version2, "%d.%d", &major2, &minor2); + + return (major1 == major2) && (minor1 == minor2); + }; + return (compareVersions("${version}", id(version_tft).c_str()) and compareVersions("${version}", id(version_blueprint).c_str())); + #- lambda: !lambda 'return (id(version_tft) == "${version}");' + #- lambda: !lambda 'return (id(version_blueprint) == "${version}");' timeout: 60s - lambda: |- + auto compareVersions = [](const char* version1, const char* version2) -> bool + { + int major1 = 0, minor1 = 0; + int major2 = 0, minor2 = 0; + + sscanf(version1, "%d.%d", &major1, &minor1); + sscanf(version2, "%d.%d", &major2, &minor2); + + return (major1 == major2) && (minor1 == minor2); + }; ESP_LOGD("script.check_versions", "ESPHome version: ${version}"); ESP_LOGD("script.check_versions", "TFT version: %s", id(version_tft).c_str()); - if (id(version_tft) != "${version}") ESP_LOGE("script.check_versions", "TFT version mismatch!"); + if (not compareVersions("${version}", id(version_tft).c_str())) ESP_LOGE("script.check_versions", "TFT version mismatch!"); ESP_LOGD("script.check_versions", "Blueprint version: %s", id(version_blueprint).c_str()); - if (id(version_blueprint) != "${version}") ESP_LOGE("script.check_versions", "Blueprint version mismatch!"); + if (not compareVersions("${version}", id(version_blueprint).c_str())) ESP_LOGE("script.check_versions", "Blueprint version mismatch!"); auto ha_event = new esphome::api::CustomAPIDevice(); ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint", {