From 3cc14c3a8d6de2924d2cee371b8ee1a5d23b3dd3 Mon Sep 17 00:00:00 2001 From: Gregg Date: Thu, 23 Dec 2021 15:37:26 -0600 Subject: [PATCH] Addressed automation issue by extending true/false parsing Added true/false parsing to all integer-based Characteristics. Previously true/false was only parsed for BOOL Characteristics. For integer-based on/off Characteristics, the Home App would send a 0 for off, and a 1 for on, consistent with HAP-R2. BUT...when using Home App AUTOMATIONS, the Home App would send true/false for integer-based Characteristics, which is inconsistent with HAP-R2. This meant automations worked with lights (that use the boolean ON Characteristic) but not with fans (that use the uint8 ACTIVE Characteristic). With this "fix", true/false will be recognized all the time (except for float- and string-based Characteristics. Confirmed that fans now work with Home App Automations. --- src/HomeSpan.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/HomeSpan.cpp b/src/HomeSpan.cpp index f3af167..9a0991f 100644 --- a/src/HomeSpan.cpp +++ b/src/HomeSpan.cpp @@ -1722,27 +1722,47 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev){ break; case INT: - if(!sscanf(val,"%d",&newValue.INT)) + if(!strcmp(val,"false")) + newValue.INT=0; + else if(!strcmp(val,"true")) + newValue.INT=1; + else if(!sscanf(val,"%d",&newValue.INT)) return(StatusCode::InvalidValue); break; case UINT8: - if(!sscanf(val,"%hhu",&newValue.UINT8)) + if(!strcmp(val,"false")) + newValue.UINT8=0; + else if(!strcmp(val,"true")) + newValue.UINT8=1; + else if(!sscanf(val,"%hhu",&newValue.UINT8)) return(StatusCode::InvalidValue); break; case UINT16: - if(!sscanf(val,"%hu",&newValue.UINT16)) + if(!strcmp(val,"false")) + newValue.UINT16=0; + else if(!strcmp(val,"true")) + newValue.UINT16=1; + else if(!sscanf(val,"%hu",&newValue.UINT16)) return(StatusCode::InvalidValue); break; case UINT32: - if(!sscanf(val,"%u",&newValue.UINT32)) + if(!strcmp(val,"false")) + newValue.UINT32=0; + else if(!strcmp(val,"true")) + newValue.UINT32=1; + else if(!sscanf(val,"%u",&newValue.UINT32)) return(StatusCode::InvalidValue); break; case UINT64: - if(!sscanf(val,"%llu",&newValue.UINT64)) + if(!strcmp(val,"false")) + newValue.UINT64=0; + else if(!strcmp(val,"true")) + newValue.UINT64=1; + else if(!sscanf(val,"%llu",&newValue.UINT64)) return(StatusCode::InvalidValue); break;