Changed deleteAccessory from int to boolean

Returns true on success, otherwise false
This commit is contained in:
Gregg 2022-05-22 13:13:34 -05:00
parent 6018f37b60
commit f75596f3cd
3 changed files with 14 additions and 12 deletions

View File

@ -123,17 +123,19 @@ void deleteAccessory(const char *buf){
return; return;
} }
if(homeSpan.deleteAccessory(n+1)!=0){ if(homeSpan.deleteAccessory(n+1)){
Serial.printf("Deleting Accessory: Light-%d\n",n);
auto it=std::remove(lights.begin(),lights.end(),n); // remove entry from lights array
*it=0; // overwrite end with a 0
nvs_set_blob(savedData,"LIGHTS",&lights,sizeof(lights)); // update data
nvs_commit(savedData);
} else {
Serial.printf("No such Accessory: Light-%d\n",n); Serial.printf("No such Accessory: Light-%d\n",n);
return;
} }
Serial.printf("Deleting Accessory: Light-%d\n",n);
auto it=std::remove(lights.begin(),lights.end(),n);
*it=0; // overwrite end with a 0
nvs_set_blob(savedData,"LIGHTS",&lights,sizeof(lights)); // update data
nvs_commit(savedData);
} }
/////////////////////////// ///////////////////////////

View File

@ -1170,16 +1170,16 @@ void Span::prettyPrint(char *buf, int nsp){
/////////////////////////// ///////////////////////////
int Span::deleteAccessory(uint32_t n){ boolean Span::deleteAccessory(uint32_t n){
auto it=homeSpan.Accessories.begin(); auto it=homeSpan.Accessories.begin();
for(;it!=homeSpan.Accessories.end() && (*it)->aid!=n; it++); for(;it!=homeSpan.Accessories.end() && (*it)->aid!=n; it++);
if(it==homeSpan.Accessories.end()) if(it==homeSpan.Accessories.end())
return(-1); return(false);
delete *it; delete *it;
return(0); return(true);
} }
/////////////////////////////// ///////////////////////////////

View File

@ -215,13 +215,13 @@ struct Span{
void commandMode(); // allows user to control and reset HomeSpan settings with the control button void commandMode(); // allows user to control and reset HomeSpan settings with the control button
void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c') void processSerialCommand(const char *c); // process command 'c' (typically from readSerial, though can be called with any 'c')
boolean updateDatabase(boolean updateMDNS=true); // updates HAP Configuration Number and Loop vector; iF updateMDNS=true and config number has changed, re-broadcasts MDNS 'c#' record; returns true if config number changed boolean updateDatabase(boolean updateMDNS=true); // updates HAP Configuration Number and Loop vector; if updateMDNS=true and config number has changed, re-broadcasts MDNS 'c#' record; returns true if config number changed
int sprintfAttributes(char *cBuf, int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator int sprintfAttributes(char *cBuf, int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
SpanCharacteristic *find(uint32_t aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found) SpanCharacteristic *find(uint32_t aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found)
int deleteAccessory(uint32_t aid); // deletes Accessory with matching aid, if found. Returns 0 on success, -1 on fail (aid not found) boolean deleteAccessory(uint32_t aid); // deletes Accessory with matching aid; returns true if found, else returns false
int countCharacteristics(char *buf); // return number of characteristic objects referenced in PUT /characteristics JSON request int countCharacteristics(char *buf); // return number of characteristic objects referenced in PUT /characteristics JSON request
int updateCharacteristics(char *buf, SpanBuf *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail int updateCharacteristics(char *buf, SpanBuf *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail