Skip to content

Commit

Permalink
GitHub #47 - Renaming group commands to align closely with Hue docume…
Browse files Browse the repository at this point in the history
…ntation and light commands.
  • Loading branch information
sqmk committed Apr 3, 2013
1 parent 867b152 commit 29e0b4d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 58 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ $group->setColorTemp(300);
$group->setEffect('colorloop');
```

Just like the bulbs, each *set* method on the ```\Phue\Group``` object will send a request for each call. To minimize calls and to change multiple properties on the group at once, use the ```SetGroupAction``` command. The ```SetGroupAction``` command has all the options as ```SetLightState```.
Just like the bulbs, each *set* method on the ```\Phue\Group``` object will send a request for each call. To minimize calls and to change multiple properties on the group at once, use the ```SetGroupState``` command. The ```SetGroupState``` command has all the options as ```SetLightState```.

```php
// Retrieve group
$group = $client->getGroups()[1];

// Setting the brightness, color temp, and transition at the same time
$command = new \Phue\Command\SetGroupAction($group);
$command = new \Phue\Command\SetGroupState($group);
$command->brightness(200)
->colorTemp(500)
->transitionTime(0);
Expand Down Expand Up @@ -384,7 +384,7 @@ Retrievable commands will return an array or single instance of a ```\Phue\Sched

```php
// Create command to dim all lights
$groupCommand = new \Phue\Command\SetGroupAction(0);
$groupCommand = new \Phue\Command\SetGroupState(0);
$groupCommand->brightness(30);

// Create schedule command to run 10 seconds from now
Expand Down Expand Up @@ -420,7 +420,7 @@ $schedule->delete();

If you noticed in the above example, a ```Schedulable``` command must be passed to ```CreateSchedule```. The only commands that are schedulable are:
* ```SetLightState```
* ```SetGroupAction```
* ```SetGroupState```

### Other commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use Phue\Transport\TransportInterface;

/**
* Set group config command
* Set group attributes command
*/
class SetGroupConfig implements CommandInterface
class SetGroupAttributes implements CommandInterface
{
/**
* Group Id
Expand All @@ -25,11 +25,11 @@ class SetGroupConfig implements CommandInterface
protected $groupId;

/**
* Config parameters
* Group attributes
*
* @var array
*/
protected $params = [];
protected $attributes = [];

/**
* Constructs a command
Expand All @@ -50,7 +50,7 @@ public function __construct($group)
*/
public function name($name)
{
$this->params['name'] = (string) $name;
$this->attributes['name'] = (string) $name;

return $this;
}
Expand All @@ -70,7 +70,7 @@ public function lights(array $lights)
$lightList[] = (string) $light;
}

$this->params['lights'] = $lightList;
$this->attributes['lights'] = $lightList;

