homebridge-nature-remo-air-purifier 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ssasuki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # homebridge-nature-remo-air-purifier
2
+ [Homebridge](https://github.com/homebridge/homebridge) plugin to send power on and off to an air purifier using [Nature Remo](https://nature.global/nature-remo/).
3
+
4
+ ## Installation
5
+ ```bash
6
+ npm install -g homebridge-nature-remo-air-purifier
7
+ ```
8
+
9
+ ## Example config.json
10
+ ```json
11
+ "accessories": [
12
+ {
13
+ "name": "[Name display in Home app]",
14
+ "access_token": "[Your access_token]",
15
+ "signal_ID_on": "[aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa]",
16
+ "signal_ID_off": "[bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb]",
17
+ "accessory": "NatureRemoAirPurifier"
18
+ }
19
+ ]
20
+ ```
21
+ - `name` can be set whatever you want
22
+ - To get `access_token`, visit https://home.nature.global/
23
+ - To get `signal_ID_on` and `signal_ID_off`, run `curl -X GET "https://api.nature.global/1/appliances" -H "Authorization: Bearer [access_token]"` and find `id` key
24
+ - `accessory` must be `NatureRemoAirPurifier`
package/index.js ADDED
@@ -0,0 +1,61 @@
1
+ let Service, Characteristic;
2
+ let exec = require("child_process").exec;
3
+
4
+ module.exports = function(homebridge) {
5
+ Service = homebridge.hap.Service;
6
+ Characteristic = homebridge.hap.Characteristic;
7
+ homebridge.registerAccessory("homebridge-nature-remo-air-purifier", "NatureRemoAirPurifier", AirPurifier);
8
+ }
9
+
10
+ function AirPurifier(log, config) {
11
+ this.log = log;
12
+
13
+ this.name = config["name"];
14
+ this.access_token = config["access_token"];
15
+ this.signal_ID_on = config["signal_ID_on"];
16
+ this.signal_ID_off = config["signal_ID_off"];
17
+
18
+ this.state = { power: false };
19
+
20
+ this.informationService = new Service.AccessoryInformation();
21
+ this.informationService
22
+ .setCharacteristic(Characteristic.Manufacturer, "Homebridge")
23
+ .setCharacteristic(Characteristic.Model, "NatureRemoAirPurifier")
24
+ .setCharacteristic(Characteristic.SerialNumber, "NRAP-" + this.name);
25
+
26
+ this.airPurifierService = new Service.AirPurifier(this.name);
27
+ this.airPurifierService.getCharacteristic(Characteristic.Active)
28
+ .on('set', this.setPower.bind(this));
29
+ }
30
+
31
+ AirPurifier.prototype.getServices = function() {
32
+ return [this.informationService, this.airPurifierService];
33
+ }
34
+
35
+ AirPurifier.prototype.setPower = function(value, callback) {
36
+ if (this.state.power != value) {
37
+ this.state.power = value;
38
+ this.log('Setting air purifier power to ' + value);
39
+
40
+ const signalID = value ? this.signal_ID_on : this.signal_ID_off;
41
+
42
+ this.cmdRequest(signalID, function(error, stdout, stderr) {
43
+ if (error) {
44
+ this.log('Failed to set power: ' + error);
45
+ callback(error);
46
+ } else {
47
+ callback();
48
+ }
49
+ }.bind(this));
50
+ } else {
51
+ callback();
52
+ }
53
+ }
54
+
55
+ AirPurifier.prototype.cmdRequest = function(signalID, callback) {
56
+ let cmd = 'curl -X POST ' +
57
+ '"https://api.nature.global/1/signals/' + signalID + '/send" ' +
58
+ '-H "accept":"application/json" ' +
59
+ '-k --header "Authorization":"Bearer ' + this.access_token + '"';
60
+ exec(cmd, function(error, stdout, stderr) { callback(error, stdout, stderr); });
61
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "homebridge-nature-remo-air-purifier",
3
+ "displayName": "Homebridge Nature Remo Air Purifier",
4
+ "version": "1.0.0",
5
+ "description": "Homebridge Plugin to send power on and off to an air purifier using Nature Remo",
6
+ "author": "Sasuki Sho",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git://github.com/ssasuki/homebridge-nature-remo-air-purifier.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ssasuki/homebridge-nature-remo-air-purifier/issues"
14
+ },
15
+ "keywords": [
16
+ "homebridge-plugin",
17
+ "homebridge",
18
+ "apple",
19
+ "homekit",
20
+ "nature",
21
+ "remo",
22
+ "air",
23
+ "purifier"
24
+ ],
25
+ "engines": {
26
+ "node": ">=10.17.0",
27
+ "homebridge": ">=0.4.8"
28
+ },
29
+ "dependencies": {}
30
+ }