Prepare for service utilities_group_refresh

This commit is contained in:
Edward Firmo
2024-03-26 09:37:04 +01:00
parent fe7eae4191
commit dd844d1d3c
3 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
// utilities.cpp
#include "utilities.h"
#include <cstdint>
#include <cstring>
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<uint8_t>(mid); // Found
}
}
return UINT8_MAX; // Not found
}
} // namespace nspanel_ha_blueprint

View File

@@ -0,0 +1,19 @@
// utilities.h
#pragma once
#include <cstdint>
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

View File

@@ -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: