Skip to content

Commit 3fe305e

Browse files
ilcatoaentinger
authored andcommitted
Fixed DimmeredLight
1 parent 5067fa9 commit 3fe305e

File tree

2 files changed

+68
-7
lines changed

2 files changed

+68
-7
lines changed

types/automation/CloudColoredLight.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ColoredLight : public Color {
4747
};
4848

4949
class CloudColoredLight : public CloudColor {
50-
protected:
50+
private:
5151
ColoredLight _value,
5252
_cloud_value;
5353
public:

types/automation/CloudDimmeredLight.h

+67-6
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,81 @@
2424

2525
#include <math.h>
2626
#include <Arduino.h>
27-
#include "CloudColoredLight.h"
27+
#include "../../ArduinoCloudProperty.h"
2828

2929
/******************************************************************************
3030
CLASS DECLARATION
3131
******************************************************************************/
32+
class DimmeredLight {
33+
public:
34+
bool swi;
35+
float bri;
36+
DimmeredLight(bool swi, float bri): swi(swi), bri(bri) {
37+
}
38+
39+
bool operator==(DimmeredLight & aLight) {
40+
return aLight.swi == swi && aLight.bri == bri;
41+
}
42+
43+
bool operator!=(DimmeredLight & aLight) {
44+
return !(operator==(aLight));
45+
}
46+
47+
};
3248

33-
class CloudDimmeredLight : public CloudColoredLight {
49+
class CloudDimmeredLight : public ArduinoCloudProperty {
3450
private:
51+
DimmeredLight _value,
52+
_cloud_value;
53+
3554
public:
36-
float getBrightness() {
37-
return _value.bri;
55+
CloudDimmeredLight() : _value(false, 0), _cloud_value(false, 0) {}
56+
CloudDimmeredLight(bool swi, float brightness) : _value(swi, brightness), _cloud_value(swi, brightness) {}
57+
58+
virtual bool isDifferentFromCloud() {
59+
60+
return _value != _cloud_value;
61+
}
62+
63+
CloudDimmeredLight& operator=(DimmeredLight aLight) {
64+
_value.swi = aLight.swi;
65+
_value.bri = aLight.bri;
66+
updateLocalTimestamp();
67+
return *this;
68+
}
69+
70+
DimmeredLight getCloudValue() {
71+
return _cloud_value;
3872
}
39-
bool getSwitch() {
40-
return _value.swi;
73+
74+
DimmeredLight getValue() {
75+
return _value;
76+
}
77+
78+
virtual void fromCloudToLocal() {
79+
_value = _cloud_value;
80+
}
81+
virtual void fromLocalToCloud() {
82+
_cloud_value = _value;
83+
}
84+
85+
virtual void appendAttributesToCloud() {
86+
appendAttribute(_value.swi);
87+
// To allow visualization through color widget
88+
// Start
89+
float hue = 0;
90+
float sat = 0;
91+
appendAttributeReal(hue, getAttributeName(".hue", '.'), encoder);
92+
appendAttributeReal(sat, getAttributeName(".sat", '.'), encoder);
93+
if (_value.swi) {
94+
appendAttribute(_value.bri);
95+
} else {
96+
float bri = 0;
97+
appendAttributeReal(bri, getAttributeName(".bri", '.'), encoder);
98+
}
99+
// should be only:
100+
// appendAttribute(_value.bri);
101+
// end
41102
}
42103

43104
virtual void setAttributesFromCloud() {

0 commit comments

Comments
 (0)