Skip to content
This repository
Browse code

GitHub #47 - Renaming group commands to align closely with Hue docume…

…ntation and light commands.
  • Loading branch information...
commit 29e0b4d4f63566275fc08e6f2b8ac0868b5640f0 1 parent 867b152
Michael Squires authored
8 README.md
Source Rendered
@@ -333,14 +333,14 @@ $group->setColorTemp(300);
333 333 $group->setEffect('colorloop');
334 334 ```
335 335
336   -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```.
  336 +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```.
337 337
338 338 ```php
339 339 // Retrieve group
340 340 $group = $client->getGroups()[1];
341 341
342 342 // Setting the brightness, color temp, and transition at the same time
343   -$command = new \Phue\Command\SetGroupAction($group);
  343 +$command = new \Phue\Command\SetGroupState($group);
344 344 $command->brightness(200)
345 345 ->colorTemp(500)
346 346 ->transitionTime(0);
@@ -384,7 +384,7 @@ Retrievable commands will return an array or single instance of a ```\Phue\Sched
384 384
385 385 ```php
386 386 // Create command to dim all lights
387   -$groupCommand = new \Phue\Command\SetGroupAction(0);
  387 +$groupCommand = new \Phue\Command\SetGroupState(0);
388 388 $groupCommand->brightness(30);
389 389
390 390 // Create schedule command to run 10 seconds from now
@@ -420,7 +420,7 @@ $schedule->delete();
420 420
421 421 If you noticed in the above example, a ```Schedulable``` command must be passed to ```CreateSchedule```. The only commands that are schedulable are:
422 422 * ```SetLightState```
423   -* ```SetGroupAction```
  423 +* ```SetGroupState```
424 424
425 425 ### Other commands
426 426
14 library/Phue/Command/SetGroupConfig.php → library/Phue/Command/SetGroupAttributes.php
@@ -13,9 +13,9 @@
13 13 use Phue\Transport\TransportInterface;
14 14
15 15 /**
16   - * Set group config command
  16 + * Set group attributes command
17 17 */
18   -class SetGroupConfig implements CommandInterface
  18 +class SetGroupAttributes implements CommandInterface
19 19 {
20 20 /**
21 21 * Group Id
@@ -25,11 +25,11 @@ class SetGroupConfig implements CommandInterface
25 25 protected $groupId;
26 26
27 27 /**
28   - * Config parameters
  28 + * Group attributes
29 29 *
30 30 * @var array
31 31 */
32   - protected $params = [];
  32 + protected $attributes = [];
33 33
34 34 /**
35 35 * Constructs a command
@@ -50,7 +50,7 @@ public function __construct($group)
50 50 */
51 51 public function name($name)
52 52 {
53   - $this->params['name'] = (string) $name;
  53 + $this->attributes['name'] = (string) $name;
54 54
55 55 return $this;
56 56 }
@@ -70,7 +70,7 @@ public function lights(array $lights)
70 70 $lightList[] = (string) $light;
71 71 }
72 72
73   - $this->params['lights'] = $lightList;
  73 + $this->attributes['lights'] = $lightList;
74 74
75 75 return $this;
76 76 }
@@ -85,7 +85,7 @@ public function send(Client $client)
85 85 $client->getTransport()->sendRequest(
86 86 "{$client->getUsername()}/groups/{$this->groupId}",
87 87 TransportInterface::METHOD_PUT,
88   - (object) $this->params
  88 + (object) $this->attributes
89 89 );
90 90 }
91 91 }
3  library/Phue/Command/SetGroupAction.php → library/Phue/Command/SetGroupState.php
@@ -15,8 +15,7 @@
15 15 /**
16 16 * Set group action command
17 17 */
18   -class SetGroupAction extends SetLightState implements
19   - SchedulableInterface
  18 +class SetGroupState extends SetLightState implements SchedulableInterface
