forked from aholstenson/miio
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding first implementation of humidifier
- Loading branch information
1 parent
5e0907b
commit a6d7fad
Showing
4 changed files
with
170 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
# Humidifier | ||
|
||
* `device.type`: `humidifier` | ||
* **Models**: zhimi-humidifier-v1 | ||
* **Model identifiers**: `zhimi-humidifier-v1` | ||
* **Models**: Mi Humidifier | ||
* **Model identifiers**: `zhimi.humidifier.v1` | ||
|
||
### Properties and sensor values | ||
### Properties | ||
|
||
* `power` | ||
* `mode` | ||
* `temp_dec` | ||
* `humidity` | ||
* `led_b` | ||
* `buzzer` | ||
* `child_lock` | ||
* `limit_hum` | ||
* `trans_level` | ||
* `cola` | ||
|
||
Example: return device.call('get_prop', ["cola","humidity","temp_dec","power","mode","led_b","buzzer","child_lock","limit_hum","trans_level"]) | ||
* `power`, boolean indicating the power state of the device | ||
* `mode`, string indicating the current mode | ||
* `temperature`, number indicating the temperature in Celsius | ||
* `humidity`, number indicating the relative humidity in percent | ||
|
||
### Power | ||
|
||
* power is specified as on or off string | ||
Example: return device.call('set_power', ["on"]) | ||
* `device.power`, read-only boolean indicating if the device is powered on | ||
* `device.setPower(boolean)`, change the power state of the device, returns a promise | ||
|
||
### Modes | ||
|
||
* `silent`, lowest speed | ||
The humidifiers have different modes that controls their speed. | ||
|
||
* `device.mode`, read-only string indicating the current mode | ||
* `device.modes`, read-only array indicating the modes supports by the device | ||
* `device.setMode(string)`, set the current mode of the device, returns a promise | ||
|
||
The modes are currently: | ||
|
||
* `idle`, turn the device off | ||
* `silent`, lower speed | ||
* `medium`, medium speed | ||
* `high`, high speed | ||
|
||
Example: return device.call('set_mode', ["medium"]) | ||
### Sensor values | ||
|
||
* `device.temperature` - number indicating the temperature in Celsius | ||
* `device.humidity` - number indicating the relative humidity in percent | ||
* `device.aqi` - number indicating the Air Quality Index (based on PM2.5) | ||
|
||
### Settings | ||
|
||
* `buzzer` - turn the buzzer on or off. | ||
Example: return device.call('set_buzzer', ['on']) | ||
* `device.buzzer` - boolean indicating if the buzzer (beep) is active | ||
* `device.setBuzzer(boolean)` - switch the buzzer on or off | ||
* `device.ledBrightness` - the LED brightness, `bright`, `dim` or `off` | ||
* `device.setLedBrightness(string)` - set the brightness of the LED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
'use strict'; | ||
|
||
const Device = require('../device'); | ||
const Power = require('./capabilities/power'); | ||
const Sensor = require('./capabilities/sensor'); | ||
|
||
/** | ||
* Abstraction over a Mi Humidifier. | ||
*/ | ||
class Humidifier extends Device { | ||
static get TYPE() { return 'humidifier' } | ||
|
||
constructor(options) { | ||
super(options); | ||
|
||
this.type = Humidifier.TYPE; | ||
|
||
this.defineProperty('power', v => v === 'on'); | ||
Power.extend(this, { | ||
set: (power) => this.call('set_power', [ power ? 'on' : 'off' ], { | ||
refresh: [ 'power', 'mode' ], | ||
refreshDelay: 200 | ||
}) | ||
}); | ||
|
||
this.capabilities.push('mode'); | ||
this.defineProperty('mode'); | ||
|
||
// Sensor values reported by the device | ||
this.defineProperty('temp_dec', { | ||
name: 'temperature', | ||
mapper: v => v / 10.0 | ||
}); | ||
Sensor.extend(this, { name : 'temperature' }); | ||
|
||
this.defineProperty('humidity'); | ||
Sensor.extend(this, { name : 'humidity' }); | ||
|
||
// Buzzer and beeping | ||
this.defineProperty('buzzer', { | ||
mapper: v => v == 'on' | ||
}); | ||
|
||
this.defineProperty('led_b', { | ||
name: 'ledBrightness', | ||
mapper: v => { | ||
switch(v) { | ||
case 0: | ||
return 'bright'; | ||
case 1: | ||
return 'dim'; | ||
case 2: | ||
return 'off'; | ||
default: | ||
return 'unknown'; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get the mode that the device is in. | ||
*/ | ||
get mode() { | ||
return this.property('mode'); | ||
} | ||
|
||
/** | ||
* Get the modes that are available to set. | ||
*/ | ||
get modes() { | ||
return [ 'idle', 'silent', 'medium', 'high' ]; | ||
} | ||
|
||
/** | ||
* Set the mode of this device. | ||
*/ | ||
setMode(mode) { | ||
return this.call('set_mode', [ mode ], { | ||
refresh: [ 'power', 'mode' ], | ||
refreshDelay: 200 | ||
}) | ||
.then(Device.checkOk) | ||
.catch(err => { | ||
throw err.code == -5001 ? new Error('Mode `' + mode + '` not supported') : err | ||
}); | ||
} | ||
|
||
/** | ||
* Get the current LED brightness, either `bright`, `dim` or `off`. | ||
*/ | ||
get ledBrightness() { | ||
return this.property('ledBrightness'); | ||
} | ||
|
||
/** | ||
* Set the LED brightness to either `bright`, `dim` or `off`. | ||
*/ | ||
setLedBrightness(level) { | ||
switch(level) { | ||
case 'bright': | ||
level = 0; | ||
break; | ||
case 'dim': | ||
level = 1; | ||
break; | ||
case 'off': | ||
level = 2; | ||
break; | ||
default: | ||
return Promise.reject(new Error('Invalid LED brigthness: ' + level)); | ||
} | ||
return this.call('set_led_b', [ level ], { refresh: true }) | ||
.then(() => null); | ||
} | ||
|
||
/** | ||
* Get if the buzzer on the device is active, where it will beep whenever | ||
* a command is performed. | ||
*/ | ||
get buzzer() { | ||
return this.property('buzzer'); | ||
} | ||
|
||
/** | ||
* Set if the device should beep whenever a command is performed. | ||
*/ | ||
setBuzzer(active) { | ||
return this.call('set_buzzer', [ active ? 'on' : 'off' ], { refresh: true }) | ||
.then(() => null); | ||
} | ||
} | ||
|
||
module.exports = Humidifier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters