mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Timer to restore light state properly implemented. Lights are not switched on after state has been saved.
Former-commit-id: 04959ea3731eb7de9f59b80a789f03cfeb2d4ba3
This commit is contained in:
parent
32f09dcc24
commit
853d002894
@ -13,9 +13,9 @@
|
|||||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) :
|
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output) :
|
||||||
host(output.c_str()), username("newdeveloper") {
|
host(output.c_str()), username("newdeveloper") {
|
||||||
http = new QHttp(host);
|
http = new QHttp(host);
|
||||||
timer.setInterval(1000);
|
timer.setInterval(3000);
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
|
LedDevicePhilipsHue::~LedDevicePhilipsHue() {
|
||||||
@ -26,6 +26,7 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
|||||||
// Save light states if not done before.
|
// Save light states if not done before.
|
||||||
if (!statesSaved()) {
|
if (!statesSaved()) {
|
||||||
saveStates(ledValues.size());
|
saveStates(ledValues.size());
|
||||||
|
switchOn(ledValues.size());
|
||||||
}
|
}
|
||||||
// Iterate through colors and set light states.
|
// Iterate through colors and set light states.
|
||||||
unsigned int lightId = 1;
|
unsigned int lightId = 1;
|
||||||
@ -110,13 +111,22 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
|||||||
}
|
}
|
||||||
// Save state object values which are subject to change.
|
// Save state object values which are subject to change.
|
||||||
Json::Value state(Json::objectValue);
|
Json::Value state(Json::objectValue);
|
||||||
|
state["on"] = json["state"]["on"];
|
||||||
|
if (json["state"]["on"] == true) {
|
||||||
state["xy"] = json["state"]["xy"];
|
state["xy"] = json["state"]["xy"];
|
||||||
state["bri"] = json["state"]["bri"];
|
state["bri"] = json["state"]["bri"];
|
||||||
|
}
|
||||||
// Save state object.
|
// Save state object.
|
||||||
states.push_back(QString(writer.write(state).c_str()).trimmed());
|
states.push_back(QString(writer.write(state).c_str()).trimmed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LedDevicePhilipsHue::switchOn(unsigned int nLights) {
|
||||||
|
for (unsigned int i = 0; i < nLights; i++) {
|
||||||
|
put(getStateRoute(i + 1), "{\"on\": true}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LedDevicePhilipsHue::restoreStates() {
|
void LedDevicePhilipsHue::restoreStates() {
|
||||||
unsigned int lightId = 1;
|
unsigned int lightId = 1;
|
||||||
for (QString state : states) {
|
for (QString state : states) {
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
///
|
///
|
||||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||||
|
|
||||||
/// Switch the leds off
|
/// Restores the original state of the leds.
|
||||||
virtual int switchOff();
|
virtual int switchOff();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -104,6 +104,13 @@ private:
|
|||||||
///
|
///
|
||||||
void saveStates(unsigned int nLights);
|
void saveStates(unsigned int nLights);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Switches the leds on.
|
||||||
|
///
|
||||||
|
/// @param nLights the number of lights
|
||||||
|
///
|
||||||
|
void switchOn(unsigned int nLights);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// @return true if light states have been saved.
|
/// @return true if light states have been saved.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user