Skip to content

Commit

Permalink
- Add the possibility to update transition time on light object (befo…
Browse files Browse the repository at this point in the history
…re setRGB or other set command).
  • Loading branch information
neoteknic committed May 17, 2018
1 parent 91ddd13 commit aaaf427
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions library/Phue/Light.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Light implements LightInterface
*/
protected $client;

protected $transition;

/**
* Construct a Phue Light object
*
Expand All @@ -54,6 +56,7 @@ public function __construct($id, \stdClass $attributes, Client $client)
$this->id = (int) $id;
$this->attributes = $attributes;
$this->client = $client;
$this->transition=null;
}

/**
Expand Down Expand Up @@ -164,6 +167,7 @@ public function setOn($flag = true)
{
$x = new SetLightState($this);
$y = $x->on((bool) $flag);
$this->updateTransition($x);
$this->client->sendCommand($y);

$this->attributes->state->on = (bool) $flag;
Expand Down Expand Up @@ -193,6 +197,7 @@ public function setAlert($mode = SetLightState::ALERT_LONG_SELECT)
{
$x = new SetLightState($this);
$y = $x->alert($mode);
$this->updateTransition($x);
$this->client->sendCommand($y);

$this->attributes->state->alert = $mode;
Expand Down Expand Up @@ -222,6 +227,7 @@ public function setEffect($mode = SetLightState::EFFECT_NONE)
{
$x = new SetLightState($this);
$y = $x->effect($mode);
$this->updateTransition($x);
$this->client->sendCommand($y);

$this->attributes->state->effect = $mode;
Expand Down Expand Up @@ -251,6 +257,7 @@ public function setBrightness($level = SetLightState::BRIGHTNESS_MAX)
{
$x = new SetLightState($this);
$y = $x->brightness((int) $level);
$this->updateTransition($x);
$this->client->sendCommand($y);

$this->attributes->state->bri = (int) $level;
Expand Down Expand Up @@ -280,6 +287,7 @@ public function setHue($value)
{
$x = new SetLightState($this);
$y = $x->hue((int) $value);
$this->updateTransition($x);
$this->client->sendCommand($y);

// Change both hue and color mode state
Expand Down Expand Up @@ -311,6 +319,7 @@ public function setSaturation($value)
{
$x = new SetLightState($this);
$y = $x->saturation((int) $value);
$this->updateTransition($x);
$this->client->sendCommand($y);

// Change both saturation and color mode state
Expand Down Expand Up @@ -347,6 +356,7 @@ public function setXY($x, $y)
{
$_x = new SetLightState($this);
$_y = $_x->xy((float) $x, (float) $y);
$this->updateTransition($_x);
$this->client->sendCommand($_y);

// Change both internal xy and colormode state
Expand Down Expand Up @@ -386,6 +396,7 @@ public function setRGB($red, $green, $blue)
{
$x = new SetLightState($this);
$y = $x->rgb((int) $red, (int) $green, (int) $blue);
$this->updateTransition($x);
$this->client->sendCommand($y);

// Change internal xy, brightness and colormode state
Expand All @@ -400,6 +411,21 @@ public function setRGB($red, $green, $blue)
return $this;
}

/**
* @param $time float Seconds
*/
public function setTransition($time)
{
$this->transition=$time;
}

private function updateTransition(SetLightState $x)
{
if($this->transition!==null){
$x->transitionTime($this->transition);
}
}

/**
* Get Color temperature
*
Expand Down

0 comments on commit aaaf427

Please sign in to comment.