-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Mi Smart Humidifier 2 (#117)
- Loading branch information
Showing
5 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,118 @@ | ||
import type * as hb from "homebridge"; | ||
import * as miio from "miio-api"; | ||
import { MiotProtocol, MiotArg } from "../protocols"; | ||
import { DeviceOptions } from "../../platform"; | ||
import { ValueOf } from "../utils"; | ||
import { Features } from "../features"; | ||
import { HumidifierConfig } from "."; | ||
|
||
enum Mode { | ||
Level1 = 1, | ||
Level2 = 2, | ||
Level3 = 3, | ||
Humidity = 4, | ||
} | ||
|
||
type Props = { | ||
power: boolean; | ||
fan_level: Mode; | ||
target_humidity: number; | ||
temperature: number; | ||
relative_humidity: number; | ||
switch_status: boolean; | ||
buzzer: boolean; | ||
}; | ||
|
||
class Proto extends MiotProtocol<Props> { | ||
protected getCallArg(key: keyof Props): MiotArg { | ||
return this.callArgs(key, null); | ||
} | ||
|
||
protected setCallArg(key: keyof Props, value: ValueOf<Props>): MiotArg { | ||
return this.callArgs(key, value); | ||
} | ||
|
||
private callArgs(key: keyof Props, value: ValueOf<Props> | null): MiotArg { | ||
const common = { did: key, value }; | ||
|
||
switch (key) { | ||
case "power": | ||
return { ...common, siid: 2, piid: 1 }; | ||
case "fan_level": | ||
return { ...common, siid: 2, piid: 5 }; | ||
case "target_humidity": | ||
return { ...common, siid: 2, piid: 6 }; | ||
case "relative_humidity": | ||
return { ...common, siid: 3, piid: 1 }; | ||
case "switch_status": | ||
return { ...common, siid: 6, piid: 1 }; | ||
case "buzzer": | ||
return { ...common, siid: 5, piid: 1 }; | ||
case "temperature": | ||
return { ...common, siid: 3, piid: 7 }; | ||
} | ||
} | ||
} | ||
|
||
export function deermaJSQ2W( | ||
device: miio.Device, | ||
feat: Features<Props>, | ||
log: hb.Logging, | ||
options: DeviceOptions, | ||
): HumidifierConfig<Props> { | ||
return { | ||
protocol: new Proto(device), | ||
features: [ | ||
feat.targetState(), | ||
feat.currentState("power", { on: true, off: false }), | ||
feat.active("power", "set_properties", { on: true, off: false }), | ||
feat.rotationSpeed("fan_level", "set_properties", { | ||
modes: [Mode.Level1, Mode.Level2, Mode.Level3, Mode.Humidity], | ||
}), | ||
feat.humidity("relative_humidity"), | ||
...(options.ledBulb?.enabled | ||
? feat.ledBulb("switch_status", "set_properties", { | ||
name: options.ledBulb.name, | ||
modes: [true, false], | ||
on: true, | ||
off: false, | ||
}) | ||
: []), | ||
|
||
...(!options.disableTargetHumidity | ||
? [ | ||
feat.humidityThreshold("target_humidity", "set_properties", { | ||
min: 40, | ||
max: 70, | ||
switchToMode: options.autoSwitchToHumidityMode | ||
? { | ||
key: "fan_level", | ||
call: "set_properties", | ||
value: Mode.Humidity, | ||
} | ||
: undefined, | ||
}), | ||
] | ||
: []), | ||
|
||
...(options.buzzerSwitch?.enabled | ||
? feat.buzzerSwitch("buzzer", "set_properties", { | ||
name: options.buzzerSwitch.name, | ||
on: true, | ||
off: false, | ||
}) | ||
: []), | ||
...(options.temperatureSensor?.enabled | ||
? feat.temperatureSensor("temperature", { | ||
name: options.temperatureSensor.name, | ||
toChar: (it) => it, | ||
}) | ||
: []), | ||
...(options.humiditySensor?.enabled | ||
? feat.humiditySensor("relative_humidity", { | ||
name: options.humiditySensor.name, | ||
}) | ||
: []), | ||
], | ||
}; | ||
} |
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