Skip to content

Commit

Permalink
Merge pull request #16 from enzomacri/master
Browse files Browse the repository at this point in the history
v2.1
  • Loading branch information
trosenblatt-zz committed Jan 7, 2016
2 parents beca061 + f25ce90 commit 5c1340f
Show file tree
Hide file tree
Showing 62 changed files with 1,997 additions and 1,557 deletions.
39 changes: 19 additions & 20 deletions Examples/CLI_Therm_API_Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
* For further information, please take a look at https://dev.netatmo.com/doc
*/
define('__ROOT__', dirname(dirname(__FILE__)));
require_once (__ROOT__.'/src/Clients/NAThermApiClient.php');
require_once (__ROOT__.'/src/Netatmo/autoload.php');
require_once ('Config.php');
require_once ('Utils.php');


$scope = NAScopes::SCOPE_READ_THERM." " .NAScopes::SCOPE_WRITE_THERM;
$scope = Netatmo\Common\NAScopes::SCOPE_READ_THERM." " .Netatmo\Common\NAScopes::SCOPE_WRITE_THERM;

//Client configuration from Config.php
$conf = array("client_id" => $client_id,
"client_secret" => $client_secret,
"username" => $test_username,
"password" => $test_password,
"scope" => $scope);
$client = new NAThermApiClient($conf);
$client = new Netatmo\Clients\NAThermApiClient($conf);

//Retrieve access token
try
{
$tokens = $client->getAccessToken();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
$error_msg = "An error happened while trying to retrieve your tokens \n" . $ex->getMessage() . "\n";
handleError($error_msg, TRUE);
Expand All @@ -36,7 +35,7 @@
{
$thermData = $client->getData();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while retrieve thermostat data: " . $ex->getMessage() . "\n", TRUE);
}
Expand Down Expand Up @@ -66,19 +65,19 @@
$scheduleName = "testSchedule";
//build schedule's zones & timetable
$zones = array(
array("type" => NAThermZone::THERMOSTAT_SCHEDULE_SLOT_DAY,
array("type" => Netatmo\Common\NAThermZone::THERMOSTAT_SCHEDULE_SLOT_DAY,
"id" => 0,
"temp" => 19),
array("type" => NAThermZone::THERMOSTAT_SCHEDULE_SLOT_NIGHT,
array("type" => Netatmo\Common\NAThermZone::THERMOSTAT_SCHEDULE_SLOT_NIGHT,
"id" => 1,
"temp" => 17),
array("type" => NAThermZone::THERMOSTAT_SCHEDULE_SLOT_AWAY,
array("type" => Netatmo\Common\NAThermZone::THERMOSTAT_SCHEDULE_SLOT_AWAY,
"id" => 2,
"temp" => 12),
array("type" => NAThermZone::THERMOSTAT_SCHEDULE_SLOT_HG,
array("type" => Netatmo\Common\NAThermZone::THERMOSTAT_SCHEDULE_SLOT_HG,
"id" => 3,
"temp" => 7),
array("type" => NAThermZone::THERMOSTAT_SCHEDULE_SLOT_ECO,
array("type" => Netatmo\Common\NAThermZone::THERMOSTAT_SCHEDULE_SLOT_ECO,
"id" => 4,
"temp" => 16),
);
Expand Down Expand Up @@ -124,7 +123,7 @@
$schedule_id = $res['schedule_id'];
printMessageWithBorder("New test Schedule created");
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while creating a new schedule: " . $ex->getMessage() . "\n", TRUE);
}
Expand All @@ -136,7 +135,7 @@
{
$client->switchSchedule($device['_id'], $module_id, $schedule_id);
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while changing the device schedule: " . $ex->getMessage(). "\n", TRUE);
}
Expand All @@ -150,7 +149,7 @@
printMessageWithBorder($device['station_name'] . " is now in Away Mode");

}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while setting the thermostat to away mode: ".$ex->getMessage()."\n");
}
Expand All @@ -163,7 +162,7 @@
printMeasure($measurements, $type, $device['place']['timezone'], "Daily Measurements of the last 30 days");

}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while retrieving measures: " . $ex->getMessage(). "\n");
}
Expand All @@ -175,7 +174,7 @@
$client->renameSchedule($device['_id'], $module_id, $schedule_id, "To be deleted");
printMessageWithBorder("Schedule renamed");
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while renaming schedule $schedule_id: " . $ex->getMessage() ."\n");
}
Expand All @@ -189,7 +188,7 @@
printMessageWithBorder("Switching back to the original schedule");
sleep(30); //wait for thermostat to reconnect so that the change will be effective and initial schedule will be set back
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while switching back to original schedule: ". $ex->getMessage() ."\n");
}
Expand All @@ -201,7 +200,7 @@
printMessageWithBorder("test Schedule deleted");
sleep(20);
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while removing schedule $schedule_id " . $ex->getMessage() ."\n");
}
Expand All @@ -213,7 +212,7 @@
printMessageWithBorder("Manual setpoint set");

}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while setting a manual setpoint ". $ex->getMessage() . "\n");
}
Expand All @@ -239,7 +238,7 @@
printMessageWithBorder("Back to original mode: " . $initialMode);
sleep(20); //wait for thermostat synchronization to make sure, it's back in its initial mode
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while setting back the initial mode: ". $ex->getMessage() . " \n");
}
Expand Down
18 changes: 9 additions & 9 deletions Examples/CLI_WS_API_Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

