mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added light ids to device config.
Former-commit-id: 601616b0d7509b0e8ebb5226f00af5028fa905b5
This commit is contained in:
parent
acc0f61e60
commit
ecea6e55ea
@ -196,7 +196,11 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
const std::string username = deviceConfig.get("username", "newdeveloper").asString();
|
||||
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
|
||||
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
||||
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime);
|
||||
std::vector<unsigned int> lightIds;
|
||||
for (size_t i = 0; i < deviceConfig["lightIds"].size(); i++) {
|
||||
lightIds.push_back(deviceConfig["lightIds"][i].asInt());
|
||||
}
|
||||
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime, lightIds);
|
||||
}
|
||||
else if (type == "test")
|
||||
{
|
||||
|
@ -133,9 +133,9 @@ CiColor PhilipsHueLamp::rgbToCiColor(float red, float green, float blue) {
|
||||
}
|
||||
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack,
|
||||
int transitiontime) :
|
||||
int transitiontime, std::vector<unsigned int> lightIds) :
|
||||
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
|
||||
transitiontime) {
|
||||
transitiontime), lightIds(lightIds) {
|
||||
http = new QHttp(host);
|
||||
timer.setInterval(3000);
|
||||
timer.setSingleShot(true);
|
||||
@ -251,10 +251,17 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||
// Use json parser to parse reponse.
|
||||
Json::Reader reader;
|
||||
Json::FastWriter writer;
|
||||
// Create light ids if none supplied by the user.
|
||||
if (lightIds.size() != nLights) {
|
||||
lightIds.clear();
|
||||
for (unsigned int i = 0; i < nLights; i++) {
|
||||
lightIds.push_back(i + 1);
|
||||
}
|
||||
}
|
||||
// Iterate lights.
|
||||
for (unsigned int i = 0; i < nLights; i++) {
|
||||
// Read the response.
|
||||
QByteArray response = get(getRoute(i + 1));
|
||||
QByteArray response = get(getRoute(lightIds.at(i)));
|
||||
// Parse JSON.
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||
@ -272,7 +279,7 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||
QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "");
|
||||
QString originalState = QString(writer.write(state).c_str()).trimmed();
|
||||
// Save state object.
|
||||
lamps.push_back(PhilipsHueLamp(i + 1, originalState, modelId));
|
||||
lamps.push_back(PhilipsHueLamp(lightIds.at(i), originalState, modelId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,10 @@ public:
|
||||
///
|
||||
/// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms).
|
||||
///
|
||||
/// @param lightIds light ids of the lights to control if not starting at one in ascending order.
|
||||
///
|
||||
LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack =
|
||||
false, int transitiontime = 1);
|
||||
false, int transitiontime = 1, std::vector<unsigned int> lightIds = {});
|
||||
|
||||
///
|
||||
/// Destructor of this device
|
||||
@ -171,6 +173,8 @@ private:
|
||||
/// Transition time in multiples of 100 ms.
|
||||
/// The default of the Hue lights will be 400 ms, but we want to have it snapier
|
||||
int transitiontime;
|
||||
/// Array of the light ids.
|
||||
std::vector<unsigned int> lightIds;
|
||||
|
||||
///
|
||||
/// Sends a HTTP GET request (blocking).
|
||||
|
Loading…
Reference in New Issue
Block a user