AlexanderBabel / homebridge-broadlink-rm

[This fork supports TV accessories] Broadlink RM Mini and Pro plugin for homebridge: https://github.com/nfarina/homebridge
Apache License 2.0
46 stars 11 forks source link

Better getstate implementation proposal #13

Closed ageorgios closed 5 years ago

ageorgios commented 5 years ago

Hello,

I have already coded a homebridge plugin for my TV but I am transitioning to your implementation. Although I have a better state management proposal as below:

  this.serviceManager
    .getCharacteristic(Characteristic.Active)
    .on('get', (callback) => {
      const { config, state } = this;
      let { tvhost } = config; 
       sping.sys.probe(tvhost, (isActive) => {
        if (isActive) { return callback(null, 1); }
        else { return callback(null,0) }
      }, {"min_reply": 1})
    })
    .on('set', (active, callback) => {
      if (active) {
        this.setSwitchState(on)
      }
      else {
        this.setSwitchState(off)
      }
      callback()
    });
AlexanderBabel commented 5 years ago

This is just a fork. I used the code style from the original author.