Advertisement
Guest User

lutronpi bridge fix

a guest
Dec 31st, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/bridges/lutron-bridge.js b/bridges/lutron-bridge.js
  2. old mode 100644
  3. new mode 100755
  4. index 2a53466..c7fc4ef
  5. --- a/bridges/lutron-bridge.js
  6. +++ b/bridges/lutron-bridge.js
  7. @@ -32,7 +32,7 @@ module.exports = {
  8.  // const assert = require('assert');
  9.  
  10.  const log = require('loglevel');
  11. -log.setLevel('info')
  12. +log.setLevel('debug')
  13.  
  14.  const net = require('net');
  15.  const tls = require('tls');
  16. @@ -56,6 +56,7 @@ const communiqueBridgeScenesRequest =
  17.     '{"CommuniqueType":"ReadRequest","Header":{"Url":"/virtualbutton"}}\n';
  18.  const communiqueBridgeButtonGroupsRequest =
  19.     '{"CommuniqueType":"ReadRequest","Header":{"Url":"/buttongroup"}}\n';
  20. +const communiqueBridgeButtonGroupsRequestUrl = '/buttongroup';
  21.  const communiqueBridgeButtonsRequest =
  22.     '{"CommuniqueType":"ReadRequest","Header":{"Url":"/button"}}\n';
  23.  const communiqueBridgeButtonProgrammingModelRequest1of2 =
  24. @@ -98,6 +99,9 @@ const communiqueBridgePicoButtonActionPressAndRelease3of3 =
  25.  const communiqueBridgePicoButtonActionPressAndHold3of3 = '"PressAndHold"}}}\n';
  26.  const communiqueBridgePicoButtonActionRelease3of3 = '"Release"}}}\n';
  27.  
  28. +const statusCodeNoContent = '204 NoContent';
  29. +const statusCodeCreated = '201 Created';
  30. +
  31.  const LB_REQUEST_TIMEOUT = 5000;   // was 1500
  32.  const LB_RESPONSE_TIMEOUT = 20000; // was 3000
  33.  const LB_RECONNECT_DELAY_RESET = 30000;
  34. @@ -247,7 +251,7 @@ function picoID(lbridgeID, picoDevice, picoButtonNumber) {
  35.     return lbridgeID + ":" + picoDevice + ":" + picoButtonNumber;
  36.  }
  37.  
  38. -function picoReportJSONFormatter(picoBridge, picoDevice, picoButtonNumber, picoOpName) {
  39. +function picoReportJSONFormatter(picoBridge, picoDevice, picoButtonNumber, picoOpName) {
  40.     return {
  41.         Header: {
  42.             MessageBodyType: "ButtonAction",
  43. @@ -809,11 +813,7 @@ Bridge.prototype._handleIncomingSSLData = function (msgStringData, digest) {
  44.         // update the buttons table from SmartThings device handlers to add LIP button number (2-6, 8-11) and press/hold mode
  45.  
  46.         this._logger.info('Lutron Bridge %s Pico info:\n%o\n', this.bridgeID, this._picoList);
  47. -       this._bridgeEvents.emit(BE_GOTBUTTONGROUPS, this.bridgeIX);
  48. -       this._bridgeEvents.emit(BE_GOTDEVICES, this.bridgeIX, this._updatedDevices); // we've got all the device info available; tell the listener(s)
  49. -
  50. -       if (this._dReqDeviceListCallback.length)
  51. -           this._dReqDeviceListCallback.shift()(this.bridgeIX);
  52. +       this._bridgeAnnounceAllDeviceInfoIsAvailable();
  53.         return;
  54.     }
  55.     else if (jsonData.Header.MessageBodyType == 'OneProgrammingModelDefinition') {
  56. @@ -901,8 +901,15 @@ Bridge.prototype._handleIncomingSSLData = function (msgStringData, digest) {
  57.         }
  58.         return;
  59.     }
  60. -   else if (jsonData.Header.StatusCode == '204 NoContent' ||
  61. -            jsonData.Header.StatusCode == '201 Created') { // probably a command acknowledgement
  62. +   else if (jsonData.Header.StatusCode == statusCodeNoContent ||
  63. +            jsonData.Header.StatusCode == statusCodeCreated) { // probably a command acknowledgement
  64. +       if (jsonData.Header.StatusCode == statusCodeNoContent &&
  65. +           jsonData.Header.Url == communiqueBridgeButtonGroupsRequestUrl) {
  66. +           // no buttons configured with bridge, close the loop
  67. +           this._logger.info('Lutron Bridge %s button groups request: nothing received', this.bridgeID);
  68. +           this._bridgeAnnounceAllDeviceInfoIsAvailable();
  69. +           return;
  70. +       }
  71.         this._logger.debug(msgStringData);
  72.         this._expectResponse(-1);
  73.         return;
  74. @@ -1065,7 +1072,7 @@ Bridge.prototype._telnetHandler = function(telnetInSessionCallback) {
  75.                         }
  76.                         // listen for a release event on this button; note that an event is created per-button
  77.                         picoEvents.on(myPicoID, function(picoNextID, picoButtonNextOp, forcedrelease) {
  78. -                           if (picoButtonNextOp == BUTTON_OP_RELEASE) { // released
  79. +                           if (picoButtonNextOp == BUTTON_OP_RELEASE) { // released
  80.                                 var nextPicoActive = picoActive[picoNextID];
  81.                                 nextPicoActive.timerQuash();
  82.                                 var elapsed = nextPicoActive.elapsed();
  83. @@ -1741,3 +1748,11 @@ Bridge.prototype.buttonRemoteSetMode = function(deviceSN, picoModeMap, picoPushT
  84.     if (typeof cb === 'function')
  85.         cb(error);
  86.  }
  87. +Bridge.prototype._bridgeAnnounceAllDeviceInfoIsAvailable = function() {
  88. +   // we've got all the device info available; tell the listener(s)
  89. +   this._bridgeEvents.emit(BE_GOTBUTTONGROUPS, this.bridgeIX);
  90. +   this._bridgeEvents.emit(BE_GOTDEVICES, this.bridgeIX, this._updatedDevices);
  91. +
  92. +   if (this._dReqDeviceListCallback.length)
  93. +       this._dReqDeviceListCallback.shift()(this.bridgeIX);
  94. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement