From b7f4ee9f210bc02272ca21673b296061d9a76bd7 Mon Sep 17 00:00:00 2001 From: Enzo Macri Date: Mon, 4 Jan 2016 17:32:16 +0100 Subject: [PATCH 1/3] Introducing Namespaces and autoloading --- Examples/CLI_Therm_API_Example.php | 39 +- Examples/CLI_WS_API_Example.php | 18 +- .../CLI_Webhooks_Registration_Example.php | 10 +- Examples/CLI_Welcome_API_Example.php | 16 +- Examples/Utils.php | 23 +- Examples/WEB_AuthorizationGrant_Example.php | 15 +- README.md | 31 +- src/Constants/AppliCommonPublic.php | 374 ------------------ src/Exceptions/NAClientException.php | 79 ---- src/Exceptions/NASDKException.php | 21 - src/{ => Netatmo}/Clients/NAApiClient.php | 20 +- .../Clients/NAThermApiClient.php | 3 +- src/{ => Netatmo}/Clients/NAWSApiClient.php | 3 +- .../Clients/NAWelcomeApiClient.php | 7 +- src/Netatmo/Common/AppliCommonPublic.php | 1 + .../Common/NABatteryLevelIndoorModule.php | 14 + src/Netatmo/Common/NABatteryLevelModule.php | 15 + .../Common/NABatteryLevelThermostat.php | 15 + .../Common/NABatteryLevelWindGaugeModule.php | 15 + src/Netatmo/Common/NACameraAlimSubStatus.php | 12 + src/Netatmo/Common/NACameraEventInfo.php | 22 ++ src/Netatmo/Common/NACameraEventType.php | 21 + src/Netatmo/Common/NACameraHomeInfo.php | 15 + src/Netatmo/Common/NACameraImageInfo.php | 12 + src/Netatmo/Common/NACameraInfo.php | 17 + src/Netatmo/Common/NACameraPersonInfo.php | 15 + src/Netatmo/Common/NACameraSDEvent.php | 18 + src/Netatmo/Common/NACameraStatus.php | 12 + src/Netatmo/Common/NACameraVideoStatus.php | 13 + src/Netatmo/Common/NAClientErrorCode.php | 10 + src/Netatmo/Common/NARadioRssTreshold.php | 14 + src/Netatmo/Common/NARestErrorCode.php | 47 +++ src/Netatmo/Common/NASDKErrorCode.php | 14 + src/Netatmo/Common/NAScopes.php | 20 + src/Netatmo/Common/NAStationSensorsMinMax.php | 26 ++ src/Netatmo/Common/NAThermZone.php | 15 + src/Netatmo/Common/NAUserUnit.php | 27 ++ src/Netatmo/Common/NAWifiRssiThreshold.php | 11 + src/Netatmo/Exceptions/NAApiErrorType.php | 27 ++ src/Netatmo/Exceptions/NAClientException.php | 32 ++ src/Netatmo/Exceptions/NACurlErrorType.php | 13 + .../Exceptions/NAInternalErrorType.php | 13 + src/Netatmo/Exceptions/NAJsonErrorType.php | 13 + .../Exceptions/NANotLoggedErrorType.php | 13 + src/Netatmo/Exceptions/NASDKException.php | 16 + .../Handlers/NAResponseHandler.php | 25 +- src/{ => Netatmo}/Objects/NACamera.php | 11 +- src/{ => Netatmo}/Objects/NAEvent.php | 17 +- src/{ => Netatmo}/Objects/NAHome.php | 13 +- src/{ => Netatmo}/Objects/NAObject.php | 15 +- src/Netatmo/Objects/NAObjectWithPicture.php | 21 + src/{ => Netatmo}/Objects/NAPerson.php | 4 +- src/Netatmo/autoload.php | 59 +++ 53 files changed, 753 insertions(+), 599 deletions(-) delete mode 100644 src/Constants/AppliCommonPublic.php delete mode 100644 src/Exceptions/NAClientException.php delete mode 100644 src/Exceptions/NASDKException.php rename src/{ => Netatmo}/Clients/NAApiClient.php (98%) rename src/{ => Netatmo}/Clients/NAThermApiClient.php (99%) rename src/{ => Netatmo}/Clients/NAWSApiClient.php (99%) rename src/{ => Netatmo}/Clients/NAWelcomeApiClient.php (96%) create mode 100644 src/Netatmo/Common/AppliCommonPublic.php create mode 100644 src/Netatmo/Common/NABatteryLevelIndoorModule.php create mode 100644 src/Netatmo/Common/NABatteryLevelModule.php create mode 100644 src/Netatmo/Common/NABatteryLevelThermostat.php create mode 100644 src/Netatmo/Common/NABatteryLevelWindGaugeModule.php create mode 100644 src/Netatmo/Common/NACameraAlimSubStatus.php create mode 100644 src/Netatmo/Common/NACameraEventInfo.php create mode 100644 src/Netatmo/Common/NACameraEventType.php create mode 100644 src/Netatmo/Common/NACameraHomeInfo.php create mode 100644 src/Netatmo/Common/NACameraImageInfo.php create mode 100644 src/Netatmo/Common/NACameraInfo.php create mode 100644 src/Netatmo/Common/NACameraPersonInfo.php create mode 100644 src/Netatmo/Common/NACameraSDEvent.php create mode 100644 src/Netatmo/Common/NACameraStatus.php create mode 100644 src/Netatmo/Common/NACameraVideoStatus.php create mode 100644 src/Netatmo/Common/NAClientErrorCode.php create mode 100644 src/Netatmo/Common/NARadioRssTreshold.php create mode 100644 src/Netatmo/Common/NARestErrorCode.php create mode 100644 src/Netatmo/Common/NASDKErrorCode.php create mode 100644 src/Netatmo/Common/NAScopes.php create mode 100644 src/Netatmo/Common/NAStationSensorsMinMax.php create mode 100644 src/Netatmo/Common/NAThermZone.php create mode 100644 src/Netatmo/Common/NAUserUnit.php create mode 100644 src/Netatmo/Common/NAWifiRssiThreshold.php create mode 100644 src/Netatmo/Exceptions/NAApiErrorType.php create mode 100644 src/Netatmo/Exceptions/NAClientException.php create mode 100644 src/Netatmo/Exceptions/NACurlErrorType.php create mode 100644 src/Netatmo/Exceptions/NAInternalErrorType.php create mode 100644 src/Netatmo/Exceptions/NAJsonErrorType.php create mode 100644 src/Netatmo/Exceptions/NANotLoggedErrorType.php create mode 100644 src/Netatmo/Exceptions/NASDKException.php rename src/{ => Netatmo}/Handlers/NAResponseHandler.php (82%) rename src/{ => Netatmo}/Objects/NACamera.php (77%) rename src/{ => Netatmo}/Objects/NAEvent.php (79%) rename src/{ => Netatmo}/Objects/NAHome.php (92%) rename src/{ => Netatmo}/Objects/NAObject.php (74%) create mode 100644 src/Netatmo/Objects/NAObjectWithPicture.php rename src/{ => Netatmo}/Objects/NAPerson.php (94%) create mode 100644 src/Netatmo/autoload.php diff --git a/Examples/CLI_Therm_API_Example.php b/Examples/CLI_Therm_API_Example.php index 57f0804..24b02e6 100755 --- a/Examples/CLI_Therm_API_Example.php +++ b/Examples/CLI_Therm_API_Example.php @@ -5,12 +5,11 @@ * 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, @@ -18,14 +17,14 @@ "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); @@ -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); } @@ -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), ); @@ -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); } @@ -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); } @@ -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"); } @@ -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"); } @@ -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"); } @@ -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"); } @@ -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"); } @@ -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"); } @@ -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"); } diff --git a/Examples/CLI_WS_API_Example.php b/Examples/CLI_WS_API_Example.php index 0905b6d..5fe9a4f 100755 --- a/Examples/CLI_WS_API_Example.php +++ b/Examples/CLI_WS_API_Example.php @@ -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'; @@ -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); } @@ -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); } @@ -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"); } @@ -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"); } @@ -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"); } diff --git a/Examples/CLI_Webhooks_Registration_Example.php b/Examples/CLI_Webhooks_Registration_Example.php index 4c62c21..c3754d3 100644 --- a/Examples/CLI_Webhooks_Registration_Example.php +++ b/Examples/CLI_Webhooks_Registration_Example.php @@ -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'; @@ -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); @@ -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(); diff --git a/Examples/CLI_Welcome_API_Example.php b/Examples/CLI_Welcome_API_Example.php index 1417ab1..f1d3a55 100755 --- a/Examples/CLI_Welcome_API_Example.php +++ b/Examples/CLI_Welcome_API_Example.php @@ -5,12 +5,12 @@ * 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, @@ -18,14 +18,14 @@ "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); @@ -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); } @@ -66,7 +66,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"); } @@ -87,7 +87,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"); } @@ -110,7 +110,7 @@ echo $snapshot . "\n"; } } - catch(NASDKException $ex) + catch(Netatmo\Exceptions\NASDKException $ex) { handleError("An error occured while retrieving event's snapshot: ". $ex->getMessage()."\n"); } diff --git a/Examples/Utils.php b/Examples/Utils.php index d9f4ce1..3afbdfd 100644 --- a/Examples/Utils.php +++ b/Examples/Utils.php @@ -1,5 +1,12 @@ '°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.*$(?getName()) ? printMessageWithBorder($home->getName()) : printMessageWithBorder($home->getId()); echo ("id: ". $home->getId() ."\n"); @@ -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"); @@ -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"; diff --git a/Examples/WEB_AuthorizationGrant_Example.php b/Examples/WEB_AuthorizationGrant_Example.php index b09f5ad..8378a9d 100644 --- a/Examples/WEB_AuthorizationGrant_Example.php +++ b/Examples/WEB_AuthorizationGrant_Example.php @@ -5,16 +5,15 @@ * For more details about Netatmo API, please take a look at https://dev.netatmo.com/doc */ define('__ROOT__', dirname(dirname(__FILE__))); -require_once __ROOT__.'/src/Clients/NAWSApiClient.php'; -require_once __ROOT__.'/src/Clients/NAThermApiClient.php'; +require_once (__ROOT__.'/src/Netatmo/autoload.php'); require_once 'Config.php'; require_once 'Utils.php'; //API client configuration $config = array("client_id" => $client_id, "client_secret" => $client_secret, - "scope" => NAScopes::SCOPE_READ_STATION); -$client = new NAWSApiClient($config); + "scope" => Netatmo\Common\NAScopes::SCOPE_READ_STATION); +$client = new Netatmo\Clients\NAWSApiClient($config); //if code is provided in get param, it means user has accepted your app and been redirected here if(isset($_GET["code"])) @@ -23,7 +22,7 @@ try{ $tokens = $client->getAccessToken(); } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { echo "An error occured while trying to retrieve your tokens \n"; echo "Reason: ".$ex->getMessage()."\n"; @@ -33,7 +32,7 @@ try{ $data = $client->getData(); } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { echo "An error occured while retrieving data: ". $ex->getMessage()."\n"; die(); @@ -193,7 +192,7 @@ function getMonthReport($device, $client) $measure = addMeasureKeys($measure, $type); $report[$device['_id']] = $measure; } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { $report[$device['_id']] = "Error retrieving measure for ".$device['_id'].": " .$ex->getMessage(); } @@ -220,7 +219,7 @@ function getMonthReport($device, $client) $measure = addMeasureKeys($measure, $type); $report[$module['_id']] = $measure; } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { $report[$module['_id']] = "Error retrieving measure for " .$module['_id']. ": ".$ex->getMessage(); } diff --git a/README.md b/README.md index 1bf5ace..a275dad 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,28 @@ # Netatmo-API-PHP +##Updating to v2.x This release is a major update, and might break the compatibility with older versions. If you were using an older version of our SDK, you will have to stop using NAApiClient class and use either NAThermApiClient or NAWSApiClient instead. As a matter of fact, those are adding an additional abstraction layer which will make it easier for you to use : API call using "api" client method are now replaced with dedicated methods along with the parameters they expect for each product API. -You also might need to change the include path of the SDK files as they are now stored in the "src" folder (API clients are stored in "src/Clients/" folder). +You also might need to change the include path of the SDK files as they are now stored in the "src" folder (API clients are stored in "src/Netatmo/Clients/" folder). + +### Updating to v2.1.x +This release introduced namespaces to avoid collisions with other packages, which is a breaking change as classes provided by the Netatmo SDK are no longer available in the global namespace. For instance, NAThermApiClient becomes Netatmo\Clients\NAThermApiClient. For more information, please see http://php.net/manual/en/language.namespaces.php. + +It also introduced an autoloader respecting the PSR-4 standards, so you only need to include the src/Netatmo/autoload.php file and you're good to go. ## Install and Configure -To install the sdk, extract the downloaded files to your project directory. Then, just include NAWSApiClient.php (for Netatmo Weather Station) or NAThermApiClient.php (for Netatmo Thermostat), or NAWelcomeApiClient.php (for Netatmo Welcome) depending on what you need and instantiate a new NAWSApiClient (or NAThermApiClient) object with your application client_id and client_secret: +To install the sdk, extract the downloaded files to your project directory. Then, just include the src/Netatmo/autoload.php file and instantiate a new NAWSApiClient (or NAThermApiClient, or NAWelcomeApiClient) object with your application client_id and client_secret: - require_once('src/Clients/NAWSApiClient.php'); $config = array(); $config['client_id'] = "YOUR_APP_ID"; $config['client_secret'] = "YOUR_APP_SECRET"; $config['scope'] = 'read_station read_thermostat write_thermostat'; - $client = new NAApiClient($config); + $client = new Netatmo\Clients\NAApiClient($config); ## Authenticate & Authorize @@ -35,7 +40,7 @@ The SDK provides helper-methods to authenticate and authorize your app to access $refresh_token = $tokens["refresh_token"]; $access_token = $tokens["access_token"]; } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { echo "An error occcured while trying to retrive your tokens \n"; } @@ -53,7 +58,7 @@ Please note that you should NOT store users' credentials (which is not secure) a $refresh_token = $tokens['refresh_token']; $access_token = $tokens['access_token']; } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { echo " An error occured while trying to retrieve your tokens \n"; } @@ -167,7 +172,7 @@ You can easily change the thermostat setpoint: $client->setToFrostGuardMode($device['_id'], $module['_id']); $client->setToProgramMode($device['_id'], $module['_id']); } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { "An error occured"; } @@ -289,7 +294,7 @@ If you are working with the objects provided by the SDK, just call the object ge ### Quick Example - $scope = NAScopes::SCOPE_READ_CAMERA; + $scope = Netatmo\Common\NAScopes::SCOPE_READ_CAMERA; //Client configuration from Config.php $conf = array("client_id" => $client_id, @@ -297,14 +302,14 @@ If you are working with the objects provided by the SDK, just call the object ge "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) { echo "An error happened while trying to retrieve your tokens \n" . $ex->getMessage() . "\n"; } @@ -316,7 +321,7 @@ If you are working with the objects provided by the SDK, just call the object ge $response = $client->getData(NULL, 10); $homes = $response->getData(); } - catch(NASDKException $ex) + catch(Netatmo\Exceptions\NASDKException $ex) { echo "An error happened while trying to retrieve home information: ".$ex->getMessage() ."\n"; } @@ -345,7 +350,7 @@ The SDK throws NASDKException when an error happens. It encapsulates Networking try{ $client->getData(); } - catch(NASDKException $ex) + catch(Netatmo\Exceptions\NASDKException $ex) { //Handle error here echo $ex->getMessage(); @@ -358,7 +363,7 @@ The client throws NAClientException if it encounters an error dealing with the A try{ $client->getData(); } - catch(NAClientException $ex) + catch(Netatmo\Exceptions\NAClientException $ex) { //Handle error here echo $ex->getMessage(); diff --git a/src/Constants/AppliCommonPublic.php b/src/Constants/AppliCommonPublic.php deleted file mode 100644 index 0ee897a..0000000 --- a/src/Constants/AppliCommonPublic.php +++ /dev/null @@ -1,374 +0,0 @@ - 8, don't use this value -} - -class NAPluvioCalibration -{ - const RAIN_SCALE_MIN = 0.01; - const RAIN_SCALE_MAX = 0.25; - const RAIN_SCALE_ML_MIN = 0; - const RAIN_SCALE_ML_MAX = 3; -} - -//CAMERA SPECIFIC DATA -class NACameraEventType -{ - const CET_PERSON = "person"; - const CET_PERSON_AWAY = "person_away"; - const CET_MODEL_IMPROVED = "model_improved"; - const CET_MOVEMENT = "movement"; - const CET_CONNECTION = "connection"; - const CET_DISCONNECTION = "disconnection"; - const CET_ON = "on"; - const CET_OFF = "off"; - const CET_END_RECORDING = "end_recording"; - const CET_LIVE = "live_rec"; - const CET_BOOT = "boot"; - const CET_SD = "sd"; - const CET_ALIM = "alim"; -} - -class NACameraEventInfo -{ - const CEI_ID = "id"; - const CEI_TYPE = "type"; - const CEI_TIME = "time"; - const CEI_PERSON_ID = "person_id"; - const CEI_SNAPSHOT = "snapshot"; - const CEI_VIDEO_ID = "video_id"; - const CEI_VIDEO_STATUS = "video_status"; - const CEI_CAMERA_ID = "camera_id"; - const CEI_MESSAGE = "message"; - const CEI_SUB_TYPE = "sub_type"; - const CEI_IS_ARRIVAL = "is_arrival"; - const CEI_ALARM_ID = "alarm_id"; - const CEI_ALARM_TYPE = "alarm_type"; -} - -class NACameraPersonInfo -{ - const CPI_ID = "id"; - const CPI_LAST_SEEN = "last_seen"; - const CPI_FACE = "face"; - const CPI_OUT_OF_SIGHT = "out_of_sight"; - const CPI_PSEUDO = "pseudo"; - const CPI_IS_CURRENT_USER = "is_current_user"; -} - -class NACameraImageInfo -{ - const CII_ID = "id"; - const CII_VERSION = "version"; - const CII_KEY = "key"; -} - -class NACameraHomeInfo -{ - const CHI_ID = "id"; - const CHI_NAME = "name"; - const CHI_PLACE = "place"; - const CHI_PERSONS = "persons"; - const CHI_EVENTS = "events"; - const CHI_CAMERAS = "cameras"; -} - -class NACameraInfo -{ - const CI_ID = "id"; - const CI_NAME = "name"; - const CI_LIVE_URL = "live_url"; - const CI_STATUS = "status"; - const CI_SD_STATUS = "sd_status"; - const CI_ALIM_STATUS = "alim_status"; - const CI_IS_LOCAL = "is_local"; - const CI_VPN_URL = "vpn_url"; -} - -class NACameraStatus -{ - const CS_ON = "on"; - const CS_OFF = "off" ; - const CS_DISCONNECTED = "disconnected"; -} - -class APIResponseFields -{ - const APIRF_SYNC_ORDER = "sync"; - const APIRF_KEEP_RECORD_ORDER = "keep_record"; - const APIRF_VIDEO_ID = "video_id"; - const APIRF_SYNC_ORDER_LIST = "sync_order_list"; - const APIRF_EVENTS_LIST = "events_list"; - const APIRF_PERSONS_LIST = "persons_list"; - const APIRF_HOMES = "homes"; - const APIRF_USER = "user"; - const APIRF_GLOBAL_INFO = "global_info"; -} - - -class NACameraVideoStatus -{ - const CVS_RECORDING = "recording"; - const CVS_DELETED = "deleted"; - const CVS_AVAILABLE = "available"; - const CVS_ERROR = "error"; -} - -class NACameraSDEvent -{ - const CSDE_ABSENT = 1; - const CSDE_INSERTED = 2; - const CSDE_FORMATED = 3; - const CSDE_OK = 4; - const CSDE_DEFECT = 5; - const CSDE_INCOMPATIBLE = 6; - const CSDE_TOO_SMALL = 7; - - static $issueEvents = array(NACameraSDEvent::CSDE_ABSENT, NACameraSDEvent::CSDE_DEFECT, NACameraSDEvent::CSDE_INCOMPATIBLE, NACameraSDEvent::CSDE_TOO_SMALL); -} - -class NACameraAlimSubStatus -{ - const CASS_DEFECT = 1; - const CASS_OK = 2; -} - -class NAThermZone { -const THERMOSTAT_SCHEDULE_SLOT_DAY = 0x00; -const THERMOSTAT_SCHEDULE_SLOT_NIGHT = 0x01; -const THERMOSTAT_SCHEDULE_SLOT_AWAY = 0x02; -const THERMOSTAT_SCHEDULE_SLOT_HG = 0x03; -const THERMOSTAT_SCHEDULE_SLOT_PERSO = 0x04; -const THERMOSTAT_SCHEDULE_SLOT_ECO = 0x05; -const THERMOSTAT_SCHEDULE_HOT_WATER_ON = 0x06; -const THERMOSTAT_SCHEDULE_HOT_WATER_OFF = 0x07; -} - -?> diff --git a/src/Exceptions/NAClientException.php b/src/Exceptions/NAClientException.php deleted file mode 100644 index b66d985..0000000 --- a/src/Exceptions/NAClientException.php +++ /dev/null @@ -1,79 +0,0 @@ -. - */ -class NAClientException extends NASDKException -{ - public $error_type; - /** - * Make a new API Exception with the given result. - * - * @param $result - * The result from the API server. - */ - public function __construct($code, $message, $error_type) - { - $this->error_type = $error_type; - parent::__construct($code, $message); - } -} - - -class NAApiErrorType extends NAClientException -{ - public $http_code; - public $http_message; - public $result; - function __construct($code, $message, $result) - { - $this->http_code = $code; - $this->http_message = $message; - $this->result = $result; - if(isset($result["error"]) && is_array($result["error"]) && isset($result["error"]["code"])) - { - parent::__construct($result["error"]["code"], $result["error"]["message"], API_ERROR_TYPE); - } - else - { - parent::__construct($code, $message, API_ERROR_TYPE); - } - } -} - -class NACurlErrorType extends NAClientException -{ - function __construct($code, $message) - { - parent::__construct($code, $message, CURL_ERROR_TYPE); - } -} - -class NAJsonErrorType extends NAClientException -{ - function __construct($code, $message) - { - parent::__construct($code, $message, JSON_ERROR_TYPE); - } -} - -class NAInternalErrorType extends NAClientException -{ - function __construct($message) - { - parent::__construct(0, $message, INTERNAL_ERROR_TYPE); - } -} - -class NANotLoggedErrorType extends NAClientException -{ - function __construct($code, $message) - { - parent::__construct($code, $message, NOT_LOGGED_ERROR_TYPE); - } -} -?> diff --git a/src/Exceptions/NASDKException.php b/src/Exceptions/NASDKException.php deleted file mode 100644 index 5ff1bfe..0000000 --- a/src/Exceptions/NASDKException.php +++ /dev/null @@ -1,21 +0,0 @@ - diff --git a/src/Clients/NAApiClient.php b/src/Netatmo/Clients/NAApiClient.php similarity index 98% rename from src/Clients/NAApiClient.php rename to src/Netatmo/Clients/NAApiClient.php index 87a1511..fb4676d 100644 --- a/src/Clients/NAApiClient.php +++ b/src/Netatmo/Clients/NAApiClient.php @@ -1,13 +1,15 @@ diff --git a/src/Netatmo/Common/NABatteryLevelModule.php b/src/Netatmo/Common/NABatteryLevelModule.php new file mode 100644 index 0000000..b13b33c --- /dev/null +++ b/src/Netatmo/Common/NABatteryLevelModule.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NABatteryLevelThermostat.php b/src/Netatmo/Common/NABatteryLevelThermostat.php new file mode 100644 index 0000000..27ce8b8 --- /dev/null +++ b/src/Netatmo/Common/NABatteryLevelThermostat.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NABatteryLevelWindGaugeModule.php b/src/Netatmo/Common/NABatteryLevelWindGaugeModule.php new file mode 100644 index 0000000..174625d --- /dev/null +++ b/src/Netatmo/Common/NABatteryLevelWindGaugeModule.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NACameraAlimSubStatus.php b/src/Netatmo/Common/NACameraAlimSubStatus.php new file mode 100644 index 0000000..3304564 --- /dev/null +++ b/src/Netatmo/Common/NACameraAlimSubStatus.php @@ -0,0 +1,12 @@ + diff --git a/src/Netatmo/Common/NACameraEventInfo.php b/src/Netatmo/Common/NACameraEventInfo.php new file mode 100644 index 0000000..01fed9f --- /dev/null +++ b/src/Netatmo/Common/NACameraEventInfo.php @@ -0,0 +1,22 @@ + diff --git a/src/Netatmo/Common/NACameraEventType.php b/src/Netatmo/Common/NACameraEventType.php new file mode 100644 index 0000000..cd9650e --- /dev/null +++ b/src/Netatmo/Common/NACameraEventType.php @@ -0,0 +1,21 @@ + diff --git a/src/Netatmo/Common/NACameraHomeInfo.php b/src/Netatmo/Common/NACameraHomeInfo.php new file mode 100644 index 0000000..6a2bc6b --- /dev/null +++ b/src/Netatmo/Common/NACameraHomeInfo.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NACameraImageInfo.php b/src/Netatmo/Common/NACameraImageInfo.php new file mode 100644 index 0000000..10d010b --- /dev/null +++ b/src/Netatmo/Common/NACameraImageInfo.php @@ -0,0 +1,12 @@ + diff --git a/src/Netatmo/Common/NACameraInfo.php b/src/Netatmo/Common/NACameraInfo.php new file mode 100644 index 0000000..88e194a --- /dev/null +++ b/src/Netatmo/Common/NACameraInfo.php @@ -0,0 +1,17 @@ + diff --git a/src/Netatmo/Common/NACameraPersonInfo.php b/src/Netatmo/Common/NACameraPersonInfo.php new file mode 100644 index 0000000..6f03aab --- /dev/null +++ b/src/Netatmo/Common/NACameraPersonInfo.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NACameraSDEvent.php b/src/Netatmo/Common/NACameraSDEvent.php new file mode 100644 index 0000000..54a6072 --- /dev/null +++ b/src/Netatmo/Common/NACameraSDEvent.php @@ -0,0 +1,18 @@ + diff --git a/src/Netatmo/Common/NACameraStatus.php b/src/Netatmo/Common/NACameraStatus.php new file mode 100644 index 0000000..72b3313 --- /dev/null +++ b/src/Netatmo/Common/NACameraStatus.php @@ -0,0 +1,12 @@ + diff --git a/src/Netatmo/Common/NACameraVideoStatus.php b/src/Netatmo/Common/NACameraVideoStatus.php new file mode 100644 index 0000000..d08a726 --- /dev/null +++ b/src/Netatmo/Common/NACameraVideoStatus.php @@ -0,0 +1,13 @@ + diff --git a/src/Netatmo/Common/NAClientErrorCode.php b/src/Netatmo/Common/NAClientErrorCode.php new file mode 100644 index 0000000..e777a16 --- /dev/null +++ b/src/Netatmo/Common/NAClientErrorCode.php @@ -0,0 +1,10 @@ + diff --git a/src/Netatmo/Common/NARadioRssTreshold.php b/src/Netatmo/Common/NARadioRssTreshold.php new file mode 100644 index 0000000..eaad1ba --- /dev/null +++ b/src/Netatmo/Common/NARadioRssTreshold.php @@ -0,0 +1,14 @@ + diff --git a/src/Netatmo/Common/NARestErrorCode.php b/src/Netatmo/Common/NARestErrorCode.php new file mode 100644 index 0000000..6120ed7 --- /dev/null +++ b/src/Netatmo/Common/NARestErrorCode.php @@ -0,0 +1,47 @@ + diff --git a/src/Netatmo/Common/NASDKErrorCode.php b/src/Netatmo/Common/NASDKErrorCode.php new file mode 100644 index 0000000..58ce6bb --- /dev/null +++ b/src/Netatmo/Common/NASDKErrorCode.php @@ -0,0 +1,14 @@ + diff --git a/src/Netatmo/Common/NAScopes.php b/src/Netatmo/Common/NAScopes.php new file mode 100644 index 0000000..3db229a --- /dev/null +++ b/src/Netatmo/Common/NAScopes.php @@ -0,0 +1,20 @@ + diff --git a/src/Netatmo/Common/NAStationSensorsMinMax.php b/src/Netatmo/Common/NAStationSensorsMinMax.php new file mode 100644 index 0000000..53d0c94 --- /dev/null +++ b/src/Netatmo/Common/NAStationSensorsMinMax.php @@ -0,0 +1,26 @@ + diff --git a/src/Netatmo/Common/NAThermZone.php b/src/Netatmo/Common/NAThermZone.php new file mode 100644 index 0000000..d0e4795 --- /dev/null +++ b/src/Netatmo/Common/NAThermZone.php @@ -0,0 +1,15 @@ + diff --git a/src/Netatmo/Common/NAUserUnit.php b/src/Netatmo/Common/NAUserUnit.php new file mode 100644 index 0000000..a50061b --- /dev/null +++ b/src/Netatmo/Common/NAUserUnit.php @@ -0,0 +1,27 @@ + diff --git a/src/Netatmo/Common/NAWifiRssiThreshold.php b/src/Netatmo/Common/NAWifiRssiThreshold.php new file mode 100644 index 0000000..13a2683 --- /dev/null +++ b/src/Netatmo/Common/NAWifiRssiThreshold.php @@ -0,0 +1,11 @@ + diff --git a/src/Netatmo/Exceptions/NAApiErrorType.php b/src/Netatmo/Exceptions/NAApiErrorType.php new file mode 100644 index 0000000..ce31004 --- /dev/null +++ b/src/Netatmo/Exceptions/NAApiErrorType.php @@ -0,0 +1,27 @@ +http_code = $code; + $this->http_message = $message; + $this->result = $result; + if(isset($result["error"]) && is_array($result["error"]) && isset($result["error"]["code"])) + { + parent::__construct($result["error"]["code"], $result["error"]["message"], API_ERROR_TYPE); + } + else + { + parent::__construct($code, $message, API_ERROR_TYPE); + } + } +} + +?> diff --git a/src/Netatmo/Exceptions/NAClientException.php b/src/Netatmo/Exceptions/NAClientException.php new file mode 100644 index 0000000..c2e53ec --- /dev/null +++ b/src/Netatmo/Exceptions/NAClientException.php @@ -0,0 +1,32 @@ +. + */ +class NAClientException extends NASDKException +{ + public $error_type; + /** + * Make a new API Exception with the given result. + * + * @param $result + * The result from the API server. + */ + public function __construct($code, $message, $error_type) + { + $this->error_type = $error_type; + parent::__construct($code, $message); + } +} + +?> diff --git a/src/Netatmo/Exceptions/NACurlErrorType.php b/src/Netatmo/Exceptions/NACurlErrorType.php new file mode 100644 index 0000000..c12ebfb --- /dev/null +++ b/src/Netatmo/Exceptions/NACurlErrorType.php @@ -0,0 +1,13 @@ + diff --git a/src/Netatmo/Exceptions/NAInternalErrorType.php b/src/Netatmo/Exceptions/NAInternalErrorType.php new file mode 100644 index 0000000..cca537e --- /dev/null +++ b/src/Netatmo/Exceptions/NAInternalErrorType.php @@ -0,0 +1,13 @@ + diff --git a/src/Netatmo/Exceptions/NAJsonErrorType.php b/src/Netatmo/Exceptions/NAJsonErrorType.php new file mode 100644 index 0000000..6dc09d7 --- /dev/null +++ b/src/Netatmo/Exceptions/NAJsonErrorType.php @@ -0,0 +1,13 @@ + diff --git a/src/Netatmo/Exceptions/NANotLoggedErrorType.php b/src/Netatmo/Exceptions/NANotLoggedErrorType.php new file mode 100644 index 0000000..588ff35 --- /dev/null +++ b/src/Netatmo/Exceptions/NANotLoggedErrorType.php @@ -0,0 +1,13 @@ + diff --git a/src/Netatmo/Exceptions/NASDKException.php b/src/Netatmo/Exceptions/NASDKException.php new file mode 100644 index 0000000..9b47d74 --- /dev/null +++ b/src/Netatmo/Exceptions/NASDKException.php @@ -0,0 +1,16 @@ + diff --git a/src/Handlers/NAResponseHandler.php b/src/Netatmo/Handlers/NAResponseHandler.php similarity index 82% rename from src/Handlers/NAResponseHandler.php rename to src/Netatmo/Handlers/NAResponseHandler.php index d4527d7..28f2844 100644 --- a/src/Handlers/NAResponseHandler.php +++ b/src/Netatmo/Handlers/NAResponseHandler.php @@ -1,11 +1,14 @@ decodedBody) && $this->validateArrayForCast($this->decodedBody, 'homes')) return; - throw new NASDKException(NASDKError::UNABLE_TO_CAST, "Unable to cast data to NAHome object"); + throw new NASDKException(NASDKErrorCode::UNABLE_TO_CAST, "Unable to cast data to NAHome object"); } /** @@ -105,7 +108,7 @@ protected function validateCastToHome($data) ) return; - throw new NASDKException(NASDKError::UNABLE_TO_CAST, "Unable to cast data to home object"); + throw new NASDKException(NASDKErrorCode::UNABLE_TO_CAST, "Unable to cast data to home object"); } /** @@ -149,7 +152,7 @@ protected function validateCastToEventCollection() ) return; - throw new NASDKException(NASDKError::UNABLE_TO_CAST, "Impossible to cast to NAEvent"); + throw new NASDKException(NASDKErrorCode::UNABLE_TO_CAST, "Impossible to cast to NAEvent"); } /** @@ -161,7 +164,7 @@ protected function validateCastToEventObject($data) if(isset($data['id']) && isset($data['time']) && isset($data['type'])) return; - throw new NASDKException(NASDKError::UNABLE_TO_CAST, "Unable to cast data to event object"); + throw new NASDKException(NASDKErrorCode::UNABLE_TO_CAST, "Unable to cast data to event object"); } } ?> diff --git a/src/Objects/NACamera.php b/src/Netatmo/Objects/NACamera.php similarity index 77% rename from src/Objects/NACamera.php rename to src/Netatmo/Objects/NACamera.php index 6f9f862..9f4a322 100644 --- a/src/Objects/NACamera.php +++ b/src/Netatmo/Objects/NACamera.php @@ -1,6 +1,11 @@ getVar(NACameraInfo::CI_VPN_URL))) return $this->getVar(NACameraInfo::CI_VPN_URL); - else throw new NASDKErrorException(NASDKErrorCode::FORBIDDEN_OPERATION, "You don't have access to this field due to the scope of your application"); + else throw new NASDKException(NASDKErrorCode::FORBIDDEN_OPERATION, "You don't have access to this field due to the scope of your application"); } /** @@ -53,7 +58,7 @@ public function isLocal() { if(!is_null($this->getVar(NACameraInfo::CI_IS_LOCAL))) return $this->getVar(NACameraInfo::CI_IS_LOCAL); - else throw new NASDKErrorException(NASDKErrorCode::FORBIDDEN_OPERATION, "You don't have access to this field due to the scope of your application"); + else throw new NASDKException(NASDKErrorCode::FORBIDDEN_OPERATION, "You don't have access to this field due to the scope of your application"); } public function getSDCardStatus() diff --git a/src/Objects/NAEvent.php b/src/Netatmo/Objects/NAEvent.php similarity index 79% rename from src/Objects/NAEvent.php rename to src/Netatmo/Objects/NAEvent.php index ec2f07b..cb6c970 100644 --- a/src/Objects/NAEvent.php +++ b/src/Netatmo/Objects/NAEvent.php @@ -1,6 +1,11 @@ getVar(NACameraEventInfo::CEI_SUB_TYPE); } - else throw new NASDKException(NASDKError::INVALID_FIELD, "This field does not exist for this type of event"); + else throw new NASDKException(NASDKErrorCode::INVALID_FIELD, "This field does not exist for this type of event"); } /** @@ -83,7 +88,7 @@ public function getPersonId() { return $this->getVar(NACameraEventInfo::CEI_PERSON_ID); } - else throw new NASDKException(NASDKError::INVALID_FIELD, "This field does not exist for this type of event"); + else throw new NASDKException(NASDKErrorCode::INVALID_FIELD, "This field does not exist for this type of event"); } @@ -103,7 +108,7 @@ public function getVideo() { if($this->hasVideo()) return $this->getVar(NACameraEventInfo::CEI_VIDEO_ID); - else throw new NASDKException(NASDKError::INVALID_FIELD, "This type of event does not have videos"); + else throw new NASDKException(NASDKErrorCode::INVALID_FIELD, "This type of event does not have videos"); } /** @@ -115,7 +120,7 @@ public function getVideoStatus() { if($this->hasVideo()) return $this->getVar(NACameraEventInfo::CEI_VIDEO_STATUS); - else throw new NASDKException(NASDKError::INVALID_FIELD, "This type of event does not have videos"); + else throw new NASDKException(NASDKErrorCode::INVALID_FIELD, "This type of event does not have videos"); } @@ -130,7 +135,7 @@ public function isPersonArrival() { return $this->getVar(NACameraEventInfo::CEI_IS_ARRIVAL); } - else throw new NASDKException(NASDKError::INVALID_FIELD, "This field does not exist for this type of event"); + else throw new NASDKException(NASDKErrorCode::INVALID_FIELD, "This field does not exist for this type of event"); } } diff --git a/src/Objects/NAHome.php b/src/Netatmo/Objects/NAHome.php similarity index 92% rename from src/Objects/NAHome.php rename to src/Netatmo/Objects/NAHome.php index 48d0e26..14c72af 100644 --- a/src/Objects/NAHome.php +++ b/src/Netatmo/Objects/NAHome.php @@ -1,9 +1,10 @@ getId()); + throw new NASDKException(NASDKErrorCode::NOT_FOUND, "camera $camera_id not found in home: " . $this->getId()); } /** @@ -153,7 +154,7 @@ public function getPerson($person_id) return $person; } - throw new NASDKException(NASDKError::NOT_FOUND, "person $person_id not found in home: " . $this->getId()); + throw new NASDKException(NASDKErrorCode::NOT_FOUND, "person $person_id not found in home: " . $this->getId()); } /** diff --git a/src/Objects/NAObject.php b/src/Netatmo/Objects/NAObject.php similarity index 74% rename from src/Objects/NAObject.php rename to src/Netatmo/Objects/NAObject.php index 1332035..4fd3d44 100644 --- a/src/Objects/NAObject.php +++ b/src/Netatmo/Objects/NAObject.php @@ -1,6 +1,6 @@ diff --git a/src/Netatmo/Objects/NAObjectWithPicture.php b/src/Netatmo/Objects/NAObjectWithPicture.php new file mode 100644 index 0000000..77e4267 --- /dev/null +++ b/src/Netatmo/Objects/NAObjectWithPicture.php @@ -0,0 +1,21 @@ + diff --git a/src/Objects/NAPerson.php b/src/Netatmo/Objects/NAPerson.php similarity index 94% rename from src/Objects/NAPerson.php rename to src/Netatmo/Objects/NAPerson.php index 08493be..0984c77 100644 --- a/src/Objects/NAPerson.php +++ b/src/Netatmo/Objects/NAPerson.php @@ -1,6 +1,8 @@ From 42d23a81d88b7b4281fbe3b376d39e5d39cba5bb Mon Sep 17 00:00:00 2001 From: Enzo Macri Date: Tue, 5 Jan 2016 14:08:44 +0100 Subject: [PATCH 2/3] Deprecating classes in global namespace, but ensuring backward compatibility --- src/Clients/NAThermApiClient.php | 17 ++++ src/Clients/NAWSApiClient.php | 17 ++++ src/Clients/NAWelcomeApiClient.php | 17 ++++ src/Constants/AppliCommonPublic.php | 93 +++++++++++++++++++ src/Exceptions/NAClientException.php | 17 ++++ src/Exceptions/NASDKException.php | 17 ++++ src/Handlers/NAResponseHandler.php | 17 ++++ ...ssTreshold.php => NARadioRssiTreshold.php} | 0 src/Objects/NACamera.php | 17 ++++ src/Objects/NAEvent.php | 17 ++++ src/Objects/NAHome.php | 17 ++++ src/Objects/NAObject.php | 21 +++++ src/Objects/NAPerson.php | 17 ++++ 13 files changed, 284 insertions(+) create mode 100644 src/Clients/NAThermApiClient.php create mode 100644 src/Clients/NAWSApiClient.php create mode 100644 src/Clients/NAWelcomeApiClient.php create mode 100644 src/Constants/AppliCommonPublic.php create mode 100644 src/Exceptions/NAClientException.php create mode 100644 src/Exceptions/NASDKException.php create mode 100644 src/Handlers/NAResponseHandler.php rename src/Netatmo/Common/{NARadioRssTreshold.php => NARadioRssiTreshold.php} (100%) create mode 100644 src/Objects/NACamera.php create mode 100644 src/Objects/NAEvent.php create mode 100644 src/Objects/NAHome.php create mode 100644 src/Objects/NAObject.php create mode 100644 src/Objects/NAPerson.php diff --git a/src/Clients/NAThermApiClient.php b/src/Clients/NAThermApiClient.php new file mode 100644 index 0000000..d9b7f14 --- /dev/null +++ b/src/Clients/NAThermApiClient.php @@ -0,0 +1,17 @@ + diff --git a/src/Clients/NAWSApiClient.php b/src/Clients/NAWSApiClient.php new file mode 100644 index 0000000..d0a7a98 --- /dev/null +++ b/src/Clients/NAWSApiClient.php @@ -0,0 +1,17 @@ + diff --git a/src/Clients/NAWelcomeApiClient.php b/src/Clients/NAWelcomeApiClient.php new file mode 100644 index 0000000..9044b43 --- /dev/null +++ b/src/Clients/NAWelcomeApiClient.php @@ -0,0 +1,17 @@ + diff --git a/src/Constants/AppliCommonPublic.php b/src/Constants/AppliCommonPublic.php new file mode 100644 index 0000000..8fc7d4d --- /dev/null +++ b/src/Constants/AppliCommonPublic.php @@ -0,0 +1,93 @@ + diff --git a/src/Exceptions/NAClientException.php b/src/Exceptions/NAClientException.php new file mode 100644 index 0000000..68a7c7c --- /dev/null +++ b/src/Exceptions/NAClientException.php @@ -0,0 +1,17 @@ + diff --git a/src/Exceptions/NASDKException.php b/src/Exceptions/NASDKException.php new file mode 100644 index 0000000..63ed628 --- /dev/null +++ b/src/Exceptions/NASDKException.php @@ -0,0 +1,17 @@ + diff --git a/src/Handlers/NAResponseHandler.php b/src/Handlers/NAResponseHandler.php new file mode 100644 index 0000000..2b945a2 --- /dev/null +++ b/src/Handlers/NAResponseHandler.php @@ -0,0 +1,17 @@ + diff --git a/src/Netatmo/Common/NARadioRssTreshold.php b/src/Netatmo/Common/NARadioRssiTreshold.php similarity index 100% rename from src/Netatmo/Common/NARadioRssTreshold.php rename to src/Netatmo/Common/NARadioRssiTreshold.php diff --git a/src/Objects/NACamera.php b/src/Objects/NACamera.php new file mode 100644 index 0000000..d2beeba --- /dev/null +++ b/src/Objects/NACamera.php @@ -0,0 +1,17 @@ + diff --git a/src/Objects/NAEvent.php b/src/Objects/NAEvent.php new file mode 100644 index 0000000..477f1c1 --- /dev/null +++ b/src/Objects/NAEvent.php @@ -0,0 +1,17 @@ + diff --git a/src/Objects/NAHome.php b/src/Objects/NAHome.php new file mode 100644 index 0000000..7074518 --- /dev/null +++ b/src/Objects/NAHome.php @@ -0,0 +1,17 @@ + diff --git a/src/Objects/NAObject.php b/src/Objects/NAObject.php new file mode 100644 index 0000000..6d72bdb --- /dev/null +++ b/src/Objects/NAObject.php @@ -0,0 +1,21 @@ + diff --git a/src/Objects/NAPerson.php b/src/Objects/NAPerson.php new file mode 100644 index 0000000..df72c7c --- /dev/null +++ b/src/Objects/NAPerson.php @@ -0,0 +1,17 @@ + From f25ce9070c5c273f40a2ab947930718ebd14899e Mon Sep 17 00:00:00 2001 From: Enzo Macri Date: Wed, 6 Jan 2016 14:32:24 +0100 Subject: [PATCH 3/3] Updating README to take namespaces into account --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a275dad..67363ec 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ You also might need to change the include path of the SDK files as they are now ### Updating to v2.1.x This release introduced namespaces to avoid collisions with other packages, which is a breaking change as classes provided by the Netatmo SDK are no longer available in the global namespace. For instance, NAThermApiClient becomes Netatmo\Clients\NAThermApiClient. For more information, please see http://php.net/manual/en/language.namespaces.php. +It means the use of Netatmo SDK classes in the global namespace is deprecated. It is still possible to use them so far, so that it won't break your existing code. However, we recommend to update your code as soon as possible to take into account those changes. + It also introduced an autoloader respecting the PSR-4 standards, so you only need to include the src/Netatmo/autoload.php file and you're good to go. ## Install and Configure @@ -138,7 +140,7 @@ If you need further information about how the Netatmo Thermostat works, please s The Thermostat API client just works the same way as the Weather Station API Client: - $client = new NAThermApiClient($config); + $client = new Netatmo\Clients\NAThermApiClient($config); It also has its own method to retrieve user's thermostats data which returns an array of devices along with their data @@ -237,7 +239,7 @@ If you need more information regarding how the Netatmo Welcome works, please see The Netatmo Welcome SDK works in a slightly different way than Netatmo Weather Stations and Netatmo Thermostat SDK do. First, instantiate the client: - $client = new NAWelcomeApiClient($config); + $client = new Netatmo\Clients\NAWelcomeApiClient($config); The Netatmo Welcome SDK enables you to retrieve the data (persons, cameras, events) of every home belonging to an user: