mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Merge pull request #538 from ntim/support_for_philips_hue
Reads hue light ids in case the user did not supply any. Former-commit-id: 7dc1e6a14c0bd2b08439d13e7e2acf9f539cf1c1
This commit is contained in:
commit
9e3b98dfc3
@ -20,33 +20,33 @@ bool operator !=(CiColor p1, CiColor p2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
|
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
|
||||||
id(id), originalState(originalState) {
|
id(id), originalState(originalState) {
|
||||||
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
||||||
// Light strips, color iris, ...
|
// Light strips, color iris, ...
|
||||||
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
||||||
"LLC013", "LLC014", "LST001" };
|
"LLC013", "LLC014", "LST001" };
|
||||||
// Hue bulbs, spots, ...
|
// Hue bulbs, spots, ...
|
||||||
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
||||||
// Hue Lightstrip plus, go ...
|
// Hue Lightstrip plus, go ...
|
||||||
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
||||||
// Find id in the sets and set the appropiate color space.
|
// Find id in the sets and set the appropiate color space.
|
||||||
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.703f, 0.296f};
|
colorSpace.red = {0.703f, 0.296f};
|
||||||
colorSpace.green = {0.2151f, 0.7106f};
|
colorSpace.green = {0.2151f, 0.7106f};
|
||||||
colorSpace.blue = {0.138f, 0.08f};
|
colorSpace.blue = {0.138f, 0.08f};
|
||||||
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.675f, 0.322f};
|
colorSpace.red = {0.675f, 0.322f};
|
||||||
colorSpace.green = {0.4091f, 0.518f};
|
colorSpace.green = {0.4091f, 0.518f};
|
||||||
colorSpace.blue = {0.167f, 0.04f};
|
colorSpace.blue = {0.167f, 0.04f};
|
||||||
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||||
colorSpace.red = {0.675f, 0.322f};
|
colorSpace.red = {0.675f, 0.322f};
|
||||||
colorSpace.green = {0.2151f, 0.7106f};
|
colorSpace.green = {0.2151f, 0.7106f};
|
||||||
colorSpace.blue = {0.167f, 0.04f};
|
colorSpace.blue = {0.167f, 0.04f};
|
||||||
} else {
|
} else {
|
||||||
colorSpace.red = {1.0f, 0.0f};
|
colorSpace.red = {1.0f, 0.0f};
|
||||||
colorSpace.green = {0.0f, 1.0f};
|
colorSpace.green = {0.0f, 1.0f};
|
||||||
colorSpace.blue = {0.0f, 0.0f};
|
colorSpace.blue = {0.0f, 0.0f};
|
||||||
}
|
}
|
||||||
// Initialize black color.
|
// Initialize black color.
|
||||||
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
||||||
// Initialize color with black
|
// Initialize color with black
|
||||||
@ -254,11 +254,19 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
|||||||
// Use json parser to parse reponse.
|
// Use json parser to parse reponse.
|
||||||
Json::Reader reader;
|
Json::Reader reader;
|
||||||
Json::FastWriter writer;
|
Json::FastWriter writer;
|
||||||
// Create light ids if none supplied by the user.
|
// Read light ids if none have been supplied by the user.
|
||||||
if (lightIds.size() != nLights) {
|
if (lightIds.size() != nLights) {
|
||||||
lightIds.clear();
|
QByteArray response = get("lights");
|
||||||
for (unsigned int i = 0; i < nLights; i++) {
|
Json::Value json;
|
||||||
lightIds.push_back(i + 1);
|
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||||
|
throw std::runtime_error("No lights found");
|
||||||
|
}
|
||||||
|
// Loop over all children.
|
||||||
|
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() <= nLights; it++) {
|
||||||
|
int lightId = atoi(it.key().asCString());
|
||||||
|
lightIds.push_back(lightId);
|
||||||
|
std::cout << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): found light with id " << lightId
|
||||||
|
<< "." << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Iterate lights.
|
// Iterate lights.
|
||||||
@ -269,6 +277,8 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
|||||||
Json::Value json;
|
Json::Value json;
|
||||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||||
// Error occured, break loop.
|
// Error occured, break loop.
|
||||||
|
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights
|
||||||
|
<< "): got invalid response from light with id " << lightIds.at(i) << "." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Get state object values which are subject to change.
|
// Get state object values which are subject to change.
|
||||||
|
Loading…
Reference in New Issue
Block a user