Skip to content

Commit

Permalink
Merge pull request #19 from Chris53897/feature/modernize
Browse files Browse the repository at this point in the history
feat: drop support for PHP < 8.1
  • Loading branch information
Chris53897 authored Apr 12, 2024
2 parents f8e9864 + 8f7c29a commit 7f101e6
Show file tree
Hide file tree
Showing 111 changed files with 1,256 additions and 821 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.0', '8.1', '8.2']
php: ['8.1', '8.2', '8.3']

name: "Tests"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ composer.lock
*.prefs

.phpunit.result.cache
.phpunit.cache
.php-cs-fixer.cache

.settings/org.eclipse.wst.common.project.facet.core.xml
Expand Down
3 changes: 2 additions & 1 deletion bin/phue-bridge-finder
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ foreach ($bridges as $key => $bridge) {
echo "\tBridge #", ++$key, "\n";
echo "\t\tID: ", $bridge->id, "\n";
echo "\t\tInternal IP Address: ", $bridge->internalipaddress, "\n";
if(isset($bridge->macaddress))
if(isset($bridge->macaddress)) {
echo "\t\tMAC Address: ", $bridge->macaddress, "\n";
}
echo "\n";
}
10 changes: 5 additions & 5 deletions bin/phue-create-user
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if (is_file(__DIR__ . '/../vendor/autoload.php')) {
// Show usage if host is not passed
if (!isset($argv[1])) {
echo "Philips Hue User Creator", "\n\n",
"Usage:", "\n",
" <host>", "\n\n";
"Usage:", "\n",
" <host>", "\n\n";
exit(1);
}

Expand All @@ -31,8 +31,8 @@ try {
}

echo "Attempting to create user:", "\n",
"Press the Bridge's button!", "\n",
"Waiting.";
"Press the Bridge's button!", "\n",
"Waiting.";

// Try X times to create user
$maxTries = 30;
Expand All @@ -49,7 +49,7 @@ for ($i = 1; $i <= $maxTries; ++$i) {
echo ".";
} catch (Exception $e) {
echo "\n\n", "Failure to create user. Please try again!",
"\n", "Reason: {$e->getMessage()}", "\n\n";
"\n", "Reason: {$e->getMessage()}", "\n\n";

break;
}
Expand Down
148 changes: 74 additions & 74 deletions bin/phue-light-finder
Original file line number Diff line number Diff line change
@@ -1,75 +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
// 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";
<?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 bin/phue-list-lights
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ if (is_file(__DIR__ . '/../vendor/autoload.php')) {
// Show usage if host and username not passed
if (!isset($argv[1], $argv[2])) {
echo "Philips Hue Light Lister", "\n\n",
"Usage:", "\n",
" <host> <username>", "\n\n";
"Usage:", "\n",
" <host> <username>", "\n\n";
exit(1);
}

Expand Down Expand Up @@ -41,5 +41,5 @@ echo "List of lights:", "\n";

foreach ($client->getLights() as $light) {
echo "\t", "#{$light->getId()} - ", $light->isOn() ? 'On' : 'Off',
" - {$light->getName()} - {$light->getModel()}", "\n";
" - {$light->getName()} - {$light->getModel()}", "\n";
}
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
}
],
"require": {
"php": "^8.0"
"php": "^8.1"
},
"require-dev": {
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.8",
"friendsofphp/php-cs-fixer": "^3.9.5",
"mockery/mockery": "^1.6.11",
"phpunit/phpunit": "^10.5.11 || ^11.1.1",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.53",
"ext-curl": "*"
},
"suggest": {
Expand Down
7 changes: 5 additions & 2 deletions examples/create-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
$lights = $client->getLights();

$groupId = $client->sendCommand(
new \Phue\Command\CreateGroup('Test Group',
new \Phue\Command\CreateGroup(
'Test Group',
array(
$lights[4],
$lights[5]
)));
)
)
);

echo 'Group Id: ', $groupId, "\n";
8 changes: 5 additions & 3 deletions examples/create-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
$cond1->setSensorId($sensor)
->setAttribute('buttonevent')
->equals()
->setValue(\Phue\SensorModel\ZgpswitchModel::BUTTON_2))
->setValue(\Phue\SensorModel\ZgpswitchModel::BUTTON_2)
)
->addCondition(
$cond2->setSensorId($sensor)
$cond2->setSensorId($sensor)
->setAttribute('lastupdated')
->changed())
->changed()
)
->addAction($g_state->brightness(2));

$ruleId = $client->sendCommand($cmd);
Expand Down
3 changes: 2 additions & 1 deletion examples/create-scene-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

// Create/modify scene
$client->sendCommand(
new \Phue\Command\CreateScene($sceneId, 'Test Scene', $lightIds));
new \Phue\Command\CreateScene($sceneId, 'Test Scene', $lightIds)
);

echo 'Buffering light states', "\n";

Expand Down
4 changes: 3 additions & 1 deletion examples/list-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@

foreach ($client->getGroups() as $group) {
echo "\t", "#{$group->getId()} - {$group->getName()}", "\n", "\t\t Type: ", $group->getType(), "\n", "\t\t Lights: ", implode(
', ', $group->getLightIds()), "\n";
', ',
$group->getLightIds()
), "\n";
}
2 changes: 1 addition & 1 deletion examples/list-scenes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

