Skip to content

Commit

Permalink
Merge pull request #105 from jonofe/master
Browse files Browse the repository at this point in the history
PHP 5.3 support for 1.x.
  • Loading branch information
sqmk committed Mar 23, 2016
2 parents 72f8411 + 686adc7 commit d7129f0
Show file tree
Hide file tree
Showing 218 changed files with 3,827 additions and 4,132 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/vendor
/.idea
composer.lock
*.buildpath
*.prefs

.settings/org.eclipse.wst.common.project.facet.core.xml
.project
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
Expand Down
62 changes: 38 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Phue - Philips Hue client for PHP
# Phue - Philips Hue client

[![Latest Stable Version](https://poser.pugx.org/sqmk/Phue/version)](https://packagist.org/packages/sqmk/Phue)
[![Build Status](https://api.travis-ci.org/sqmk/Phue.svg?branch=master)](https://travis-ci.org/sqmk/Phue)


## Introduction

Phue is a PHP client used to connect to and manage the Philips Hue lighting system.
Expand All @@ -20,11 +21,11 @@ The client has the ability to make full use of the Hue's API, including:
* Managing software updates to the bridge and lights
* Getting portal configuration

Interested in API docs? You can check out the auto-generated documentation at [GitApiDoc](http://gitapidoc.com/api/sqmk/Phue/)
Interested in API docs? You can check out the [Philips API documentation](http://www.developers.meethue.com/philips-hue-api)

## Requirements

* PHP 5.4+
* PHP 5.3+
* cURL extension (optional)

## Installation
Expand Down Expand Up @@ -77,7 +78,8 @@ In the above example, you'll notice that to send a command, you instantiate a co

```php
try {
(new \Phue\Command\Ping)->send($client);
$ping = new \Phue\Command\Ping;
$ping->send($client);
} catch (\Phue\Transport\Exception\ConnectionException $e) {
echo 'There was a problem accessing the bridge';
}
Expand Down Expand Up @@ -140,7 +142,8 @@ You can also retrieve a single light. You can either dereference from the list o

```php
// Retrieve light of id 3 from convenience method
$light = $client->getLights()[3];
$lights = $client->getLights();
$light = $lights[3];

echo $light->getName(), "\n";

Expand All @@ -158,7 +161,8 @@ Now that you can retrieve ```\Phue\Light``` objects, you can start manipulating

```php
// Get a specific light
$light = $client->getLights()[3];
$lights = $client->getLights();
$light = $lights[3];

// Retrieving light properties:
echo $light->getId(), "\n",
Expand Down Expand Up @@ -210,7 +214,8 @@ Each *set* method above issues a single request to the bridge. In order to updat

```php
// Retrieve light
$light = $client->getLights()[3];
$lights = $client->getLights();
$light = $lights[3];

// Setting the brightness, hue, and saturation at the same time
$command = new \Phue\Command\SetLightState($light);
Expand Down Expand Up @@ -239,23 +244,25 @@ Creating a group is easy. All you need is a name, and a list of lights (ids, or
```php
// Create group with list of ids, and get group
$groupId = $client->sendCommand(
new \Phue\Command\CreateGroup('Office Lights', [1, 2])
new \Phue\Command\CreateGroup('Office Lights', array(1, 2))
);

$group = $client->getGroups()[$groupId];
$groups = $client->getGroups();
$group = $groups[$groupId];

// Create group with list of lights, and get group
$groupId2 = $client->sendCommand(
new \Phue\Command\CreateGroup(
'Office Lights #2',
[
array(
$client->getLights()[1],
$client->getLights()[2],
]
)
)
);

$group = $client->getGroups()[$groupId2];
$groups = $client->getGroups();
$group = $groups[$groupId2];
```

There are multiple ways of retrieving groups. Each way returns either an array or single instance of ```Phue\Group``` objects:
Expand All @@ -278,7 +285,8 @@ foreach ($client->getGroups() as $groupId => $group) {
}

// Convenient way of retrieving a single group by id
$group = $client->getGroups()[1];
$groups = $client->getGroups();
$group = $groups[1];

echo $group->getId(), ' - ',
$group->getName(), "\n";
Expand All @@ -296,7 +304,8 @@ Most of the methods available on ```\Phue\Light``` objects are also available on

```php
// Get a specific group
$group = $client->getGroups()[1];
$groups = $client->getGroups();
$group = $groups[1];

// Retrieving group properties:
echo $group->getId(), "\n",
Expand All @@ -316,10 +325,11 @@ echo $group->getId(), "\n",
$group->setName('Office');

// Setting lights
$group->setLights([
$client->getLights()[1],
$client->getLights()[2]
]);
$lights = $client->getLights();
$group->setLights(array(
$lights[1],
$lights[2]
));

// Setting on/off state (true|false)
$group->setOn(true);
Expand Down Expand Up @@ -348,7 +358,8 @@ Just like the bulbs, each *set* method on the ```\Phue\Group``` object will send

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

// Setting the brightness, color temp, and transition at the same time
$command = new \Phue\Command\SetGroupState($group);
Expand All @@ -366,7 +377,8 @@ Deleting a group is also simple. You can either delete from the ```\Phue\Group``

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

// Send command
Expand Down Expand Up @@ -413,18 +425,20 @@ $scheduleCommand->description('Dims all lights in house to 30');
$client->sendCommand($scheduleCommand);

// Show list of schedules
$command = $schedule->getCommand();
foreach ($client->getSchedules() as $scheduleId => $schedule) {
echo $schedule->getId(), "\n",
$schedule->getName(), "\n",
$schedule->getDescription(), "\n",
$schedule->getTime(), "\n",
$schedule->getCommand()['address'], "\n",
$schedule->getCommand()['method'], "\n",
json_encode($schedule->getCommand()['body']), "\n";
$command['address'], "\n",
$command['method'], "\n",
json_encode($command['body']), "\n";
}

// Delete a given schedule
$schedule = $client->getSchedules()[2];
$schedules = $client->getSchedules();
$schedule = $schedules[2];
$schedule->delete();
```

Expand Down
148 changes: 75 additions & 73 deletions bin/phue-light-finder
Original file line number Diff line number Diff line change
@@ -1,73 +1,75 @@
#!/usr/bin/env php
<?php

if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
} else {
require_once __DIR__ . '/../../../autoload.php';
}

// Show usage if host and username not passed
if (!isset($argv[1], $argv[2])) {
echo "Philips Hue Light Finder", "\n\n",
"Usage:", "\n",
" <host> <username>", "\n\n";
exit(1);
}

// Initialize client
$client = new \Phue\Client($argv[1], $argv[2]);

echo "Testing connection to bridge at {$client->getHost()}", "\n";

try {
$client->sendCommand(
new \Phue\Command\Ping
);
} catch (\Phue\Transport\Exception\ConnectionException $e) {
echo "Issue connecting to bridge", "\n";

exit(1);
}

// Quit if user is not authenticated
if (!$client->sendCommand(new \Phue\Command\IsAuthorized)) {
echo "{$client->getUsername()} is not authenticated with the bridge. Aborting.", "\n\n";

exit(1);
}

// Start light scan,
$client->sendCommand(
new \Phue\Command\StartLightScan
);

echo "Scanning for lights. Turn at least one light off, then on...", "\n";

// Found lights
$lights = [];

do {
$response = $client->sendCommand(
new \Phue\Command\GetNewLights
);

// Don't continue if the scan isn't active
if (!$response->isScanActive()) {
break;
}

// Iterate through each found light
foreach ($response->getLights() as $lightId => $lightName) {
// Light already found in poll
if (isset($lights[$lightId])) {
continue;
}

$lights[$lightId] = $lightName;

echo "Found: Light #{$lightId}, {$lightName}", "\n";
}
} while(true);

echo "Done scanning", "\n\n";
#!/usr/bin/env php
<?php

if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
} else {
require_once __DIR__ . '/../../../autoload.php';
}

// Show usage if host and username not passed
if (!isset($argv[1], $argv[2])) {
echo "Philips Hue Light Finder", "\n\n",
"Usage:", "\n",
" <host> <username>", "\n\n";
exit(1);
}

// Initialize client
$client = new \Phue\Client($argv[1], $argv[2]);

echo "Testing connection to bridge at {$client->getHost()}", "\n";

try {
$client->sendCommand(
new \Phue\Command\Ping
);
} catch (\Phue\Transport\Exception\ConnectionException $e) {
echo "Issue connecting to bridge", "\n";

exit(1);
}

// Quit if user is not authenticated
if (!$client->sendCommand(new \Phue\Command\IsAuthorized)) {
echo "{$client->getUsername()} is not authenticated with the bridge. Aborting.", "\n\n";

exit(1);
}

// Start light scan,
$client->sendCommand(
new \Phue\Command\StartLightScan
);

echo "Scanning for lights. Turn at least one light off, then on...", "\n";

// Found lights
// TODO $lights = [];

$lights = array();

do {
$response = $client->sendCommand(
new \Phue\Command\GetNewLights
);

// Don't continue if the scan isn't active
if (!$response->isScanActive()) {
break;
}

// Iterate through each found light
foreach ($response->getLights() as $lightId => $lightName) {
// Light already found in poll
if (isset($lights[$lightId])) {
continue;
}

$lights[$lightId] = $lightName;

echo "Found: Light #{$lightId}, {$lightName}", "\n";
}
} while(true);

echo "Done scanning", "\n\n";
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sqmk/phue",
"name": "jonofe/phue",
"description": "Phue - Philips Hue PHP client",
"type": "library",
"keywords": [
Expand All @@ -8,7 +8,7 @@
"hue",
"client"
],
"homepage": "http://github.com/sqmk/Phue",
"homepage": "http://github.com/jonofe/Phue",
"license": "BSD-3-Clause",
"authors": [
{
Expand All @@ -18,7 +18,7 @@
}
],
"require": {
"php": ">=5.4.0"
"php": ">=5.3.0"
},
"require-dev": {
"mockery/mockery": "0.8.0",
Expand Down
9 changes: 4 additions & 5 deletions examples/all-lights-colorloop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
*
* Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php all-lights-colorloop.php
*/

require_once 'common.php';

$client = new \Phue\Client($hueHost, $hueUsername);

echo 'Setting all lights to colorloop effect.', "\n";

$client->sendCommand(
(new \Phue\Command\SetGroupState(0))
->effect('colorloop')
);

$x = new \Phue\Command\SetGroupState(0);
$y = $x->effect('colorloop');
$client->sendCommand($y);
Loading

0 comments on commit d7129f0

Please sign in to comment.