Added check to ensure Custom Characteristic has valid UUID

And also converted ERRORS to WARNINGS when a Characteristic that is not in the REQ or OPT list is specified for a Service.   This allows the user to add any Characteristic to any Service without forcing an Error (just a Warning).
This commit is contained in:
Gregg 2021-10-29 22:54:10 -05:00
parent 61a2be533b
commit 226548defa
3 changed files with 12 additions and 9 deletions

View File

@ -442,9 +442,12 @@ struct SpanCharacteristic{
uvSet(stepValue,0);
}
boolean isCustom=strchr(type,'-');
int x=0;
sscanf(type,"%*8[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*4[0-9a-fA-F]-%*12[0-9a-fA-F]%n",&x);
boolean isCustom=(strlen(type)==36 && x==36);
homeSpan.configLog+="(" + uvPrint(value) + ")" + ": IID=" + String(iid) + ", UUID=\"" + String(type) + "\"";
homeSpan.configLog+="(" + uvPrint(value) + ")" + ": IID=" + String(iid) + ", " + (isCustom?"Custom-":"") + "UUID=\"" + String(type) + "\"";
if(format!=FORMAT::STRING && format!=FORMAT::BOOL)
homeSpan.configLog+= ", Range=[" + String(uvPrint(minValue)) + "," + String(uvPrint(maxValue)) + "]";
@ -462,8 +465,8 @@ struct SpanCharacteristic{
valid=!strcmp(type,homeSpan.Accessories.back()->Services.back()->opt[i]->type);
if(!valid){
homeSpan.configLog+=" *** ERROR! Service does not support this Characteristic. ***";
homeSpan.nFatalErrors++;
homeSpan.configLog+=" *** WARNING! Service does not support this Characteristic. ***";
homeSpan.nWarnings++;
}
boolean repeated=false;

View File

@ -329,7 +329,6 @@ namespace Service {
struct Television : SpanService { Television() : SpanService{"D8","Television"}{
REQ(Active);
OPT(ConfiguredName);
OPT(ConfiguredNameStatic);
OPT(ActiveIdentifier);
OPT(RemoteKey);
OPT(PowerModeSelection);

View File

@ -4,7 +4,7 @@
#include "HomeSpan.h"
CUSTOM_CHAR(CustomActive, AB-123-B0, PW+PR+EV, UINT8, 0, 0, 1, false);
CUSTOM_CHAR(CustomActive, E863F10A-079E-48FF-8F27-9C2605A29F52, PR+EV, UINT16, 0, 0, 4800, false);
void setup() {
@ -45,19 +45,18 @@ void setup() {
new Service::LightBulb();
new Characteristic::On(0);
SpanCharacteristic *active = new Characteristic::CustomActive();
new Characteristic::CustomActive(1200);
new Characteristic::Brightness(50);
new Characteristic::Name("Light 1");
new Characteristic::ColorTemperature();
new Characteristic::Active();
new Service::LightBulb();
new Characteristic::On(0,true);
(new Characteristic::Brightness(50,true))->setRange(10,100,5);
(new Characteristic::Brightness(50,false))->setRange(10,100,5);
new Characteristic::Name("Light 2");
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
// active->setRange(0,10,3);
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics
new Characteristic::Name("HomeSpan Test"); // Name of the Accessory, which shows up on the HomeKit "tiles", and should be unique across Accessories
new Characteristic::Manufacturer("HomeSpan"); // Manufacturer of the Accessory (arbitrary text string, and can be the same for every Accessory)
@ -73,6 +72,8 @@ void setup() {
new Characteristic::On(0,true);
(new Characteristic::Brightness(50,true))->setRange(10,100,5);
new Characteristic::Name("Light 3");
new Characteristic::TargetPosition();
new Characteristic::OzoneDensity();
} // end of setup()