sort Accessories by AID to ensure same order all the time during dynamic changes

This commit is contained in:
HomeSpan 2022-05-18 16:31:15 -05:00
parent f471e7377b
commit 2e98b163b2
2 changed files with 4 additions and 0 deletions

View File

@ -34,6 +34,7 @@
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include <esp_sntp.h> #include <esp_sntp.h>
#include <esp_ota_ops.h> #include <esp_ota_ops.h>
#include <algorithm>
#include "HomeSpan.h" #include "HomeSpan.h"
#include "HAP.h" #include "HAP.h"
@ -1471,6 +1472,8 @@ int Span::sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf){
boolean Span::updateDatabase(boolean updateMDNS){ boolean Span::updateDatabase(boolean updateMDNS){
std::sort(Accessories.begin(),Accessories.end(),SpanAccessory::compare);
uint8_t tHash[48]; uint8_t tHash[48];
TempBuffer <char> tBuf(sprintfAttributes(NULL,GET_META|GET_PERMS|GET_TYPE|GET_DESC)+1); TempBuffer <char> tBuf(sprintfAttributes(NULL,GET_META|GET_PERMS|GET_TYPE|GET_DESC)+1);
sprintfAttributes(tBuf.buf,GET_META|GET_PERMS|GET_TYPE|GET_DESC); sprintfAttributes(tBuf.buf,GET_META|GET_PERMS|GET_TYPE|GET_DESC);

View File

@ -288,6 +288,7 @@ struct SpanAccessory{
~SpanAccessory(); ~SpanAccessory();
int sprintfAttributes(char *cBuf, int flags); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL int sprintfAttributes(char *cBuf, int flags); // prints Accessory JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
static boolean compare(SpanAccessory *a, SpanAccessory *b){return(a->aid<b->aid);}
}; };
/////////////////////////////// ///////////////////////////////