From 5389d242b3618dfc4e556b49e1dbeaa5cd02cf0c Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 19:38:15 +0100 Subject: [PATCH 1/7] added default config and allowed for auto configuration --- config/philipshue.php | 10 ++++++++++ src/PhilipsHueServiceProvider.php | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 config/philipshue.php diff --git a/config/philipshue.php b/config/philipshue.php new file mode 100644 index 0000000..3af171d --- /dev/null +++ b/config/philipshue.php @@ -0,0 +1,10 @@ + [ + 'client_id' => env('PHILIPS_HUE_CLIENT_ID'), + 'client_secret' => env('PHILIPS_HUE_CLIENT_SECRET'), + 'app_id' => env('PHILIPS_HUE_APP_ID'), + 'device_id' => env('PHILIPS_HUE_DEVICE_ID'), + 'user' => env('PHILIPS_HUE_USERNAME') + ] +]; \ No newline at end of file diff --git a/src/PhilipsHueServiceProvider.php b/src/PhilipsHueServiceProvider.php index c3448ee..ecb44fa 100644 --- a/src/PhilipsHueServiceProvider.php +++ b/src/PhilipsHueServiceProvider.php @@ -6,6 +6,10 @@ class PhilipsHueServiceProvider extends ServiceProvider { + public function register() { + $this->mergeConfigFrom(__DIR__ . '/../config/philipshue.php', 'services'); + } + public function boot() { // If we do not disable the routes, load in the roads & views. From 53ba3877511224a7d051fc0c93bb664670bd6fd0 Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 19:43:37 +0100 Subject: [PATCH 2/7] changed config key --- src/PhilipsHueServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhilipsHueServiceProvider.php b/src/PhilipsHueServiceProvider.php index ecb44fa..12219c3 100644 --- a/src/PhilipsHueServiceProvider.php +++ b/src/PhilipsHueServiceProvider.php @@ -7,7 +7,7 @@ class PhilipsHueServiceProvider extends ServiceProvider { public function register() { - $this->mergeConfigFrom(__DIR__ . '/../config/philipshue.php', 'services'); + $this->mergeConfigFrom(__DIR__ . '/../config/philipshue.php', 'philipshue'); } public function boot() From 1d76116310c518899a2395c2a490b8516cb2e9c5 Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 23:44:13 +0100 Subject: [PATCH 3/7] added phpdoc to Hueclient to show return types --- config/{philipshue.php => philips-hue.php} | 0 src/HueClient.php | 37 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) rename config/{philipshue.php => philips-hue.php} (100%) diff --git a/config/philipshue.php b/config/philips-hue.php similarity index 100% rename from config/philipshue.php rename to config/philips-hue.php diff --git a/src/HueClient.php b/src/HueClient.php index dd2ad44..61f22e9 100644 --- a/src/HueClient.php +++ b/src/HueClient.php @@ -18,6 +18,15 @@ public function __construct() $this->guzzle = new Client; } + /** + * Sends a request and returns response from Hue api + * + * @param $url + * @param string $method + * @param array $params + * + * @return mixed + */ public function send($url, $method = 'get', $params = []) { $options = [ @@ -36,6 +45,11 @@ public function send($url, $method = 'get', $params = []) return json_decode($r->getBody()->getContents()); } + /** + * @param $code + * + * @return mixed + */ public function getAccessTokenForTheFirstTime($code) { $r = $this->guzzle->post($this->baseUrl . '/oauth2/token', [ @@ -56,6 +70,9 @@ public function getAccessTokenForTheFirstTime($code) return json_decode($tokens); } + /** + * @return mixed + */ public function refreshAndGetAccessToken() { $tokens = json_decode(file_get_contents(storage_path('app/hue.json'))); @@ -83,6 +100,9 @@ public function refreshAndGetAccessToken() return object_get(json_decode($tokens), 'access_token'); } + /** + * @return void + */ public function startOAuth() { $parameters = http_build_query([ @@ -96,6 +116,11 @@ public function startOAuth() exit; } + /** + * @param $data + * + * @return void + */ public function setTokenFile($data) { $data = json_decode($data); @@ -110,21 +135,33 @@ public function setTokenFile($data) \Storage::put('hue.json', json_encode($data)); } + /** + * @return HueLight + */ public function lights() { return new HueLight; } + /** + * @return HueGroups + */ public function groups() { return new HueGroups; } + /** + * @return HueUser + */ public function users() { return new HueUser; } + /** + * @return HueSchedule + */ public function schedules() { return new HueSchedule; From 1d0ab087217a8c5ee14a7a9986c4d4f0de5d45fd Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 23:46:03 +0100 Subject: [PATCH 4/7] revert changes --- config/philips-hue.php | 10 ---------- src/Resources/HueLightResource.php | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 config/philips-hue.php diff --git a/config/philips-hue.php b/config/philips-hue.php deleted file mode 100644 index 3af171d..0000000 --- a/config/philips-hue.php +++ /dev/null @@ -1,10 +0,0 @@ - [ - 'client_id' => env('PHILIPS_HUE_CLIENT_ID'), - 'client_secret' => env('PHILIPS_HUE_CLIENT_SECRET'), - 'app_id' => env('PHILIPS_HUE_APP_ID'), - 'device_id' => env('PHILIPS_HUE_DEVICE_ID'), - 'user' => env('PHILIPS_HUE_USERNAME') - ] -]; \ No newline at end of file diff --git a/src/Resources/HueLightResource.php b/src/Resources/HueLightResource.php index bf67cd5..1025a72 100644 --- a/src/Resources/HueLightResource.php +++ b/src/Resources/HueLightResource.php @@ -4,6 +4,9 @@ class HueLightResource extends BaseHueResource { + /** + * @return mixed + */ public function isLightOn() { return $this->state->on; From 84277da3fbc868eb03c55305bc2fc5eda89d963c Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 23:47:20 +0100 Subject: [PATCH 5/7] revert changes --- src/PhilipsHueServiceProvider.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/PhilipsHueServiceProvider.php b/src/PhilipsHueServiceProvider.php index 12219c3..b95a6d8 100644 --- a/src/PhilipsHueServiceProvider.php +++ b/src/PhilipsHueServiceProvider.php @@ -6,9 +6,6 @@ class PhilipsHueServiceProvider extends ServiceProvider { - public function register() { - $this->mergeConfigFrom(__DIR__ . '/../config/philipshue.php', 'philipshue'); - } public function boot() { From 226ad6b68db1eddc05a8992342b275d3f3baa27f Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Thu, 31 Oct 2019 23:48:22 +0100 Subject: [PATCH 6/7] removed doc due to return type not yet clear --- src/Resources/HueLightResource.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Resources/HueLightResource.php b/src/Resources/HueLightResource.php index 1025a72..0cc3880 100644 --- a/src/Resources/HueLightResource.php +++ b/src/Resources/HueLightResource.php @@ -4,9 +4,7 @@ class HueLightResource extends BaseHueResource { - /** - * @return mixed - */ + public function isLightOn() { return $this->state->on; From 68399bd75c8f548cee91927d85f4d89d3b4026f6 Mon Sep 17 00:00:00 2001 From: Allen Taylor Date: Fri, 1 Nov 2019 00:20:19 +0100 Subject: [PATCH 7/7] added phpdoc to properties --- src/HueClient.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/HueClient.php b/src/HueClient.php index 61f22e9..29d37d0 100644 --- a/src/HueClient.php +++ b/src/HueClient.php @@ -7,8 +7,19 @@ class HueClient { + /** + * @var Client + */ private $guzzle; + + /** + * @var string + */ private $baseUrl = 'https://api.meethue.com'; + + /** + * @var string + */ protected $baseUser; public function __construct()