-
Notifications
You must be signed in to change notification settings - Fork 45
/
GetGroups.php
47 lines (40 loc) · 970 Bytes
/
GetGroups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Phue: Philips Hue PHP Client
*
* @author Michael Squires <sqmk@php.net>
* @copyright Copyright (c) 2012 Michael K. Squires
* @license http://github.com/sqmk/Phue/wiki/License
*/
namespace Phue\Command;
use Phue\Client;
use Phue\Group;
/**
* Get groups command
*/
class GetGroups implements CommandInterface
{
/**
* Send command
*
* @param Client $client Phue Client
*
* @return array List of Group objects
*/
public function send(Client $client)
{
// Get response
$response = $client->getTransport()->sendRequest(
$client->getUsername()
);
// Return empty list if no groups
if (!isset($response->groups)) {
return [];
}
$groups = [];
foreach ($response->groups as $groupId => $attributes) {
$groups[$groupId] = new Group($groupId, $attributes, $client);
}
return $groups;
}
}