Skip to content

Commit

Permalink
Add useDryForCool
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Jul 2, 2020
1 parent a23032f commit fd1a719
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# homebridge-nature-remo-aircon
# homebridge-nature-remo-cloud-aircon

Homebridge Plug-in for Air Conditioner Managed by Nature Remo

Expand All @@ -11,13 +11,15 @@ Example:
{
"accessory": "NatureRemoAircon",
"name": "Air Conditioner",
"access_token": "xxxxxxxxx_xxxxxxxxxxxxxxx_x_xxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"appliance_id": ""
"useDryForCool": false,
"accessToken": "xxxxxxxxx_xxxxxxxxxxxxxxx_x_xxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"applianceId": ""
}
]

...
```

* Please get your access token at https://home.nature.global/ and set it to `access_token`.
* `appliance_id` can be left blank if you only have one aircon.
* `applianceId` can be left blank if you only have one aircon.
* `useDryForCool` can make map cool mode to dry mode in Home.
34 changes: 18 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ let hap;

module.exports = homebridge => {
hap = homebridge.hap;
homebridge.registerAccessory('homebridge-nature-remo-aircon', 'NatureRemoAircon', NatureRemoAircon);
homebridge.registerAccessory('homebridge-nature-remo-cloud-aircon', 'NatureRemoCloudAircon', NatureRemoCloudAircon);
};

class NatureRemoAircon {
class NatureRemoCloudAircon {

constructor(log, config) {
log('NatureRemoAircon init');
log('NatureRemoCloudAircon init');

this.log = log;
this.appliance_id = config.appliance_id || null;
this.access_token = config.access_token;
this.useDryForCool = config.useDryForCool || false;
this.applianceId = config.applianceId || null;
this.accessToken = config.accessToken;
this.schedule = config.schedule || '* * * * *';

this.service = null;
Expand Down Expand Up @@ -50,7 +51,7 @@ class NatureRemoAircon {

const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
uri: `/appliances/${this.record.id}/aircon_settings`,
headers: {'authorization': `Bearer ${this.access_token}`},
headers: {'authorization': `Bearer ${this.accessToken}`},
method: 'POST',
form: this.requestParams
});
Expand Down Expand Up @@ -94,7 +95,7 @@ class NatureRemoAircon {
this.log('refreshing target appliance record');
const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
uri: '/appliances',
headers: {'authorization': `Bearer ${this.access_token}`}
headers: {'authorization': `Bearer ${this.accessToken}`}
});

request(options, (error, response, body) => {
Expand All @@ -113,9 +114,9 @@ class NatureRemoAircon {
return;
}
let appliance;
if (this.appliance_id) {
if (this.applianceId) {
appliance = json.find((app, i) => {
return app.id === this.appliance_id;
return app.id === this.applianceId;
});
} else {
appliance = json.filter(app => {
Expand All @@ -128,12 +129,12 @@ class NatureRemoAircon {
if (appliance) {
this.log(`Target aircon ID: ${appliance.id}`);
this.record = appliance;
this.appliance_id = appliance.id; // persist discovered ID
this.applianceId = appliance.id; // persist discovered ID
this._refreshTemperature();
this._notifyConfigurationIfNeeded();
this._notifyLatestValues();
} else {
this.log('Target aircon could not be found. You can leave `appliance_id` blank to automatically use the first aircon.');
this.log('Target aircon could not be found. You can leave `applianceId` blank to automatically use the first aircon.');
}
});
}
Expand All @@ -147,7 +148,7 @@ class NatureRemoAircon {
this.log('refreshing temperature record');
const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
uri: '/devices',
headers: {'authorization': `Bearer ${this.access_token}`}
headers: {'authorization': `Bearer ${this.accessToken}`}
});

request(options, (error, response, body) => {
Expand Down Expand Up @@ -226,7 +227,8 @@ class NatureRemoAircon {
return 0;
} else if (settings.mode === 'warm') {
return 1;
} else if (settings.mode === 'cool') {
} else if (settings.mode === 'cool' ||
settings.mode === 'dry') {
return 2;
} else if (settings.mode === 'auto') {
return 3;
Expand Down Expand Up @@ -256,7 +258,7 @@ class NatureRemoAircon {
} else if (value == 2) {
// cool
params.button = '';
params.operation_mode = 'cool';
params.operation_mode = this.useDryForCool ? 'dry' : 'cool';
} else if (value == 3) {
// auto
if ('auto' in this.record.aircon.range.modes) {
Expand Down Expand Up @@ -377,7 +379,7 @@ class NatureRemoAircon {
const modes = this.record.aircon.range.modes;

for (const mode in modes) {
if (! (mode === 'cool' || mode === 'warm')) {
if (!(mode === 'cool' || mode === 'warm' || mode === 'dry')) {
continue;
}
const temperatures = modes[mode].temp.filter(t => t.match(/^\d+(\.\d+)?$/)).map(t => parseInt(t));
Expand All @@ -387,4 +389,4 @@ class NatureRemoAircon {
return allTemperatures;
}

} // class NatureRemoAircon
} // class NatureRemoCloudAircon
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "homebridge-nature-remo-aircon",
"name": "homebridge-nature-remo-cloud-aircon",
"version": "1.0.0",
"description": "Homebridge Plug-in for Air Conditioner Managed by Nature Remo",
"main": "index.js",
Expand All @@ -10,7 +10,7 @@
"license": "ISC",
"repository": {
"type": "git",
"url": "https://github.com/kmaehashi/homebridge-nature-remo-aircon.git"
"url": "https://github.com/japaniot/homebridge-nature-remo-cloud-aircon.git"
},
"keywords": ["homebridge-plugin"],
"engines": {
Expand Down

0 comments on commit fd1a719

Please sign in to comment.