|
本帖最后由 felix13 于 2017-6-4 11:27 编辑
用了大神的插件插件介绍,实现了很多功能!
但是在测试车库门的时候出现了问题,车库门可以修改打开时间,但是无法修改打开后等待关闭相应的时间。。每次打开车库门,等车库门一打开就变成正在关闭状态了,感觉是大神在写配置文件的时候太仓促,只是声明了等待时间参数,并没用赋予它默认值及参与到自动关门中!
源代码如下:
const sendData = require('../helpers/sendData');
const delayForDuration = require('../helpers/delayForDuration');
const BroadlinkRMAccessory = require('./accessory');
class GarageDoorOpenerAccessory extends BroadlinkRMAccessory {
correctReloadedState (state) {
state.targetDoorState = state.currentDoorState;
}
async setTargetDoorState (hexData) {
const { autoCloseDelay, config, data, host, log, name, state } = this;
let { openCloseDuration } = config;
if (!openCloseDuration) openCloseDuration = 8;
sendData({ host, hexData, log, name });
if (!state.targetDoorState) {
if (this.finishedClosingTimeout) clearTimeout(this.finishedClosingTimeout);
this.finishedOpeningTimeout = setTimeout(() => {
log(`${name} setCurrentDoorState: open`);
this.garageDoorOpenerService.setCharacteristic(Characteristic.CurrentDoorState, 0);
this.autoCloseTimeout = setTimeout(() => {
this.garageDoorOpenerService.setCharacteristic(Characteristic.TargetDoorState, 1);
}, autoCloseDelay * 1000);
}, openCloseDuration * 1000);
} else {
if (this.garageDoorOpenerService) clearTimeout(this.garageDoorOpenerService);
if (this.autoCloseTimeout) clearTimeout(this.autoCloseTimeout);
this.finishedClosingTimeout = setTimeout(() => {
log(`${name} setCurrentDoorState: closed`);
this.garageDoorOpenerService.setCharacteristic(Characteristic.CurrentDoorState, 1);
}, openCloseDuration * 1000)
}
}
async setLockTargetState (hexData) {
const { config, data, host, log, name, state } = this;
sendData({ host, hexData, log, name });
if (!state.lockTargetState) {
log(`${name} setCurrentDoorState: unlocked`)
this.garageDoorOpenerService.setCharacteristic(Characteristic.LockCurrentState, Characteristic.LockCurrentState.UNSECURED);
} else {
log(`${name} setCurrentDoorState: locked`)
this.garageDoorOpenerService.setCharacteristic(Characteristic.LockCurrentState, Characteristic.LockCurrentState.SECURED);
}
}
getServices () {
const services = super.getServices();
const { data, name } = this;
const { open, close, lock, unlock } = data;
const service = new Service.GarageDoorOpener(name);
this.addNameService(service);
this.createToggleCharacteristic({
service,
characteristicType: Characteristic.CurrentDoorState,
propertyName: 'currentDoorState',
});
this.createToggleCharacteristic({
service,
characteristicType: Characteristic.TargetDoorState,
propertyName: 'targetDoorState',
onData: open,
offData: close,
setValuePromise: this.setTargetDoorState.bind(this)
});
this.createToggleCharacteristic({
service,
characteristicType: Characteristic.LockTargetState,
propertyName: 'lockTargetState',
onData: lock,
offData: unlock,
setValuePromise: this.setLockTargetState.bind(this)
});
this.createToggleCharacteristic({
service,
characteristicType: Characteristic.LockCurrentState,
propertyName: 'lockCurrentState',
});
this.garageDoorOpenerService = service;
services.push(service);
return services;
}
}
module.exports = GarageDoorOpenerAccessory;
有懂的大神看看要怎么修改一下 |
|