From 6f765e89886544b3a20f02451b7a1068995b6359 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 7 Nov 2021 20:45:44 -0600 Subject: [PATCH] Added non-notify option to setVal() Second optional argument to setVal() determines whether or not HomeSpan sends notification of new value to HomeKit. Default if left blank is "true" for backwards compatibility. --- src/HomeSpan.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 299c0b8..fed75c0 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -534,7 +534,7 @@ struct SpanCharacteristic{ } // setString() - template void setVal(T val){ + template void setVal(T val, boolean notify=true){ if((perms & EV) == 0){ Serial.printf("\n*** WARNING: Attempt to update Characteristic::%s with setVal() ignored. No NOTIFICATION permission on this characteristic\n\n",hapName); @@ -550,17 +550,19 @@ struct SpanCharacteristic{ uvSet(newValue,value); updateTime=homeSpan.snapTime; - - SpanBuf sb; // create SpanBuf object - sb.characteristic=this; // set characteristic - sb.status=StatusCode::OK; // set status - char dummy[]=""; - sb.val=dummy; // set dummy "val" so that sprintfNotify knows to consider this "update" - homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector - if(nvsKey){ - nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data - nvs_commit(homeSpan.charNVS); + if(notify){ + SpanBuf sb; // create SpanBuf object + sb.characteristic=this; // set characteristic + sb.status=StatusCode::OK; // set status + char dummy[]=""; + sb.val=dummy; // set dummy "val" so that sprintfNotify knows to consider this "update" + homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector + + if(nvsKey){ + nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data + nvs_commit(homeSpan.charNVS); + } } } // setVal()