Skip to content

Commit

Permalink
2.0.0: Replace request with Axios (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael5r authored Mar 15, 2022
1 parent 311b8c5 commit 381c898
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ Temporary Items

.fuse_hidden*
.directory
.Trash-*
.Trash-*

node_modules
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This module requires MagicMirror version `2.5` or later.

This module displays the status of your [Philips Hue](http://meethue.com) lights and light groups on your Magic Mirror and and supports multiple view types and modes.

Please note that this module still uses v1 of the Hue API - once v2 of the Hue API has been released, I'll get the module updated.

![image](https://user-images.githubusercontent.com/3209660/49979103-2e3cd400-ff13-11e8-8f76-bc4c7d5e7b76.png)

*An example showing light groups on the left and lights on the right in the Grid view.*
Expand All @@ -30,7 +32,8 @@ This module displays the status of your [Philips Hue](http://meethue.com) lights


## Installing the module
Run `git clone https://github.com/michael5r/mmm-hue-lights.git` from inside your `MagicMirror/modules` folder.
1. Run `git clone https://github.com/michael5r/mmm-hue-lights.git` from inside your `MagicMirror/modules` folder.
2. Enter the new `mmm-hue-lights` directory and execute `npm install`.


## Getting the Hue credentials
Expand All @@ -41,7 +44,7 @@ In order for you to have access to your Hue lights, you need a [Hue developer ac

Please follow the instructions on this page to get both:

https://www.developers.meethue.com/documentation/getting-started
https://developers.meethue.com/develop/get-started-2/

If you don't have a Hue developer account already, click the `register` link on the page above to set one up (it's free).

Expand Down
27 changes: 14 additions & 13 deletions node_helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var NodeHelper = require('node_helper');
var request = require('request');
var axios = require('axios').default;

module.exports = NodeHelper.create({

Expand All @@ -17,20 +17,21 @@ module.exports = NodeHelper.create({
var url = 'http://' + bridgeIp + '/api/' + user;
var self = this;

request(url, {method: 'GET'}, function(err, res, body) {

if ((err) || (res.statusCode !== 200)) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: ' + err);
} else {
if (body === {}) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: No Hue data was received.');
axios.get(url)
.then(function (res) {
if (res.status !== 200) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: ' + res.status);
} else {
var data = JSON.parse(body);
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA', data);
if (res.data === {}) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: No Hue data was received.');
} else {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA', res.data);
}
}
}

});
})
.catch(function (err) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: ' + err);
});

}
}
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "mmm-hue-lights",
"version": "2.0.0",
"description": "Display the status of your Philips Hue lights and light groups on your MagicMirror. Supports multiple view types and modes.",
"repository": {
"type": "git",
"url": "git+https://github.com/michael5r/mmm-hue-lights"
},
"main": "mmm-hue-lights.js",
"scripts": {
"test": "echo \"Error: No tests specified\" && exit 1"
},
"author": "Michael Schmidt",
"license": "MIT",
"dependencies": {
"axios": "^0.26.0"
}
}

0 comments on commit 381c898

Please sign in to comment.