Skip to content

Commit fd1a719

Browse files
committed
Add useDryForCool
1 parent a23032f commit fd1a719

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# homebridge-nature-remo-aircon
1+
# homebridge-nature-remo-cloud-aircon
22

33
Homebridge Plug-in for Air Conditioner Managed by Nature Remo
44

@@ -11,13 +11,15 @@ Example:
1111
{
1212
"accessory": "NatureRemoAircon",
1313
"name": "Air Conditioner",
14-
"access_token": "xxxxxxxxx_xxxxxxxxxxxxxxx_x_xxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
15-
"appliance_id": ""
14+
"useDryForCool": false,
15+
"accessToken": "xxxxxxxxx_xxxxxxxxxxxxxxx_x_xxxxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
16+
"applianceId": ""
1617
}
1718
]
1819

1920
...
2021
```
2122

2223
* Please get your access token at https://home.nature.global/ and set it to `access_token`.
23-
* `appliance_id` can be left blank if you only have one aircon.
24+
* `applianceId` can be left blank if you only have one aircon.
25+
* `useDryForCool` can make map cool mode to dry mode in Home.

index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ let hap;
1010

1111
module.exports = homebridge => {
1212
hap = homebridge.hap;
13-
homebridge.registerAccessory('homebridge-nature-remo-aircon', 'NatureRemoAircon', NatureRemoAircon);
13+
homebridge.registerAccessory('homebridge-nature-remo-cloud-aircon', 'NatureRemoCloudAircon', NatureRemoCloudAircon);
1414
};
1515

16-
class NatureRemoAircon {
16+
class NatureRemoCloudAircon {
1717

1818
constructor(log, config) {
19-
log('NatureRemoAircon init');
19+
log('NatureRemoCloudAircon init');
2020

2121
this.log = log;
22-
this.appliance_id = config.appliance_id || null;
23-
this.access_token = config.access_token;
22+
this.useDryForCool = config.useDryForCool || false;
23+
this.applianceId = config.applianceId || null;
24+
this.accessToken = config.accessToken;
2425
this.schedule = config.schedule || '* * * * *';
2526

2627
this.service = null;
@@ -50,7 +51,7 @@ class NatureRemoAircon {
5051

5152
const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
5253
uri: `/appliances/${this.record.id}/aircon_settings`,
53-
headers: {'authorization': `Bearer ${this.access_token}`},
54+
headers: {'authorization': `Bearer ${this.accessToken}`},
5455
method: 'POST',
5556
form: this.requestParams
5657
});
@@ -94,7 +95,7 @@ class NatureRemoAircon {
9495
this.log('refreshing target appliance record');
9596
const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
9697
uri: '/appliances',
97-
headers: {'authorization': `Bearer ${this.access_token}`}
98+
headers: {'authorization': `Bearer ${this.accessToken}`}
9899
});
99100

100101
request(options, (error, response, body) => {
@@ -113,9 +114,9 @@ class NatureRemoAircon {
113114
return;
114115
}
115116
let appliance;
116-
if (this.appliance_id) {
117+
if (this.applianceId) {
117118
appliance = json.find((app, i) => {
118-
return app.id === this.appliance_id;
119+
return app.id === this.applianceId;
119120
});
120121
} else {
121122
appliance = json.filter(app => {
@@ -128,12 +129,12 @@ class NatureRemoAircon {
128129
if (appliance) {
129130
this.log(`Target aircon ID: ${appliance.id}`);
130131
this.record = appliance;
131-
this.appliance_id = appliance.id; // persist discovered ID
132+
this.applianceId = appliance.id; // persist discovered ID
132133
this._refreshTemperature();
133134
this._notifyConfigurationIfNeeded();
134135
this._notifyLatestValues();
135136
} else {
136-
this.log('Target aircon could not be found. You can leave `appliance_id` blank to automatically use the first aircon.');
137+
this.log('Target aircon could not be found. You can leave `applianceId` blank to automatically use the first aircon.');
137138
}
138139
});
139140
}
@@ -147,7 +148,7 @@ class NatureRemoAircon {
147148
this.log('refreshing temperature record');
148149
const options = Object.assign({}, DEFAULT_REQUEST_OPTIONS, {
149150
uri: '/devices',
150-
headers: {'authorization': `Bearer ${this.access_token}`}
151+
headers: {'authorization': `Bearer ${this.accessToken}`}
151152
});
152153

153154
request(options, (error, response, body) => {
@@ -226,7 +227,8 @@ class NatureRemoAircon {
226227
return 0;
227228
} else if (settings.mode === 'warm') {
228229
return 1;
229-
} else if (settings.mode === 'cool') {
230+
} else if (settings.mode === 'cool' ||
231+
settings.mode === 'dry') {
230232
return 2;
231233
} else if (settings.mode === 'auto') {
232234
return 3;
@@ -256,7 +258,7 @@ class NatureRemoAircon {
256258
} else if (value == 2) {
257259
// cool
258260
params.button = '';
259-
params.operation_mode = 'cool';
261+
params.operation_mode = this.useDryForCool ? 'dry' : 'cool';
260262
} else if (value == 3) {
261263
// auto
262264
if ('auto' in this.record.aircon.range.modes) {
@@ -377,7 +379,7 @@ class NatureRemoAircon {
377379
const modes = this.record.aircon.range.modes;
378380

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

390-
} // class NatureRemoAircon
392+
} // class NatureRemoCloudAircon

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "homebridge-nature-remo-aircon",
2+
"name": "homebridge-nature-remo-cloud-aircon",
33
"version": "1.0.0",
44
"description": "Homebridge Plug-in for Air Conditioner Managed by Nature Remo",
55
"main": "index.js",
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"repository": {
1212
"type": "git",
13-
"url": "https://github.com/kmaehashi/homebridge-nature-remo-aircon.git"
13+
"url": "https://github.com/japaniot/homebridge-nature-remo-cloud-aircon.git"
1414
},
1515
"keywords": ["homebridge-plugin"],
1616
"engines": {

0 commit comments

Comments
 (0)