Skip to content

Commit

Permalink
Add missing setRGB and getRGB functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbey authored Nov 14, 2016
1 parent db67f88 commit 8ec46ff
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions library/Phue/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,47 @@ public function setXY($x, $y)
return $this;
}

/**
* Get calculated RGB
*
* @return array red, green, blue key/value
*/
public function getRGB()
{
$xy = $this->getXY();
$bri = $this->getBrightness();
$rgb = ColorConversion::convertXYToRGB($xy['x'], $xy['y'], $bri);

return $rgb;
}

/**
* Set XY and brightness calculated from RGB
*
* @param int $red Red value
* @param int $green Green value
* @param int $blue Blue value
*
* @return self This object
*/
public function setRGB($red, $green, $blue)
{
$x = new SetGroupState($this);
$y = $x->rgb((int) $red, (int) $green, (int) $blue);
$this->client->sendCommand($y);

// Change internal xy, brightness and colormode state
$xy = ColorConversion::convertRGBToXY($red, $green, $blue);
$this->attributes->action->xy = array(
$xy['x'],
$xy['y']
);
$this->attributes->action->bri = $xy['bri'];
$this->attributes->action->colormode = 'xy';

return $this;
}

/**
* Get Color temperature
*
Expand Down

0 comments on commit 8ec46ff

Please sign in to comment.