Skip to content

Commit

Permalink
Update device address in controller object on "report address" signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafostar committed Sep 19, 2019
1 parent fb35ba3 commit ca1940a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ module.exports = class Client
if(logicalAddress && logicalAddress.length === 1)
{
ctl_debug('Received report address request on broadcast');
var lineCmd = line.split('>> ')[1];

if(
this.devices.hasOwnProperty('dev' + logicalAddress)
&& this.devices['dev' + logicalAddress].address === 'f.f.f.f'
&& lineCmd.endsWith(`:0${logicalAddress}`)
) {
var addArr = lineCmd.substring(
lineCmd.indexOf('f:84:') + 5, lineCmd.indexOf(`:0${logicalAddress}`)
).split(':');

if(addArr.length === 2)
{
var newAddr = addArr[0].charAt(0) + '.' + addArr[0].charAt(1) +
'.' + addArr[1].charAt(0) + '.' + addArr[1].charAt(1);

this.devices['dev' + logicalAddress].address = newAddr;
ctl_debug(`Updated dev${logicalAddress} address to: ${newAddr}`);
}
}

if(line.includes(`>> ${logicalAddress}f:84:`))
this._checkDevicesStatus(`dev${logicalAddress}`);
Expand Down

0 comments on commit ca1940a

Please sign in to comment.