Skip to content

Commit

Permalink
Merge pull request #112 from KarimGeiger/feature/extend_light_interface
Browse files Browse the repository at this point in the history
Extend Group and Light from LightInterface
  • Loading branch information
sqmk authored Oct 17, 2016
2 parents b94bc8c + 3f510b7 commit 1a389ae
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 25 deletions.
48 changes: 24 additions & 24 deletions library/Phue/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Group object
*/
class Group
class Group implements LightInterface
{

/**
Expand Down Expand Up @@ -99,9 +99,9 @@ public function setName($name)
$x = new SetGroupAttributes($this);
$y = $x->name((string) $name);
$this->client->sendCommand($y);

$this->attributes->name = (string) $name;

return $this;
}

Expand All @@ -126,17 +126,17 @@ public function getLightIds()
public function setLights(array $lights)
{
$lightIds = array();

foreach ($lights as $light) {
$lightIds[] = (string) $light;
}

$x = new SetGroupAttributes($this);
$y = $x->lights($lightIds);
$this->client->sendCommand($y);

$this->attributes->lights = $lightIds;

return $this;
}

Expand All @@ -163,9 +163,9 @@ public function setOn($flag = true)
$x = new SetGroupState($this);
$y = $x->on((bool) $flag);
$this->client->sendCommand($y);

$this->attributes->action->on = (bool) $flag;

return $this;
}

Expand Down Expand Up @@ -194,8 +194,8 @@ public function setAlert($mode = SetLightState::ALERT_LONG_SELECT)
$this->attributes->action->alert = $mode;
return $this;
}


/**
* Get brightness
*
Expand All @@ -219,9 +219,9 @@ public function setBrightness($level = SetLightState::BRIGHTNESS_MAX)
$x = new SetGroupState($this);
$y = $x->brightness((int) $level);
$this->client->sendCommand($y);

$this->attributes->action->bri = (int) $level;

return $this;
}

Expand All @@ -248,11 +248,11 @@ public function setHue($value)
$x = new SetGroupState($this);
$y = $x->hue((int) $value);
$this->client->sendCommand($y);

// Change both hue and color mode state
$this->attributes->action->hue = (int) $value;
$this->attributes->action->colormode = 'hs';

return $this;
}

Expand All @@ -279,11 +279,11 @@ public function setSaturation($value)
$x = new SetGroupState($this);
$y = $x->saturation((int) $value);
$this->client->sendCommand($y);

// Change both saturation and color mode state
$this->attributes->action->sat = (int) $value;
$this->attributes->action->colormode = 'hs';

return $this;
}

Expand Down Expand Up @@ -319,14 +319,14 @@ public function setXY($x, $y)
$_x = new SetGroupState($this);
$_y = $_x->xy((float) $x, (float) $y);
$this->client->sendCommand($_y);

// Change both internal xy and colormode state
$this->attributes->action->xy = array(
$x,
$y
);
$this->attributes->action->colormode = 'xy';

return $this;
}

Expand All @@ -353,11 +353,11 @@ public function setColorTemp($value)
$x = new SetGroupState($this);
$y = $x->colorTemp((int) $value);
$this->client->sendCommand($y);

// Change both internal color temp and colormode state
$this->attributes->action->ct = (int) $value;
$this->attributes->action->colormode = 'ct';

return $this;
}

Expand All @@ -384,9 +384,9 @@ public function setEffect($mode = SetLightState::EFFECT_NONE)
$x = new SetGroupState($this);
$y = $x->effect($mode);
$this->client->sendCommand($y);

$this->attributes->action->effect = $mode;

return $this;
}

Expand All @@ -413,7 +413,7 @@ public function setScene($scene)
$x = new SetGroupState($this);
$y = $x->scene((string) $scene);
$this->client->sendCommand($y);

return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Phue/Light.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Light object
*/
class Light
class Light implements LightInterface
{
/**
* Id
Expand Down
191 changes: 191 additions & 0 deletions library/Phue/LightInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php
/**
* Phue: Philips Hue PHP Client
*
* @author Karim Geiger <geiger@karim.email>
* @copyright Copyright (c) 2016 Michael K. Squires
* @license http://github.com/sqmk/Phue/wiki/License
*/
namespace Phue;

use Phue\Command\SetLightState;

/**
* Interface for lights and groups.
*/
interface LightInterface
{
/**
* Get light or group Id
*
* @return int Light/Group id
*/
public function getId();

/**
* Get assigned name of light or group
*
* @return string Name of light/group
*/
public function getName();

/**
* Set name of light/group
*
* @param string $name
*
* @return \Phue\LightInterface
*/
public function setName($name);

/**
* Get type
*
* @return string Type
*/
public function getType();

/**
* Is the light or group on?
*
* @return bool True if on, false if not
*/
public function isOn();

/**
* Set light or group on/off
*
* @param bool $flag
* True for on, false for off
*
* @return \Phue\LightInterface
*/
public function setOn($flag = true);

/**
* Get alert
*
* @return string Alert mode
*/
public function getAlert();

/**
* Set light or group alert
*
* @param string $mode
* Alert mode
*
* @return \Phue\LightInterface
*/
public function setAlert($mode = SetLightState::ALERT_LONG_SELECT);

/**
* Get effect mode
*
* @return string effect mode
*/
public function getEffect();

/**
* Set effect
*
* @param string $mode
* Effect mode
*
* @return \Phue\LightInterface
*/
public function setEffect($mode = SetLightState::EFFECT_NONE);

/**
* Get brightness
*
* @return int Brightness level
*/
public function getBrightness();

/**
* Set brightness
*
* @param int $level
* Brightness level
*
* @return \Phue\LightInterface
*/
public function setBrightness($level = SetLightState::BRIGHTNESS_MAX);

/**
* Get hue
*
* @return int Hue value
*/
public function getHue();

/**
* Set hue
*
* @param int $value
* Hue value
*
* @return \Phue\LightInterface
*/
public function setHue($value);

/**
* Get saturation
*
* @return int Saturation value
*/
public function getSaturation();

/**
* Set saturation
*
* @param int $value
* Saturation value
*
* @return \Phue\LightInterface
*/
public function setSaturation($value);

/**
* Get XY
*
* @return array X, Y key/value
*/
public function getXY();

/**
* Set XY
*
* @param float $x
* X value
* @param float $y
* Y value
*
* @return \Phue\LightInterface
*/
public function setXY($x, $y);

/**
* Get Color temperature
*
* @return int Color temperature value
*/
public function getColorTemp();

/**
* Set Color temperature
*
* @param int $value Color temperature value
*
* @return \Phue\LightInterface
*/
public function setColorTemp($value);

/**
* Get color mode of light
*
* @return string Color mode
*/
public function getColorMode();
}

0 comments on commit 1a389ae

Please sign in to comment.