『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 9395|回复: 4

[求助] 新人求助:broadlink RM插件控制车库门总自动关闭

[复制链接]

1

主题

2

帖子

40

积分

新手上路

Rank: 1

积分
40
金钱
38
HASS币
0
发表于 2017-6-4 11:25:01 | 显示全部楼层 |阅读模式
本帖最后由 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;


有懂的大神看看要怎么修改一下
回复

使用道具 举报

1

主题

52

帖子

167

积分

注册会员

Rank: 2

积分
167
金钱
115
HASS币
0
发表于 2017-6-4 15:10:32 | 显示全部楼层
只能等待大神给您答复~
回复

使用道具 举报

3

主题

343

帖子

1598

积分

严重灌水用户

积分
1598
金钱
1254
HASS币
0
发表于 2017-6-4 23:30:45 | 显示全部楼层

只能等待大神给您答复~
回复

使用道具 举报

0

主题

9

帖子

30

积分

新手上路

Rank: 1

积分
30
金钱
21
HASS币
0
发表于 2017-6-13 16:56:45 | 显示全部楼层

谢谢分享
回复

使用道具 举报

27

主题

1307

帖子

5947

积分

元老级技术达人

积分
5947
金钱
4615
HASS币
100
发表于 2017-7-1 15:27:47 | 显示全部楼层
{
          "name":"Open",
          "type":"switch-repeat",
          "sendCount":2,
          "interval":0.3,
          "data":""
        },
你是通过这种switch-repeat 做的开关么?
是的话你修改这里的interval就是间隔时间,时间内重复发送两次开关指令是不是就自动关了?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-23 01:27 , Processed in 0.101341 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表