2016-06-03 16:46:45 +02:00
|
|
|
// Local-Hyperion includes
|
|
|
|
#include "LedDevicePhilipsHue.h"
|
|
|
|
|
|
|
|
// jsoncpp includes
|
|
|
|
#include <json/json.h>
|
|
|
|
|
|
|
|
// qt includes
|
|
|
|
#include <QtCore/qmath.h>
|
|
|
|
#include <QEventLoop>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <set>
|
2016-07-24 22:43:26 +02:00
|
|
|
#include <cmath>
|
2016-06-03 16:46:45 +02:00
|
|
|
|
|
|
|
bool operator ==(CiColor p1, CiColor p2) {
|
|
|
|
return (p1.x == p2.x) && (p1.y == p2.y) && (p1.bri == p2.bri);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator !=(CiColor p1, CiColor p2) {
|
|
|
|
return !(p1 == p2);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId)
|
|
|
|
: id(id)
|
|
|
|
, originalState(originalState)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
|
|
|
// Light strips, color iris, ...
|
|
|
|
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
|
|
|
"LLC013", "LLC014", "LST001" };
|
|
|
|
// Hue bulbs, spots, ...
|
|
|
|
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
|
|
|
// Hue Lightstrip plus, go ...
|
|
|
|
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
|
|
|
// Find id in the sets and set the appropiate color space.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
colorSpace.red = {0.703f, 0.296f};
|
|
|
|
colorSpace.green = {0.2151f, 0.7106f};
|
|
|
|
colorSpace.blue = {0.138f, 0.08f};
|
2016-08-14 10:46:44 +02:00
|
|
|
}
|
|
|
|
else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
colorSpace.red = {0.675f, 0.322f};
|
|
|
|
colorSpace.green = {0.4091f, 0.518f};
|
|
|
|
colorSpace.blue = {0.167f, 0.04f};
|
2016-08-14 10:46:44 +02:00
|
|
|
}
|
|
|
|
else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
colorSpace.red = {0.675f, 0.322f};
|
|
|
|
colorSpace.green = {0.2151f, 0.7106f};
|
|
|
|
colorSpace.blue = {0.167f, 0.04f};
|
2016-08-14 10:46:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
colorSpace.red = {1.0f, 0.0f};
|
|
|
|
colorSpace.green = {0.0f, 1.0f};
|
|
|
|
colorSpace.blue = {0.0f, 0.0f};
|
|
|
|
}
|
|
|
|
// Initialize black color.
|
|
|
|
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
|
|
|
// Initialize color with black
|
|
|
|
color = {black.x, black.y, black.bri};
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
float PhilipsHueLight::crossProduct(CiColor p1, CiColor p2)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return p1.x * p2.y - p1.y * p2.x;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
bool PhilipsHueLight::isPointInLampsReach(CiColor p)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
CiColor v1 = { colorSpace.green.x - colorSpace.red.x, colorSpace.green.y - colorSpace.red.y };
|
|
|
|
CiColor v2 = { colorSpace.blue.x - colorSpace.red.x, colorSpace.blue.y - colorSpace.red.y };
|
|
|
|
CiColor q = { p.x - colorSpace.red.x, p.y - colorSpace.red.y };
|
|
|
|
float s = crossProduct(q, v2) / crossProduct(v1, v2);
|
|
|
|
float t = crossProduct(v1, q) / crossProduct(v1, v2);
|
2016-08-14 10:46:44 +02:00
|
|
|
if ((s >= 0.0f) && (t >= 0.0f) && (s + t <= 1.0f))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
CiColor PhilipsHueLight::getClosestPointToPoint(CiColor a, CiColor b, CiColor p)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
CiColor AP = { p.x - a.x, p.y - a.y };
|
|
|
|
CiColor AB = { b.x - a.x, b.y - a.y };
|
|
|
|
float ab2 = AB.x * AB.x + AB.y * AB.y;
|
|
|
|
float ap_ab = AP.x * AB.x + AP.y * AB.y;
|
|
|
|
float t = ap_ab / ab2;
|
2016-08-14 10:46:44 +02:00
|
|
|
if (t < 0.0f)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
t = 0.0f;
|
2016-08-14 10:46:44 +02:00
|
|
|
}
|
|
|
|
else if (t > 1.0f)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
t = 1.0f;
|
|
|
|
}
|
|
|
|
return {a.x + AB.x * t, a.y + AB.y * t};
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
float PhilipsHueLight::getDistanceBetweenTwoPoints(CiColor p1, CiColor p2)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Horizontal difference.
|
|
|
|
float dx = p1.x - p2.x;
|
|
|
|
// Vertical difference.
|
|
|
|
float dy = p1.y - p2.y;
|
|
|
|
// Absolute value.
|
|
|
|
return sqrt(dx * dx + dy * dy);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Apply gamma correction.
|
|
|
|
float r = (red > 0.04045f) ? powf((red + 0.055f) / (1.0f + 0.055f), 2.4f) : (red / 12.92f);
|
|
|
|
float g = (green > 0.04045f) ? powf((green + 0.055f) / (1.0f + 0.055f), 2.4f) : (green / 12.92f);
|
|
|
|
float b = (blue > 0.04045f) ? powf((blue + 0.055f) / (1.0f + 0.055f), 2.4f) : (blue / 12.92f);
|
|
|
|
// Convert to XYZ space.
|
|
|
|
float X = r * 0.649926f + g * 0.103455f + b * 0.197109f;
|
|
|
|
float Y = r * 0.234327f + g * 0.743075f + b * 0.022598f;
|
|
|
|
float Z = r * 0.0000000f + g * 0.053077f + b * 1.035763f;
|
|
|
|
// Convert to x,y space.
|
|
|
|
float cx = X / (X + Y + Z);
|
|
|
|
float cy = Y / (X + Y + Z);
|
2016-08-14 10:46:44 +02:00
|
|
|
if (std::isnan(cx))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
cx = 0.0f;
|
|
|
|
}
|
2016-08-14 10:46:44 +02:00
|
|
|
if (std::isnan(cy))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
cy = 0.0f;
|
|
|
|
}
|
|
|
|
// Brightness is simply Y in the XYZ space.
|
|
|
|
CiColor xy = { cx, cy, Y };
|
|
|
|
// Check if the given XY value is within the color reach of our lamps.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!isPointInLampsReach(xy))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// It seems the color is out of reach let's find the closes color we can produce with our lamp and send this XY value out.
|
|
|
|
CiColor pAB = getClosestPointToPoint(colorSpace.red, colorSpace.green, xy);
|
|
|
|
CiColor pAC = getClosestPointToPoint(colorSpace.blue, colorSpace.red, xy);
|
|
|
|
CiColor pBC = getClosestPointToPoint(colorSpace.green, colorSpace.blue, xy);
|
|
|
|
// Get the distances per point and see which point is closer to our Point.
|
|
|
|
float dAB = getDistanceBetweenTwoPoints(xy, pAB);
|
|
|
|
float dAC = getDistanceBetweenTwoPoints(xy, pAC);
|
|
|
|
float dBC = getDistanceBetweenTwoPoints(xy, pBC);
|
|
|
|
float lowest = dAB;
|
|
|
|
CiColor closestPoint = pAB;
|
2016-08-14 10:46:44 +02:00
|
|
|
if (dAC < lowest)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
lowest = dAC;
|
|
|
|
closestPoint = pAC;
|
|
|
|
}
|
2016-08-14 10:46:44 +02:00
|
|
|
if (dBC < lowest)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
lowest = dBC;
|
|
|
|
closestPoint = pBC;
|
|
|
|
}
|
|
|
|
// Change the xy value to a value which is within the reach of the lamp.
|
|
|
|
xy.x = closestPoint.x;
|
|
|
|
xy.y = closestPoint.y;
|
|
|
|
}
|
|
|
|
return xy;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack, int transitiontime, std::vector<unsigned int> lightIds)
|
|
|
|
: LedDevice()
|
|
|
|
, host(output.c_str())
|
|
|
|
, username(username.c_str())
|
|
|
|
, switchOffOnBlack(switchOffOnBlack)
|
|
|
|
, transitiontime(transitiontime)
|
|
|
|
, lightIds(lightIds)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
manager = new QNetworkAccessManager();
|
|
|
|
timer.setInterval(3000);
|
|
|
|
timer.setSingleShot(true);
|
|
|
|
connect(&timer, SIGNAL(timeout()), this, SLOT(restoreStates()));
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
LedDevicePhilipsHue::~LedDevicePhilipsHue()
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
delete manager;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Save light states if not done before.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!areStatesSaved())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
saveStates((unsigned int) ledValues.size());
|
|
|
|
switchOn((unsigned int) ledValues.size());
|
|
|
|
}
|
|
|
|
// If there are less states saved than colors given, then maybe something went wrong before.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (lights.size() != ledValues.size())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
restoreStates();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Iterate through colors and set light states.
|
|
|
|
unsigned int idx = 0;
|
2016-08-14 10:46:44 +02:00
|
|
|
for (const ColorRgb& color : ledValues)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Get lamp.
|
|
|
|
PhilipsHueLight& lamp = lights.at(idx);
|
|
|
|
// Scale colors from [0, 255] to [0, 1] and convert to xy space.
|
|
|
|
CiColor xy = lamp.rgbToCiColor(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f);
|
|
|
|
// Write color if color has been changed.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (xy != lamp.color)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// From a color to black.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (switchOffOnBlack && lamp.color != lamp.black && xy == lamp.black)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
put(getStateRoute(lamp.id), QString("{\"on\": false}"));
|
|
|
|
}
|
|
|
|
// From black to a color
|
2016-08-14 10:46:44 +02:00
|
|
|
else if (switchOffOnBlack && lamp.color == lamp.black && xy != lamp.black)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Send adjust color and brightness command in JSON format.
|
|
|
|
// We have to set the transition time each time.
|
|
|
|
// Send also command to switch the lamp on.
|
|
|
|
put(getStateRoute(lamp.id),
|
|
|
|
QString("{\"on\": true, \"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(
|
|
|
|
xy.y).arg(qRound(xy.bri * 255.0f)).arg(transitiontime));
|
|
|
|
}
|
|
|
|
// Normal color change.
|
2016-08-14 10:46:44 +02:00
|
|
|
else
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Send adjust color and brightness command in JSON format.
|
|
|
|
// We have to set the transition time each time.
|
|
|
|
put(getStateRoute(lamp.id),
|
|
|
|
QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
|
|
|
|
qRound(xy.bri * 255.0f)).arg(transitiontime));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remember last color.
|
|
|
|
lamp.color = xy;
|
|
|
|
// Next light id.
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
timer.start();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
int LedDevicePhilipsHue::switchOff()
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
timer.stop();
|
|
|
|
// If light states have been saved before, ...
|
2016-08-14 10:46:44 +02:00
|
|
|
if (areStatesSaved())
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// ... restore them.
|
|
|
|
restoreStates();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
void LedDevicePhilipsHue::put(QString route, QString content)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
QString url = getUrl(route);
|
|
|
|
// Perfrom request
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
QNetworkReply* reply = manager->put(request, content.toLatin1());
|
|
|
|
// Connect finished signal to quit slot of the loop.
|
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
|
|
|
// Go into the loop until the request is finished.
|
|
|
|
loop.exec();
|
|
|
|
// Free space.
|
|
|
|
reply->deleteLater();
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
QByteArray LedDevicePhilipsHue::get(QString route)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
QString url = getUrl(route);
|
|
|
|
// Perfrom request
|
|
|
|
QNetworkRequest request(url);
|
|
|
|
QNetworkReply* reply = manager->get(request);
|
|
|
|
// Connect requestFinished signal to quit slot of the loop.
|
|
|
|
QEventLoop loop;
|
|
|
|
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
|
|
|
// Go into the loop until the request is finished.
|
|
|
|
loop.exec();
|
|
|
|
// Read all data of the response.
|
|
|
|
QByteArray response = reply->readAll();
|
|
|
|
// Free space.
|
|
|
|
reply->deleteLater();
|
|
|
|
// Return response
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return QString("lights/%1/state").arg(lightId);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
QString LedDevicePhilipsHue::getRoute(unsigned int lightId)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return QString("lights/%1").arg(lightId);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
QString LedDevicePhilipsHue::getUrl(QString route)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
void LedDevicePhilipsHue::saveStates(unsigned int nLights)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Clear saved lamps.
|
|
|
|
lights.clear();
|
|
|
|
// Use json parser to parse reponse.
|
|
|
|
Json::Reader reader;
|
|
|
|
Json::FastWriter writer;
|
|
|
|
// Read light ids if none have been supplied by the user.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (lightIds.size() != nLights)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
lightIds.clear();
|
|
|
|
//
|
|
|
|
QByteArray response = get("lights");
|
|
|
|
Json::Value json;
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!reader.parse(QString(response).toStdString(), json))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
throw std::runtime_error(("No lights found at " + getUrl("lights")).toStdString());
|
|
|
|
}
|
|
|
|
// Loop over all children.
|
2016-08-14 10:46:44 +02:00
|
|
|
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
int lightId = atoi(it.key().asCString());
|
|
|
|
lightIds.push_back(lightId);
|
2016-06-25 22:08:17 +02:00
|
|
|
Debug(_log, "nLights=%d: found light with id %d.", nLights, lightId);
|
2016-06-03 16:46:45 +02:00
|
|
|
}
|
|
|
|
// Check if we found enough lights.
|
2016-08-14 10:46:44 +02:00
|
|
|
if (lightIds.size() != nLights)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
throw std::runtime_error(("Not enough lights found at " + getUrl("lights")).toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Iterate lights.
|
2016-08-14 10:46:44 +02:00
|
|
|
for (unsigned int i = 0; i < nLights; i++)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Read the response.
|
|
|
|
QByteArray response = get(getRoute(lightIds.at(i)));
|
|
|
|
// Parse JSON.
|
|
|
|
Json::Value json;
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!reader.parse(QString(response).toStdString(), json))
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
// Error occured, break loop.
|
2016-06-25 22:08:17 +02:00
|
|
|
Error(_log, "saveStates(nLights=%d): got invalid response from light %s.", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
2016-06-03 16:46:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Get state object values which are subject to change.
|
|
|
|
Json::Value state(Json::objectValue);
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!json.isMember("state"))
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Error(_log, "saveStates(nLights=%d): got no state for light from %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
2016-06-03 16:46:45 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-08-14 10:46:44 +02:00
|
|
|
if (!json["state"].isMember("on"))
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Error(_log, "saveStates(nLights=%d,): got no valid state from light %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
2016-06-03 16:46:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
state["on"] = json["state"]["on"];
|
2016-08-14 10:46:44 +02:00
|
|
|
if (json["state"]["on"] == true)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
state["xy"] = json["state"]["xy"];
|
|
|
|
state["bri"] = json["state"]["bri"];
|
|
|
|
}
|
|
|
|
// Determine the model id.
|
|
|
|
QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "");
|
|
|
|
QString originalState = QString(writer.write(state).c_str()).trimmed();
|
|
|
|
// Save state object.
|
|
|
|
lights.push_back(PhilipsHueLight(lightIds.at(i), originalState, modelId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
void LedDevicePhilipsHue::switchOn(unsigned int nLights)
|
|
|
|
{
|
|
|
|
for (PhilipsHueLight light : lights)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
put(getStateRoute(light.id), "{\"on\": true}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
void LedDevicePhilipsHue::restoreStates()
|
|
|
|
{
|
|
|
|
for (PhilipsHueLight light : lights)
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
put(getStateRoute(light.id), light.originalState);
|
|
|
|
}
|
|
|
|
// Clear saved light states.
|
|
|
|
lights.clear();
|
|
|
|
}
|
|
|
|
|
2016-08-14 10:46:44 +02:00
|
|
|
bool LedDevicePhilipsHue::areStatesSaved()
|
|
|
|
{
|
2016-06-03 16:46:45 +02:00
|
|
|
return !lights.empty();
|
|
|
|
}
|