20 19 {
21 20 /**
22 21 * Group Id
22 library/Phue/Group.php
@@ -9,8 +9,8 @@
9 9
10 10 namespace Phue;
11 11
12   -use Phue\Command\SetGroupConfig;
13   -use Phue\Command\SetGroupAction;
  12 +use Phue\Command\SetGroupAttributes;
  13 +use Phue\Command\SetGroupState;
14 14 use Phue\Command\SetLightState;
15 15 use Phue\Command\DeleteGroup;
16 16
@@ -82,7 +82,7 @@ public function getName()
82 82 public function setName($name)
83 83 {
84 84 $this->client->sendCommand(
85   - (new SetGroupConfig($this))->name((string) $name)
  85 + (new SetGroupAttributes($this))->name((string) $name)
86 86 );
87 87
88 88 $this->attributes->name = (string) $name;
@@ -116,7 +116,7 @@ public function setLights(array $lights)
116 116 }
117 117
118 118 $this->client->sendCommand(
119   - (new SetGroupConfig($this))->lights($lightIds)
  119 + (new SetGroupAttributes($this))->lights($lightIds)
120 120 );
121 121
122 122 $this->attributes->lights = $lightIds;
@@ -144,7 +144,7 @@ public function isOn()
144 144 public function setOn($flag = true)
145 145 {
146 146 $this->client->sendCommand(
147   - (new SetGroupAction($this))->on((bool) $flag)
  147 + (new SetGroupState($this))->on((bool) $flag)
148 148 );
149 149
150 150 $this->attributes->action->on = (bool) $flag;
@@ -172,7 +172,7 @@ public function getBrightness()
172 172 public function setBrightness($level = SetLightState::BRIGHTNESS_MAX)
173 173 {
174 174 $this->client->sendCommand(
175   - (new SetGroupAction($this))->brightness((int) $level)
  175 + (new SetGroupState($this))->brightness((int) $level)
176 176 );
177 177
178 178 $this->attributes->action->bri = (int) $level;
@@ -200,7 +200,7 @@ public function getHue()
200 200 public function setHue($value)
201 201 {
202 202 $this->client->sendCommand(
203   - (new SetGroupAction($this))->hue((int) $value)
  203 + (new SetGroupState($this))->hue((int) $value)
204 204 );
205 205
206 206 // Change both hue and color mode state
@@ -230,7 +230,7 @@ public function getSaturation()
230 230 public function setSaturation($value)
231 231 {
232 232 $this->client->sendCommand(
233   - (new SetGroupAction($this))->saturation((int) $value)
  233 + (new SetGroupState($this))->saturation((int) $value)
234 234 );
235 235
236 236 // Change both saturation and color mode state
@@ -264,7 +264,7 @@ public function getXY()
264 264 public function setXY($x, $y)
265 265 {
266 266 $this->client->sendCommand(
267   - (new SetGroupAction($this))->xy((float) $x, (float) $y)
  267 + (new SetGroupState($this))->xy((float) $x, (float) $y)
268 268 );
269 269
270 270 // Change both internal xy and colormode state
@@ -294,7 +294,7 @@ public function getColorTemp()
294 294 public function setColorTemp($value)
295 295 {
296 296 $this->client->sendCommand(
297   - (new SetGroupAction($this))->colorTemp((int) $value)
  297 + (new SetGroupState($this))->colorTemp((int) $value)
298 298 );
299 299
300 300 // Change both internal color temp and colormode state
@@ -324,7 +324,7 @@ public function getEffect()
324 324 public function setEffect($mode = SetLightState::EFFECT_NONE)
325 325 {
326 326 $this->client->sendCommand(
327   - (new SetGroupAction($this))->effect($mode)
  327 + (new SetGroupState($this))->effect($mode)
328 328 );
329 329
330 330 $this->attributes->action->effect = $mode;
22 tests/PhueTest/Command/SetGroupConfigTest.php → tests/PhueTest/Command/SetGroupAttributesTest.php
@@ -9,14 +9,14 @@
9 9
10 10 namespace PhueTest\Command;
11 11
12   -use Phue\Command\SetGroupConfig;
  12 +use Phue\Command\SetGroupAttributes;
13 13 use Phue\Client;
14 14 use Phue\Transport\TransportInterface;
15 15
16 16 /**
17   - * Tests for Phue\Command\SetGroupConfig
  17 + * Tests for Phue\Command\SetGroupAttributes
18 18 */
19   -class SetGroupConfigTest extends \PHPUnit_Framework_TestCase
  19 +class SetGroupAttributesTest extends \PHPUnit_Framework_TestCase
20 20 {
21 21 /**
22 22 * Set up
@@ -57,15 +57,15 @@ public function setUp()
57 57 /**
58 58 * Test: Send command
59 59 *
60   - * @covers \Phue\Command\SetGroupConfig::__construct
61   - * @covers \Phue\Command\SetGroupConfig::name
62   - * @covers \Phue\Command\SetGroupConfig::lights
63   - * @covers \Phue\Command\SetGroupConfig::send
  60 + * @covers \Phue\Command\SetGroupAttributes::__construct
  61 + * @covers \Phue\Command\SetGroupAttributes::name
  62 + * @covers \Phue\Command\SetGroupAttributes::lights
  63 + * @covers \Phue\Command\SetGroupAttributes::send
64 64 */
65 65 public function testSend()
66 66 {
67 67 // Build command
68   - $setGroupConfigCmd = new SetGroupConfig($this->mockGroup);
  68 + $setGroupAttributesCmd = new SetGroupAttributes($this->mockGroup);
69 69
70 70 // Set expected payload
71 71 $this->stubTransportSendRequestWithPayload(
@@ -76,9 +76,9 @@ public function testSend()
76 76 );
77 77
78 78 // Change name and lights
79   - $setGroupConfigCmd->name('Dummy!')
80   - ->lights([3])
81   - ->send($this->mockClient);
  79 + $setGroupAttributesCmd->name('Dummy!')
  80 + ->lights([3])
  81 + ->send($this->mockClient);
82 82 }
83 83
84 84 /**
24 tests/PhueTest/Command/SetGroupActionTest.php → tests/PhueTest/Command/SetGroupStateTest.php
@@ -9,14 +9,14 @@
9 9
10 10 namespace PhueTest\Command;
11 11
12   -use Phue\Command\SetGroupAction;
  12 +use Phue\Command\SetGroupState;
13 13 use Phue\Client;
14 14 use Phue\Transport\TransportInterface;
15 15
16 16 /**
17   - * Tests for Phue\Command\SetGroupAction
  17 + * Tests for Phue\Command\SetGroupState
18 18 */
19   -class SetGroupActionTest extends \PHPUnit_Framework_TestCase
  19 +class SetGroupStateTest extends \PHPUnit_Framework_TestCase
20 20 {
21 21 /**
22 22 * Set up
@@ -57,13 +57,13 @@ public function setUp()
57 57 /**
58 58 * Test: Send command
59 59 *
60   - * @covers \Phue\Command\SetGroupAction::__construct
61   - * @covers \Phue\Command\SetGroupAction::send
  60 + * @covers \Phue\Command\SetGroupState::__construct
  61 + * @covers \Phue\Command\SetGroupState::send
62 62 */
63 63 public function testSend()
64 64 {
65 65 // Build command
66   - $setGroupActionCmd = new SetGroupAction($this->mockGroup);
  66 + $setGroupStateCmd = new SetGroupState($this->mockGroup);
67 67
68 68 // Set expected payload
69 69 $this->stubTransportSendRequestWithPayload(
@@ -73,26 +73,26 @@ public function testSend()
73 73 );
74 74
75 75 // Change color temp and set state
76   - $setGroupActionCmd->colorTemp(300)
77   - ->send($this->mockClient);
  76 + $setGroupStateCmd->colorTemp(300)
  77 + ->send($this->mockClient);
78 78 }
79 79
80 80 /**
81 81 * Test: Get schedulable params
82 82 *
83   - * @covers \Phue\Command\SetGroupAction::getSchedulableParams
  83 + * @covers \Phue\Command\SetGroupState::getSchedulableParams
84 84 */
85 85 public function testGetSchedulableParams()
86 86 {
87 87 // Build command
88   - $setGroupActionCmd = new SetGroupAction($this->mockGroup);
  88 + $setGroupStateCmd = new SetGroupState($this->mockGroup);
89 89
90 90 // Change alert
91   - $setGroupActionCmd->alert('select');
  91 + $setGroupStateCmd->alert('select');
92 92
93 93 // Ensure schedulable params are expected
94 94 $this->assertEquals(
95   - $setGroupActionCmd->getSchedulableParams($this->mockClient),
  95 + $setGroupStateCmd->getSchedulableParams($this->mockClient),
96 96 [
97 97 'address' => "{$this->mockClient->getUsername()}/groups/{$this->mockGroup->getId()}/action",
98 98 'method' => 'PUT',
22 tests/PhueTest/GroupTest.php
@@ -88,7 +88,7 @@ public function testSetName()
88 88 // Stub client's sendCommand method
89 89 $this->mockClient->expects($this->once())
90 90 ->method('sendCommand')
91   - ->with($this->isInstanceOf('\Phue\Command\SetGroupConfig'))
  91 + ->with($this->isInstanceOf('\Phue\Command\SetGroupAttributes'))
92 92 ->will($this->returnValue($this->group));
93 93
94 94 // Ensure setName returns self
@@ -128,7 +128,7 @@ public function testSetLights()
128 128 // Stub client's sendCommand method
129 129 $this->mockClient->expects($this->once())
130 130 ->method('sendCommand')
131   - ->with($this->isInstanceOf('\Phue\Command\SetGroupConfig'))
  131 + ->with($this->isInstanceOf('\Phue\Command\SetGroupAttributes'))
132 132 ->will($this->returnValue($this->group));
133 133
134 134 // Ensure setLights return self
@@ -152,7 +152,7 @@ public function testSetLights()
152 152 */
153 153 public function testIsSetOn()
154 154 {
155   - $this->stubMockClientSendSetGroupActionCommand();
  155 + $this->stubMockClientSendSetGroupStateCommand();
156 156
157 157 // Make sure original on action is retrievable
158 158 $this->assertFalse($this->group->isOn());
@@ -175,7 +175,7 @@ public function testIsSetOn()
175 175 */
176 176 public function testGetSetBrightness()
177 177 {
178   - $this->stubMockClientSendSetGroupActionCommand();
  178 + $this->stubMockClientSendSetGroupStateCommand();
179 179
180 180 // Make sure original brightness is retrievable
181 181 $this->assertEquals(
@@ -204,7 +204,7 @@ public function testGetSetBrightness()
204 204 */
205 205 public function testGetSetHue()
206 206 {
207   - $this->stubMockClientSendSetGroupActionCommand();
  207 + $this->stubMockClientSendSetGroupStateCommand();
208 208
209 209 // Make sure original hue is retrievable
210 210 $this->assertEquals(
@@ -233,7 +233,7 @@ public function testGetSetHue()
233 233 */
234 234 public function testGetSetSaturation()
235 235 {
236   - $this->stubMockClientSendSetGroupActionCommand();
  236 + $this->stubMockClientSendSetGroupStateCommand();
237 237
238 238 // Make sure original saturation is retrievable
239 239 $this->assertEquals(
@@ -262,7 +262,7 @@ public function testGetSetSaturation()
262 262 */
263 263 public function testGetSetXY()
264 264 {
265   - $this->stubMockClientSendSetGroupActionCommand();
  265 + $this->stubMockClientSendSetGroupStateCommand();
266 266
267 267 // Make sure original xy is retrievable
268 268 $this->assertEquals(
@@ -294,7 +294,7 @@ public function testGetSetXY()
294 294 */
295 295 public function testGetSetColorTemp()
296 296 {
297   - $this->stubMockClientSendSetGroupActionCommand();
  297 + $this->stubMockClientSendSetGroupStateCommand();
298 298
299 299 // Make sure original color temp is retrievable
300 300 $this->assertEquals(
@@ -323,7 +323,7 @@ public function testGetSetColorTemp()
323 323 */
324 324 public function testGetSetEffect()
325 325 {
326   - $this->stubMockClientSendSetGroupActionCommand();
  326 + $this->stubMockClientSendSetGroupStateCommand();
327 327
328 328 // Make sure original effect is retrievable
329 329 $this->assertEquals(
@@ -387,10 +387,10 @@ public function testToString()
387 387 /**
388 388 * Stub mock client's send command
389 389 */
390   - protected function stubMockClientSendSetGroupActionCommand()
  390 + protected function stubMockClientSendSetGroupStateCommand()
391 391 {
392 392 $this->mockClient->expects($this->once())
393 393 ->method('sendCommand')
394   - ->with($this->isInstanceOf('\Phue\Command\SetGroupAction'));
  394 + ->with($this->isInstanceOf('\Phue\Command\SetGroupState'));
395 395 }
396 396 }

0 comments on commit 29e0b4d

Please sign in to comment.
Something went wrong with that request. Please try again.