From 99bf1f4a4b876328e02d25b35fe497fd248f2f50 Mon Sep 17 00:00:00 2001 From: tobiswelten <45980402+tobiswelten@users.noreply.github.com> Date: Thu, 7 Dec 2023 09:12:36 +0100 Subject: [PATCH] Update index.js Only showing updated state if needed and not ever seconds in the log. pretty annoying to me and not needed. --- index.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 3d34788..1026804 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var Service, Characteristic +var Service, Characteristic, oldresponsebody const packageJson = require('./package.json') const request = require('request') @@ -69,24 +69,28 @@ GarageDoorOpener.prototype = { callback(error, response, body) }) }, + - _getStatus: function (callback) { - var url = this.statusURL - this.log.debug('Getting status: %s', url) +_getStatus: function (callback) { + var url = this.statusURL; + this.log.debug('Getting status: %s', url); this._httpRequest(url, '', 'GET', function (error, response, responseBody) { - if (error) { - this.log.warn('Error getting status: %s', error.message) - this.service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(new Error('Polling failed')) - callback(error) - } else { - this.service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(responseBody) - this.service.getCharacteristic(Characteristic.TargetDoorState).updateValue(responseBody) - this.log('Updated state to: %s', responseBody) - callback() - } - }.bind(this)) - }, + if (error) { + this.log.warn('Error getting status: %s', error.message); + this.service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(new Error('Polling failed')); + callback(error); + } else { + this.service.getCharacteristic(Characteristic.CurrentDoorState).updateValue(responseBody); + this.service.getCharacteristic(Characteristic.TargetDoorState).updateValue(responseBody); + if (oldresponsebody !== responseBody) { + this.log('Updated state to: %s', responseBody); + oldresponsebody = responseBody; + callback(); + } + } + }.bind(this)); +}, setTargetDoorState: function (value, callback) { var url