diff --git a/components/nspanel_ha_blueprint/utilities.cpp b/components/nspanel_ha_blueprint/utilities.cpp new file mode 100644 index 0000000..7851a2e --- /dev/null +++ b/components/nspanel_ha_blueprint/utilities.cpp @@ -0,0 +1,40 @@ +// utilities.cpp +#include "utilities.h" +#include +#include + +namespace nspanel_ha_blueprint { + + // Definition and initialization of the global variable + UtilitiesGroupValues UtilitiesGroups[8] = { + { "grid", "\0", "\0", 0 }, + { "group01", "\0", "\0", 0 }, + { "group02", "\0", "\0", 0 }, + { "group03", "\0", "\0", 0 }, + { "group04", "\0", "\0", 0 }, + { "group05", "\0", "\0", 0 }, + { "group06", "\0", "\0", 0 }, + { "home", "\0", "\0", 0 } + }; + + uint8_t findUtilitiesGroupIndex(const char* group_id) { + int low = 0; + int high = sizeof(UtilitiesGroups) / sizeof(UtilitiesGroups[0]) - 1; + + while (low <= high) { + int mid = low + (high - low) / 2; + int cmp = strcmp(UtilitiesGroups[mid].group_id, group_id); + + if (cmp < 0) { + low = mid + 1; + } else if (cmp > 0) { + high = mid - 1; + } else { + return static_cast(mid); // Found + } + } + + return UINT8_MAX; // Not found + } + +} // namespace nspanel_ha_blueprint diff --git a/components/nspanel_ha_blueprint/utilities.h b/components/nspanel_ha_blueprint/utilities.h new file mode 100644 index 0000000..176fdba --- /dev/null +++ b/components/nspanel_ha_blueprint/utilities.h @@ -0,0 +1,19 @@ +// utilities.h +#pragma once + +#include + +namespace nspanel_ha_blueprint { + + struct UtilitiesGroupValues { + char group_id[8]; // 7 characters + null terminator + char value1[11]; // 10 characters + null terminator + char value2[11]; // 11 characters + null terminator + int8_t direction; + }; + + extern UtilitiesGroupValues UtilitiesGroups[8]; + + uint8_t findUtilitiesGroupIndex(const char* group_id); + +} // namespace nspanel_ha_blueprint diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 72c7f4a..285c935 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -775,6 +775,16 @@ api: then: - lambda: if (!id(is_uploading_tft)) buzzer->play(tone); + # Utilities group refresh + - service: utilities_group_refresh + variables: + group_id: string + value1: string + value2: string + direction: int + then: + # Do nothing for now + # Updates an entity to display specific values with dynamic icons, names, and color codes. - service: value variables: