mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added config options for username and transitiontime
Former-commit-id: 2ae179c670fda838115d985f40d970e10ef002ef
This commit is contained in:
parent
d106a9645c
commit
9d506b888d
@ -192,8 +192,10 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
else if (type == "philipshue")
|
||||
{
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
const std::string username = deviceConfig.get("username", "newdeveloper").asString();
|
||||
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
|
||||
device = new LedDevicePhilipsHue(output, switchOffOnBlack);
|
||||
const int transitiontime = deviceConfig.get("transitiontime", 4).asInt();
|
||||
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime);
|
||||
}
|
||||
else if (type == "test")
|
||||
{
|
||||
|
@ -132,8 +132,10 @@ CiColor PhilipsHueLamp::rgbToCiColor(float red, float green, float blue) {
|
||||
return xy;
|
||||
}
|
||||
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack) :
|
||||
host(output.c_str()), username("newdeveloper"), switchOffOnBlack(switchOffOnBlack) {
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack,
|
||||
int transitiontime) :
|
||||
host(output.c_str()), username(username.c_str()), switchOffOnBlack(switchOffOnBlack), transitiontime(
|
||||
transitiontime) {
|
||||
http = new QHttp(host);
|
||||
timer.setInterval(3000);
|
||||
timer.setSingleShot(true);
|
||||
@ -166,11 +168,13 @@ int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
|
||||
if (xy != lamp.color) {
|
||||
// Switch on if the lamp has been previously switched off.
|
||||
if (switchOffOnBlack && lamp.color == lamp.black) {
|
||||
|
||||
put(getStateRoute(lamp.id), QString("{\"on\": true}"));
|
||||
}
|
||||
// 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}").arg(xy.x).arg(xy.y).arg(qRound(xy.bri * 255.0f)));
|
||||
QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
|
||||
qRound(xy.bri * 255.0f)).arg(transitiontime));
|
||||
|
||||
}
|
||||
// Switch lamp off if switchOffOnBlack is enabled and the lamp is currently on.
|
||||
|
@ -125,9 +125,14 @@ public:
|
||||
///
|
||||
/// @param output the ip address of the bridge
|
||||
///
|
||||
/// @param switchOffOnBlack kill lights for black
|
||||
/// @param username username of the hue bridge (default: newdeveloper)
|
||||
///
|
||||
LedDevicePhilipsHue(const std::string& output, bool switchOffOnBlack);
|
||||
/// @param switchOffOnBlack kill lights for black (default: false)
|
||||
///
|
||||
/// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms).
|
||||
///
|
||||
LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack =
|
||||
false, int transitiontime = 4);
|
||||
|
||||
///
|
||||
/// Destructor of this device
|
||||
@ -163,6 +168,9 @@ private:
|
||||
QTimer timer;
|
||||
///
|
||||
bool switchOffOnBlack;
|
||||
/// 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;
|
||||
|
||||
///
|
||||
/// Sends a HTTP GET request (blocking).
|
||||
|
Loading…
Reference in New Issue
Block a user