snowdd1 / homebridge-knx

KNX platform shim for homebridge
https://github.com/nfarina/homebridge
GNU General Public License v2.0
97 stars 55 forks source link

"ListenNoRead" and optimized knx startup #36

Closed bytefactory73 closed 8 years ago

bytefactory73 commented 8 years ago

if you like you can pull my changes into your branch. i added 2 things:

  1. Add a hashmap to track already scanned group addresses in startup phase. 'alreadyScanned' contains a hashmap with all scanned addresses. This prevents homebridge from reading the same address multiple times.
  2. ListenNoRead allows to add listener addresses without reading these addresses on startup. I use this for all my central addresses because it makes no sense to read them from the bus. Otherwise the bus responds with undefined behaviour because multiple devices which listen to this central addresses will send a response.

"services":[ { "type":"Lightbulb", "name":"Stehlampe", "description":"", "On":{ "Set":"1/1/50", "Listen":["1/1/50"], "ListenNoRead":["1/0/1"] } }]

have fun.

cheers

snowdd1 commented 8 years ago

Hi, I like the idea - espc as I had the same in mind (define which addresses to read at startup) for the next release (of which I am talking for a year now, I know.)
The hashmap is very good also - I did just ignore the white noise in my installation as my homebridge is running 24/7 (battery back up) for ages now. Central addresses like "all lights off" are unreadable in my installation by default, so no one will answer that read request.

But I have some questions regarding your implementation of the ListenNoRead: You create a "noread" version of the listening addresses (https://github.com/bytefactory73/homebridge-knx/blob/master/index.js#L815)

var listenaddressesNoRead = listenaddresses;

Then you add the ListenNoRead addresses from the config.json for that service to the original list:

if ('ListenNoRead' in config) {
    listenaddresses = listenaddresses.concat(config.ListenNoRead || []); 
}

All of the combined list are registered for listening, eg.

    this.knxregister_bool(listenaddresses, myCharacteristic);

But only the list listenaddressesNoRead is sent for reading. (https://github.com/bytefactory73/homebridge-knx/blob/master/index.js#L844)

this.knxreadarray(listenaddressesNoRead);

Might it be the list is misnamed and should be named ListenWithRead instead of NoRead?

As you seem to have fun digging in JavaScript - any interest in helping with the next version?

bytefactory73 commented 8 years ago

regarding the variable name you are absolutely right. it should better be named "addressesToRead" or something like this. shall i rename that or will you do that?.

javascript is foreign to me. usually i programm in c++ but javascript is not that far from that.

my time is also a bit limited but if you have some ideas to implement i can try to help here and there.

btw. i noticed that one datatype is not supported in your code. i have a few somfy ilt devices which send a 2 byte percent value (EIS7 if i recall correctly from memory). maybe i will add this as well.

bytefactory73 commented 8 years ago

i renamed the variable.