diff --git a/src/property/Property.cpp b/src/property/Property.cpp index c6c3db9e4..326e25584 100644 --- a/src/property/Property.cpp +++ b/src/property/Property.cpp @@ -170,7 +170,7 @@ void Property::execCallbackOnSync() { CborError Property::append(CborEncoder *encoder, bool lightPayload) { _lightPayload = lightPayload; _attributeIdentifier = 0; - CHECK_CBOR(appendAttributesToCloudReal(encoder)); + CHECK_CBOR(appendAttributesToCloud(encoder)); fromLocalToCloud(); _has_been_updated_once = true; _has_been_modified_in_callback = false; @@ -181,7 +181,7 @@ CborError Property::append(CborEncoder *encoder, bool lightPayload) { return CborNoError; } -CborError Property::appendAttributeReal(bool value, String attributeName, CborEncoder *encoder) { +CborError Property::appendAttribute(bool value, String attributeName, CborEncoder *encoder) { return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) { CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::BooleanValue))); @@ -190,7 +190,7 @@ CborError Property::appendAttributeReal(bool value, String attributeName, CborEn }, encoder); } -CborError Property::appendAttributeReal(int value, String attributeName, CborEncoder *encoder) { +CborError Property::appendAttribute(int value, String attributeName, CborEncoder *encoder) { return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) { CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); @@ -199,7 +199,7 @@ CborError Property::appendAttributeReal(int value, String attributeName, CborEnc }, encoder); } -CborError Property::appendAttributeReal(unsigned int value, String attributeName, CborEncoder *encoder) { +CborError Property::appendAttribute(unsigned int value, String attributeName, CborEncoder *encoder) { return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) { CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); @@ -208,7 +208,7 @@ CborError Property::appendAttributeReal(unsigned int value, String attributeName }, encoder); } -CborError Property::appendAttributeReal(float value, String attributeName, CborEncoder *encoder) { +CborError Property::appendAttribute(float value, String attributeName, CborEncoder *encoder) { return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) { CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::Value))); @@ -217,7 +217,7 @@ CborError Property::appendAttributeReal(float value, String attributeName, CborE }, encoder); } -CborError Property::appendAttributeReal(String value, String attributeName, CborEncoder *encoder) { +CborError Property::appendAttribute(String value, String attributeName, CborEncoder *encoder) { return appendAttributeName(attributeName, [value](CborEncoder & mapEncoder) { CHECK_CBOR(cbor_encode_int(&mapEncoder, static_cast(CborIntegerMapKey::StringValue))); @@ -278,8 +278,8 @@ void Property::setAttributesFromCloud(std::list * map_data_list) { setAttributesFromCloud(); } -void Property::setAttributeReal(bool& value, String attributeName) { - setAttributeReal(attributeName, [&value](CborMapData & md) { +void Property::setAttribute(bool& value, String attributeName) { + setAttribute(attributeName, [&value](CborMapData & md) { // Manage the case to have boolean values received as integers 0/1 if (md.bool_val.isSet()) { value = md.bool_val.get(); @@ -295,34 +295,34 @@ void Property::setAttributeReal(bool& value, String attributeName) { }); } -void Property::setAttributeReal(int& value, String attributeName) { - setAttributeReal(attributeName, [&value](CborMapData & md) { +void Property::setAttribute(int& value, String attributeName) { + setAttribute(attributeName, [&value](CborMapData & md) { value = md.val.get(); }); } -void Property::setAttributeReal(unsigned int& value, String attributeName) { - setAttributeReal(attributeName, [&value](CborMapData & md) { +void Property::setAttribute(unsigned int& value, String attributeName) { + setAttribute(attributeName, [&value](CborMapData & md) { value = md.val.get(); }); } -void Property::setAttributeReal(float& value, String attributeName) { - setAttributeReal(attributeName, [&value](CborMapData & md) { +void Property::setAttribute(float& value, String attributeName) { + setAttribute(attributeName, [&value](CborMapData & md) { value = md.val.get(); }); } -void Property::setAttributeReal(String& value, String attributeName) { - setAttributeReal(attributeName, [&value](CborMapData & md) { +void Property::setAttribute(String& value, String attributeName) { + setAttribute(attributeName, [&value](CborMapData & md) { value = md.str_val.get(); }); } #ifdef __AVR__ -void Property::setAttributeReal(String attributeName, nonstd::functionsetValue) +void Property::setAttribute(String attributeName, nonstd::functionsetValue) #else -void Property::setAttributeReal(String attributeName, std::functionsetValue) +void Property::setAttribute(String attributeName, std::functionsetValue) #endif { if (attributeName != "") { @@ -354,13 +354,6 @@ void Property::setAttributeReal(String attributeName, std::functionf, CborEncoder *encoder); - void setAttributeReal(String attributeName, std::functionsetValue); + void setAttribute(String attributeName, std::functionsetValue); #else CborError appendAttributeName(String attributeName, nonstd::functionf, CborEncoder *encoder); - void setAttributeReal(String attributeName, nonstd::functionsetValue); + void setAttribute(String attributeName, nonstd::functionsetValue); #endif void setAttributesFromCloud(std::list * map_data_list); - void setAttributeReal(bool& value, String attributeName = ""); - void setAttributeReal(int& value, String attributeName = ""); - void setAttributeReal(unsigned int& value, String attributeName = ""); - void setAttributeReal(float& value, String attributeName = ""); - void setAttributeReal(String& value, String attributeName = ""); - String getAttributeName(String propertyName, char separator); + void setAttribute(bool& value, String attributeName = ""); + void setAttribute(int& value, String attributeName = ""); + void setAttribute(unsigned int& value, String attributeName = ""); + void setAttribute(float& value, String attributeName = ""); + void setAttribute(String& value, String attributeName = ""); virtual bool isDifferentFromCloud() = 0; virtual void fromCloudToLocal() = 0; virtual void fromLocalToCloud() = 0; - virtual CborError appendAttributesToCloudReal(CborEncoder *encoder) = 0; + virtual CborError appendAttributesToCloud(CborEncoder *encoder) = 0; virtual void setAttributesFromCloud() = 0; virtual bool isPrimitive() { return false; diff --git a/src/property/types/CloudBool.h b/src/property/types/CloudBool.h index e0b9f1f30..3434656fc 100644 --- a/src/property/types/CloudBool.h +++ b/src/property/types/CloudBool.h @@ -52,11 +52,11 @@ class CloudBool : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } //modifiers CloudBool& operator=(bool v) { diff --git a/src/property/types/CloudColor.h b/src/property/types/CloudColor.h index 294a2bb8d..54cb4f30f 100644 --- a/src/property/types/CloudColor.h +++ b/src/property/types/CloudColor.h @@ -188,16 +188,16 @@ class CloudColor : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.hue)); - CHECK_CBOR_MULTI(appendAttribute(_value.sat)); - CHECK_CBOR_MULTI(appendAttribute(_value.bri)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.hue, "hue", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.sat, "sat", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder)); return CborNoError; } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.hue); - setAttribute(_cloud_value.sat); - setAttribute(_cloud_value.bri); + setAttribute(_cloud_value.hue, "hue"); + setAttribute(_cloud_value.sat, "sat"); + setAttribute(_cloud_value.bri, "bri"); } }; diff --git a/src/property/types/CloudFloat.h b/src/property/types/CloudFloat.h index b68fe70fe..514df7866 100644 --- a/src/property/types/CloudFloat.h +++ b/src/property/types/CloudFloat.h @@ -54,11 +54,11 @@ class CloudFloat : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } //modifiers CloudFloat& operator=(float v) { diff --git a/src/property/types/CloudInt.h b/src/property/types/CloudInt.h index 0ce65777a..37e4d3cae 100644 --- a/src/property/types/CloudInt.h +++ b/src/property/types/CloudInt.h @@ -52,11 +52,11 @@ class CloudInt : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } //modifiers CloudInt& operator=(int v) { diff --git a/src/property/types/CloudLocation.h b/src/property/types/CloudLocation.h index 25636cd97..cd4f0dc67 100644 --- a/src/property/types/CloudLocation.h +++ b/src/property/types/CloudLocation.h @@ -89,14 +89,14 @@ class CloudLocation : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.lat)); - CHECK_CBOR_MULTI(appendAttribute(_value.lon)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.lat, "lat", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.lon, "lon", encoder)); return CborNoError; } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.lat); - setAttribute(_cloud_value.lon); + setAttribute(_cloud_value.lat, "lat"); + setAttribute(_cloud_value.lon, "lon"); } }; diff --git a/src/property/types/CloudSchedule.h b/src/property/types/CloudSchedule.h index 47827c59c..ecf6345ec 100644 --- a/src/property/types/CloudSchedule.h +++ b/src/property/types/CloudSchedule.h @@ -417,18 +417,18 @@ class CloudSchedule : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.frm)); - CHECK_CBOR_MULTI(appendAttribute(_value.to)); - CHECK_CBOR_MULTI(appendAttribute(_value.len)); - CHECK_CBOR_MULTI(appendAttribute(_value.msk)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.frm, "frm", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.to, "to", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.len, "len", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.msk, "msk", encoder)); return CborNoError; } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.frm); - setAttribute(_cloud_value.to); - setAttribute(_cloud_value.len); - setAttribute(_cloud_value.msk); + setAttribute(_cloud_value.frm, "frm"); + setAttribute(_cloud_value.to, "to"); + setAttribute(_cloud_value.len, "len"); + setAttribute(_cloud_value.msk, "msk"); } }; diff --git a/src/property/types/CloudString.h b/src/property/types/CloudString.h index f07f59ccf..f884720c0 100644 --- a/src/property/types/CloudString.h +++ b/src/property/types/CloudString.h @@ -58,11 +58,11 @@ class CloudString : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } //modifiers CloudString& operator=(String v) { diff --git a/src/property/types/CloudUnsignedInt.h b/src/property/types/CloudUnsignedInt.h index 37ec2d1cb..40bed697a 100644 --- a/src/property/types/CloudUnsignedInt.h +++ b/src/property/types/CloudUnsignedInt.h @@ -52,11 +52,11 @@ class CloudUnsignedInt : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } //modifiers CloudUnsignedInt& operator=(unsigned int v) { diff --git a/src/property/types/CloudWrapperBool.h b/src/property/types/CloudWrapperBool.h index 701e7c87d..8fffd4209 100644 --- a/src/property/types/CloudWrapperBool.h +++ b/src/property/types/CloudWrapperBool.h @@ -45,11 +45,11 @@ class CloudWrapperBool : public CloudWrapperBase { virtual void fromLocalToCloud() { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_primitive_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_primitive_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } virtual bool isPrimitive() { return true; diff --git a/src/property/types/CloudWrapperFloat.h b/src/property/types/CloudWrapperFloat.h index db0f640cf..7ce857c85 100644 --- a/src/property/types/CloudWrapperFloat.h +++ b/src/property/types/CloudWrapperFloat.h @@ -47,11 +47,11 @@ class CloudWrapperFloat : public CloudWrapperBase { virtual void fromLocalToCloud() { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_primitive_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_primitive_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } virtual bool isPrimitive() { return true; diff --git a/src/property/types/CloudWrapperInt.h b/src/property/types/CloudWrapperInt.h index 261c72d46..73623abfc 100644 --- a/src/property/types/CloudWrapperInt.h +++ b/src/property/types/CloudWrapperInt.h @@ -45,11 +45,11 @@ class CloudWrapperInt : public CloudWrapperBase { virtual void fromLocalToCloud() { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_primitive_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_primitive_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } virtual bool isPrimitive() { return true; diff --git a/src/property/types/CloudWrapperString.h b/src/property/types/CloudWrapperString.h index 3e1c0a3e3..7c75db0db 100644 --- a/src/property/types/CloudWrapperString.h +++ b/src/property/types/CloudWrapperString.h @@ -49,11 +49,11 @@ class CloudWrapperString : public CloudWrapperBase { virtual void fromLocalToCloud() { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_primitive_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_primitive_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } virtual bool isPrimitive() { return true; diff --git a/src/property/types/CloudWrapperUnsignedInt.h b/src/property/types/CloudWrapperUnsignedInt.h index d722f585f..34ed01ef3 100644 --- a/src/property/types/CloudWrapperUnsignedInt.h +++ b/src/property/types/CloudWrapperUnsignedInt.h @@ -45,11 +45,11 @@ class CloudWrapperUnsignedInt : public CloudWrapperBase { virtual void fromLocalToCloud() { _cloud_value = _primitive_value; } - virtual CborError appendAttributesToCloud() { - return appendAttribute(_primitive_value); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + return appendAttribute(_primitive_value, "", encoder); } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value); + setAttribute(_cloud_value, ""); } virtual bool isPrimitive() { return true; diff --git a/src/property/types/automation/CloudColoredLight.h b/src/property/types/automation/CloudColoredLight.h index f38b8354a..031590a39 100644 --- a/src/property/types/automation/CloudColoredLight.h +++ b/src/property/types/automation/CloudColoredLight.h @@ -118,18 +118,18 @@ class CloudColoredLight : public CloudColor { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.swi)); - CHECK_CBOR_MULTI(appendAttribute(_value.hue)); - CHECK_CBOR_MULTI(appendAttribute(_value.sat)); - CHECK_CBOR_MULTI(appendAttribute(_value.bri)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.swi, "swi", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.hue, "hue", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.sat, "sat", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder)); return CborNoError; } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.swi); - setAttribute(_cloud_value.hue); - setAttribute(_cloud_value.sat); - setAttribute(_cloud_value.bri); + setAttribute(_cloud_value.swi, "swi"); + setAttribute(_cloud_value.hue, "hue"); + setAttribute(_cloud_value.sat, "sat"); + setAttribute(_cloud_value.bri, "bri"); } }; diff --git a/src/property/types/automation/CloudDimmedLight.h b/src/property/types/automation/CloudDimmedLight.h index e14da0f75..8e0c0b39f 100644 --- a/src/property/types/automation/CloudDimmedLight.h +++ b/src/property/types/automation/CloudDimmedLight.h @@ -98,15 +98,15 @@ class CloudDimmedLight : public Property { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.swi)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.swi, "swi", encoder)); // To allow visualization through color widget // Start float hue = 0; float sat = 0; - CHECK_CBOR_MULTI(appendAttributeReal(hue, getAttributeName(".hue", '.'), encoder)); - CHECK_CBOR_MULTI(appendAttributeReal(sat, getAttributeName(".sat", '.'), encoder)); - CHECK_CBOR_MULTI(appendAttribute(_value.bri)); + CHECK_CBOR_MULTI(appendAttribute(hue, "hue", encoder)); + CHECK_CBOR_MULTI(appendAttribute(sat, "sat", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.bri, "bri", encoder)); // should be only: // appendAttribute(_value.bri); // end @@ -114,8 +114,8 @@ class CloudDimmedLight : public Property { } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.swi); - setAttribute(_cloud_value.bri); + setAttribute(_cloud_value.swi, "swi"); + setAttribute(_cloud_value.bri, "bri"); } }; diff --git a/src/property/types/automation/CloudTelevision.h b/src/property/types/automation/CloudTelevision.h index 921f1ea56..75967dd4f 100644 --- a/src/property/types/automation/CloudTelevision.h +++ b/src/property/types/automation/CloudTelevision.h @@ -213,22 +213,22 @@ class CloudTelevision : public Property { virtual void fromLocalToCloud() { _cloud_value = _value; } - virtual CborError appendAttributesToCloud() { - CHECK_CBOR_MULTI(appendAttribute(_value.swi)); - CHECK_CBOR_MULTI(appendAttribute(_value.vol)); - CHECK_CBOR_MULTI(appendAttribute(_value.mut)); - CHECK_CBOR_MULTI(appendAttribute((int)_value.pbc)); - CHECK_CBOR_MULTI(appendAttribute((int)_value.inp)); - CHECK_CBOR_MULTI(appendAttribute(_value.cha)); + virtual CborError appendAttributesToCloud(CborEncoder *encoder) { + CHECK_CBOR_MULTI(appendAttribute(_value.swi, "swi", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.vol, "vol", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.mut, "mut", encoder)); + CHECK_CBOR_MULTI(appendAttribute((int)_value.pbc, "pbc", encoder)); + CHECK_CBOR_MULTI(appendAttribute((int)_value.inp, "inp", encoder)); + CHECK_CBOR_MULTI(appendAttribute(_value.cha, "cha", encoder)); return CborNoError; } virtual void setAttributesFromCloud() { - setAttribute(_cloud_value.swi); - setAttribute(_cloud_value.vol); - setAttribute(_cloud_value.mut); - setAttribute((int&)_cloud_value.pbc); - setAttribute((int&)_cloud_value.inp); - setAttribute(_cloud_value.cha); + setAttribute(_cloud_value.swi, "swi"); + setAttribute(_cloud_value.vol, "vol"); + setAttribute(_cloud_value.mut, "mut"); + setAttribute((int&)_cloud_value.pbc, "pbc"); + setAttribute((int&)_cloud_value.inp, "inp"); + setAttribute(_cloud_value.cha, "cha"); } };