mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Blocking PUT requests. Only save the brightness and [x,y] state of the lights.
Former-commit-id: 5887fdf1b350172dcdd52c46bd8da74dab521444
This commit is contained in:
parent
ab5e17e105
commit
9220c346bb
@ -54,9 +54,15 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
QHttpRequestHeader header("PUT", url);
|
||||
header.setValue("Host", host);
|
||||
header.setValue("Accept-Encoding", "identity");
|
||||
header.setValue("Connection", "keep-alive");
|
||||
header.setValue("Content-Length", QString("%1").arg(content.size()));
|
||||
http->setHost(host);
|
||||
QEventLoop loop;
|
||||
// Connect requestFinished signal to quit slot of the loop.
|
||||
loop.connect(http, SIGNAL(requestFinished(int, bool)), SLOT(quit()));
|
||||
// Perfrom request
|
||||
http->request(header, content.toAscii());
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
@ -92,13 +98,17 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||
// Read the response.
|
||||
QByteArray response = get(getRoute(i + 1));
|
||||
// Parse JSON.
|
||||
Json::Value state;
|
||||
if (!reader.parse(QString(response).toStdString(), state)) {
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||
// Error occured, break loop.
|
||||
break;
|
||||
}
|
||||
// Save state object values which are subject to change.
|
||||
Json::Value state(Json::objectValue);
|
||||
state["xy"] = json["state"]["xy"];
|
||||
state["bri"] = json["state"]["bri"];
|
||||
// Save state object.
|
||||
states.push_back(QString(writer.write(state["state"]).c_str()));
|
||||
states.push_back(QString(writer.write(state).c_str()).trimmed());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user