Skip to content

Commit

Permalink
* -a lets users change a light's name.
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Aug 3, 2013
1 parent 245d847 commit 483eeb0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions huecli.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function echoHelp()
"\n\t-o [0 for turning the light off, 1 for turning it on]".
"\n\t-r [transition time, in seconds. Decimals are legal (\".1\", for instance)]".
"\n\t-n [color name (see below)]".
"\n\t-a [new name for the light]".
"\n\t-e [command to execute before changing light setting]\n";
}

Expand All @@ -42,8 +43,8 @@ function echoLightState( $lights )
return $state;
}

$args = getopt( 'i:k:l:h:s:b:t:o:r:n:e:cfg' );
$oneParamSet = isset( $args['h'] ) || isset( $args['s'] ) || isset( $args['b'] ) || isset( $args['t'] ) || isset( $args['o'] ) || isset( $args['n'] ) || isset( $args['f'] ) || isset( $args['c'] );
$args = getopt( 'i:k:l:h:s:b:t:o:r:n:e:a:cfg' );
$oneParamSet = isset( $args['h'] ) || isset( $args['s'] ) || isset( $args['b'] ) || isset( $args['t'] ) || isset( $args['o'] ) || isset( $args['n'] ) || isset( $args['f'] ) || isset( $args['c'] ) || isset( $args['a'] );
$command = array();

if ( isset( $args['i'] ) && isset( $args['g'] ) )
Expand All @@ -67,7 +68,7 @@ function echoLightState( $lights )
// we require a bridge ip and key to be specified
if ( !isset( $args['i'] ) || !isset( $args['k'] ) || !$oneParamSet )
{
$oneParamHelp = $oneParamSet ? "" : " and at least one of the following options: -f, -c, -h, -s, -b, -t, -o or -n";
$oneParamHelp = $oneParamSet ? "" : " and at least one of the following options: -f, -c, -h, -s, -b, -t, -o, -n or -a";
echo "Error: You need to specify an ip (-i) & key (-k)$oneParamHelp.\n\n";

echoHelp();
Expand All @@ -91,6 +92,19 @@ function echoLightState( $lights )
else
$lights[] = $args['l'];

if ( isset( $args['a'] ) )
{
if ( count( $lights ) != 1 )
{
echo "Error: -a must be invoked with exactly one light (-l).";
exit( 0 );
}

$hue->lights()[$lights[0]]->setName( $args['a'] );
echoLightState( $lights );
exit( 0 );
}

// do we want to get the lights' state
if ( isset( $args['c'] ) )
{
Expand Down

0 comments on commit 483eeb0

Please sign in to comment.