Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Fix dimmed typo #45

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ArduinoCloudThing.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

#include "types/automation/CloudColoredLight.h"
#include "types/automation/CloudContactSensor.h"
#include "types/automation/CloudDimmeredLight.h"
#include "types/automation/CloudDimmedLight.h"
#include "types/automation/CloudLight.h"
#include "types/automation/CloudMotionSensor.h"
#include "types/automation/CloudSmartPlug.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// a commercial license, send an email to [email protected].
//

#ifndef CLOUDDIMMEREDLIGHT_H_
#define CLOUDDIMMEREDLIGHT_H_
#ifndef CLOUDDIMMEDLIGHT_H_
#define CLOUDDIMMEDLIGHT_H_

/******************************************************************************
INCLUDE
Expand All @@ -29,49 +29,49 @@
/******************************************************************************
CLASS DECLARATION
******************************************************************************/
class DimmeredLight {
class DimmedLight {
public:
bool swi;
float bri;
DimmeredLight(bool swi, float bri): swi(swi), bri(bri) {
DimmedLight(bool swi, float bri): swi(swi), bri(bri) {
}

bool operator==(DimmeredLight & aLight) {
bool operator==(DimmedLight & aLight) {
return aLight.swi == swi && aLight.bri == bri;
}

bool operator!=(DimmeredLight & aLight) {
bool operator!=(DimmedLight & aLight) {
return !(operator==(aLight));
}

};

class CloudDimmeredLight : public ArduinoCloudProperty {
class CloudDimmedLight : public ArduinoCloudProperty {
private:
DimmeredLight _value,
_cloud_value;
DimmedLight _value,
_cloud_value;

public:
CloudDimmeredLight() : _value(false, 0), _cloud_value(false, 0) {}
CloudDimmeredLight(bool swi, float brightness) : _value(swi, brightness), _cloud_value(swi, brightness) {}
CloudDimmedLight() : _value(false, 0), _cloud_value(false, 0) {}
CloudDimmedLight(bool swi, float brightness) : _value(swi, brightness), _cloud_value(swi, brightness) {}

virtual bool isDifferentFromCloud() {

return _value != _cloud_value;
}

CloudDimmeredLight& operator=(DimmeredLight aLight) {
CloudDimmedLight& operator=(DimmedLight aLight) {
_value.swi = aLight.swi;
_value.bri = aLight.bri;
updateLocalTimestamp();
return *this;
}

DimmeredLight getCloudValue() {
DimmedLight getCloudValue() {
return _cloud_value;
}

DimmeredLight getValue() {
DimmedLight getValue() {
return _value;
}

Expand Down Expand Up @@ -118,4 +118,4 @@ class CloudDimmeredLight : public ArduinoCloudProperty {
}
};

#endif /* CLOUDDIMMEREDLIGHT_H_ */
#endif /* CLOUDDIMMEDLIGHT_H_ */
10 changes: 5 additions & 5 deletions test/src/test_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "types/CloudWrapperString.h"
#include "types/automation/CloudColoredLight.h"
#include "types/automation/CloudContactSensor.h"
#include "types/automation/CloudDimmeredLight.h"
#include "types/automation/CloudDimmedLight.h"
#include "types/automation/CloudLight.h"
#include "types/automation/CloudMotionSensor.h"
#include "types/automation/CloudSmartPlug.h"
Expand Down Expand Up @@ -191,21 +191,21 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")

/************************************************************************************/

WHEN("A DimmeredLight property is changed via CBOR message") {
WHEN("A DimmedLight property is changed via CBOR message") {
GIVEN("CloudProtocol::V2") {
ArduinoCloudThing thing;
thing.begin();

CloudDimmeredLight light_test = CloudDimmeredLight(false, 0.0);
CloudDimmedLight light_test = CloudDimmedLight(false, 0.0);

thing.addPropertyReal(light_test, "test", Permission::ReadWrite);

/* [{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 */
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};
thing.decode(payload, sizeof(payload) / sizeof(uint8_t));

DimmeredLight light_compare = DimmeredLight(true, 2.0);
DimmeredLight value_light_test = light_test.getValue();
DimmedLight light_compare = DimmedLight(true, 2.0);
DimmedLight value_light_test = light_test.getValue();
bool verify = (value_light_test == light_compare);
REQUIRE(verify);
REQUIRE(value_light_test.swi == light_compare.swi);
Expand Down
4 changes: 2 additions & 2 deletions test/src/test_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]")

/************************************************************************************/

WHEN("A 'DimmeredLight' property is added") {
WHEN("A 'DimmedLight' property is added") {
GIVEN("CloudProtocol::V2") {
ArduinoCloudThing thing;
thing.begin();
encode(thing);

CloudDimmeredLight color_test = CloudDimmeredLight(true, 2.0);
CloudDimmedLight color_test = CloudDimmedLight(true, 2.0);
thing.addPropertyReal(color_test, "test", Permission::ReadWrite);

/* [{0: "test:swi", 4: true},{0: "test:hue", 2: 0.0},{0: "test:sat", 2: 0.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 00 00 00 00 A2 00 68 74 65 73 74 3A 73 61 74 02 FA 00 00 00 00 A2 00 68 74 65 73 74 3A 62 72 69 02 FA 40 00 00 00 FF*/
Expand Down