return $this;
}
Expand All @@ -85,7 +85,7 @@ public function send(Client $client)
$client->getTransport()->sendRequest(
"{$client->getUsername()}/groups/{$this->groupId}",
TransportInterface::METHOD_PUT,
(object) $this->params
(object) $this->attributes
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
/**
* Set group action command
*/
class SetGroupAction extends SetLightState implements
SchedulableInterface
class SetGroupState extends SetLightState implements SchedulableInterface
{
/**
* Group Id
Expand Down
22 changes: 11 additions & 11 deletions library/Phue/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Phue;

use Phue\Command\SetGroupConfig;
use Phue\Command\SetGroupAction;
use Phue\Command\SetGroupAttributes;
use Phue\Command\SetGroupState;
use Phue\Command\SetLightState;
use Phue\Command\DeleteGroup;

Expand Down Expand Up @@ -82,7 +82,7 @@ public function getName()
public function setName($name)
{
$this->client->sendCommand(
(new SetGroupConfig($this))->name((string) $name)
(new SetGroupAttributes($this))->name((string) $name)
);

$this->attributes->name = (string) $name;
Expand Down Expand Up @@ -116,7 +116,7 @@ public function setLights(array $lights)
}

$this->client->sendCommand(
(new SetGroupConfig($this))->lights($lightIds)
(new SetGroupAttributes($this))->lights($lightIds)
);

$this->attributes->lights = $lightIds;
Expand Down Expand Up @@ -144,7 +144,7 @@ public function isOn()
public function setOn($flag = true)
{
$this->client->sendCommand(
(new SetGroupAction($this))->on((bool) $flag)
(new SetGroupState($this))->on((bool) $flag)
);

$this->attributes->action->on = (bool) $flag;
Expand Down Expand Up @@ -172,7 +172,7 @@ public function getBrightness()
public function setBrightness($level = SetLightState::BRIGHTNESS_MAX)
{
$this->client->sendCommand(
(new SetGroupAction($this))->brightness((int) $level)
(new SetGroupState($this))->brightness((int) $level)
);

$this->attributes->action->bri = (int) $level;
Expand Down Expand Up @@ -200,7 +200,7 @@ public function getHue()
public function setHue($value)
{
$this->client->sendCommand(
(new SetGroupAction($this))->hue((int) $value)
(new SetGroupState($this))->hue((int) $value)
);

// Change both hue and color mode state
Expand Down Expand Up @@ -230,7 +230,7 @@ public function getSaturation()
public function setSaturation($value)
{
$this->client->sendCommand(
(new SetGroupAction($this))->saturation((int) $value)
(new SetGroupState($this))->saturation((int) $value)
);

// Change both saturation and color mode state
Expand Down Expand Up @@ -264,7 +264,7 @@ public function getXY()
public function setXY($x, $y)
{
$this->client->sendCommand(
(new SetGroupAction($this))->xy((float) $x, (float) $y)
(new SetGroupState($this))->xy((float) $x, (float) $y)
);

// Change both internal xy and colormode state
Expand Down Expand Up @@ -294,7 +294,7 @@ public function getColorTemp()
public function setColorTemp($value)
{
$this->client->sendCommand(
(new SetGroupAction($this))->colorTemp((int) $value)
(new SetGroupState($this))->colorTemp((int) $value)
);

// Change both internal color temp and colormode state
Expand Down Expand Up @@ -324,7 +324,7 @@ public function getEffect()
public function setEffect($mode = SetLightState::EFFECT_NONE)
{
$this->client->sendCommand(
(new SetGroupAction($this))->effect($mode)
(new SetGroupState($this))->effect($mode)
);

$this->attributes->action->effect = $mode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace PhueTest\Command;

use Phue\Command\SetGroupConfig;
use Phue\Command\SetGroupAttributes;
use Phue\Client;
use Phue\Transport\TransportInterface;

/**
* Tests for Phue\Command\SetGroupConfig
* Tests for Phue\Command\SetGroupAttributes
*/
class SetGroupConfigTest extends \PHPUnit_Framework_TestCase
class SetGroupAttributesTest extends \PHPUnit_Framework_TestCase
{
/**
* Set up
Expand Down Expand Up @@ -57,15 +57,15 @@ public function setUp()
/**
* Test: Send command
*
* @covers \Phue\Command\SetGroupConfig::__construct
* @covers \Phue\Command\SetGroupConfig::name
* @covers \Phue\Command\SetGroupConfig::lights
* @covers \Phue\Command\SetGroupConfig::send
* @covers \Phue\Command\SetGroupAttributes::__construct
* @covers \Phue\Command\SetGroupAttributes::name
* @covers \Phue\Command\SetGroupAttributes::lights
* @covers \Phue\Command\SetGroupAttributes::send
*/
public function testSend()
{
// Build command
$setGroupConfigCmd = new SetGroupConfig($this->mockGroup);
$setGroupAttributesCmd = new SetGroupAttributes($this->mockGroup);

// Set expected payload
$this->stubTransportSendRequestWithPayload(
Expand All @@ -76,9 +76,9 @@ public function testSend()
);

// Change name and lights
$setGroupConfigCmd->name('Dummy!')
->lights([3])
->send($this->mockClient);
$setGroupAttributesCmd->name('Dummy!')
->lights([3])
->send($this->mockClient);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace PhueTest\Command;

use Phue\Command\SetGroupAction;
use Phue\Command\SetGroupState;
use Phue\Client;
use Phue\Transport\TransportInterface;

/**
* Tests for Phue\Command\SetGroupAction
* Tests for Phue\Command\SetGroupState
*/
class SetGroupActionTest extends \PHPUnit_Framework_TestCase
class SetGroupStateTest extends \PHPUnit_Framework_TestCase
{
/**
* Set up
Expand Down Expand Up @@ -57,13 +57,13 @@ public function setUp()
/**
* Test: Send command
*
* @covers \Phue\Command\SetGroupAction::__construct
* @covers \Phue\Command\SetGroupAction::send
* @covers \Phue\Command\SetGroupState::__construct
* @covers \Phue\Command\SetGroupState::send
*/
public function testSend()
{
// Build command
$setGroupActionCmd = new SetGroupAction($this->mockGroup);
$setGroupStateCmd = new SetGroupState($this->mockGroup);

// Set expected payload
$this->stubTransportSendRequestWithPayload(
Expand All @@ -73,26 +73,26 @@ public function testSend()
);

// Change color temp and set state
$setGroupActionCmd->colorTemp(300)
->send($this->mockClient);
$setGroupStateCmd->colorTemp(300)
->send($this->mockClient);
}

/**
* Test: Get schedulable params
*
* @covers \Phue\Command\SetGroupAction::getSchedulableParams
* @covers \Phue\Command\SetGroupState::getSchedulableParams
*/
public function testGetSchedulableParams()
{
// Build command
$setGroupActionCmd = new SetGroupAction($this->mockGroup);
$setGroupStateCmd = new SetGroupState($this->mockGroup);

// Change alert
$setGroupActionCmd->alert('select');
$setGroupStateCmd->alert('select');

// Ensure schedulable params are expected
$this->assertEquals(
$setGroupActionCmd->getSchedulableParams($this->mockClient),
$setGroupStateCmd->getSchedulableParams($this->mockClient),
[
'address' => "{$this->mockClient->getUsername()}/groups/{$this->mockGroup->getId()}/action",
'method' => 'PUT',
Expand Down
Loading

0 comments on commit 29e0b4d

Please sign in to comment.