Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 04959ea

Browse files
committed
Timer to restore light state properly implemented. Lights are not switched on after state has been saved.
1 parent ee3816f commit 04959ea

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

libsrc/leddevice/LedDevicePhilipsHue.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) :
1414
host(output.c_str()), username("newdeveloper") {
1515
http = new QHttp(host);
16-
timer.setInterval(1000);
16+
timer.setInterval(3000);
1717
timer.setSingleShot(true);
18-
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()()));
18+
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
1919
}
2020

2121
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
@@ -26,6 +26,7 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
2626
// Save light states if not done before.
2727
if (!statesSaved()) {
2828
saveStates(ledValues.size());
29+
switchOn(ledValues.size());
2930
}
3031
// Iterate through colors and set light states.
3132
unsigned int lightId = 1;
@@ -110,13 +111,22 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
110111
}
111112
// Save state object values which are subject to change.
112113
Json::Value state(Json::objectValue);
113-
state["xy"] = json["state"]["xy"];
114-
state["bri"] = json["state"]["bri"];
114+
state["on"] = json["state"]["on"];
115+
if (json["state"]["on"] == true) {
116+
state["xy"] = json["state"]["xy"];
117+
state["bri"] = json["state"]["bri"];
118+
}
115119
// Save state object.
116120
states.push_back(QString(writer.write(state).c_str()).trimmed());
117121
}
118122
}
119123

124+
void LedDevicePhilipsHue::switchOn(unsigned int nLights) {
125+
for (unsigned int i = 0; i < nLights; i++) {
126+
put(getStateRoute(i + 1), "{\"on\": true}");
127+
}
128+
}
129+
120130
void LedDevicePhilipsHue::restoreStates() {
121131
unsigned int lightId = 1;
122132
for (QString state : states) {

libsrc/leddevice/LedDevicePhilipsHue.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Q_OBJECT
4646
///
4747
virtual int write(const std::vector<ColorRgb> & ledValues);
4848

49-
/// Switch the leds off
49+
/// Restores the original state of the leds.
5050
virtual int switchOff();
5151

5252
private slots:
@@ -104,6 +104,13 @@ private slots:
104104
///
105105
void saveStates(unsigned int nLights);
106106

107+
///
108+
/// Switches the leds on.
109+
///
110+
/// @param nLights the number of lights
111+
///
112+
void switchOn(unsigned int nLights);
113+
107114
///
108115
/// @return true if light states have been saved.
109116
///

0 commit comments

Comments
 (0)