feat: NetatmoClient with token rotation, OpenMeteoClient, LiveSource, netatmo-init
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Eenmalig: sla de Netatmo refresh token op.
|
||||
*
|
||||
* php bin/netatmo-init.php <refresh_token> [access_token]
|
||||
*
|
||||
* De token komt van de token generator op dev.netatmo.com (scope read_station).
|
||||
* Het access token is optioneel; zonder wordt er bij het eerste verzoek ververst.
|
||||
* Let op: de refresh token roteert bij elke verversing. Gebruik daarna nooit meer de oude.
|
||||
*/
|
||||
|
||||
use Weerscherm\Config;
|
||||
use Weerscherm\TokenStore;
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
$refresh = $argv[1] ?? '';
|
||||
$access = $argv[2] ?? '';
|
||||
if ($refresh === '' || $refresh === '-h' || $refresh === '--help') {
|
||||
fwrite(STDERR, "Gebruik: php bin/netatmo-init.php <refresh_token> [access_token]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$configFile = dirname(__DIR__) . '/config.php';
|
||||
if (!is_file($configFile)) {
|
||||
fwrite(STDERR, "config.php ontbreekt. Kopieer config.example.php naar config.php en vul de Netatmo-gegevens in.\n");
|
||||
exit(1);
|
||||
}
|
||||
$config = Config::load($configFile);
|
||||
$file = rtrim((string) $config->get('storage_path'), '/') . '/netatmo-token.json';
|
||||
|
||||
$store = new TokenStore($file);
|
||||
$store->withLock(static function () use ($store, $refresh, $access): void {
|
||||
$store->write(['access_token' => $access, 'refresh_token' => $refresh, 'expires_at' => 0]);
|
||||
});
|
||||
|
||||
printf("Token opgeslagen in %s (mode %s).\n", $file, substr(sprintf('%o', fileperms($file)), -4));
|
||||
echo "Bij het eerste verzoek wordt het access token ververst; de nieuwe refresh token wordt dan automatisch bewaard.\n";
|
||||
Reference in New Issue
Block a user