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.
This commit is contained in:
Gregg 2021-11-07 20:45:44 -06:00
parent 835d49adc5
commit 6f765e8988
1 changed files with 13 additions and 11 deletions

View File

@ -534,7 +534,7 @@ struct SpanCharacteristic{
} // setString()
template <typename T> void setVal(T val){
template <typename T> 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);
@ -551,16 +551,18 @@ struct SpanCharacteristic{
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(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);
if(nvsKey){
nvs_set_blob(homeSpan.charNVS,nvsKey,&value,sizeof(UVal)); // store data
nvs_commit(homeSpan.charNVS);
}
}
} // setVal()