foreach ($client->getScenes() as $scene) {
echo "\t", "#{$scene->getId()} - {$scene->getName()}", "\n",
"\t\t", "Light Ids: ", implode(', ', $scene->getLightIds()), "\n";
"\t\t", "Light Ids: ", implode(', ', $scene->getLightIds()), "\n";
}
10 changes: 5 additions & 5 deletions examples/list-schedules.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

echo 'Listing schedules:', "\n";

foreach ($client->getSchedules() as $schedule)
{
foreach ($client->getSchedules() as $schedule) {
$cmd = $schedule->getCommand();

echo "\t", "#{$schedule->getId()} - {$schedule->getName()}", "\n", "\t\t", "Time scheduled: {$schedule->getTime()}", "\n",
"\t\t", "Method: {$cmd['method']}", "\n", "\t\t", "Address: {$cmd['address']}", "\n", "\t\t", "Body: ", json_encode(
$cmd['body']), "\n", "\t\t", "Status: ", $schedule->getStatus(), "\n", "\t\t", "Autodelete: ", $schedule->isAutoDeleted() ? 'Yes' : 'No', "\n";
echo "\t", "#{$schedule->getId()} - {$schedule->getName()}", "\n", "\t\t", "Time scheduled: {$schedule->getTime()}", "\n",
"\t\t", "Method: {$cmd['method']}", "\n", "\t\t", "Address: {$cmd['address']}", "\n", "\t\t", "Body: ", json_encode(
$cmd['body']
), "\n", "\t\t", "Status: ", $schedule->getStatus(), "\n", "\t\t", "Autodelete: ", $schedule->isAutoDeleted() ? 'Yes' : 'No', "\n";
}
14 changes: 10 additions & 4 deletions examples/schedule-all-lights-change.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@

$x1 = new \Phue\TimePattern\Timer(1);
$y1 = new \Phue\Command\SetGroupState(0);
$z1 = new \Phue\Command\CreateSchedule('Dim all lights', $x1->repeat(3),
$y1->brightness(1));
$z1 = new \Phue\Command\CreateSchedule(
'Dim all lights',
$x1->repeat(3),
$y1->brightness(1)
);
$client->sendCommand($z1);

$x2 = new \Phue\TimePattern\Timer(1);
$y2 = new \Phue\Command\SetGroupState(0);
$z2 = new \Phue\Command\CreateSchedule('Brighten all lights', $x2->repeat(3),
$y2->brightness(255));
$z2 = new \Phue\Command\CreateSchedule(
'Brighten all lights',
$x2->repeat(3),
$y2->brightness(255)
);
$client->sendCommand($z2);

echo 'Done.', "\n";
12 changes: 9 additions & 3 deletions examples/schedule-recurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@

$timePattern = new \Phue\TimePattern\RecurringTime(
\Phue\TimePattern\RecurringTime::THURSDAY |
\Phue\TimePattern\RecurringTime::SATURDAY, 7, 50);
\Phue\TimePattern\RecurringTime::SATURDAY,
7,
50
);

$x = new \Phue\Command\SetGroupState(0);
$y = new \Phue\Command\CreateSchedule('Dim all lights', $timePattern,
$x->brightness(1));
$y = new \Phue\Command\CreateSchedule(
'Dim all lights',
$timePattern,
$x->brightness(1)
);
$client->sendCommand($y);

echo 'Done.', "\n";
4 changes: 3 additions & 1 deletion examples/show-bridge-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
echo 'Showing portal configuration', "\n", "\t Signed on: ", $portal->isSignedOn() ? 'Yes' : 'No', "\n", "\t Incoming: ", $portal->isIncoming() ? 'Yes' : 'No', "\n", "\t Outgoing: ", $portal->isOutgoing() ? 'Yes' : 'No', "\n", "\t Communication: ", $portal->getCommunication(), "\n\n";

echo 'Showing software update configuration', "\n", "\t Checking for update: ", $softwareUpdate->checkingForUpdate() ? 'Yes' : 'No', "\n", "\t Bridge updatable: ", $softwareUpdate->isBridgeUpdatable() ? 'Yes' : 'No', "\n", "\t Lights updatable: ", implode(
', ', $softwareUpdate->getUpdatableLights()), "\n", "\t Release notes URL: ", $softwareUpdate->getReleaseNotesUrl(), "\n", "\t Release notes brief: ", $softwareUpdate->getReleaseNotesBrief(), "\n", "\t Install notification: ", $softwareUpdate->isInstallNotificationEnabled() ? 'Yes' : 'No', "\n\n";
', ',
$softwareUpdate->getUpdatableLights()
), "\n", "\t Release notes URL: ", $softwareUpdate->getReleaseNotesUrl(), "\n", "\t Release notes brief: ", $softwareUpdate->getReleaseNotesBrief(), "\n", "\t Install notification: ", $softwareUpdate->isInstallNotificationEnabled() ? 'Yes' : 'No', "\n\n";
5 changes: 3 additions & 2 deletions examples/update-rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
$y2 = new \Phue\Command\SetGroupState(0);
$z = $x->name('New name')
->addCondition(
$y1->setSensorId($sensor)
$y1->setSensorId($sensor)
->setAttribute('lastupdated')
->changed())
->changed()
)
->addAction($y2->brightness(200));

$client->sendCommand($z);
Loading

0 comments on commit 7f101e6

Please sign in to comment.