-
Notifications
You must be signed in to change notification settings - Fork 0
/
lights
executable file
·41 lines (33 loc) · 1.22 KB
/
lights
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
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Phue\Client;
use Phue\Command\IsAuthorized;
use Phue\Transport\Exception\ConnectionException;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Finder\Finder;
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
$dotenv->required(['HUE_BRIDGE_HOST', 'HUE_BRIDGE_USER']);
$hueClient = new Client(getenv('HUE_BRIDGE_HOST'), getenv('HUE_BRIDGE_USER'));
try {
if (!$hueClient->sendCommand(new IsAuthorized)) {
throw new RuntimeException('You are not authorized to access the Hue bridge.');
}
} catch (ConnectionException $e) {
throw new RuntimeException('Could not connect to the Hue bridge.');
}
$application = new Application();
foreach ((new Finder())->in(__DIR__.'/commands')->files() as $command) {
$command = 'Lights\\Commands'.str_replace(
['/', '.php'],
['\\', ''],
array_reverse(explode(__DIR__.'/commands', $command->getPathname(), 2))[0]
);
if (is_subclass_of($command, Command::class) &&
!(new ReflectionClass($command))->isAbstract()) {
$application->add(new $command($hueClient));
}
}
$application->run();