|
14 | 14 | #include "types/CloudWrapperFloat.h" |
15 | 15 | #include "types/CloudWrapperInt.h" |
16 | 16 | #include "types/CloudWrapperString.h" |
| 17 | +#include "types/automation/CloudColoredLight.h" |
| 18 | +#include "types/automation/CloudContactSensor.h" |
| 19 | +#include "types/automation/CloudDimmeredLight.h" |
| 20 | +#include "types/automation/CloudLight.h" |
| 21 | +#include "types/automation/CloudMotionSensor.h" |
| 22 | +#include "types/automation/CloudSmartPlug.h" |
| 23 | +#include "types/automation/CloudSwitch.h" |
| 24 | +#include "types/automation/CloudTemperature.h" |
17 | 25 |
|
18 | 26 | /************************************************************************************** |
19 | 27 | TEST CODE |
@@ -157,6 +165,176 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]") |
157 | 165 |
|
158 | 166 | /************************************************************************************/ |
159 | 167 |
|
| 168 | + WHEN("A ColoredLight property is changed via CBOR message") { |
| 169 | + GIVEN("CloudProtocol::V2") { |
| 170 | + ArduinoCloudThing thing; |
| 171 | + thing.begin(); |
| 172 | + |
| 173 | + CloudColoredLight color_test = CloudColoredLight(false, 0.0, 0.0, 0.0); |
| 174 | + |
| 175 | + thing.addPropertyReal(color_test, "test", Permission::ReadWrite); |
| 176 | + |
| 177 | + /* [{0: "test:swi", 4: true},{0: "test:hue", 2: 2.0},{0: "test:sat", 2: 2.0},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 68 75 65 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 40 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ |
| 178 | + uint8_t const payload[] = {0x84, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x68, 0x75, 0x65, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x61, 0x74, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00 }; |
| 179 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 180 | + |
| 181 | + ColoredLight color_compare = ColoredLight(true, 2.0, 2.0, 2.0); |
| 182 | + ColoredLight value_color_test = color_test.getValue(); |
| 183 | + bool verify = (value_color_test == color_compare); |
| 184 | + REQUIRE(verify); |
| 185 | + REQUIRE(value_color_test.swi == color_compare.swi); |
| 186 | + REQUIRE(value_color_test.hue == color_compare.hue); |
| 187 | + REQUIRE(value_color_test.sat == color_compare.sat); |
| 188 | + REQUIRE(value_color_test.bri == color_compare.bri); |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + /************************************************************************************/ |
| 193 | + |
| 194 | + WHEN("A DimmeredLight property is changed via CBOR message") { |
| 195 | + GIVEN("CloudProtocol::V2") { |
| 196 | + ArduinoCloudThing thing; |
| 197 | + thing.begin(); |
| 198 | + |
| 199 | + CloudDimmeredLight light_test = CloudDimmeredLight(false, 0.0); |
| 200 | + |
| 201 | + thing.addPropertyReal(light_test, "test", Permission::ReadWrite); |
| 202 | + |
| 203 | + /* [{0: "test:swi", 4: true},{0: "test:bri", 2: 2.0}] = 83 A2 00 68 74 65 73 74 3A 73 77 69 04 F5 //A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 */ |
| 204 | + uint8_t const payload[] = {0x82, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x73, 0x77, 0x69, 0x04, 0xF5, 0xA2, 0x00, 0x68, 0x74, 0x65, 0x73, 0x74, 0x3A, 0x62, 0x72, 0x69, 0x02, 0xFA, 0x40, 0x00, 0x00, 0x00}; |
| 205 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 206 | + |
| 207 | + DimmeredLight light_compare = DimmeredLight(true, 2.0); |
| 208 | + DimmeredLight value_light_test = light_test.getValue(); |
| 209 | + bool verify = (value_light_test == light_compare); |
| 210 | + REQUIRE(verify); |
| 211 | + REQUIRE(value_light_test.swi == light_compare.swi); |
| 212 | + REQUIRE(value_light_test.bri == light_compare.bri); |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + /************************************************************************************/ |
| 217 | + |
| 218 | + WHEN("A Light property is changed via CBOR message") { |
| 219 | + GIVEN("CloudProtocol::V2") { |
| 220 | + ArduinoCloudThing thing; |
| 221 | + thing.begin(); |
| 222 | + |
| 223 | + CloudLight light_test; |
| 224 | + light_test = false; |
| 225 | + |
| 226 | + thing.addPropertyReal(light_test, "test", Permission::ReadWrite); |
| 227 | + |
| 228 | + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ |
| 229 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; |
| 230 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 231 | + |
| 232 | + REQUIRE(light_test == true); |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + /************************************************************************************/ |
| 237 | + |
| 238 | + WHEN("A ContactSensor property is changed via CBOR message") { |
| 239 | + GIVEN("CloudProtocol::V2") { |
| 240 | + ArduinoCloudThing thing; |
| 241 | + thing.begin(); |
| 242 | + |
| 243 | + CloudContactSensor contact_test; |
| 244 | + contact_test = false; |
| 245 | + |
| 246 | + thing.addPropertyReal(contact_test, "test", Permission::ReadWrite); |
| 247 | + |
| 248 | + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ |
| 249 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; |
| 250 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 251 | + |
| 252 | + REQUIRE(contact_test == true); |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + /************************************************************************************/ |
| 257 | + |
| 258 | + WHEN("A MotionSensor property is changed via CBOR message") { |
| 259 | + GIVEN("CloudProtocol::V2") { |
| 260 | + ArduinoCloudThing thing; |
| 261 | + thing.begin(); |
| 262 | + |
| 263 | + CloudMotionSensor motion_test; |
| 264 | + motion_test = false; |
| 265 | + |
| 266 | + thing.addPropertyReal(motion_test, "test", Permission::ReadWrite); |
| 267 | + |
| 268 | + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ |
| 269 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; |
| 270 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 271 | + |
| 272 | + REQUIRE(motion_test == true); |
| 273 | + } |
| 274 | + } |
| 275 | + |
| 276 | + /************************************************************************************/ |
| 277 | + |
| 278 | + WHEN("A SmartPlug property is changed via CBOR message") { |
| 279 | + GIVEN("CloudProtocol::V2") { |
| 280 | + ArduinoCloudThing thing; |
| 281 | + thing.begin(); |
| 282 | + |
| 283 | + CloudSmartPlug plug_test; |
| 284 | + plug_test = false; |
| 285 | + |
| 286 | + thing.addPropertyReal(plug_test, "test", Permission::ReadWrite); |
| 287 | + |
| 288 | + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ |
| 289 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; |
| 290 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 291 | + |
| 292 | + REQUIRE(plug_test == true); |
| 293 | + } |
| 294 | + } |
| 295 | + |
| 296 | + /************************************************************************************/ |
| 297 | + |
| 298 | + WHEN("A Switch property is changed via CBOR message") { |
| 299 | + GIVEN("CloudProtocol::V2") { |
| 300 | + ArduinoCloudThing thing; |
| 301 | + thing.begin(); |
| 302 | + |
| 303 | + CloudSwitch switch_test; |
| 304 | + switch_test = false; |
| 305 | + |
| 306 | + thing.addPropertyReal(switch_test, "test", Permission::ReadWrite); |
| 307 | + |
| 308 | + /* [{0: "test", 4: true}] = 81 A2 00 64 74 65 73 74 04 F5 */ |
| 309 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x04, 0xF5}; |
| 310 | + thing.decode(payload, sizeof(payload) / sizeof(uint8_t)); |
| 311 | + |
| 312 | + REQUIRE(switch_test == true); |
| 313 | + } |
| 314 | + } |
| 315 | + |
| 316 | + /************************************************************************************/ |
| 317 | + |
| 318 | + WHEN("A Temperature property is changed via CBOR message") { |
| 319 | + GIVEN("CloudProtocol::V2") { |
| 320 | + ArduinoCloudThing thing; |
| 321 | + thing.begin(); |
| 322 | + |
| 323 | + CloudTemperature test; |
| 324 | + test = 0.0f; |
| 325 | + thing.addPropertyReal(test, "test", Permission::ReadWrite); |
| 326 | + |
| 327 | + /* [{0: "test", 2: 3.1459}] = 81 A2 00 64 74 65 73 74 02 FB 40 09 2A CD 9E 83 E4 26 */ |
| 328 | + uint8_t const payload[] = {0x81, 0xA2, 0x00, 0x64, 0x74, 0x65, 0x73, 0x74, 0x02, 0xFB, 0x40, 0x09, 0x2A, 0xCD, 0x9E, 0x83, 0xE4, 0x26}; |
| 329 | + int const payload_length = sizeof(payload) / sizeof(uint8_t); |
| 330 | + thing.decode(payload, payload_length); |
| 331 | + |
| 332 | + REQUIRE(test == Approx(3.1459).epsilon(0.01)); |
| 333 | + } |
| 334 | + } |
| 335 | + |
| 336 | + /************************************************************************************/ |
| 337 | + |
160 | 338 | WHEN("Multiple properties is changed via CBOR message") { |
161 | 339 | GIVEN("CloudProtocol::V2") { |
162 | 340 | WHEN("Multiple properties of different type are changed via CBOR message") { |
|
0 commit comments