forked from danray0424/phpHue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorset.php
executable file
·53 lines (41 loc) · 1.17 KB
/
colorset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/php
<?php
require("hue.php");
$args = getopt('l:h:s:b:t:o:r:n:');
$command = array();
// if we didn't get a -l parameter, build an array of all lights
if (isset($args['l'])) {
$light = $args['l'];
} else {
$light = getLightIdsList();
}
//handle predefined colors
if (isset($args['n'])) {
$command = predefinedColors($args['n']);
}
// clean up other inputs
// the hue interface will keep numeric parms within range for us, just sanitize the
// types for clean json encoding, and do the math on the hue input.
$fields = array('h' => 'hue', 's' => 'sat', 'b' => 'bri',
't' => 'ct', 'o' => 'on', 'r' => 'transitiontime');
foreach ($fields as $name => $value) {
if (isset($args[$name])) {
if ($name == 'o') {
$command[$value] = (bool)$args[$name];
}
elseif ($name == 'h'){
$command['hue'] = 182 * $args['h'];
$command['on'] = true;
}
elseif ($name == 'r') {
$command['transitiontime'] = 10 * $args['r'];
}
else {
$command[$value] = (int)$args[$name];
$command['on'] = true;
}
}
}
$result = setLight($light, $command);
//echo "$result\n";
?>