@nubisco/homebridge-tuya-local-platform 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/LICENSE +9 -0
- package/README.md +48 -0
- package/config.schema.json +852 -0
- package/dist/accessories/AirConditioner.accessory.d.ts +50 -0
- package/dist/accessories/AirConditioner.accessory.d.ts.map +1 -0
- package/dist/accessories/AirConditioner.accessory.js +447 -0
- package/dist/accessories/AirConditioner.accessory.js.map +1 -0
- package/dist/accessories/AirPurifier.accessory.d.ts +37 -0
- package/dist/accessories/AirPurifier.accessory.d.ts.map +1 -0
- package/dist/accessories/AirPurifier.accessory.js +414 -0
- package/dist/accessories/AirPurifier.accessory.js.map +1 -0
- package/dist/accessories/Base.accessory.d.ts +43 -0
- package/dist/accessories/Base.accessory.d.ts.map +1 -0
- package/dist/accessories/Base.accessory.js +310 -0
- package/dist/accessories/Base.accessory.js.map +1 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.d.ts +47 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.d.ts.map +1 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.js +274 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.js.map +1 -0
- package/dist/accessories/Convector.accessory.d.ts +43 -0
- package/dist/accessories/Convector.accessory.d.ts.map +1 -0
- package/dist/accessories/Convector.accessory.js +297 -0
- package/dist/accessories/Convector.accessory.js.map +1 -0
- package/dist/accessories/CustomMultiOutlet.accessory.d.ts +15 -0
- package/dist/accessories/CustomMultiOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/CustomMultiOutlet.accessory.js +105 -0
- package/dist/accessories/CustomMultiOutlet.accessory.js.map +1 -0
- package/dist/accessories/Dehumidifier.accessory.d.ts +38 -0
- package/dist/accessories/Dehumidifier.accessory.d.ts.map +1 -0
- package/dist/accessories/Dehumidifier.accessory.js +264 -0
- package/dist/accessories/Dehumidifier.accessory.js.map +1 -0
- package/dist/accessories/EnergyCharacteristics.d.ts +4 -0
- package/dist/accessories/EnergyCharacteristics.d.ts.map +1 -0
- package/dist/accessories/EnergyCharacteristics.js +103 -0
- package/dist/accessories/EnergyCharacteristics.js.map +1 -0
- package/dist/accessories/GarageDoor.accessory.d.ts +30 -0
- package/dist/accessories/GarageDoor.accessory.d.ts.map +1 -0
- package/dist/accessories/GarageDoor.accessory.js +228 -0
- package/dist/accessories/GarageDoor.accessory.js.map +1 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.d.ts +49 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.d.ts.map +1 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.js +292 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.js.map +1 -0
- package/dist/accessories/MultiOutlet.accessory.d.ts +15 -0
- package/dist/accessories/MultiOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/MultiOutlet.accessory.js +101 -0
- package/dist/accessories/MultiOutlet.accessory.js.map +1 -0
- package/dist/accessories/OilDiffuser.accessory.d.ts +67 -0
- package/dist/accessories/OilDiffuser.accessory.d.ts.map +1 -0
- package/dist/accessories/OilDiffuser.accessory.js +466 -0
- package/dist/accessories/OilDiffuser.accessory.js.map +1 -0
- package/dist/accessories/Outlet.accessory.d.ts +11 -0
- package/dist/accessories/Outlet.accessory.d.ts.map +1 -0
- package/dist/accessories/Outlet.accessory.js +87 -0
- package/dist/accessories/Outlet.accessory.js.map +1 -0
- package/dist/accessories/RGBTWLight.accessory.d.ts +37 -0
- package/dist/accessories/RGBTWLight.accessory.d.ts.map +1 -0
- package/dist/accessories/RGBTWLight.accessory.js +237 -0
- package/dist/accessories/RGBTWLight.accessory.js.map +1 -0
- package/dist/accessories/RGBTWOutlet.accessory.d.ts +38 -0
- package/dist/accessories/RGBTWOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/RGBTWOutlet.accessory.js +305 -0
- package/dist/accessories/RGBTWOutlet.accessory.js.map +1 -0
- package/dist/accessories/SimpleBlinds.accessory.d.ts +32 -0
- package/dist/accessories/SimpleBlinds.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleBlinds.accessory.js +286 -0
- package/dist/accessories/SimpleBlinds.accessory.js.map +1 -0
- package/dist/accessories/SimpleDimmer.accessory.d.ts +14 -0
- package/dist/accessories/SimpleDimmer.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleDimmer.accessory.js +54 -0
- package/dist/accessories/SimpleDimmer.accessory.js.map +1 -0
- package/dist/accessories/SimpleDimmer2.accessory.d.ts +14 -0
- package/dist/accessories/SimpleDimmer2.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleDimmer2.accessory.js +53 -0
- package/dist/accessories/SimpleDimmer2.accessory.js.map +1 -0
- package/dist/accessories/SimpleFan.accessory.d.ts +21 -0
- package/dist/accessories/SimpleFan.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleFan.accessory.js +125 -0
- package/dist/accessories/SimpleFan.accessory.js.map +1 -0
- package/dist/accessories/SimpleFanLight.accessory.d.ts +31 -0
- package/dist/accessories/SimpleFanLight.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleFanLight.accessory.js +191 -0
- package/dist/accessories/SimpleFanLight.accessory.js.map +1 -0
- package/dist/accessories/SimpleHeater.accessory.d.ts +28 -0
- package/dist/accessories/SimpleHeater.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleHeater.accessory.js +175 -0
- package/dist/accessories/SimpleHeater.accessory.js.map +1 -0
- package/dist/accessories/SimpleLight.accessory.d.ts +11 -0
- package/dist/accessories/SimpleLight.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleLight.accessory.js +38 -0
- package/dist/accessories/SimpleLight.accessory.js.map +1 -0
- package/dist/accessories/Switch.accessory.d.ts +15 -0
- package/dist/accessories/Switch.accessory.d.ts.map +1 -0
- package/dist/accessories/Switch.accessory.js +101 -0
- package/dist/accessories/Switch.accessory.js.map +1 -0
- package/dist/accessories/TWLight.accessory.d.ts +19 -0
- package/dist/accessories/TWLight.accessory.d.ts.map +1 -0
- package/dist/accessories/TWLight.accessory.js +88 -0
- package/dist/accessories/TWLight.accessory.js.map +1 -0
- package/dist/accessories/Valve.accessory.d.ts +15 -0
- package/dist/accessories/Valve.accessory.d.ts.map +1 -0
- package/dist/accessories/Valve.accessory.js +144 -0
- package/dist/accessories/Valve.accessory.js.map +1 -0
- package/dist/accessories/index.d.ts +25 -0
- package/dist/accessories/index.d.ts.map +1 -0
- package/dist/accessories/index.js +55 -0
- package/dist/accessories/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +206 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/TuyaAccessory.d.ts +45 -0
- package/dist/protocol/TuyaAccessory.d.ts.map +1 -0
- package/dist/protocol/TuyaAccessory.js +646 -0
- package/dist/protocol/TuyaAccessory.js.map +1 -0
- package/dist/protocol/TuyaDiscovery.d.ts +27 -0
- package/dist/protocol/TuyaDiscovery.d.ts.map +1 -0
- package/dist/protocol/TuyaDiscovery.js +141 -0
- package/dist/protocol/TuyaDiscovery.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Base_accessory_1 = __importDefault(require("./Base.accessory"));
|
|
7
|
+
const async_1 = __importDefault(require("async"));
|
|
8
|
+
class MultiOutletAccessory extends Base_accessory_1.default {
|
|
9
|
+
static getCategory(Categories) {
|
|
10
|
+
return Categories.OUTLET;
|
|
11
|
+
}
|
|
12
|
+
_justRegistered;
|
|
13
|
+
_pendingPower = null;
|
|
14
|
+
constructor(...props) {
|
|
15
|
+
super(...props);
|
|
16
|
+
}
|
|
17
|
+
_registerPlatformAccessory() {
|
|
18
|
+
this._verifyCachedPlatformAccessory();
|
|
19
|
+
this._justRegistered = true;
|
|
20
|
+
super._registerPlatformAccessory();
|
|
21
|
+
}
|
|
22
|
+
_verifyCachedPlatformAccessory() {
|
|
23
|
+
if (this._justRegistered)
|
|
24
|
+
return;
|
|
25
|
+
const { Service } = this.hap;
|
|
26
|
+
const outletCount = parseInt(this.device.context.outletCount) || 1;
|
|
27
|
+
const _validServices = [];
|
|
28
|
+
for (let i = 0; i++ < outletCount;) {
|
|
29
|
+
let service = this.accessory.getServiceByUUIDAndSubType(Service.Outlet, 'outlet ' + i);
|
|
30
|
+
if (service)
|
|
31
|
+
this._checkServiceName(service, this.device.context.name + ' ' + i);
|
|
32
|
+
else
|
|
33
|
+
service = this.accessory.addService(Service.Outlet, this.device.context.name + ' ' + i, 'outlet ' + i);
|
|
34
|
+
_validServices.push(service);
|
|
35
|
+
}
|
|
36
|
+
this.accessory.services
|
|
37
|
+
.filter((service) => service.UUID === Service.Outlet.UUID && !_validServices.includes(service))
|
|
38
|
+
.forEach((service) => {
|
|
39
|
+
this.log.info('Removing', service.displayName);
|
|
40
|
+
this.accessory.removeService(service);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
_registerCharacteristics(dps) {
|
|
44
|
+
this._verifyCachedPlatformAccessory();
|
|
45
|
+
const { Service, Characteristic } = this.hap;
|
|
46
|
+
const characteristics = {};
|
|
47
|
+
this.accessory.services.forEach((service) => {
|
|
48
|
+
if (service.UUID !== Service.Outlet.UUID || !service.subtype)
|
|
49
|
+
return false;
|
|
50
|
+
let match;
|
|
51
|
+
if ((match = service.subtype.match(/^outlet (\d+)$/)) === null)
|
|
52
|
+
return;
|
|
53
|
+
characteristics[match[1]] = service
|
|
54
|
+
.getCharacteristic(Characteristic.On)
|
|
55
|
+
.updateValue(dps[match[1]])
|
|
56
|
+
.on('get', this.getPower.bind(this, match[1]))
|
|
57
|
+
.on('set', this.setPower.bind(this, match[1]));
|
|
58
|
+
});
|
|
59
|
+
this.device.on('change', (changes, _state) => {
|
|
60
|
+
Object.keys(changes).forEach((key) => {
|
|
61
|
+
if (characteristics[key] && characteristics[key].value !== changes[key])
|
|
62
|
+
characteristics[key].updateValue(changes[key]);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
getPower(dp, callback) {
|
|
67
|
+
callback(null, this.device.state[dp]);
|
|
68
|
+
}
|
|
69
|
+
setPower(dp, value, callback) {
|
|
70
|
+
if (!this._pendingPower) {
|
|
71
|
+
this._pendingPower = { props: {}, callbacks: [] };
|
|
72
|
+
}
|
|
73
|
+
if (dp) {
|
|
74
|
+
if (this._pendingPower.timer)
|
|
75
|
+
clearTimeout(this._pendingPower.timer);
|
|
76
|
+
this._pendingPower.props = { ...this._pendingPower.props, ...{ [dp]: value } };
|
|
77
|
+
this._pendingPower.callbacks.push(callback);
|
|
78
|
+
this._pendingPower.timer = setTimeout(() => {
|
|
79
|
+
this.setPower();
|
|
80
|
+
}, 500);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const callbacks = this._pendingPower.callbacks;
|
|
84
|
+
const callEachBack = (err) => {
|
|
85
|
+
async_1.default.eachSeries(callbacks, (callback, next) => {
|
|
86
|
+
try {
|
|
87
|
+
callback(err);
|
|
88
|
+
}
|
|
89
|
+
catch (_ex) {
|
|
90
|
+
/* ignore */
|
|
91
|
+
}
|
|
92
|
+
next();
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
const newValue = this._pendingPower.props;
|
|
96
|
+
this._pendingPower = null;
|
|
97
|
+
this.setMultiState(newValue, callEachBack);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.default = MultiOutletAccessory;
|
|
101
|
+
//# sourceMappingURL=MultiOutlet.accessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultiOutlet.accessory.js","sourceRoot":"","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EAAE,CAAC,EAAE,CAAC,EAAE,KAAM,EAAE,EAAE,CAAC;YAChF,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,QAAS,CAAC,CAAC;YAE7C,IAAI,CAAC,aAAa,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;gBACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,CAAC,EAAE,GAAG,CAAC,CAAC;YACR,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC;QAC/C,MAAM,YAAY,GAAG,CAAC,GAAiB,EAAE,EAAE;YACzC,eAAK,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC,QAA4B,EAAE,IAAgB,EAAE,EAAE;gBAC7E,IAAI,CAAC;oBACH,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,YAAY;gBACd,CAAC;gBACD,IAAI,EAAE,CAAC;YACT,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAE1B,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;CACF;AAED,kBAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import BaseAccessory from './Base.accessory';
|
|
2
|
+
import type { DPSState, DPSValue, HomebridgeCallback, HSBColor } from '../types';
|
|
3
|
+
declare class OilDiffuserAccessory extends BaseAccessory {
|
|
4
|
+
static getCategory(Categories: any): number;
|
|
5
|
+
dpLight: string;
|
|
6
|
+
dpMode: string;
|
|
7
|
+
dpColor: string;
|
|
8
|
+
dpActive: string;
|
|
9
|
+
dpRotationSpeed: string;
|
|
10
|
+
dpWaterLevel: string;
|
|
11
|
+
maxSpeed: number;
|
|
12
|
+
cmdInterval: string;
|
|
13
|
+
cmdContinuous: string;
|
|
14
|
+
cmdLow: string;
|
|
15
|
+
cmdHigh: string;
|
|
16
|
+
cmdMiddle: string;
|
|
17
|
+
cmdWhite: string;
|
|
18
|
+
cmdColor: string;
|
|
19
|
+
characteristicHue: any;
|
|
20
|
+
characteristicSaturation: any;
|
|
21
|
+
characteristicColorTemperature: any;
|
|
22
|
+
characteristicBrightness: any;
|
|
23
|
+
characteristicActive: any;
|
|
24
|
+
characteristicRotationSpeed: any;
|
|
25
|
+
adaptiveLightingController: any;
|
|
26
|
+
enableFlipSpeedSlider?: boolean;
|
|
27
|
+
_hkRotationSpeed?: number;
|
|
28
|
+
_pendingHueSaturation: {
|
|
29
|
+
props: Partial<HSBColor>;
|
|
30
|
+
callbacks: HomebridgeCallback[];
|
|
31
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
32
|
+
} | null;
|
|
33
|
+
_justRegistered?: boolean;
|
|
34
|
+
constructor(...props: any[]);
|
|
35
|
+
_isBelleLife(): boolean;
|
|
36
|
+
_isGeeni(): boolean;
|
|
37
|
+
_isAsakuki(): boolean;
|
|
38
|
+
_registerPlatformAccessory(): void;
|
|
39
|
+
_verifyCachedPlatformAccessory(): void;
|
|
40
|
+
_registerCharacteristics(dps: DPSState): void;
|
|
41
|
+
getBrightness(callback: HomebridgeCallback): void;
|
|
42
|
+
setBrightness(value: number, callback: HomebridgeCallback): void;
|
|
43
|
+
getColorTemperature(callback: HomebridgeCallback): void;
|
|
44
|
+
setColorTemperature(value: number, callback: HomebridgeCallback): void;
|
|
45
|
+
getHue(callback: HomebridgeCallback): void;
|
|
46
|
+
setHue(value: number, callback: HomebridgeCallback): void;
|
|
47
|
+
getSaturation(callback: HomebridgeCallback): void;
|
|
48
|
+
setSaturation(value: number, callback: HomebridgeCallback): void;
|
|
49
|
+
_setHueSaturation(prop?: Partial<HSBColor>, callback?: HomebridgeCallback): void;
|
|
50
|
+
getActive(callback: HomebridgeCallback): void;
|
|
51
|
+
_getActive(dp: DPSValue): number;
|
|
52
|
+
setActive(value: DPSValue, callback: HomebridgeCallback): void;
|
|
53
|
+
getCurrentHumidifierDehumidifierState(callback: HomebridgeCallback): void;
|
|
54
|
+
_getCurrentHumidifierDehumidifierState(dps: DPSState): number;
|
|
55
|
+
getTargetHumidifierDehumidifierState(callback: HomebridgeCallback): void;
|
|
56
|
+
_getTargetHumidifierDehumidifierState(): number;
|
|
57
|
+
setTargetHumidifierDehumidifierState(value: DPSValue, callback: HomebridgeCallback): void;
|
|
58
|
+
getWaterLevel(callback: HomebridgeCallback): void;
|
|
59
|
+
_getWaterLevel(value: DPSValue): number;
|
|
60
|
+
getRotationSpeed(callback: HomebridgeCallback): void;
|
|
61
|
+
_getRotationSpeed(dps: DPSState): number;
|
|
62
|
+
setRotationSpeed(value: number, callback: HomebridgeCallback): void;
|
|
63
|
+
convertRotationSpeedFromTuyaToHomeKit(value: DPSValue): number;
|
|
64
|
+
convertRotationSpeedFromHomeKitToTuya(value: number): string;
|
|
65
|
+
}
|
|
66
|
+
export default OilDiffuserAccessory;
|
|
67
|
+
//# sourceMappingURL=OilDiffuser.accessory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OilDiffuser.accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/OilDiffuser.accessory.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEjF,cAAM,oBAAqB,SAAQ,aAAa;IAC9C,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,GAAG,GAAG,MAAM;IAI3C,OAAO,EAAG,MAAM,CAAC;IACjB,MAAM,EAAG,MAAM,CAAC;IACR,OAAO,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAG,MAAM,CAAC;IAClB,eAAe,EAAG,MA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,GAAG,MAAM;IAc9D,qCAAqC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAgB7D;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Base_accessory_1 = __importDefault(require("./Base.accessory"));
|
|
7
|
+
const async_1 = __importDefault(require("async"));
|
|
8
|
+
class OilDiffuserAccessory extends Base_accessory_1.default {
|
|
9
|
+
static getCategory(Categories) {
|
|
10
|
+
return Categories.DEHUMIDIFIER;
|
|
11
|
+
}
|
|
12
|
+
dpLight;
|
|
13
|
+
dpMode;
|
|
14
|
+
dpActive;
|
|
15
|
+
dpRotationSpeed;
|
|
16
|
+
dpWaterLevel;
|
|
17
|
+
maxSpeed;
|
|
18
|
+
cmdInterval;
|
|
19
|
+
cmdContinuous;
|
|
20
|
+
cmdLow;
|
|
21
|
+
cmdHigh;
|
|
22
|
+
cmdMiddle;
|
|
23
|
+
cmdWhite;
|
|
24
|
+
cmdColor;
|
|
25
|
+
characteristicHue;
|
|
26
|
+
characteristicSaturation;
|
|
27
|
+
characteristicColorTemperature;
|
|
28
|
+
characteristicBrightness;
|
|
29
|
+
characteristicActive;
|
|
30
|
+
characteristicRotationSpeed;
|
|
31
|
+
adaptiveLightingController;
|
|
32
|
+
enableFlipSpeedSlider;
|
|
33
|
+
_hkRotationSpeed;
|
|
34
|
+
_pendingHueSaturation = null;
|
|
35
|
+
_justRegistered;
|
|
36
|
+
constructor(...props) {
|
|
37
|
+
super(...props);
|
|
38
|
+
}
|
|
39
|
+
_isBelleLife() {
|
|
40
|
+
return this.device.context.manufacturer.trim().toLowerCase() === 'bellelife';
|
|
41
|
+
}
|
|
42
|
+
_isGeeni() {
|
|
43
|
+
return this.device.context.manufacturer.trim().toLowerCase() === 'geeni';
|
|
44
|
+
}
|
|
45
|
+
_isAsakuki() {
|
|
46
|
+
return this.device.context.manufacturer.trim().toLowerCase() === 'asakuki';
|
|
47
|
+
}
|
|
48
|
+
_registerPlatformAccessory() {
|
|
49
|
+
this._verifyCachedPlatformAccessory();
|
|
50
|
+
this._justRegistered = true;
|
|
51
|
+
super._registerPlatformAccessory();
|
|
52
|
+
}
|
|
53
|
+
_verifyCachedPlatformAccessory() {
|
|
54
|
+
if (this._justRegistered)
|
|
55
|
+
return;
|
|
56
|
+
const { Service } = this.hap;
|
|
57
|
+
const humidifierName = this.device.context.name;
|
|
58
|
+
let humidifierService = this.accessory.getServiceByUUIDAndSubType(Service.HumidifierDehumidifier, 'humidifier');
|
|
59
|
+
if (humidifierService)
|
|
60
|
+
this._checkServiceName(humidifierService, humidifierName);
|
|
61
|
+
else
|
|
62
|
+
humidifierService = this.accessory.addService(Service.HumidifierDehumidifier, humidifierName, 'humidifier');
|
|
63
|
+
const lightName = this.device.context.name + ' Light';
|
|
64
|
+
let lightService = this.accessory.getServiceByUUIDAndSubType(Service.Lightbulb, 'lightbulb');
|
|
65
|
+
if (lightService)
|
|
66
|
+
this._checkServiceName(lightService, lightName);
|
|
67
|
+
else
|
|
68
|
+
lightService = this.accessory.addService(Service.Lightbulb, lightName, 'lightbulb');
|
|
69
|
+
this.accessory.services.forEach((service) => {
|
|
70
|
+
if ((service.UUID === Service.HumidifierDehumidifier.UUID && service !== humidifierService) ||
|
|
71
|
+
(service.UUID === Service.Lightbulb.UUID && service !== lightService))
|
|
72
|
+
this.accessory.removeService(service);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
_registerCharacteristics(dps) {
|
|
76
|
+
this._verifyCachedPlatformAccessory();
|
|
77
|
+
const { Service, AdaptiveLightingController, Characteristic } = this.hap;
|
|
78
|
+
const humidifierService = this.accessory.getServiceByUUIDAndSubType(Service.HumidifierDehumidifier, 'humidifier');
|
|
79
|
+
const lightService = this.accessory.getServiceByUUIDAndSubType(Service.Lightbulb, 'lightbulb');
|
|
80
|
+
this.dpLight = this._getCustomDP(this.device.context.dpLight) || '5';
|
|
81
|
+
this.dpMode = this._getCustomDP(this.device.context.dpMode) || '6';
|
|
82
|
+
this.dpColor = this._getCustomDP(this.device.context.dpColor) || '8';
|
|
83
|
+
this.dpActive = this._getCustomDP(this.device.context.dpActive) || '1';
|
|
84
|
+
this.dpRotationSpeed = this._getCustomDP(this.device.context.dpRotationSpeed) || '2';
|
|
85
|
+
this.dpWaterLevel = this._getCustomDP(this.device.context.dpWaterLevel) || '9';
|
|
86
|
+
this.maxSpeed = parseInt(this.device.context.maxSpeed) || 2;
|
|
87
|
+
if (this._isBelleLife()) {
|
|
88
|
+
this.cmdInterval = 'interval';
|
|
89
|
+
this.cmdLow = 'small';
|
|
90
|
+
this.cmdHigh = 'large';
|
|
91
|
+
}
|
|
92
|
+
else if (this._isGeeni()) {
|
|
93
|
+
this.cmdInterval = '2';
|
|
94
|
+
this.cmdContinuous = '1';
|
|
95
|
+
}
|
|
96
|
+
else if (this._isAsakuki()) {
|
|
97
|
+
this.cmdLow = 'small';
|
|
98
|
+
this.cmdHigh = 'big';
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.cmdInterval = this.device.context.cmdInterval || '2';
|
|
102
|
+
this.cmdContinuous = this.device.context.cmdContinuous || '1';
|
|
103
|
+
}
|
|
104
|
+
this._detectColorFunction(dps[this.dpColor]);
|
|
105
|
+
this.cmdWhite = 'white';
|
|
106
|
+
if (this.device.context.cmdWhite) {
|
|
107
|
+
if (/^w[a-z]+$/i.test(this.device.context.cmdWhite))
|
|
108
|
+
this.cmdWhite = ('' + this.device.context.cmdWhite).trim();
|
|
109
|
+
else
|
|
110
|
+
throw new Error(`The cmdWhite doesn't appear to be valid: ${this.device.context.cmdWhite}`);
|
|
111
|
+
}
|
|
112
|
+
this.cmdColor = 'colour';
|
|
113
|
+
if (this.device.context.cmdColor) {
|
|
114
|
+
if (/^c[a-z]+$/i.test(this.device.context.cmdColor))
|
|
115
|
+
this.cmdColor = ('' + this.device.context.cmdColor).trim();
|
|
116
|
+
else
|
|
117
|
+
throw new Error(`The cmdColor doesn't appear to be valid: ${this.device.context.cmdColor}`);
|
|
118
|
+
}
|
|
119
|
+
else if (this.device.context.cmdColour) {
|
|
120
|
+
if (/^c[a-z]+$/i.test(this.device.context.cmdColour))
|
|
121
|
+
this.cmdColor = ('' + this.device.context.cmdColour).trim();
|
|
122
|
+
else
|
|
123
|
+
throw new Error(`The cmdColour doesn't appear to be valid: ${this.device.context.cmdColour}`);
|
|
124
|
+
}
|
|
125
|
+
// Led Light
|
|
126
|
+
const characteristicLightOn = lightService
|
|
127
|
+
.getCharacteristic(Characteristic.On)
|
|
128
|
+
.updateValue(dps[this.dpLight])
|
|
129
|
+
.on('get', this.getState.bind(this, this.dpLight))
|
|
130
|
+
.on('set', this.setState.bind(this, this.dpLight));
|
|
131
|
+
const characteristicBrightness = lightService
|
|
132
|
+
.getCharacteristic(Characteristic.Brightness)
|
|
133
|
+
.updateValue(dps[this.dpMode] === this.cmdWhite
|
|
134
|
+
? this.convertBrightnessFromTuyaToHomeKit(dps[this.dpColor])
|
|
135
|
+
: this.convertColorFromTuyaToHomeKit(dps[this.dpColor]).b)
|
|
136
|
+
.on('get', this.getBrightness.bind(this))
|
|
137
|
+
.on('set', this.setBrightness.bind(this));
|
|
138
|
+
const characteristicColorTemperature = lightService
|
|
139
|
+
.getCharacteristic(Characteristic.ColorTemperature)
|
|
140
|
+
.setProps({
|
|
141
|
+
minValue: 0,
|
|
142
|
+
maxValue: 600,
|
|
143
|
+
})
|
|
144
|
+
.updateValue(dps[this.dpMode] === this.cmdWhite
|
|
145
|
+
? this.convertColorTemperatureFromTuyaToHomeKit(dps[this.dpColorTemperature])
|
|
146
|
+
: 0)
|
|
147
|
+
.on('get', this.getColorTemperature.bind(this))
|
|
148
|
+
.on('set', this.setColorTemperature.bind(this));
|
|
149
|
+
const characteristicHue = lightService
|
|
150
|
+
.getCharacteristic(Characteristic.Hue)
|
|
151
|
+
.updateValue(this.convertColorFromTuyaToHomeKit(dps[this.dpColor]).h)
|
|
152
|
+
.on('get', this.getHue.bind(this))
|
|
153
|
+
.on('set', this.setHue.bind(this));
|
|
154
|
+
const characteristicSaturation = lightService
|
|
155
|
+
.getCharacteristic(Characteristic.Saturation)
|
|
156
|
+
.updateValue(this.convertColorFromTuyaToHomeKit(dps[this.dpColor]).s)
|
|
157
|
+
.on('get', this.getSaturation.bind(this))
|
|
158
|
+
.on('set', this.setSaturation.bind(this));
|
|
159
|
+
this.characteristicHue = characteristicHue;
|
|
160
|
+
this.characteristicSaturation = characteristicSaturation;
|
|
161
|
+
this.characteristicColorTemperature = characteristicColorTemperature;
|
|
162
|
+
this.characteristicBrightness = characteristicBrightness;
|
|
163
|
+
if (this.adaptiveLightingSupport()) {
|
|
164
|
+
this.adaptiveLightingController = new AdaptiveLightingController(lightService);
|
|
165
|
+
this.accessory.configureController(this.adaptiveLightingController);
|
|
166
|
+
this.accessory.adaptiveLightingController = this.adaptiveLightingController;
|
|
167
|
+
}
|
|
168
|
+
// Humidifier
|
|
169
|
+
const characteristicActive = humidifierService
|
|
170
|
+
.getCharacteristic(Characteristic.Active)
|
|
171
|
+
.updateValue(this._getActive(dps[this.dpActive]))
|
|
172
|
+
.on('get', this.getActive.bind(this))
|
|
173
|
+
.on('set', this.setActive.bind(this));
|
|
174
|
+
humidifierService
|
|
175
|
+
.getCharacteristic(Characteristic.CurrentHumidifierDehumidifierState)
|
|
176
|
+
.updateValue(this._getCurrentHumidifierDehumidifierState(dps))
|
|
177
|
+
.on('get', this.getCurrentHumidifierDehumidifierState.bind(this));
|
|
178
|
+
humidifierService
|
|
179
|
+
.getCharacteristic(Characteristic.TargetHumidifierDehumidifierState)
|
|
180
|
+
.setProps({
|
|
181
|
+
minValue: 1,
|
|
182
|
+
maxValue: 1,
|
|
183
|
+
validValues: [1],
|
|
184
|
+
})
|
|
185
|
+
.updateValue(this._getTargetHumidifierDehumidifierState())
|
|
186
|
+
.on('get', this.getTargetHumidifierDehumidifierState.bind(this))
|
|
187
|
+
.on('set', this.setTargetHumidifierDehumidifierState.bind(this));
|
|
188
|
+
const characteristicWaterLevel = humidifierService
|
|
189
|
+
.getCharacteristic(Characteristic.WaterLevel)
|
|
190
|
+
.updateValue(this._getWaterLevel(dps[this.dpWaterLevel]))
|
|
191
|
+
.on('get', this.getWaterLevel.bind(this));
|
|
192
|
+
humidifierService
|
|
193
|
+
.getCharacteristic(Characteristic.CurrentRelativeHumidity)
|
|
194
|
+
.updateValue(this.dpActive ? 1 : 0)
|
|
195
|
+
.on('get', this.getRotationSpeed.bind(this));
|
|
196
|
+
const characteristicRotationSpeed = humidifierService
|
|
197
|
+
.getCharacteristic(Characteristic.RotationSpeed)
|
|
198
|
+
.setProps({
|
|
199
|
+
minValue: 0,
|
|
200
|
+
maxValue: this.maxSpeed,
|
|
201
|
+
minStep: 1,
|
|
202
|
+
})
|
|
203
|
+
.updateValue(this._getRotationSpeed(dps))
|
|
204
|
+
.on('get', this.getRotationSpeed.bind(this))
|
|
205
|
+
.on('set', this.setRotationSpeed.bind(this));
|
|
206
|
+
this.characteristicActive = characteristicActive;
|
|
207
|
+
this.characteristicRotationSpeed = characteristicRotationSpeed;
|
|
208
|
+
this.device.on('change', (changes, _state) => {
|
|
209
|
+
if (changes.hasOwnProperty(this.dpLight) && characteristicLightOn.value !== changes[this.dpLight])
|
|
210
|
+
characteristicLightOn.updateValue(changes[this.dpLight]);
|
|
211
|
+
if (changes.hasOwnProperty(this.dpActive)) {
|
|
212
|
+
const newActive = this._getActive(changes[this.dpActive]);
|
|
213
|
+
if (characteristicActive.value !== newActive)
|
|
214
|
+
characteristicActive.updateValue(newActive);
|
|
215
|
+
}
|
|
216
|
+
if (changes.hasOwnProperty(this.dpRotationSpeed)) {
|
|
217
|
+
const newValue = this._getRotationSpeed(changes[this.dpRotationSpeed]);
|
|
218
|
+
if (characteristicRotationSpeed.value !== newValue)
|
|
219
|
+
characteristicRotationSpeed.updateValue(newValue);
|
|
220
|
+
}
|
|
221
|
+
if (changes.hasOwnProperty(this.dpWaterLevel) && characteristicWaterLevel) {
|
|
222
|
+
const waterLevel = changes[this.dpWaterLevel];
|
|
223
|
+
if (characteristicWaterLevel.value !== waterLevel)
|
|
224
|
+
characteristicWaterLevel.updateValue(waterLevel);
|
|
225
|
+
}
|
|
226
|
+
if (changes.hasOwnProperty(this.dpColor)) {
|
|
227
|
+
const oldColor = this.convertColorFromTuyaToHomeKit(this.convertColorFromHomeKitToTuya({
|
|
228
|
+
h: characteristicHue.value,
|
|
229
|
+
s: characteristicSaturation.value,
|
|
230
|
+
b: characteristicBrightness.value,
|
|
231
|
+
}));
|
|
232
|
+
const newColor = this.convertColorFromTuyaToHomeKit(changes[this.dpColor]);
|
|
233
|
+
if (oldColor.h !== newColor.h)
|
|
234
|
+
characteristicHue.updateValue(newColor.h);
|
|
235
|
+
if (oldColor.s !== newColor.s)
|
|
236
|
+
characteristicSaturation.updateValue(newColor.s);
|
|
237
|
+
if (oldColor.b !== newColor.b)
|
|
238
|
+
characteristicBrightness.updateValue(newColor.b);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
getBrightness(callback) {
|
|
243
|
+
if (this.device.state[this.dpMode] === this.cmdWhite)
|
|
244
|
+
return callback(null, this.convertBrightnessFromTuyaToHomeKit(this.device.state[this.dpColor]));
|
|
245
|
+
callback(null, this.convertColorFromTuyaToHomeKit(this.device.state[this.dpColor]).b);
|
|
246
|
+
}
|
|
247
|
+
setBrightness(value, callback) {
|
|
248
|
+
if (value === 0) {
|
|
249
|
+
return this.setState(this.dpLight, false, callback);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (this.device.state[this.dpMode] === this.cmdWhite)
|
|
253
|
+
return this.setState(this.dpColor, this.convertBrightnessFromHomeKitToTuya(value), callback);
|
|
254
|
+
this.device.state[this.dpMode] = this.cmdColor;
|
|
255
|
+
this.setMultiState({ [this.dpMode]: this.cmdColor, [this.dpColor]: this.convertColorFromHomeKitToTuya({ b: value }) }, callback);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
getColorTemperature(callback) {
|
|
259
|
+
if (this.device.state[this.dpMode] !== this.cmdWhite)
|
|
260
|
+
return callback(null, 0);
|
|
261
|
+
callback(null, this.convertColorTemperatureFromTuyaToHomeKit(this.device.state[this.dpColorTemperature]));
|
|
262
|
+
}
|
|
263
|
+
setColorTemperature(value, callback) {
|
|
264
|
+
if (value === 0)
|
|
265
|
+
return callback(null, true);
|
|
266
|
+
const newColor = this.convertHomeKitColorTemperatureToHomeKitColor(value);
|
|
267
|
+
this.characteristicHue.updateValue(newColor.h);
|
|
268
|
+
this.characteristicSaturation.updateValue(newColor.s);
|
|
269
|
+
this.device.state[this.dpMode] = this.cmdColor;
|
|
270
|
+
this.setMultiState({ [this.dpMode]: this.cmdColor, [this.dpColor]: this.convertColorFromHomeKitToTuya(newColor) }, callback);
|
|
271
|
+
}
|
|
272
|
+
getHue(callback) {
|
|
273
|
+
if (this.device.state[this.dpMode] === this.cmdWhite)
|
|
274
|
+
return callback(null, 0);
|
|
275
|
+
callback(null, this.convertColorFromTuyaToHomeKit(this.device.state[this.dpColor]).h);
|
|
276
|
+
}
|
|
277
|
+
setHue(value, callback) {
|
|
278
|
+
this._setHueSaturation({ h: value }, callback);
|
|
279
|
+
}
|
|
280
|
+
getSaturation(callback) {
|
|
281
|
+
callback(null, this.convertColorFromTuyaToHomeKit(this.device.state[this.dpColor]).s);
|
|
282
|
+
}
|
|
283
|
+
setSaturation(value, callback) {
|
|
284
|
+
this._setHueSaturation({ s: value }, callback);
|
|
285
|
+
}
|
|
286
|
+
_setHueSaturation(prop, callback) {
|
|
287
|
+
if (!this._pendingHueSaturation) {
|
|
288
|
+
this._pendingHueSaturation = { props: {}, callbacks: [] };
|
|
289
|
+
}
|
|
290
|
+
if (prop) {
|
|
291
|
+
if (this._pendingHueSaturation.timer)
|
|
292
|
+
clearTimeout(this._pendingHueSaturation.timer);
|
|
293
|
+
this._pendingHueSaturation.props = { ...this._pendingHueSaturation.props, ...prop };
|
|
294
|
+
this._pendingHueSaturation.callbacks.push(callback);
|
|
295
|
+
this._pendingHueSaturation.timer = setTimeout(() => {
|
|
296
|
+
this._setHueSaturation();
|
|
297
|
+
}, 500);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const callbacks = this._pendingHueSaturation.callbacks;
|
|
301
|
+
const callEachBack = (err) => {
|
|
302
|
+
async_1.default.eachSeries(callbacks, (callback, next) => {
|
|
303
|
+
try {
|
|
304
|
+
callback(err);
|
|
305
|
+
}
|
|
306
|
+
catch (_ex) {
|
|
307
|
+
/* ignore */
|
|
308
|
+
}
|
|
309
|
+
next();
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
const newValue = this.convertColorFromHomeKitToTuya(this._pendingHueSaturation.props);
|
|
313
|
+
this._pendingHueSaturation = null;
|
|
314
|
+
this.setMultiState({ [this.dpMode]: this.cmdColor, [this.dpColor]: newValue }, callEachBack);
|
|
315
|
+
}
|
|
316
|
+
getActive(callback) {
|
|
317
|
+
this.getState(this.dpActive, (err, dp) => {
|
|
318
|
+
if (err)
|
|
319
|
+
return callback(err);
|
|
320
|
+
callback(null, this._getActive(dp));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
_getActive(dp) {
|
|
324
|
+
const { Characteristic } = this.hap;
|
|
325
|
+
return dp ? Characteristic.Active.ACTIVE : Characteristic.Active.INACTIVE;
|
|
326
|
+
}
|
|
327
|
+
setActive(value, callback) {
|
|
328
|
+
if (this.characteristicActive.value !== value) {
|
|
329
|
+
const { Characteristic } = this.hap;
|
|
330
|
+
switch (value) {
|
|
331
|
+
case Characteristic.Active.ACTIVE:
|
|
332
|
+
return this.setState(this.dpActive, true, callback);
|
|
333
|
+
case Characteristic.Active.INACTIVE:
|
|
334
|
+
return this.setState(this.dpActive, false, callback);
|
|
335
|
+
}
|
|
336
|
+
callback();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
getCurrentHumidifierDehumidifierState(callback) {
|
|
340
|
+
this.getState([this.dpActive], (err, dps) => {
|
|
341
|
+
if (err)
|
|
342
|
+
return callback(err);
|
|
343
|
+
callback(null, this._getCurrentHumidifierDehumidifierState(dps));
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
_getCurrentHumidifierDehumidifierState(dps) {
|
|
347
|
+
const { Characteristic } = this.hap;
|
|
348
|
+
return dps[this.dpActive]
|
|
349
|
+
? Characteristic.CurrentHumidifierDehumidifierState.HUMIDIFYING
|
|
350
|
+
: Characteristic.CurrentHumidifierDehumidifierState.INACTIVE;
|
|
351
|
+
}
|
|
352
|
+
getTargetHumidifierDehumidifierState(callback) {
|
|
353
|
+
this.getState([this.dpActive], (err, _dps) => {
|
|
354
|
+
if (err)
|
|
355
|
+
return callback(err);
|
|
356
|
+
callback(null, this._getTargetHumidifierDehumidifierState());
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
_getTargetHumidifierDehumidifierState() {
|
|
360
|
+
const { Characteristic } = this.hap;
|
|
361
|
+
return Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER;
|
|
362
|
+
}
|
|
363
|
+
setTargetHumidifierDehumidifierState(value, callback) {
|
|
364
|
+
this.setState(this.dpActive, true, callback);
|
|
365
|
+
}
|
|
366
|
+
getWaterLevel(callback) {
|
|
367
|
+
this.getState(this.dpWaterLevel, (err, dp) => {
|
|
368
|
+
if (err)
|
|
369
|
+
return callback(err);
|
|
370
|
+
callback(null, this._getWaterLevel(dp));
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
_getWaterLevel(value) {
|
|
374
|
+
if (parseFloat(String(value)) == 0) {
|
|
375
|
+
return 69;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
return 0;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
getRotationSpeed(callback) {
|
|
382
|
+
this.getState([this.dpActive, this.dpRotationSpeed], (err, dps) => {
|
|
383
|
+
if (err)
|
|
384
|
+
return callback(err);
|
|
385
|
+
callback(null, this._getRotationSpeed(dps));
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
_getRotationSpeed(dps) {
|
|
389
|
+
if (!dps[this.dpActive])
|
|
390
|
+
return 0;
|
|
391
|
+
if (this._hkRotationSpeed) {
|
|
392
|
+
const currentRotationSpeed = this.convertRotationSpeedFromHomeKitToTuya(this._hkRotationSpeed);
|
|
393
|
+
return currentRotationSpeed === dps[this.dpRotationSpeed]
|
|
394
|
+
? this._hkRotationSpeed
|
|
395
|
+
: this.convertRotationSpeedFromTuyaToHomeKit(dps[this.dpRotationSpeed]);
|
|
396
|
+
}
|
|
397
|
+
return (this._hkRotationSpeed = this.convertRotationSpeedFromTuyaToHomeKit(dps[this.dpRotationSpeed]));
|
|
398
|
+
}
|
|
399
|
+
setRotationSpeed(value, callback) {
|
|
400
|
+
if (value === 0) {
|
|
401
|
+
this.setState(this.dpActive, false, callback);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
this._hkRotationSpeed = value;
|
|
405
|
+
const newSpeed = this.convertRotationSpeedFromHomeKitToTuya(value);
|
|
406
|
+
const currentSpeed = this.convertRotationSpeedFromHomeKitToTuya(this.characteristicRotationSpeed.value);
|
|
407
|
+
if (this.enableFlipSpeedSlider)
|
|
408
|
+
this._hkRotationSpeed = this.convertRotationSpeedFromTuyaToHomeKit(newSpeed);
|
|
409
|
+
if (newSpeed !== currentSpeed) {
|
|
410
|
+
this.characteristicRotationSpeed.updateValue(this._hkRotationSpeed);
|
|
411
|
+
this.setMultiState({ [this.dpActive]: true, [this.dpRotationSpeed]: newSpeed }, callback);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
callback();
|
|
415
|
+
if (this.enableFlipSpeedSlider)
|
|
416
|
+
process.nextTick(() => {
|
|
417
|
+
this.characteristicRotationSpeed.updateValue(this._hkRotationSpeed);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
convertRotationSpeedFromTuyaToHomeKit(value) {
|
|
423
|
+
if (this._isBelleLife()) {
|
|
424
|
+
return { [this.cmdInterval]: 1, [this.cmdLow]: 2, [this.cmdHigh]: 3 }[value];
|
|
425
|
+
}
|
|
426
|
+
else if (this._isGeeni()) {
|
|
427
|
+
return { [this.cmdInterval]: 1, [this.cmdContinuous]: 2 }[value];
|
|
428
|
+
}
|
|
429
|
+
else if (this._isAsakuki()) {
|
|
430
|
+
return { [this.cmdLow]: 1, [this.cmdHigh]: 2 }[value];
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
return { [this.cmdInterval]: 1, [this.cmdContinuous]: 2 }[value];
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
convertRotationSpeedFromHomeKitToTuya(value) {
|
|
437
|
+
if (this._isBelleLife()) {
|
|
438
|
+
if (value < 2)
|
|
439
|
+
return this.cmdLow;
|
|
440
|
+
else if (value < 3)
|
|
441
|
+
return this.cmdMiddle;
|
|
442
|
+
else
|
|
443
|
+
return this.cmdHigh;
|
|
444
|
+
}
|
|
445
|
+
else if (this._isGeeni()) {
|
|
446
|
+
if (value < 2)
|
|
447
|
+
return this.cmdInterval;
|
|
448
|
+
else
|
|
449
|
+
return this.cmdContinuous;
|
|
450
|
+
}
|
|
451
|
+
else if (this._isAsakuki()) {
|
|
452
|
+
if (value < 2)
|
|
453
|
+
return this.cmdLow;
|
|
454
|
+
else
|
|
455
|
+
return this.cmdHigh;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
if (value < 2)
|
|
459
|
+
return this.cmdLow;
|
|
460
|
+
else
|
|
461
|
+
return this.cmdHigh;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
exports.default = OilDiffuserAccessory;
|
|
466
|
+
//# sourceMappingURL=OilDiffuser.accessory.js.map
|