define('__ROOT__', dirname(dirname(__FILE__)));
require_once __ROOT__ . '/src/Clients/NAWSApiClient.php';
require_once (__ROOT__.'/src/Netatmo/autoload.php');
require_once 'Utils.php';
require_once 'Config.php';

Expand All @@ -33,20 +33,20 @@ function printDevices($devices, $title = NULL)


//App client configuration
$scope = NAScopes::SCOPE_READ_STATION;
$scope = Netatmo\Common\NAScopes::SCOPE_READ_STATION;
$config = array("client_id" => $client_id,
"client_secret" => $client_secret,
"username" => $test_username,
"password" => $test_password);

$client = new NAWSApiClient($config);
$client = new Netatmo\Clients\NAWSApiClient($config);

//Authentication with Netatmo server (OAuth2)
try
{
$tokens = $client->getAccessToken();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error happened while trying to retrieve your tokens: " .$ex->getMessage()."\n", TRUE);
}
Expand All @@ -59,7 +59,7 @@ function printDevices($devices, $title = NULL)
$data = $client->getData(NULL, TRUE);
printMessageWithBorder("Weather Stations Basic Information");
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while retrieving data: ". $ex->getMessage()."\n", TRUE);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ function printDevices($devices, $title = NULL)
$measure = $client->getMeasure($device['_id'], NULL, "1day" , $type, time() - 24*3600*30, time(), 30, FALSE, FALSE);
printMeasure($measure, $type, $tz, $device['_id'] ."'s daily measurements of the last 30 days");
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while retrieving main device's daily measurements: " . $ex->getMessage() . "\n");
}
Expand All @@ -120,14 +120,14 @@ function printDevices($devices, $title = NULL)
break;
case "NAModule1" : $type = "temperature,humidity";
break;
default : $type = "temperature,Co2,humidity,noise,pressure";
default : $type = "temperature,Co2,humidity";
}
try
{
$measure = $client->getMeasure($device['_id'], $module['_id'], "1day" , $type, time()-24*3600*30 , time(), 30, FALSE, FALSE);
printMeasure($measure, $type, $tz, $module['_id']. "'s daily measurements of the last 30 days ");
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occured while retrieving main device's daily measurements: " . $ex->getMessage() . "\n");
}
Expand All @@ -141,7 +141,7 @@ function printDevices($devices, $title = NULL)
$measures = $client->getMeasure($device['_id'], NULL, "1month", $type, NULL, "last", 1, FALSE, FALSE);
printMeasure($measures, $type, $tz, "Last month information of " .$device['_id'], TRUE);
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
handleError("An error occcured while retrieving last month info: ".$ex->getMessage() . " \n");
}
Expand Down
10 changes: 5 additions & 5 deletions Examples/CLI_Webhooks_Registration_Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

define('__ROOT__', dirname(dirname(__FILE__)));
require_once __ROOT__.'/src/Clients/NAWelcomeApiClient.php';
require_once (__ROOT__.'/src/Netatmo/autoload.php');
require_once 'Config.php';
require_once 'Utils.php';

Expand All @@ -15,15 +15,15 @@
"client_secret" => $client_secret,
"username" => $test_username,
"password" => $test_password,
"scope" => NAScopes::SCOPE_READ_CAMERA);
$client = new NAWelcomeApiClient($config);
"scope" => Netatmo\Common\NAScopes::SCOPE_READ_CAMERA);
$client = new Netatmo\Clients\NAWelcomeApiClient($config);

