Skip to content

Commit

Permalink
quick fix netatmo API auth change
Browse files Browse the repository at this point in the history
  • Loading branch information
larknafets committed Aug 17, 2023
1 parent d2c3857 commit 2ef9dba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 6 additions & 2 deletions examples/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
// -- https://dev.netatmo.com/
$netatmo_client_id = 'client id';
$netatmo_client_secret = 'client secret';
$netatmo_username = 'your email';
$netatmo_password = 'your password';
$netatmo_username = 'your email'; // depricated
$netatmo_password = 'your password'; // deprecated
// Generate tokens first with you app: https://dev.netatmo.com/apps/
$netatmo_access_token = 'access|token';
$netatmo_refresh_token = 'refresh|token';

// Netatmo-API-PHP is used.
// -- https://github.com/Netatmo/Netatmo-API-PHP
$netatmo_nawsapiclient = '../netatmo/Clients/NAWSApiClient.php'; // Path to NAWSApiClient.php
Expand Down
27 changes: 17 additions & 10 deletions src/weather-data-netatmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@
$config['scope'] = 'read_station';

$client = new NAWSApiClient($config);
$client->setVariable('username',$netatmo_username);
$client->setVariable('password',$netatmo_password);
try {
$tokens = $client->getAccessToken();
$refresh_token = $tokens['refresh_token'];
$access_token = $tokens['access_token'];
}
catch(NAClientException $ex) {
echo 'Netatmo Wetterstation Daten: Es ist ein Fehler bei der Authorisation aufgetreten.';
}

# --- Auth #1 - not working anymore
#$client->setVariable('username',$netatmo_username);
#$client->setVariable('password',$netatmo_password);
#try {
# $tokens = $client->getAccessToken();
# $refresh_token = $tokens['refresh_token'];
# $access_token = $tokens['access_token'];
#}
#catch(Netatmo\Exceptions\NAClientException $ex) {
# echo 'Netatmo Wetterstation Daten: Es ist ein Fehler bei der Authorisation aufgetreten.';
#}

# --- Auth #2 - working for now
$tokens = array("access_token" => $netatmo_access_token,
"refresh_token" => $netatmo_refresh_token);
$client->setTokensFromStore($tokens);

$netatmo_outdoor_module = false;
$netatmo_rain_module = false;
Expand Down

0 comments on commit 2ef9dba

Please sign in to comment.