//Retrieve access token
try
{
$tokens = $client->getAccessToken();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
$error_msg = "An error happened while trying to retrieve your tokens \n" . $ex->getMessage() . "\n";
handleError($error_msg, TRUE);
Expand All @@ -38,7 +38,7 @@
//Droping your webhook notification for the current user
$client->dropWebhook();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
echo "An error occured while trying to subscribe to a webhook";
die();
Expand Down
16 changes: 8 additions & 8 deletions Examples/CLI_Welcome_API_Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
* For further information, please take a look at https://dev.netatmo.com/doc
*/
define('__ROOT__', dirname(dirname(__FILE__)));
require_once (__ROOT__.'/src/Clients/NAWelcomeApiClient.php');
require_once (__ROOT__.'/src/Netatmo/autoload.php');
require_once ('Config.php');
require_once ('Utils.php');


$scope = NAScopes::SCOPE_READ_CAMERA;
$scope = Netatmo\Common\NAScopes::SCOPE_READ_CAMERA;

//Client configuration from Config.php
$conf = array("client_id" => $client_id,
"client_secret" => $client_secret,
"username" => $test_username,
"password" => $test_password,
"scope" => $scope);
$client = new NAWelcomeApiClient($conf);
$client = new Netatmo\Clients\NAWelcomeApiClient($conf);

//Retrieve access token
try
{
$tokens = $client->getAccessToken();
}
catch(NAClientException $ex)
catch(Netatmo\Exceptions\NAClientException $ex)
{
$error_msg = "An error happened while trying to retrieve your tokens \n" . $ex->getMessage() . "\n";
handleError($error_msg, TRUE);
Expand All @@ -38,7 +38,7 @@
$response = $client->getData(NULL, 10);
$homes = $response->getData();
}
catch(NASDKException $ex)
catch(Netatmo\Exceptions\NASDKException $ex)
{
handleError("An error happened while trying to retrieve home information: ".$ex->getMessage() ."\n", TRUE);
}
Expand Down Expand Up @@ -67,7 +67,7 @@
$response = $client->getLastEventOf($home->getId(), $person->getId());
$eventList = $response->getData();
}
catch(NASDKException $ex)
catch(Netatmo\Exceptions\NASDKException $ex)
{
handleError("An error occured while retrieving last event of ".$person->getPseudo() . "\n");
}
Expand All @@ -88,7 +88,7 @@
$response = $client->getNextEvents($home->getId(), $lastEvent->getId(), 10);
$data = $response->getData();
}
catch(NASDKException $ex)
catch(Netatmo\Exceptions\NASDKException $ex)
{
handleError("An error occured while retrieving events: ". $ex->getMessage(). "\n");
}
Expand All @@ -111,7 +111,7 @@
echo $snapshot . "\n";
}
}
catch(NASDKException $ex)
catch(Netatmo\Exceptions\NASDKException $ex)
{
handleError("An error occured while retrieving event's snapshot: ". $ex->getMessage()."\n");
}
Expand Down
23 changes: 15 additions & 8 deletions Examples/Utils.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

if (!defined('__ROOT__'))
{
define('__ROOT__', dirname(dirname(__FILE__)));
}

require_once (__ROOT__.'/src/Netatmo/autoload.php');

function handleError($message, $exit = FALSE)
{
echo $message;
Expand Down Expand Up @@ -151,7 +158,7 @@ function printUnit($key)
$typeUnit = array('temp' => '°C', 'hum' => '%', 'noise' => 'db', 'strength' => 'km/h', 'angle' => '°', 'rain' => 'mm', 'pressure' => 'mbar', 'co2' => 'ppm');
foreach($typeUnit as $type => $unit)
{
if(preg_match("/.*$type.*/i", $key))
if(preg_match("/$type.*$(?<!_trend)/i", $key))
{
echo " ".$unit;
return;
Expand Down Expand Up @@ -229,7 +236,7 @@ function getCurrentMode($module)

}

function printHomeInformation(NAHome $home)
function printHomeInformation(Netatmo\Objects\NAHome $home)
{
!is_null($home->getName()) ? printMessageWithBorder($home->getName()) : printMessageWithBorder($home->getId());
echo ("id: ". $home->getId() ."\n");
Expand Down Expand Up @@ -270,7 +277,7 @@ function printHomeInformation(NAHome $home)
}


function printPersonInformation(NAPerson $person, $tz)
function printPersonInformation(Netatmo\Objects\NAPerson $person, $tz)
{
$person->isKnown() ? printMessageWithBorder($person->getPseudo()) : printMessageWithBorder("Inconnu");
echo("id: ". $person->getId(). "\n");
Expand All @@ -283,21 +290,21 @@ function printPersonInformation(NAPerson $person, $tz)
echo ("\n");
}

function printEventInformation(NAEvent $event, $tz)
function printEventInformation(Netatmo\Objects\NAEvent $event, $tz)
{
printTimeInTz($event->getTime(), $tz, "j F H:i");
$message = removeHTMLTags($event->getMessage());
echo(": ".$message. "\n");
}

function printCameraInformation(NACamera $camera)
function printCameraInformation(Netatmo\Objects\NACamera $camera)
{
!is_null($camera->getName()) ? printMessageWithBorder($camera->getName()) : printMessageWithBorder($camera->getId());

echo("id: ". $camera->getId() ."\n");
echo("Monitoring status: ". $camera->getVar(NACameraInfo::CI_STATUS) ."\n");
echo("SD card status: " .$camera->getVar(NACameraInfo::CI_SD_STATUS) . "\n");
echo ("Power status: ". $camera->getVar(NACameraInfo::CI_ALIM_STATUS) ."\n");
echo("Monitoring status: ". $camera->getVar(Netatmo\Common\NACameraInfo::CI_STATUS) ."\n");
echo("SD card status: " .$camera->getVar(Netatmo\Common\NACameraInfo::CI_SD_STATUS) . "\n");
echo ("Power status: ". $camera->getVar(Netatmo\Common\NACameraInfo::CI_ALIM_STATUS) ."\n");

if($camera->getGlobalStatus())
$globalStatus = "OK";
Expand Down
Loading

0 comments on commit 5c1340f

Please sign in to comment.