diff --git a/index.js b/index.js index 4776090..3899cb6 100755 --- a/index.js +++ b/index.js @@ -182,40 +182,39 @@ JeedomPlatform.prototype.ConfigCMD = function(req, res) { // -- Return : nothing JeedomPlatform.prototype.addAccessories = function() { try{ - const that = this; - that.log('Synchronisation Jeedom <> Homebridge...'); - that.jeedomClient.getModel() - .then(function(model){ // we got the base Model from the API + this.log('Synchronisation Jeedom <> Homebridge...'); + this.jeedomClient.getModel() + .then((model) => { // we got the base Model from the API if(model && typeof model === 'object' && model.config && typeof model.config === 'object' && model.config.datetime) { - that.lastPoll=model.config.datetime; + this.lastPoll=model.config.datetime; - that.log('debug','Enumération des objets Jeedom (Pièces)...'); + this.log('debug','Enumération des objets Jeedom (Pièces)...'); if(model.objects && typeof model.objects === 'object' && Object.keys(model.objects).length !== 0) { - model.objects.map(function(r){ - that.rooms[r.id] = r.name; - that.log('debug','Pièce > ' + r.name); + model.objects.map((r) => { + this.rooms[r.id] = r.name; + this.log('debug','Pièce > ' + r.name); }); } else { - that.log('error','Pièce > '+model.objects); + this.log('error','Pièce > '+model.objects); throw new Error("Liste des pièces vide ou invalide, vérifiez que vous avez bien coché au moins une pièce à envoyer à homebridge !"); } - that.log('Enumération des scénarios Jeedom...'); - that.JeedomScenarios2HomeKitAccessories(model.scenarios); + this.log('Enumération des scénarios Jeedom...'); + this.JeedomScenarios2HomeKitAccessories(model.scenarios); - that.log('Enumération des périphériques Jeedom...'); + this.log('Enumération des périphériques Jeedom...'); if(model.eqLogics && typeof model.eqLogics === 'object' && Object.keys(model.eqLogics).length !== 0) { - that.JeedomDevices2HomeKitAccessories(model.eqLogics); + this.JeedomDevices2HomeKitAccessories(model.eqLogics); } else { - that.log('error','Périf > '+model.eqLogics); + this.log('error','Périf > '+model.eqLogics); throw new Error('eqLogics list empty'); } } else { - that.log('error','Model invalide > ',model); + this.log('error','Model invalide > ',model); throw new Error('Invalid Model'); } - }).catch(function(err) { - that.log('error','#2 Erreur de récupération des données Jeedom: ' , err); + }).catch((err) => { + this.log('error','#2 Erreur de récupération des données Jeedom: ' , err); if(err && err.stack) { console.error(err.stack); } }); } @@ -227,28 +226,22 @@ JeedomPlatform.prototype.addAccessories = function() { JeedomPlatform.prototype.JeedomScenarios2HomeKitAccessories = function(scenarios) { try{ - const that = this; + if (scenarios) { - scenarios.sort(function compare(a, b) { + scenarios.sort((a, b) => { // reorder by room name asc and name asc - const aC = that.rooms[a.object_id]+a.name; - const bC = that.rooms[b.object_id]+b.name; - if (aC > bC) { - return 1; - } - if (aC < bC) { - return -1; - } - return 0; + const aC = this.rooms[a.object_id] + a.name; + const bC = this.rooms[b.object_id] + b.name; + return aC.localeCompare(bC); }); - scenarios.map(function(scenario) { + scenarios.map((scenario) => { if (scenario.isActive == '1' && scenario.object_id != null && scenario.sendToHomebridge == '1') { - that.log('debug','Scenario > '+JSON.stringify(scenario).replace("\n",'')); - that.log('┌──── ' + that.rooms[scenario.object_id] + ' > ' +scenario.name+' ('+scenario.id+')'); + this.log('debug','Scenario > '+JSON.stringify(scenario).replace("\n",'')); + this.log('┌──── ' + this.rooms[scenario.object_id] + ' > ' +scenario.name+' ('+scenario.id+')'); const HBservice = { @@ -267,11 +260,11 @@ JeedomPlatform.prototype.JeedomScenarios2HomeKitAccessories = function(scenarios Serv.subtype = Serv.subtype || ''; Serv.subtype = scenario.id + '-' + Serv.subtype; - if(that.fakegato && !scenario.hasLogging) { + if(this.fakegato && !scenario.hasLogging) { // HBservice.characteristics.push(Characteristic.Sensitivity,Characteristic.Duration,Characteristic.LastActivation); // eqLogic.loggingService = {type:"motion", options:{storage:'googleDrive',folder:'fakegato',keyPath:'/home/pi/.homebridge/'},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; - scenario.loggingService = {type:"switch", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + scenario.loggingService = {type:"switch", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; scenario.hasLogging=true; } @@ -279,29 +272,29 @@ JeedomPlatform.prototype.JeedomScenarios2HomeKitAccessories = function(scenarios scenario.eqType_name = "Scenario"; scenario.logicalId = ""; - const createdAccessory = that.createAccessory([HBservice], scenario); - that.addAccessory(createdAccessory); - that.log('└─────────'); + const createdAccessory = this.createAccessory([HBservice], scenario); + this.addAccessory(createdAccessory); + this.log('└─────────'); } else { - that.log('debug','Scenario > '+JSON.stringify(scenario).replace("\n",'')); - that.log('┌──── ' + that.rooms[scenario.object_id] + ' > ' +scenario.name+' ('+scenario.id+')'); + this.log('debug','Scenario > '+JSON.stringify(scenario).replace("\n",'')); + this.log('┌──── ' + this.rooms[scenario.object_id] + ' > ' +scenario.name+' ('+scenario.id+')'); var Messg= '│ Scenario '; Messg += scenario.isVisible == '1' ? 'visible' : 'invisible'; Messg += scenario.isActive == '1' ? ', activé' : ', désactivé'; Messg += scenario.object_id != null ? '' : ', pas dans une pièce'; Messg += scenario.sendToHomebridge == '1' ? '' : ', pas coché pour Homebridge'; - that.log(Messg); + this.log(Messg); scenario.eqType_name = "Scenario"; scenario.logicalId = ""; - that.delAccessory( - that.createAccessory([], scenario) // create a cached lookalike object for unregistering it + this.delAccessory( + this.createAccessory([], scenario) // create a cached lookalike object for unregistering it ); - that.log('└─────────'); + this.log('└─────────'); } }); @@ -321,43 +314,42 @@ JeedomPlatform.prototype.JeedomScenarios2HomeKitAccessories = function(scenarios // -- Return : nothing JeedomPlatform.prototype.JeedomDevices2HomeKitAccessories = function(devices) { try{ - const that = this; if (devices) { devices.sort((a, b) => { // reorder by room name asc and name asc - const aC = that.rooms[a.object_id] + a.name; - const bC = that.rooms[b.object_id] + b.name; + const aC = this.rooms[a.object_id] + a.name; + const bC = this.rooms[b.object_id] + b.name; return aC.localeCompare(bC); }); - devices.map(function(device) { + devices.map((device) => { if (// device.isVisible == '1' && device.isEnable == '1' && device.object_id != null && device.sendToHomebridge != '0') { - that.AccessoireCreateHomebridge( - that.jeedomClient.ParseGenericType( + this.AccessoireCreateHomebridge( + this.jeedomClient.ParseGenericType( device, - that.jeedomClient.getDeviceCmdFromCache(device.id) + this.jeedomClient.getDeviceCmdFromCache(device.id) ) ); } else { - that.log('debug','eqLogic > '+JSON.stringify(device).replace("\n",'')); - that.log('┌──── ' + that.rooms[device.object_id] + ' > ' +device.name+((device.pseudo)?' > pseudo: '+device.pseudo:'')+' ('+device.id+')'); + this.log('debug','eqLogic > '+JSON.stringify(device).replace("\n",'')); + this.log('┌──── ' + this.rooms[device.object_id] + ' > ' +device.name+((device.pseudo)?' > pseudo: '+device.pseudo:'')+' ('+device.id+')'); var Messg= '│ Accessoire '; Messg += device.isVisible == '1' ? 'visible' : 'invisible'; Messg += device.isEnable == '1' ? ', activé' : ', désactivé'; Messg += device.object_id != null ? '' : ', pas dans une pièce'; Messg += device.sendToHomebridge != '0' ? '' : ', pas coché pour Homebridge'; - that.log(Messg); + this.log(Messg); - that.delAccessory( - that.createAccessory([], device) // create a cached lookalike object for unregistering it + this.delAccessory( + this.createAccessory([], device) // create a cached lookalike object for unregistering it ); - that.log('└─────────'); + this.log('└─────────'); } }); @@ -365,38 +357,38 @@ JeedomPlatform.prototype.JeedomDevices2HomeKitAccessories = function(devices) { var countA=0; if(!hasError) { - that.log('┌────RAMASSE-MIETTES─────'); - that.log('│ (Suppression des accessoires qui sont dans le cache mais plus dans jeedom (peut provenir de renommage ou changement de pièce))'); + this.log('┌────RAMASSE-MIETTES─────'); + this.log('│ (Suppression des accessoires qui sont dans le cache mais plus dans jeedom (peut provenir de renommage ou changement de pièce))'); var hasDeleted = false; - for (const a in that.accessories) + for (const a in this.accessories) { - if (that.accessories.hasOwnProperty(a)) { - if(!that.accessories[a].reviewed && - that.accessories[a].displayName) { - that.log('│ ┌──── Trouvé: '+that.accessories[a].displayName); - that.delAccessory(that.accessories[a],true); - that.log('│ │ Supprimé du cache !'); - that.log('│ └─────────'); + if (this.accessories.hasOwnProperty(a)) { + if(!this.accessories[a].reviewed && + this.accessories[a].displayName) { + this.log('│ ┌──── Trouvé: '+this.accessories[a].displayName); + this.delAccessory(this.accessories[a],true); + this.log('│ │ Supprimé du cache !'); + this.log('│ └─────────'); hasDeleted=true; - }else if(that.accessories[a].reviewed && - that.accessories[a].displayName) {countA++;} + }else if(this.accessories[a].reviewed && + this.accessories[a].displayName) {countA++;} } } - if(!hasDeleted) {that.log('│ Rien à supprimer');} - that.log('└────────────────────────'); + if(!hasDeleted) {this.log('│ Rien à supprimer');} + this.log('└────────────────────────'); } else { - that.log('error','!!! ERREUR DETECTÉE, ON QUITTE HOMEBRIDGE !!!'); + this.log('error','!!! ERREUR DETECTÉE, ON QUITTE HOMEBRIDGE !!!'); process.exit(1); } const endLog = '--== Homebridge est démarré et a intégré '+countA+' accessoire'+ (countA>1 ? 's' : '') +' ! ==--'; - that.log(endLog); - if(countA >= 150) {that.log('error','!!! ATTENTION !!! Vous avez '+countA+' accessoires + Jeedom et HomeKit en supporte 150 max au total !!');} - else if(countA >= 140) {that.log('warn','!! Avertissement, vous avez '+countA+' accessoires + Jeedom et HomeKit en supporte 150 max au total !!');} + this.log(endLog); + if(countA >= 150) {this.log('error','!!! ATTENTION !!! Vous avez '+countA+' accessoires + Jeedom et HomeKit en supporte 150 max au total !!');} + else if(countA >= 140) {this.log('warn','!! Avertissement, vous avez '+countA+' accessoires + Jeedom et HomeKit en supporte 150 max au total !!');} - that.log('debug','==START POLLING=='); - that.startPollingUpdate(); + this.log('debug','==START POLLING=='); + this.startPollingUpdate(); } catch(e){ this.log('error','Erreur de la fonction JeedomDevices2HomeKitAccessories :',e); @@ -412,18 +404,17 @@ JeedomPlatform.prototype.JeedomDevices2HomeKitAccessories = function(devices) { JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { var createdAccessory; try { - const that = this; var HBservices = []; var HBservice = null; const eqServicesCopy = eqLogic.services; - that.log('debug','eqLogic > '+JSON.stringify(eqLogic).replace("\n",'')); - that.log('┌──── ' + that.rooms[eqLogic.object_id] + ' > ' + eqLogic.name +((eqLogic.pseudo)?' > pseudo: '+eqLogic.pseudo:'')+ ' (' + eqLogic.id + ')'); + this.log('debug','eqLogic > '+JSON.stringify(eqLogic).replace("\n",'')); + this.log('┌──── ' + this.rooms[eqLogic.object_id] + ' > ' + eqLogic.name +((eqLogic.pseudo)?' > pseudo: '+eqLogic.pseudo:'')+ ' (' + eqLogic.id + ')'); eqLogic.origName=eqLogic.name; if(eqLogic.pseudo) { eqLogic.name = eqLogic.pseudo; } if (eqLogic.services.light) { - eqLogic.services.light.forEach(function(cmd) { + eqLogic.services.light.forEach((cmd) => { if (cmd.state) { let LightType="Switch"; HBservice = { @@ -438,7 +429,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { if(eqLogic.OnAfterBrightness) {Serv.OnAfterBrightness=true;} if(eqLogic.ignoreOnCommandOnBrightnessChange) {Serv.ignoreOnCommandOnBrightnessChange=true;} - eqServicesCopy.light.forEach(function(cmd2) { + eqServicesCopy.light.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on=cmd2.on; } else if (cmd2.off) { @@ -459,13 +450,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.brightness=cmd2.brightness; } }); - if (Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique "Action/Lumière OFF"');} - if (!Serv.actions.on && Serv.actions.off) {that.log('warn','Pas de type générique "Action/Lumière ON"');} - if (!Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique "Action/Lumière ON" et "Action/Lumière OFF"');} - if (Serv.infos.color && !Serv.actions.setcolor) {that.log('warn','Pas de type générique "Action/Lumière Couleur"');} - if (!Serv.infos.color && Serv.actions.setcolor) {that.log('warn','Pas de type générique "Info/Lumière Couleur"');} - if (Serv.infos.color_temp && !Serv.actions.setcolor_temp) {that.log('warn','Pas de type générique "Action/Lumière Température Couleur"');} - if (!Serv.infos.color_temp && Serv.actions.setcolor_temp) {that.log('warn','Pas de type générique "Info/Lumière Température Couleur"');} + if (Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique "Action/Lumière OFF"');} + if (!Serv.actions.on && Serv.actions.off) {this.log('warn','Pas de type générique "Action/Lumière ON"');} + if (!Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique "Action/Lumière ON" et "Action/Lumière OFF"');} + if (Serv.infos.color && !Serv.actions.setcolor) {this.log('warn','Pas de type générique "Action/Lumière Couleur"');} + if (!Serv.infos.color && Serv.actions.setcolor) {this.log('warn','Pas de type générique "Info/Lumière Couleur"');} + if (Serv.infos.color_temp && !Serv.actions.setcolor_temp) {this.log('warn','Pas de type générique "Action/Lumière Température Couleur"');} + if (!Serv.infos.color_temp && Serv.actions.setcolor_temp) {this.log('warn','Pas de type générique "Info/Lumière Température Couleur"');} if(Serv.actions.slider) { if(Serv.actions.slider.configuration && Serv.actions.slider.configuration.maxValue && parseInt(Serv.actions.slider.configuration.maxValue)) { @@ -477,7 +468,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.Brightness); Serv.addCharacteristic(Characteristic.Brightness); } else { - that.log('info','La lumière n\'a pas de variateur'); + this.log('info','La lumière n\'a pas de variateur'); } if(Serv.infos.color) { LightType += "_RGB"; @@ -516,7 +507,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { LightType+=Serv.colorTempType; } } else { - that.log('error','"Action/Lumière Température Couleur" doit avoir un minimum et un maximum !'); + this.log('error','"Action/Lumière Température Couleur" doit avoir un minimum et un maximum !'); props.minValue = 0; // if not set in Jeedom it's 0 props.maxValue = 20000; // if not set in Jeedom it's 100 } @@ -528,7 +519,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } if(eqLogic.hasAdaptive) { - if (that.adaptiveLightingSupport()) { + if (this.adaptiveLightingSupport()) { LightType+='_Adaptive'; } else { eqLogic.hasAdaptive=false; @@ -536,9 +527,9 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); - that.log('info','La lumière est du type :',LightType); + this.log('info','La lumière est du type :',LightType); Serv.LightType = LightType; Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -548,13 +539,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Lumière Etat"'); + this.log('warn','Pas de type générique "Info/Lumière Etat"'); } else { HBservice = null; } } if (eqLogic.services.flap) { - eqLogic.services.flap.forEach(function(cmd) { + eqLogic.services.flap.forEach((cmd) => { if (cmd.state || cmd.stateClosing) { HBservice = { controlService : new Service.WindowCovering(eqLogic.name), @@ -589,7 +580,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } - eqServicesCopy.flap.forEach(function(cmd2) { + eqServicesCopy.flap.forEach((cmd2) => { if (cmd2.up) { Serv.actions.up = cmd2.up; } else if (cmd2.down) { @@ -606,14 +597,14 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.VerTiltState = cmd2.VerTiltState; } }); - if(Serv.actions.up && !Serv.actions.down) {that.log('warn','Pas de type générique "Action/Volet Bouton Descendre"');} - if(!Serv.actions.up && Serv.actions.down) {that.log('warn','Pas de type générique "Action/Volet Bouton Monter"');} - if(!Serv.actions.up && !Serv.actions.down) {that.log('warn','Pas de type générique "Action/Volet Bouton Descendre" et "Action/Volet Bouton Monter"');} - if(!Serv.actions.up && !Serv.actions.down && !Serv.actions.slider) {that.log('warn','Pas de type générique "Action/Volet Bouton Slider" et "Action/Volet Bouton Monter" et "Action/Volet Bouton Descendre"');} - if(Serv.actions.HorTiltSlider && !Serv.infos.HorTiltState) {that.log('warn','Pas de type générique "Info/Volet Etat Inclinaison Horizontale" malgré l\'action "Action/Volet Slider Inclinaison Horizontale"');} - if(Serv.actions.VerTiltSlider && !Serv.infos.VerTiltState) {that.log('warn','Pas de type générique "Info/Volet Etat Inclinaison Verticale" malgré l\'action "Action/Volet Slider Inclinaison Verticale"');} - if(!Serv.actions.HorTiltSlider && Serv.infos.HorTiltState) {that.log('warn','Pas de type générique "Action/Volet Slider Inclinaison Horizontale" malgré l\'état "Info/Volet Etat Inclinaison Horizontale"');} - if(!Serv.actions.VerTiltSlider && Serv.infos.VerTiltState) {that.log('warn','Pas de type générique "Action/Volet Slider Inclinaison Verticale" malgré l\'état "Info/Volet Etat Inclinaison Verticale"');} + if(Serv.actions.up && !Serv.actions.down) {this.log('warn','Pas de type générique "Action/Volet Bouton Descendre"');} + if(!Serv.actions.up && Serv.actions.down) {this.log('warn','Pas de type générique "Action/Volet Bouton Monter"');} + if(!Serv.actions.up && !Serv.actions.down) {this.log('warn','Pas de type générique "Action/Volet Bouton Descendre" et "Action/Volet Bouton Monter"');} + if(!Serv.actions.up && !Serv.actions.down && !Serv.actions.slider) {this.log('warn','Pas de type générique "Action/Volet Bouton Slider" et "Action/Volet Bouton Monter" et "Action/Volet Bouton Descendre"');} + if(Serv.actions.HorTiltSlider && !Serv.infos.HorTiltState) {this.log('warn','Pas de type générique "Info/Volet Etat Inclinaison Horizontale" malgré l\'action "Action/Volet Slider Inclinaison Horizontale"');} + if(Serv.actions.VerTiltSlider && !Serv.infos.VerTiltState) {this.log('warn','Pas de type générique "Info/Volet Etat Inclinaison Verticale" malgré l\'action "Action/Volet Slider Inclinaison Verticale"');} + if(!Serv.actions.HorTiltSlider && Serv.infos.HorTiltState) {this.log('warn','Pas de type générique "Action/Volet Slider Inclinaison Horizontale" malgré l\'état "Info/Volet Etat Inclinaison Horizontale"');} + if(!Serv.actions.VerTiltSlider && Serv.infos.VerTiltState) {this.log('warn','Pas de type générique "Action/Volet Slider Inclinaison Verticale" malgré l\'état "Info/Volet Etat Inclinaison Verticale"');} Serv.minValue=0; if(Serv.infos.state.subType == 'binary') { Serv.maxValue=1; @@ -648,7 +639,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.TargetHorizontalTiltAngle); Serv.addCharacteristic(Characteristic.TargetHorizontalTiltAngle); Serv.getCharacteristic(Characteristic.TargetHorizontalTiltAngle).setProps(props); - that.log('debug','Horizontal Slider props :'+JSON.stringify(props)+'/'+JSON.stringify(Serv.actions.HorTiltSlider.configuration)); + this.log('debug','Horizontal Slider props :'+JSON.stringify(props)+'/'+JSON.stringify(Serv.actions.HorTiltSlider.configuration)); } if(Serv.actions.VerTiltSlider) { @@ -670,11 +661,11 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.TargetVerticalTiltAngle); Serv.addCharacteristic(Characteristic.TargetVerticalTiltAngle); Serv.getCharacteristic(Characteristic.TargetVerticalTiltAngle).setProps(props); - that.log('debug','Vertical Slider props :'+JSON.stringify(props)+'/'+JSON.stringify(Serv.actions.VerTiltSlider.configuration)); + this.log('debug','Vertical Slider props :'+JSON.stringify(props)+'/'+JSON.stringify(Serv.actions.VerTiltSlider.configuration)); } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = Serv.infos.state.id; Serv.eqID = eqLogic.id; @@ -685,8 +676,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Volet Etat" ou "Info/Volet Etat Fermeture" on regarde s\'il y a uniquement les boutons...'); - eqLogic.services.flap.forEach(function(cmd) { + this.log('warn','Pas de type générique "Info/Volet Etat" ou "Info/Volet Etat Fermeture" on regarde s\'il y a uniquement les boutons...'); + eqLogic.services.flap.forEach((cmd) => { if (cmd.up) { const SwitchName=cmd.up.name; HBservice = { @@ -706,7 +697,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.ConfiguredName).setValue(SwitchName); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.up.id; Serv.eqID = eqLogic.id; @@ -733,7 +724,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.ConfiguredName).setValue(SwitchName); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.down.id; Serv.eqID = eqLogic.id; @@ -760,7 +751,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.ConfiguredName).setValue(SwitchName); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.stop.id; Serv.eqID = eqLogic.id; @@ -770,7 +761,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Action/Volet Bouton Monter" ou "Action/Volet Bouton Descendre" ou "Action/Volet Bouton Stop"'); + this.log('warn','Pas de type générique "Action/Volet Bouton Monter" ou "Action/Volet Bouton Descendre" ou "Action/Volet Bouton Stop"'); } else { HBservice = null; } @@ -779,7 +770,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } if (eqLogic.services.windowMoto) { - eqLogic.services.windowMoto.forEach(function(cmd) { + eqLogic.services.windowMoto.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.Window(eqLogic.name), @@ -791,7 +782,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.windowMoto.forEach(function(cmd2) { + eqServicesCopy.windowMoto.forEach((cmd2) => { if (cmd2.up) { Serv.actions.up = cmd2.up; } else if (cmd2.down) { @@ -802,10 +793,10 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); Serv.maxValue = 100; // if not set in Jeedom it's 100 Serv.minValue = 0; // if not set in Jeedom it's 0 - if(Serv.actions.up && !Serv.actions.down) {that.log('warn','Pas de type générique "Action/Fenêtre Motorisée Descendre"');} - if(!Serv.actions.up && Serv.actions.down) {that.log('warn','Pas de type générique "Action/Fenêtre Motorisée Monter"');} - if(!Serv.actions.up && !Serv.actions.down) {that.log('warn','Pas de type générique "Action/Fenêtre Motorisée Descendre" et "Action/Fenêtre Motorisée Monter"');} - if(!Serv.actions.up && !Serv.actions.down && !Serv.actions.slider) {that.log('warn','Pas de type générique "Action/Fenêtre Motorisée Slider" et "Action/Fenêtre Motorisée Monter" et "Action/Fenêtre Motorisée Descendre"');} + if(Serv.actions.up && !Serv.actions.down) {this.log('warn','Pas de type générique "Action/Fenêtre Motorisée Descendre"');} + if(!Serv.actions.up && Serv.actions.down) {this.log('warn','Pas de type générique "Action/Fenêtre Motorisée Monter"');} + if(!Serv.actions.up && !Serv.actions.down) {this.log('warn','Pas de type générique "Action/Fenêtre Motorisée Descendre" et "Action/Fenêtre Motorisée Monter"');} + if(!Serv.actions.up && !Serv.actions.down && !Serv.actions.slider) {this.log('warn','Pas de type générique "Action/Fenêtre Motorisée Slider" et "Action/Fenêtre Motorisée Monter" et "Action/Fenêtre Motorisée Descendre"');} if(Serv.actions.slider) { if(Serv.actions.slider.configuration && Serv.actions.slider.configuration.maxValue && parseInt(Serv.actions.slider.configuration.maxValue)) { Serv.maxValue = parseInt(Serv.actions.slider.configuration.maxValue); @@ -815,7 +806,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -826,13 +817,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Fenêtre Motorisée Etat"'); + this.log('warn','Pas de type générique "Info/Fenêtre Motorisée Etat"'); } else { HBservice = null; } } if (eqLogic.services.energy) { - eqLogic.services.energy.forEach(function(cmd) { + eqLogic.services.energy.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.Outlet(eqLogic.name), @@ -843,7 +834,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.energy.forEach(function(cmd2) { + eqServicesCopy.energy.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { @@ -852,12 +843,12 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.inuse = cmd2.inuse; } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Prise Bouton On"');} - if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Prise Bouton Off"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Prise Bouton On"');} + if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Prise Bouton Off"');} // Test for AdminOnlyAccess, state need to have OwnerOnly attribute to True ou 1 if(Serv.infos.state.OwnerOnly) {Serv.getCharacteristic(Characteristic.On).setProps({adminOnlyAccess: [Access.WRITE]});} // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -867,13 +858,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Prise Etat"'); + this.log('warn','Pas de type générique "Info/Prise Etat"'); } else { HBservice = null; } } if (eqLogic.services.faucet) { - eqLogic.services.faucet.forEach(function(cmd) { + eqLogic.services.faucet.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.Valve(eqLogic.name), @@ -886,18 +877,18 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.state=cmd.state; Serv.getCharacteristic(Characteristic.ValveType).setValue(Characteristic.ValveType.WATER_FAUCET); Serv.ValveType=Characteristic.ValveType.WATER_FAUCET; - eqServicesCopy.faucet.forEach(function(cmd2) { + eqServicesCopy.faucet.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { Serv.actions.off = cmd2.off; } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Robinet Bouton On"');} - if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Robinet Bouton Off"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Robinet Bouton On"');} + if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Robinet Bouton Off"');} // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -907,13 +898,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Robinet Etat"'); + this.log('warn','Pas de type générique "Info/Robinet Etat"'); } else { HBservice = null; } } if (eqLogic.services.irrigation) { - eqLogic.services.irrigation.forEach(function(cmd) { + eqLogic.services.irrigation.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.Valve(eqLogic.name), @@ -926,18 +917,18 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.state=cmd.state; Serv.getCharacteristic(Characteristic.ValveType).setValue(Characteristic.ValveType.IRRIGATION); Serv.ValveType=Characteristic.ValveType.IRRIGATION; - eqServicesCopy.irrigation.forEach(function(cmd2) { + eqServicesCopy.irrigation.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { Serv.actions.off = cmd2.off; } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Irrigation Bouton On"');} - if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Irrigation Bouton Off"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Irrigation Bouton On"');} + if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Irrigation Bouton Off"');} // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -947,13 +938,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Irrigation Etat"'); + this.log('warn','Pas de type générique "Info/Irrigation Etat"'); } else { HBservice = null; } } if (eqLogic.services.valve) { - eqLogic.services.valve.forEach(function(cmd) { + eqLogic.services.valve.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.Valve(eqLogic.name), @@ -966,7 +957,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.state=cmd.state; Serv.getCharacteristic(Characteristic.ValveType).setValue(Characteristic.ValveType.GENERIC_VALVE); Serv.ValveType=Characteristic.ValveType.GENERIC_VALVE; - eqServicesCopy.valve.forEach(function(cmd2) { + eqServicesCopy.valve.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { @@ -977,8 +968,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.remainingDuration = cmd2.remainingDuration; } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Valve générique Bouton On"');} - if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Valve générique Bouton Off"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Valve générique Bouton On"');} + if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Valve générique Bouton Off"');} if(Serv.actions.setDuration) { HBservice.characteristics.push(Characteristic.SetDuration); @@ -990,7 +981,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -1000,13 +991,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Valve générique Etat"'); + this.log('warn','Pas de type générique "Info/Valve générique Etat"'); } else { HBservice = null; } } if (eqLogic.services.fan) { - eqLogic.services.fan.forEach(function(cmd) { + eqLogic.services.fan.forEach((cmd) => { if (cmd.state) { let FanType="Switch"; let maxPower; @@ -1020,7 +1011,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.fan.forEach(function(cmd2) { + eqServicesCopy.fan.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on=cmd2.on; } else if (cmd2.off) { @@ -1029,9 +1020,9 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions.slider=cmd2.slider; } }); - if (Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique "Action/Ventilateur OFF"');} - if (!Serv.actions.on && Serv.actions.off) {that.log('warn','Pas de type générique "Action/Ventilateur ON"');} - if (!Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique "Action/Ventilateur ON" et "Action/Ventilateur OFF"');} + if (Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique "Action/Ventilateur OFF"');} + if (!Serv.actions.on && Serv.actions.off) {this.log('warn','Pas de type générique "Action/Ventilateur ON"');} + if (!Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique "Action/Ventilateur ON" et "Action/Ventilateur OFF"');} if(Serv.actions.slider) { if(Serv.actions.slider.configuration && Serv.actions.slider.configuration.maxValue && parseInt(Serv.actions.slider.configuration.maxValue)) { @@ -1043,13 +1034,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.RotationSpeed); Serv.addCharacteristic(Characteristic.RotationSpeed); } else { - that.log('info','Le ventilateur n\'a pas de variateur'); + this.log('info','Le ventilateur n\'a pas de variateur'); } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); - that.log('info','Le ventilateur est du type :',FanType+((maxPower)?','+maxPower:'')); + this.log('info','Le ventilateur est du type :',FanType+((maxPower)?','+maxPower:'')); Serv.FanType = FanType; Serv.maxPower = maxPower; Serv.cmd_id = cmd.state.id; @@ -1060,17 +1051,17 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Ventilateur Etat"'); + this.log('warn','Pas de type générique "Info/Ventilateur Etat"'); } else { HBservice = null; } } if (eqLogic.services.Switch) { - eqLogic.services.Switch.forEach(function(cmd) { + eqLogic.services.Switch.forEach((cmd) => { if (cmd.state) { let SwitchName = eqLogic.name; if(cmd.state.generic_type == 'CAMERA_RECORD_STATE' || (cmd.state.generic_type == 'SWITCH_STATE' && eqLogic.numSwitches>1)) { - that.log('debug',"Switchs multiples dans même équipement, il y en a "+eqLogic.numSwitches); + this.log('debug',"Switchs multiples dans même équipement, il y en a "+eqLogic.numSwitches); SwitchName=cmd.state.name; } HBservice = { @@ -1079,7 +1070,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }; const Serv = HBservice.controlService; if(cmd.state.generic_type == 'CAMERA_RECORD_STATE' || (cmd.state.generic_type == 'SWITCH_STATE' && eqLogic.numSwitches>1)) { - that.log('debug',"Nom du switch (multi) : "+SwitchName); + this.log('debug',"Nom du switch (multi) : "+SwitchName); Serv.getCharacteristic(Characteristic.On).displayName = SwitchName; Serv.ConfiguredName=SwitchName; @@ -1091,7 +1082,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.Switch.forEach(function(cmd2) { + eqServicesCopy.Switch.forEach((cmd2) => { if (cmd2.on) { if(Serv.infos.state.generic_type == 'SWITCH_STATE' && eqLogic.numSwitches>1) { if(cmd2.on.value == cmd.state.id) { @@ -1110,22 +1101,22 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Interrupteur Bouton On"');} - if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Interrupteur Bouton Off"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Interrupteur Bouton On"');} + if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Interrupteur Bouton Off"');} // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { // HBservice.characteristics.push(Characteristic.Sensitivity,Characteristic.Duration,Characteristic.LastActivation); // eqLogic.loggingService = {type:"motion", options:{storage:'googleDrive',folder:'fakegato',keyPath:'/home/pi/.homebridge/'},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; - eqLogic.loggingService = {type:"switch", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService = {type:"switch", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1134,13 +1125,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Interrupteur Etat"'); + this.log('warn','Pas de type générique "Info/Interrupteur Etat"'); } else { HBservice = null; } } if (eqLogic.services.Push) { - eqLogic.services.Push.forEach(function(cmd) { + eqLogic.services.Push.forEach((cmd) => { if (cmd.Push && cmd.Push.subType == 'other') { const SwitchName=cmd.Push.name; HBservice = { @@ -1158,7 +1149,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.ConfiguredName).setValue(SwitchName); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.Push.id; Serv.eqID = eqLogic.id; @@ -1168,13 +1159,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','La Commande Action associée doit être du type "Autre"'); + this.log('warn','La Commande Action associée doit être du type "Autre"'); } else { HBservice = null; } } if (eqLogic.services.power || (eqLogic.services.power && eqLogic.services.consumption)) { - eqLogic.services.power.forEach(function(cmd) { + eqLogic.services.power.forEach((cmd) => { if (cmd.power) { HBservice = { controlService : new Service.PowerMonitor(eqLogic.name), @@ -1186,10 +1177,10 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.power=cmd.power; // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); if(eqServicesCopy.consumption) { - eqServicesCopy.consumption.forEach(function(cmd2) { + eqServicesCopy.consumption.forEach((cmd2) => { if (cmd2.consumption) { Serv.infos.consumption=cmd2.consumption; } @@ -1200,9 +1191,9 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { // HBservice.characteristics.push(Characteristic.ResetTotal); - eqLogic.loggingService = {type:"energy", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService = {type:"energy", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1212,7 +1203,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.battery) { - eqLogic.services.battery.forEach(function(cmd) { + eqLogic.services.battery.forEach((cmd) => { if (cmd.battery) { HBservice = { controlService : new Service.BatteryService(eqLogic.name), @@ -1224,7 +1215,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.battery=cmd.battery; Serv.infos.batteryCharging=cmd.batteryCharging || {id:'NOT'}; - eqServicesCopy.battery.forEach(function(cmd2) { + eqServicesCopy.battery.forEach((cmd2) => { if (cmd2.batteryCharging) { Serv.infos.batteryCharging=cmd2.batteryCharging; } else { @@ -1241,7 +1232,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.Noise) { - eqLogic.services.Noise.forEach(function(cmd) { + eqLogic.services.Noise.forEach((cmd) => { if (cmd.Noise) { HBservice = { controlService : new Service.NoiseSensor(eqLogic.name), @@ -1287,7 +1278,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.CO) { - eqLogic.services.CO.forEach(function(cmd) { + eqLogic.services.CO.forEach((cmd) => { if (cmd.CO) { HBservice = { controlService : new Service.CarbonMonoxideSensor(eqLogic.name), @@ -1311,7 +1302,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.CO2) { - eqLogic.services.CO2.forEach(function(cmd) { + eqLogic.services.CO2.forEach((cmd) => { if (cmd.CO2) { HBservice = { controlService : new Service.AirQualitySensor(eqLogic.name), @@ -1351,7 +1342,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.CarbonDioxideLevel).setProps(propsCO2); } - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { HBservice.characteristics.push(Characteristic.PPM); Serv.addCharacteristic(Characteristic.PPM); const unite = Serv.infos.CO2.unite ? Serv.infos.CO2.unite : ''; @@ -1363,7 +1354,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.AQExtraCharacteristic); Serv.addCharacteristic(Characteristic.AQExtraCharacteristic); - eqLogic.loggingService ={type:"room", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService ={type:"room", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1373,7 +1364,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.AirQualityCustom) { - eqLogic.services.AirQualityCustom.forEach(function(cmd) { + eqLogic.services.AirQualityCustom.forEach((cmd) => { if (cmd.Index) { HBservice = { controlService : new Service.AirQualitySensor(eqLogic.name), @@ -1390,35 +1381,35 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { if(eqLogic.customizedValues.EXCELLENT && eqLogic.customizedValues.EXCELLENT != "NOT") { Serv.levelNum[Characteristic.AirQuality.EXCELLENT] = parseInt(eqLogic.customizedValues.EXCELLENT); } else { - that.log('warn',"Pas de config de la valeur 'Excellent', on la défini sur 50"); + this.log('warn',"Pas de config de la valeur 'Excellent', on la défini sur 50"); Serv.levelNum[Characteristic.AirQuality.EXCELLENT]=50; } if(eqLogic.customizedValues.GOOD && eqLogic.customizedValues.GOOD != "NOT") { Serv.levelNum[Characteristic.AirQuality.GOOD] = parseInt(eqLogic.customizedValues.GOOD); } else { - that.log('warn',"Pas de config de la valeur 'Bon', on la défini sur 100"); + this.log('warn',"Pas de config de la valeur 'Bon', on la défini sur 100"); Serv.levelNum[Characteristic.AirQuality.GOOD]=100; } if(eqLogic.customizedValues.FAIR && eqLogic.customizedValues.FAIR != "NOT") { Serv.levelNum[Characteristic.AirQuality.FAIR] = parseInt(eqLogic.customizedValues.FAIR); } else { - that.log('warn',"Pas de config de la valeur 'Moyen', on la défini sur 150"); + this.log('warn',"Pas de config de la valeur 'Moyen', on la défini sur 150"); Serv.levelNum[Characteristic.AirQuality.FAIR]=150; } if(eqLogic.customizedValues.INFERIOR && eqLogic.customizedValues.INFERIOR != "NOT") { Serv.levelNum[Characteristic.AirQuality.INFERIOR] = parseInt(eqLogic.customizedValues.INFERIOR); } else { - that.log('warn',"Pas de config de la valeur 'Inférieur', on la défini sur 200"); + this.log('warn',"Pas de config de la valeur 'Inférieur', on la défini sur 200"); Serv.levelNum[Characteristic.AirQuality.INFERIOR]=200; } if(eqLogic.customizedValues.POOR && eqLogic.customizedValues.POOR != "NOT") { Serv.levelNum[Characteristic.AirQuality.POOR] = parseInt(eqLogic.customizedValues.POOR); } else { - that.log('warn',"Pas de config de la valeur 'Faible', on la défini sur 1000"); + this.log('warn',"Pas de config de la valeur 'Faible', on la défini sur 1000"); Serv.levelNum[Characteristic.AirQuality.POOR]=1000; } - } else if(that.myPlugin == "homebridge") { - that.log('warn',"Pas de config numérique des valeurs que qualité d'air"); + } else if(this.myPlugin == "homebridge") { + this.log('warn',"Pas de config numérique des valeurs que qualité d'air"); } @@ -1428,7 +1419,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { HBservice.characteristics.push(Characteristic.VOCDensity); Serv.addCharacteristic(Characteristic.VOCDensity); const unite = Serv.infos.Index.unite ? Serv.infos.Index.unite : ''; @@ -1441,7 +1432,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { HBservice.characteristics.push(Characteristic.AQExtraCharacteristic); Serv.addCharacteristic(Characteristic.AQExtraCharacteristic); - eqLogic.loggingService ={type:"room2", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService ={type:"room2", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1451,7 +1442,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.AirQuality) { - eqLogic.services.AirQuality.forEach(function(cmd) { + eqLogic.services.AirQuality.forEach((cmd) => { if (cmd.Index) { HBservice = { controlService : new Service.AirQualitySensor(eqLogic.name), @@ -1462,7 +1453,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.Index=cmd.Index; - eqServicesCopy.AirQuality.forEach(function(cmd2) { + eqServicesCopy.AirQuality.forEach((cmd2) => { if (cmd2.PM25) { Serv.infos.PM25= cmd2.PM25; } @@ -1503,11 +1494,11 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.presence) { - eqLogic.services.presence.forEach(function(cmd) { + eqLogic.services.presence.forEach((cmd) => { if (cmd.presence) { let SensorName=eqLogic.name; if(eqLogic.numDetector>1) { - that.log('debug',"Detecteurs multiples dans même équipement, il y en a "+eqLogic.numDetector); + this.log('debug',"Detecteurs multiples dans même équipement, il y en a "+eqLogic.numDetector); SensorName=cmd.presence.name; } HBservice = { @@ -1516,7 +1507,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }; const Serv = HBservice.controlService; if(eqLogic.numDetector>1) { - that.log('debug',"Nom du détecteur (multi) : "+SensorName); + this.log('debug',"Nom du détecteur (multi) : "+SensorName); Serv.getCharacteristic(Characteristic.MotionDetected).displayName = SensorName; Serv.ConfiguredName=SensorName; @@ -1533,21 +1524,21 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.invertBinary=cmd.presence.display.invertBinary; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.presence.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { HBservice.characteristics.push(Characteristic.Sensitivity,Characteristic.Duration,Characteristic.LastActivation); Serv.addOptionalCharacteristic(Characteristic.Sensitivity); Serv.addOptionalCharacteristic(Characteristic.Duration); Serv.addOptionalCharacteristic(Characteristic.LastActivation); // eqLogic.loggingService = {type:"motion", options:{storage:'googleDrive',folder:'fakegato',keyPath:'/home/pi/.homebridge/'},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; - eqLogic.loggingService = {type:"motion", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService = {type:"motion", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1558,11 +1549,11 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.occupancy) { - eqLogic.services.occupancy.forEach(function(cmd) { + eqLogic.services.occupancy.forEach((cmd) => { if (cmd.occupancy) { let SensorName=eqLogic.name; if(eqLogic.numDetector>1) { - that.log('debug',"Detecteurs occupancy multiples dans même équipement, il y en a "+eqLogic.numDetector); + this.log('debug',"Detecteurs occupancy multiples dans même équipement, il y en a "+eqLogic.numDetector); SensorName=cmd.occupancy.name; } HBservice = { @@ -1571,7 +1562,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }; const Serv = HBservice.controlService; if(eqLogic.numDetector>1) { - that.log('debug',"Nom du détecteur (multi) : "+SensorName); + this.log('debug',"Nom du détecteur (multi) : "+SensorName); Serv.getCharacteristic(Characteristic.OccupancyDetected).displayName = SensorName; Serv.ConfiguredName=SensorName; @@ -1588,7 +1579,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.invertBinary=cmd.occupancy.display.invertBinary; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.occupancy.id; Serv.eqID = eqLogic.id; @@ -1600,7 +1591,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.generic) { - eqLogic.services.generic.forEach(function(cmd) { + eqLogic.services.generic.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.CustomService(cmd.state.name), @@ -1612,12 +1603,12 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.state=cmd.state; // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); var props = {}; var unite = ''; if(cmd.state.subType=="numeric") { - that.log('debug','Le générique',cmd.state.name,'est un numérique'); + this.log('debug','Le générique',cmd.state.name,'est un numérique'); // test if default value is Float or Int ? var CharactToSet=Characteristic.GenericFLOAT; var NumericGenericType='float'; @@ -1625,7 +1616,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { CharactToSet=Characteristic.GenericINT; NumericGenericType='int'; } - that.log('debug','Sur base de sa valeur actuelle',cmd.state.currentValue,', on determine un type :',NumericGenericType); + this.log('debug','Sur base de sa valeur actuelle',cmd.state.currentValue,', on determine un type :',NumericGenericType); HBservice.characteristics.push(CharactToSet); Serv.addCharacteristic(CharactToSet); Serv.getCharacteristic(CharactToSet).displayName = cmd.state.name; @@ -1642,16 +1633,16 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } if(Object.keys(props).length !== 0) { - that.log('debug','On lui set les props suivants :',props); + this.log('debug','On lui set les props suivants :',props); Serv.getCharacteristic(CharactToSet).setProps(props); } } else if (cmd.state.subType=="binary") { - that.log('debug','Le générique',cmd.state.name,'est un booléen'); + this.log('debug','Le générique',cmd.state.name,'est un booléen'); HBservice.characteristics.push(Characteristic.GenericBOOL); Serv.addCharacteristic(Characteristic.GenericBOOL); Serv.getCharacteristic(Characteristic.GenericBOOL).displayName = cmd.state.name; } else if (cmd.state.subType=="string" || cmd.state.subType=="other") { - that.log('debug','Le générique',cmd.state.name,'est une chaîne'); + this.log('debug','Le générique',cmd.state.name,'est une chaîne'); HBservice.characteristics.push(Characteristic.GenericSTRING); Serv.addCharacteristic(Characteristic.GenericSTRING); Serv.getCharacteristic(Characteristic.GenericSTRING).displayName = cmd.state.name; @@ -1659,7 +1650,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { unite = cmd.state.unite ? cmd.state.unite : ''; if(unite) {props.unit=unite;} if(Object.keys(props).length !== 0) { - that.log('debug','On lui set les props suivants :',props); + this.log('debug','On lui set les props suivants :',props); Serv.getCharacteristic(Characteristic.GenericSTRING).setProps(props); } } @@ -1673,7 +1664,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.uv) { - eqLogic.services.uv.forEach(function(cmd) { + eqLogic.services.uv.forEach((cmd) => { if (cmd.uv) { HBservice = { controlService : new Service.WeatherService(eqLogic.name), @@ -1694,7 +1685,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.speaker) { - eqLogic.services.speaker.forEach(function(cmd) { + eqLogic.services.speaker.forEach((cmd) => { if (cmd.volume) { HBservice = { controlService : new Service.Speaker(eqLogic.name), @@ -1705,7 +1696,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.volume=cmd.volume; - eqServicesCopy.speaker.forEach(function(cmd2) { + eqServicesCopy.speaker.forEach((cmd2) => { if (cmd2.mute_toggle) { Serv.actions.mute_toggle = cmd2.mute_toggle; } else if (cmd2.mute_on) { @@ -1718,10 +1709,10 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.mute=cmd2.mute; } }); - if(!Serv.actions.set_volume) {that.log('warn','Pas de type générique "Action/Haut-Parleur Volume"');} - if(!Serv.actions.mute_toggle && !Serv.actions.mute_on && Serv.actions.mute_off) {that.log('warn','Pas de type générique "Action/Haut-Parleur Mute"');} - if(!Serv.actions.mute_toggle && Serv.actions.mute_on && !Serv.actions.mute_off) {that.log('warn','Pas de type générique "Action/Haut-Parleur UnMute"');} - if(!Serv.actions.mute_toggle && !Serv.actions.mute_on && !Serv.actions.mute_off) {that.log('warn','Pas de type générique "Action/Haut-Parleur Toggle Mute" / "Action/Haut-Parleur Mute" / "Action/Haut-Parleur UnMute"');} + if(!Serv.actions.set_volume) {this.log('warn','Pas de type générique "Action/Haut-Parleur Volume"');} + if(!Serv.actions.mute_toggle && !Serv.actions.mute_on && Serv.actions.mute_off) {this.log('warn','Pas de type générique "Action/Haut-Parleur Mute"');} + if(!Serv.actions.mute_toggle && Serv.actions.mute_on && !Serv.actions.mute_off) {this.log('warn','Pas de type générique "Action/Haut-Parleur UnMute"');} + if(!Serv.actions.mute_toggle && !Serv.actions.mute_on && !Serv.actions.mute_off) {this.log('warn','Pas de type générique "Action/Haut-Parleur Toggle Mute" / "Action/Haut-Parleur Mute" / "Action/Haut-Parleur UnMute"');} Serv.cmd_id = cmd.volume.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; @@ -1730,13 +1721,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Haut-Parleur Volume"'); + this.log('warn','Pas de type générique "Info/Haut-Parleur Volume"'); } else { HBservice = null; } } if (eqLogic.services.temperature) { - eqLogic.services.temperature.forEach(function(cmd) { + eqLogic.services.temperature.forEach((cmd) => { if (cmd.temperature) { HBservice = { controlService : new Service.TemperatureSensor(eqLogic.name), @@ -1753,14 +1744,14 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.TemperatureDisplayUnits).updateValue(Characteristic.TemperatureDisplayUnits.CELSIUS); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.temperature.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1771,7 +1762,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } if (eqLogic.services.humidity) { - eqLogic.services.humidity.forEach(function(cmd) { + eqLogic.services.humidity.forEach((cmd) => { if (cmd.humidity) { HBservice = { controlService : new Service.HumiditySensor(eqLogic.name), @@ -1783,15 +1774,15 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.humidity=cmd.humidity; // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.humidity.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService = {type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService = {type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1801,7 +1792,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.pressure) { - eqLogic.services.pressure.forEach(function(cmd) { + eqLogic.services.pressure.forEach((cmd) => { if (cmd.pressure) { HBservice = { controlService : new Service.PressureSensor(eqLogic.name), @@ -1817,8 +1808,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService = {type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService = {type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1828,7 +1819,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.smoke) { - eqLogic.services.smoke.forEach(function(cmd) { + eqLogic.services.smoke.forEach((cmd) => { if (cmd.smoke) { HBservice = { controlService : new Service.SmokeSensor(eqLogic.name), @@ -1844,7 +1835,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.invertBinary=cmd.smoke.display.invertBinary; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.smoke.id; Serv.eqID = eqLogic.id; @@ -1856,7 +1847,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.flood) { - eqLogic.services.flood.forEach(function(cmd) { + eqLogic.services.flood.forEach((cmd) => { if (cmd.flood) { HBservice = { controlService : new Service.LeakSensor(eqLogic.name), @@ -1872,7 +1863,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.invertBinary=cmd.flood.display.invertBinary; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.flood.id; Serv.eqID = eqLogic.id; @@ -1884,7 +1875,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.opening) { - eqLogic.services.opening.forEach(function(cmd) { + eqLogic.services.opening.forEach((cmd) => { if (cmd.opening) { HBservice = { controlService : new Service.ContactSensor(eqLogic.name), @@ -1900,14 +1891,14 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.invertBinary=cmd.opening.display.invertBinary; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.opening.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { // Serv.eqLogic.numberOpened = 0; HBservice.characteristics.push(Characteristic.TimesOpened,Characteristic.Char118,Characteristic.Char119,Characteristic.ResetTotal,Characteristic.LastActivation); Serv.addOptionalCharacteristic(Characteristic.TimesOpened); @@ -1916,7 +1907,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.addOptionalCharacteristic(Characteristic.ResetTotal); Serv.addOptionalCharacteristic(Characteristic.LastActivation); - eqLogic.loggingService = {type:"door", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService = {type:"door", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1926,7 +1917,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.brightness) { - eqLogic.services.brightness.forEach(function(cmd) { + eqLogic.services.brightness.forEach((cmd) => { if (cmd.brightness) { HBservice = { controlService : new Service.LightSensor(eqLogic.name), @@ -1938,17 +1929,17 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.brightness=cmd.brightness; // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.brightness.id; Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { + if(this.fakegato && !eqLogic.hasLogging) { // HBservice.characteristics.push(Characteristic.Sensitivity,Characteristic.Duration,Characteristic.LastActivation); // eqLogic.loggingService = {type:"motion", options:{storage:'googleDrive',folder:'fakegato',keyPath:'/home/pi/.homebridge/'},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; - eqLogic.loggingService = {type:"custom", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + eqLogic.loggingService = {type:"custom", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -1958,7 +1949,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.GarageDoor) { - eqLogic.services.GarageDoor.forEach(function(cmd) { + eqLogic.services.GarageDoor.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.GarageDoorOpener(eqLogic.name), @@ -1969,7 +1960,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.GarageDoor.forEach(function(cmd2) { + eqServicesCopy.GarageDoor.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { @@ -1978,16 +1969,16 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions.toggle = cmd2.toggle; } }); - if(!Serv.actions.toggle && !Serv.actions.on && Serv.actions.off) {that.log('warn','Pas de type générique "Action/Portail ou garage bouton d\'ouverture"');} - if(!Serv.actions.toggle && Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique "Action/Portail ou garage bouton de fermeture"');} - if(!Serv.actions.toggle && !Serv.actions.on && !Serv.actions.off) {that.log('warn','Pas de type générique ""Action/Portail ou garage bouton toggle" / "Action/Portail ou garage bouton d\'ouverture" / "Action/Portail ou garage bouton de fermeture"');} + if(!Serv.actions.toggle && !Serv.actions.on && Serv.actions.off) {this.log('warn','Pas de type générique "Action/Portail ou garage bouton d\'ouverture"');} + if(!Serv.actions.toggle && Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique "Action/Portail ou garage bouton de fermeture"');} + if(!Serv.actions.toggle && !Serv.actions.on && !Serv.actions.off) {this.log('warn','Pas de type générique ""Action/Portail ou garage bouton toggle" / "Action/Portail ou garage bouton d\'ouverture" / "Action/Portail ou garage bouton de fermeture"');} if(eqLogic.customizedValues) { Serv.customizedValues = eqLogic.customizedValues; } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -1997,13 +1988,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Garage état ouvrant" ou "Info/Portail état ouvrant"'); + this.log('warn','Pas de type générique "Info/Garage état ouvrant" ou "Info/Portail état ouvrant"'); } else { HBservice = null; } } if (eqLogic.services.lock) { - eqLogic.services.lock.forEach(function(cmd) { + eqLogic.services.lock.forEach((cmd) => { if (cmd.state) { HBservice = { controlService : new Service.LockMechanism(eqLogic.name), @@ -2014,18 +2005,18 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.actions={}; Serv.infos={}; Serv.infos.state=cmd.state; - eqServicesCopy.lock.forEach(function(cmd2) { + eqServicesCopy.lock.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on = cmd2.on; } else if (cmd2.off) { Serv.actions.off = cmd2.off; } }); - if(!Serv.actions.on) {that.log('warn','Pas de type générique "Action/Serrure Bouton Ouvrir"');} - // if(!Serv.actions.off) {that.log('warn','Pas de type générique "Action/Serrure Bouton Fermer"');} + if(!Serv.actions.on) {this.log('warn','Pas de type générique "Action/Serrure Bouton Ouvrir"');} + // if(!Serv.actions.off) {this.log('warn','Pas de type générique "Action/Serrure Bouton Fermer"');} // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.state.id; Serv.eqID = eqLogic.id; @@ -2035,13 +2026,13 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); if(!HBservice) { - that.log('warn','Pas de type générique "Info/Serrure Etat"'); + this.log('warn','Pas de type générique "Info/Serrure Etat"'); } else { HBservice = null; } } if (eqLogic.services.StatelessSwitch) { - eqLogic.services.StatelessSwitch.forEach(function(cmd) { + eqLogic.services.StatelessSwitch.forEach((cmd) => { if(cmd.eventType) { let buttonSingle,buttonDouble,buttonLong; @@ -2081,7 +2072,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { if(buttonSingle[b].trim() != '') {values.push(Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);} if(buttonDouble[b].trim() != '') {values.push(Characteristic.ProgrammableSwitchEvent.DOUBLE_PRESS);} if(buttonLong[b].trim() != '') {values.push(Characteristic.ProgrammableSwitchEvent.LONG_PRESS);} - that.log('debug','ValidValues',values); + this.log('debug','ValidValues',values); Serv.getCharacteristic(Characteristic.ProgrammableSwitchEvent).setProps({validValues:values}); Serv.getCharacteristic(Characteristic.ServiceLabelIndex).updateValue(Serv.ServiceLabelIndex); @@ -2111,14 +2102,14 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } } else { - that.log('warn',"Pas le même nombre de boutons pour chaque évènement (il doit y avoir le même nombre de ';')"); + this.log('warn',"Pas le même nombre de boutons pour chaque évènement (il doit y avoir le même nombre de ';')"); } } }); } if (eqLogic.services.StatelessSwitchMono) { const buttonList=[]; - eqLogic.services.StatelessSwitchMono.forEach(function(cmd) { + eqLogic.services.StatelessSwitchMono.forEach((cmd) => { if(cmd.Single || cmd.Double || cmd.Long) { let Label = ""; if(cmd.Single) {Label = "Simple";} @@ -2169,7 +2160,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.cmd_id += Serv.infos.Long.id; break; } - that.log('debug','ValidValues 0 Mono',values); + this.log('debug','ValidValues 0 Mono',values); Serv.getCharacteristic(Characteristic.ProgrammableSwitchEvent).setProps({validValues:values}); @@ -2225,7 +2216,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.Long=cmdType.Long; Serv.cmd_id += Serv.infos.Long.id; } - that.log('debug','ValidValues '+b+' Mono',values); + this.log('debug','ValidValues '+b+' Mono',values); Serv.getCharacteristic(Characteristic.ProgrammableSwitchEvent).setProps({validValues:values}); @@ -2260,7 +2251,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } if (eqLogic.services.weather) { - eqLogic.services.weather.forEach(function(cmd) { + eqLogic.services.weather.forEach((cmd) => { if(cmd.temperature) { HBservice = { controlService : new Service.TemperatureSensor(eqLogic.name), @@ -2278,7 +2269,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.TemperatureDisplayUnits).updateValue(Characteristic.TemperatureDisplayUnits.CELSIUS); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); Serv.cmd_id = cmd.temperature.id; Serv.eqID = eqLogic.id; @@ -2286,8 +2277,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -2311,8 +2302,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -2336,8 +2327,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService ={type:"weather", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } @@ -2355,7 +2346,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.condition=cmd.condition; - eqServicesCopy.weather.forEach(function(cmd2) { + eqServicesCopy.weather.forEach((cmd2) => { if (cmd2.wind_speed) { Serv.infos.wind_speed=cmd2.wind_speed; HBservice.characteristics.push(Characteristic.WindSpeed); @@ -2420,7 +2411,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.thermostat) { - eqLogic.services.thermostat.forEach(function(cmd) { + eqLogic.services.thermostat.forEach((cmd) => { if(cmd.setpoint) { HBservice = { controlService : new Service.Thermostat(eqLogic.name), @@ -2437,7 +2428,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.addOptionalCharacteristic(Characteristic.TemperatureDisplayUnits); Serv.getCharacteristic(Characteristic.TemperatureDisplayUnits).updateValue(Characteristic.TemperatureDisplayUnits.CELSIUS); - eqServicesCopy.thermostat.forEach(function(cmd2) { + eqServicesCopy.thermostat.forEach((cmd2) => { if (cmd2.state_name) { Serv.infos.state_name=cmd2.state_name; } else if (cmd2.lock) { @@ -2471,7 +2462,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.TargetTemperature).setProps(props); } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); props = {}; props.validValues=[0]; @@ -2483,7 +2474,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermo.chauf.mode_id = splitted[0]; props.validValues.push(1); } else { - that.log('warn','Pas de config du mode Chauffage'); + this.log('warn','Pas de config du mode Chauffage'); } if(eqLogic.thermoModes.Clim && eqLogic.thermoModes.Clim != "NOT") { Serv.thermo.clim = {}; @@ -2492,7 +2483,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermo.clim.mode_id = splitted[0]; props.validValues.push(2); } else { - that.log('warn','Pas de config du mode Climatisation'); + this.log('warn','Pas de config du mode Climatisation'); } if(eqLogic.thermoModes.Off && eqLogic.thermoModes.Off != "NOT") { Serv.thermo.off = {}; @@ -2500,8 +2491,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermo.off.mode_label = splitted[1]; Serv.thermo.off.mode_id = splitted[0]; } - } else if(that.myPlugin == "homebridge") { - that.log('warn','Pas de config des modes du thermostat'); + } else if(this.myPlugin == "homebridge") { + this.log('warn','Pas de config des modes du thermostat'); } // Serv.getCharacteristic(Characteristic.CurrentHeatingCoolingState).setProps(props); props.validValues.push(3); @@ -2510,8 +2501,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.eqID = eqLogic.id; Serv.subtype = Serv.subtype || ''; Serv.subtype = eqLogic.id + '-' + Serv.cmd_id + '-' + Serv.subtype; - if(that.fakegato && !eqLogic.hasLogging) { - eqLogic.loggingService ={type:"thermo", options:{storage:'fs',path:that.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; + if(this.fakegato && !eqLogic.hasLogging) { + eqLogic.loggingService ={type:"thermo", options:{storage:'fs',path:this.pathHomebridgeConf},subtype:Serv.eqID+'-history',cmd_id:Serv.eqID}; eqLogic.hasLogging=true; } HBservices.push(HBservice); @@ -2520,7 +2511,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.thermostatHC) { - eqLogic.services.thermostatHC.forEach(function(cmd) { + eqLogic.services.thermostatHC.forEach((cmd) => { if(cmd.setpointH) { HBservice = { controlService : new Service.HeaterCooler(eqLogic.name), @@ -2537,7 +2528,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.addOptionalCharacteristic(Characteristic.TemperatureDisplayUnits); Serv.getCharacteristic(Characteristic.TemperatureDisplayUnits).updateValue(Characteristic.TemperatureDisplayUnits.CELSIUS); - eqServicesCopy.thermostatHC.forEach(function(cmd2) { + eqServicesCopy.thermostatHC.forEach((cmd2) => { if (cmd2.setpointC) { Serv.infos.setpointC=cmd2.setpointC; } else if (cmd2.state_name) { @@ -2585,7 +2576,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.CoolingThresholdTemperature).setProps(props); } // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); props = {}; props.validValues=[0]; @@ -2597,7 +2588,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermoHC.chauf.mode_id = splitted[0]; props.validValues.push(1); } else { - that.log('warn','Pas de config du mode Chauffage'); + this.log('warn','Pas de config du mode Chauffage'); } if(eqLogic.thermoModes.Clim && eqLogic.thermoModes.Clim != "NOT") { Serv.thermoHC.clim = {}; @@ -2606,7 +2597,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermoHC.clim.mode_id = splitted[0]; props.validValues.push(2); } else { - that.log('warn','Pas de config du mode Climatisation'); + this.log('warn','Pas de config du mode Climatisation'); } if(eqLogic.thermoModes.Off && eqLogic.thermoModes.Off != "NOT") { Serv.thermoHC.off = {}; @@ -2615,8 +2606,8 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.thermoHC.off.mode_id = splitted[0]; } } - else if(that.myPlugin == "homebridge") { - that.log('warn','Pas de config des modes du thermostatHC'); + else if(this.myPlugin == "homebridge") { + this.log('warn','Pas de config des modes du thermostatHC'); } // Serv.getCharacteristic(Characteristic.CurrentHeatingCoolingState).setProps(props); props.validValues.push(3); @@ -2632,7 +2623,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } if (eqLogic.services.mode) { let modeState=null; - eqLogic.services.mode.forEach(function(cmd) { + eqLogic.services.mode.forEach((cmd) => { if(cmd.state) { HBservice = { controlService : new Service.CustomService(eqLogic.name), @@ -2658,9 +2649,9 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); if(modeState) { var set_state_previous = null; - eqLogic.services.mode.forEach(function(cmd) { + eqLogic.services.mode.forEach((cmd) => { if (cmd.set_state) { - cmd.set_state.forEach(function(set_action) { + cmd.set_state.forEach((set_action) => { var ModeName = ""; if(set_action.name.toLowerCase().includes('mode') || set_action.name.toLowerCase().includes('modo')) { ModeName = set_action.name; @@ -2682,7 +2673,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.getCharacteristic(Characteristic.ConfiguredName).setValue(ModeName); if(!set_state_previous) { - eqServicesCopy.mode.forEach(function(cmd2) { + eqServicesCopy.mode.forEach((cmd2) => { if (cmd2.set_state_previous) { Serv.actions.set_state_previous=cmd2.set_state_previous; set_state_previous=cmd2.set_state_previous; @@ -2706,11 +2697,11 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } }); } else { - that.log('warn','Vous utilisez le type générique Mode en dehors du plugin Mode !'); + this.log('warn','Vous utilisez le type générique Mode en dehors du plugin Mode !'); } } if (eqLogic.services.siren) { - eqLogic.services.siren.forEach(function(cmd) { + eqLogic.services.siren.forEach((cmd) => { if(cmd.state) { HBservice = { controlService : new Service.SecuritySystem(eqLogic.name), @@ -2723,7 +2714,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos.state=cmd.state; Serv.siren=true; - eqServicesCopy.siren.forEach(function(cmd2) { + eqServicesCopy.siren.forEach((cmd2) => { if (cmd2.on) { Serv.actions.on=cmd2.on; } else if (cmd2.off) { @@ -2732,7 +2723,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); // Serv.getCharacteristic(Characteristic.SecuritySystemCurrentState).setProps({validValues:[3,4]}); Serv.getCharacteristic(Characteristic.SecuritySystemTargetState).setProps({validValues:[3]}); @@ -2746,7 +2737,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); } if (eqLogic.services.alarm) { - eqLogic.services.alarm.forEach(function(cmd) { + eqLogic.services.alarm.forEach((cmd) => { if(cmd.enable_state) { HBservice = { controlService : new Service.SecuritySystem(eqLogic.name), @@ -2758,7 +2749,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { Serv.infos={}; Serv.infos.enable_state=cmd.enable_state; Serv.alarm={}; - eqServicesCopy.alarm.forEach(function(cmd2) { + eqServicesCopy.alarm.forEach((cmd2) => { if (cmd2.state) { Serv.infos.state=cmd2.state; } else if (cmd2.mode) { @@ -2767,7 +2758,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { }); // add Active, Tampered and Defect Characteristics if needed - HBservice=that.createStatusCharact(HBservice,eqServicesCopy); + HBservice=this.createStatusCharact(HBservice,eqServicesCopy); var props = {}; props.validValues=[]; @@ -2781,7 +2772,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { props.validValues.push(Characteristic.SecuritySystemTargetState.STAY_ARM); Serv.hasAlarmModes=true; } else { - that.log('warn','Pas de config du mode Domicile/Présence'); + this.log('warn','Pas de config du mode Domicile/Présence'); } if(eqLogic.alarmModes.SetModeAbsent && eqLogic.alarmModes.SetModeAbsent != "NOT") { Serv.alarm.away = {}; @@ -2791,7 +2782,7 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { props.validValues.push(Characteristic.SecuritySystemTargetState.AWAY_ARM); Serv.hasAlarmModes=true; } else { - that.log('warn','Pas de config du mode À distance/Absence'); + this.log('warn','Pas de config du mode À distance/Absence'); } if(eqLogic.alarmModes.SetModeNuit && eqLogic.alarmModes.SetModeNuit != "NOT") { Serv.alarm.night = {}; @@ -2801,12 +2792,12 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { props.validValues.push(Characteristic.SecuritySystemTargetState.NIGHT_ARM); Serv.hasAlarmModes=true; } else { - that.log('warn','Pas de config du mode Nuit'); + this.log('warn','Pas de config du mode Nuit'); } } - if(that.myPlugin == "homebridge" && !Serv.hasAlarmModes) { + if(this.myPlugin == "homebridge" && !Serv.hasAlarmModes) { props.validValues.push(Characteristic.SecuritySystemTargetState.AWAY_ARM); - that.log('warn','Pas de config des modes de l\'alarme'); + this.log('warn','Pas de config des modes de l\'alarme'); } props.validValues.push(Characteristic.SecuritySystemTargetState.DISARM); Serv.getCharacteristic(Characteristic.SecuritySystemTargetState).setProps(props); @@ -2821,18 +2812,18 @@ JeedomPlatform.prototype.AccessoireCreateHomebridge = function(eqLogic) { } if (HBservices.length != 0) { - if (DEV_DEBUG) {that.log('debug','HBservices : '+JSON.stringify(HBservices));} - createdAccessory = that.createAccessory(HBservices, eqLogic); - that.addAccessory(createdAccessory); + if (DEV_DEBUG) {this.log('debug','HBservices : '+JSON.stringify(HBservices));} + createdAccessory = this.createAccessory(HBservices, eqLogic); + this.addAccessory(createdAccessory); HBservices = []; } else { - that.log('│ Accessoire sans Type Générique d\'Etat'); - createdAccessory = that.createAccessory([], eqLogic); // create a cached lookalike object for unregistering it - that.delAccessory(createdAccessory); + this.log('│ Accessoire sans Type Générique d\'Etat'); + createdAccessory = this.createAccessory([], eqLogic); // create a cached lookalike object for unregistering it + this.delAccessory(createdAccessory); } - that.log('└─────────'); + this.log('└─────────'); } catch(e){ this.log('error','Erreur de la fonction AccessoireCreateHomebridge :',e); @@ -3166,8 +3157,6 @@ JeedomPlatform.prototype.bindCharacteristicEvents = function(characteristic, ser // -- Return : nothing JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, service) { try{ - const that = this; - var action,rgb,cmdId; switch (characteristic.UUID) { case Characteristic.ConfiguredName.UUID : @@ -3184,10 +3173,10 @@ JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, ser action = 'stop'; cmdId = service.cmd_id; - that.jeedomClient.executeScenarioAction(cmdId, action).then(function(response) { - that.log('info','[Commande Scenario envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande Scenario ' + action + ' vers ' + cmdId , err); + this.jeedomClient.executeScenarioAction(cmdId, action).then((response) => { + this.log('info','[Commande Scenario envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande Scenario ' + action + ' vers ' + cmdId , err); if(err && err.stack) { console.error(err.stack); } }); } else { @@ -3195,27 +3184,27 @@ JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, ser action = 'run'; cmdId = service.cmd_id; - that.jeedomClient.executeScenarioAction(cmdId, action).then(function(response) { - that.log('info','[Commande Scenario envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande Scenario ' + action + ' vers ' + cmdId , err); + this.jeedomClient.executeScenarioAction(cmdId, action).then((response) => { + this.log('info','[Commande Scenario envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande Scenario ' + action + ' vers ' + cmdId , err); if(err && err.stack) { console.error(err.stack); } }); } } else if (service.actions.Push){ if(value == 1) { this.command('Pushed', null, service); - setTimeout(function() { + setTimeout(() => { characteristic.updateValue(sanitizeValue(false,characteristic), undefined, 'fromSetValue'); }, 100); } } else if (service.modeSwitch) { // modes plugin if(value == 0) {// turnOff // execute set mode Previous - that.log('debug','info about previous mode',service); + this.log('debug','info about previous mode',service); this.command('modeSetPrevious', null, service); } else {// turnOn - that.log('debug','info about mode',service); + this.log('debug','info about mode',service); this.command('modeSet', null, service); } } else { @@ -3245,7 +3234,7 @@ JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, ser } else { value = characteristic.value; } - setTimeout(function() { + setTimeout(() => { characteristic.updateValue(sanitizeValue(value,characteristic), undefined, 'fromSetValue'); }, 100); break; @@ -3256,7 +3245,7 @@ JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, ser } else { value = characteristic.value; } - setTimeout(function() { + setTimeout(() => { characteristic.updateValue(sanitizeValue(value,characteristic), undefined, 'fromSetValue'); }, 100); break; @@ -3267,7 +3256,7 @@ JeedomPlatform.prototype.setAccessoryValue = function(value, characteristic, ser } else { value = characteristic.value; } - setTimeout(function() { + setTimeout(() => { characteristic.updateValue(sanitizeValue(value,characteristic), undefined, 'fromSetValue'); }, 100); break; @@ -3574,21 +3563,20 @@ JeedomPlatform.prototype.findAccessoryByService = function(serviceToFind) { }; JeedomPlatform.prototype.changeAccessoryValue = function(characteristic, service) { - const that = this; - const cmdList = that.jeedomClient.getDeviceCmdFromCache(service.eqID); + const cmdList = this.jeedomClient.getDeviceCmdFromCache(service.eqID); switch (characteristic.UUID) { case Characteristic.ContactSensorState.UUID : for (const cmd of cmdList) { if ((cmd.generic_type == 'OPENING' || cmd.generic_type == 'OPENING_WINDOW') && cmd.id == service.cmd_id) { - if(that.fakegato) { + if(this.fakegato) { const realValue = parseInt(service.invertBinary)==0 ? toBool(cmd.currentValue) : !toBool(cmd.currentValue); // invertBinary ? if(realValue === false) { service.eqLogic.numberOpened++; } service.eqLogic.lastAct=Math.round(new Date().valueOf() / 1000)-service.eqLogic.loggingService.getInitialTime(); - that.api.updatePlatformAccessories([this.findAccessoryByService(service)]); + this.api.updatePlatformAccessories([this.findAccessoryByService(service)]); } break; } @@ -3597,9 +3585,9 @@ JeedomPlatform.prototype.changeAccessoryValue = function(characteristic, service case Characteristic.MotionDetected.UUID : for (const cmd of cmdList) { if (cmd.generic_type == 'PRESENCE' && cmd.id == service.cmd_id) { - if(that.fakegato) { + if(this.fakegato) { service.eqLogic.lastAct=Math.round(new Date().valueOf() / 1000)-service.eqLogic.loggingService.getInitialTime(); - that.api.updatePlatformAccessories([this.findAccessoryByService(service)]); + this.api.updatePlatformAccessories([this.findAccessoryByService(service)]); } break; } @@ -3616,8 +3604,6 @@ JeedomPlatform.prototype.changeAccessoryValue = function(characteristic, service // -- Return : nothing JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, info=null) { try{ - const that = this; - let customizedValues={}; if(service.customizedValues) { customizedValues=service.customizedValues; @@ -3627,7 +3613,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i let returnValue = 0; let HRreturnValue; - const cmdList = that.jeedomClient.getDeviceCmdFromCache(service.eqID); + const cmdList = this.jeedomClient.getDeviceCmdFromCache(service.eqID); let targetValueToTest,currentValueToTest; let hsv,mode_PRESENT,mode_AWAY,mode_NIGHT,mode_CLIM,mode_CHAUF; @@ -3643,7 +3629,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; case Characteristic.On.UUID : if(service.infos.scenario) { - const scenario = that.jeedomClient.getScenarioPropertiesFromCache(service.infos.scenario.id); + const scenario = this.jeedomClient.getScenarioPropertiesFromCache(service.infos.scenario.id); switch(scenario.state) { case 'stop': returnValue = false; @@ -3652,7 +3638,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i returnValue = true; break; } - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), status: ((returnValue)?1:0), @@ -3711,7 +3697,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; } else if ((cmd.generic_type == "SWITCH_STATE" || cmd.generic_type == "CAMERA_RECORD_STATE") && cmd.id == service.cmd_id) { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), status: ((returnValue)?1:0), @@ -3750,11 +3736,11 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; // Generics case Characteristic.TimesOpened.UUID : - that.log('info','Demande du nombre d\'ouverture de la porte',service.eqLogic.numberOpened); + this.log('info','Demande du nombre d\'ouverture de la porte',service.eqLogic.numberOpened); returnValue = service.eqLogic.numberOpened; break; case Characteristic.LastActivation.UUID : - that.log('info','Demande de la dernière activation',service.eqLogic.lastAct); + this.log('info','Demande de la dernière activation',service.eqLogic.lastAct); returnValue = service.eqLogic.lastAct; break; case Characteristic.ServiceLabelIndex.UUID : @@ -3825,7 +3811,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'CO2' && cmd.id == service.cmd_id) { returnValue = parseInt(cmd.currentValue); - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), ppm: returnValue, @@ -3842,7 +3828,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(service.infos.Index && service.infos.Index.unite && service.infos.Index.unite.toLowerCase() == 'ppb') { // unit should be µg/m3 if it's ppb, multiply it by 4.57 returnValue = parseInt(returnValue*4.57); } - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), voc: returnValue, @@ -3914,7 +3900,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } else { returnValue = Characteristic.ContactSensorState.CONTACT_DETECTED; } - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { /* if(returnValue === Characteristic.ContactSensorState.CONTACT_NOT_DETECTED) { service.eqLogic.numberOpened++; } */ @@ -3932,7 +3918,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'BRIGHTNESS' && cmd.id == service.cmd_id) { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), lux: returnValue, @@ -3950,7 +3936,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i (cmd.generic_type == 'WEATHER_TEMPERATURE' && cmd.id == service.infos.temperature.id)) { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { if (cmd.generic_type == 'TEMPERATURE' || cmd.generic_type == 'WEATHER_TEMPERATURE') { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), @@ -3976,7 +3962,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i (cmd.generic_type == 'WEATHER_HUMIDITY' && cmd.id == service.infos.humidity.id)) { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), humidity: returnValue, @@ -3992,7 +3978,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i (cmd.generic_type == 'WEATHER_PRESSURE' && cmd.id == service.infos.pressure.id)) { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), pressure: returnValue, @@ -4074,7 +4060,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if (cmd.generic_type == 'PRESENCE' && cmd.id == service.cmd_id) { // returnValue = parseInt(service.invertBinary)==0 ? !toBool(cmd.currentValue) : toBool(cmd.currentValue); // invertBinary ? returnValue = toBool(cmd.currentValue); - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), status: returnValue?1:0, @@ -4138,8 +4124,8 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(maxJeedom) { returnValue = Math.round((returnValue / maxJeedom)*100); } - if (DEV_DEBUG) {that.log('debug','---------update Power(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} - // that.log('debug','------------PowerVentilo jeedom :',cmd.currentValue,'soit en homekit :',returnValue); + if (DEV_DEBUG) {this.log('debug','---------update Power(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} + // this.log('debug','------------PowerVentilo jeedom :',cmd.currentValue,'soit en homekit :',returnValue); break; } } @@ -4190,7 +4176,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; } } - hsv = that.updateHomeKitColorFromJeedom(returnValue, service); + hsv = this.updateHomeKitColorFromJeedom(returnValue, service); returnValue = Math.round(hsv.h); break; case Characteristic.Saturation.UUID : @@ -4200,7 +4186,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; } } - hsv = that.updateHomeKitColorFromJeedom(returnValue, service); + hsv = this.updateHomeKitColorFromJeedom(returnValue, service); returnValue = Math.round(hsv.s); break; case Characteristic.ColorTemperature.UUID : @@ -4224,8 +4210,8 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(maxJeedom != 0) { returnValue = Math.round((returnValue / maxJeedom)*100); } - if (DEV_DEBUG) {that.log('debug','---------update Bright(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} - // that.log('debug','------------Brightness jeedom :',cmd.currentValue,'soit en homekit :',returnValue); + if (DEV_DEBUG) {this.log('debug','---------update Bright(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} + // this.log('debug','------------Brightness jeedom :',cmd.currentValue,'soit en homekit :',returnValue); break; } else if (cmd.generic_type == 'LIGHT_BRIGHTNESS' && cmd.id == service.infos.brightness.id) { const maxJeedom = parseInt(service.maxBright) || 100; @@ -4233,8 +4219,8 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(maxJeedom != 0) { returnValue = Math.round((returnValue / maxJeedom)*100); } - if (DEV_DEBUG) {that.log('debug','---------update Bright(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} - // that.log('debug','------------Brightness jeedom :',cmd.currentValue,'soit en homekit :',returnValue); + if (DEV_DEBUG) {this.log('debug','---------update Bright(refresh):',returnValue,'% soit',cmd.currentValue,' / ',maxJeedom);} + // this.log('debug','------------Brightness jeedom :',cmd.currentValue,'soit en homekit :',returnValue); break; } } @@ -4249,34 +4235,34 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } for (const cmd of cmdList) { if (cmd.generic_type == 'SIREN_STATE') { - if (DEV_DEBUG) {that.log('debug',"Siren_state T=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Siren_state T=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemTargetState.DISARM; break; } if(!service.hasAlarmModes) { if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 1) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state T=",cmd.currentValue,"NO MODES");} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state T=",cmd.currentValue,"NO MODES");} returnValue = Characteristic.SecuritySystemTargetState.AWAY_ARM; break; } else if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 0) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state T=",cmd.currentValue,"NO MODES");} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state T=",cmd.currentValue,"NO MODES");} returnValue = Characteristic.SecuritySystemTargetState.DISARM; break; } } else { if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 0) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state T=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state T=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemTargetState.DISARM; break; } if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 1) { // if there is mode and alarm is enabled, will continue the search for mode instead ! - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state T=",cmd.currentValue,'return undefined');} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state T=",cmd.currentValue,'return undefined');} returnValue = undefined; continue; } if (cmd.generic_type == 'ALARM_MODE') { - if (DEV_DEBUG) {that.log('debug',"alarm_mode T=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"alarm_mode T=",cmd.currentValue);} if(service.alarm.present && service.alarm.present.mode_label != undefined) { mode_PRESENT=service.alarm.present.mode_label?.toLowerCase(); @@ -4289,23 +4275,23 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } switch (cmd.currentValue?.toLowerCase()) { case undefined: - if (DEV_DEBUG) {that.log('debug',"renvoie absent T via undefined",Characteristic.SecuritySystemTargetState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent T via undefined",Characteristic.SecuritySystemTargetState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemTargetState.AWAY_ARM; break; default: // back compatibility - if (DEV_DEBUG) {that.log('debug',"renvoie absent T via default",Characteristic.SecuritySystemTargetState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent T via default",Characteristic.SecuritySystemTargetState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemTargetState.AWAY_ARM; break; case mode_PRESENT: - if (DEV_DEBUG) {that.log('debug',"renvoie present T",Characteristic.SecuritySystemTargetState.STAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie present T",Characteristic.SecuritySystemTargetState.STAY_ARM);} returnValue = Characteristic.SecuritySystemTargetState.STAY_ARM; break; case mode_AWAY: - if (DEV_DEBUG) {that.log('debug',"renvoie absent T",Characteristic.SecuritySystemTargetState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent T",Characteristic.SecuritySystemTargetState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemTargetState.AWAY_ARM; break; case mode_NIGHT: - if (DEV_DEBUG) {that.log('debug',"renvoie nuit T",Characteristic.SecuritySystemTargetState.NIGHT_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie nuit T",Characteristic.SecuritySystemTargetState.NIGHT_ARM);} returnValue = Characteristic.SecuritySystemTargetState.NIGHT_ARM; break; } @@ -4325,56 +4311,56 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'SIREN_STATE') { if (cmd.currentValue == 1) { - if (DEV_DEBUG) {that.log('debug',"Siren_State C=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Siren_State C=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED; break; } else if (cmd.currentValue == 0) { - if (DEV_DEBUG) {that.log('debug',"Siren_state C=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Siren_state C=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemCurrentState.DISARMED; break; } else { - if (DEV_DEBUG) {that.log('debug',"Siren_state C IMPOSSIBLE =",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Siren_state C IMPOSSIBLE =",cmd.currentValue);} returnValue = Characteristic.SecuritySystemCurrentState.DISARMED; break; } } if (cmd.generic_type == 'ALARM_STATE') { if(cmd.currentValue == 1) { - if (DEV_DEBUG) {that.log('debug',"Alarm_State C=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Alarm_State C=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemCurrentState.ALARM_TRIGGERED; break; } else { continue; } } if (!service.hasAlarmModes) { if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 1) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state C=",cmd.currentValue,"NO MODES");} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state C=",cmd.currentValue,"NO MODES");} returnValue = Characteristic.SecuritySystemCurrentState.AWAY_ARM; break; } else if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 0) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state C=",cmd.currentValue,"NO MODES");} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state C=",cmd.currentValue,"NO MODES");} returnValue = Characteristic.SecuritySystemCurrentState.DISARMED; break; } } else { if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 0) { - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state C=",cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state C=",cmd.currentValue);} returnValue = Characteristic.SecuritySystemCurrentState.DISARMED; break; } if (cmd.generic_type == 'ALARM_ENABLE_STATE' && cmd.currentValue == 1) { // if there is mode and alarm is enabled, will continue the search for mode instead ! - if (DEV_DEBUG) {that.log('debug',"Alarm_enable_state C=",cmd.currentValue,'return undefined');} + if (DEV_DEBUG) {this.log('debug',"Alarm_enable_state C=",cmd.currentValue,'return undefined');} returnValue = undefined; if(info && info.generic_type == 'ALARM_ENABLE_STATE') { - if (DEV_DEBUG) {that.log('debug',"And break");} + if (DEV_DEBUG) {this.log('debug',"And break");} break; } else { - if (DEV_DEBUG) {that.log('debug',"And continue");} + if (DEV_DEBUG) {this.log('debug',"And continue");} continue; } } if (cmd.generic_type == 'ALARM_MODE') { - if (DEV_DEBUG) {that.log('debug',"alarm_mode C=",cmd.currentValue?.toLowerCase());} + if (DEV_DEBUG) {this.log('debug',"alarm_mode C=",cmd.currentValue?.toLowerCase());} if(service.alarm.present && service.alarm.present.mode_label != undefined) { mode_PRESENT=service.alarm.present.mode_label?.toLowerCase(); @@ -4387,23 +4373,23 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } switch (cmd.currentValue?.toLowerCase()) { case undefined: - if (DEV_DEBUG) {that.log('debug',"renvoie absent C via undefined",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent C via undefined",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemCurrentState.AWAY_ARM; break; default: // back compatibility - if (DEV_DEBUG) {that.log('debug',"renvoie absent C via default",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent C via default",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemCurrentState.AWAY_ARM; break; case mode_PRESENT: - if (DEV_DEBUG) {that.log('debug',"renvoie present C",Characteristic.SecuritySystemCurrentState.STAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie present C",Characteristic.SecuritySystemCurrentState.STAY_ARM);} returnValue = Characteristic.SecuritySystemCurrentState.STAY_ARM; break; case mode_AWAY: - if (DEV_DEBUG) {that.log('debug',"renvoie absent C",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie absent C",Characteristic.SecuritySystemCurrentState.AWAY_ARM);} returnValue = Characteristic.SecuritySystemCurrentState.AWAY_ARM; break; case mode_NIGHT: - if (DEV_DEBUG) {that.log('debug',"renvoie nuit C",Characteristic.SecuritySystemCurrentState.NIGHT_ARM);} + if (DEV_DEBUG) {this.log('debug',"renvoie nuit C",Characteristic.SecuritySystemCurrentState.NIGHT_ARM);} returnValue = Characteristic.SecuritySystemCurrentState.NIGHT_ARM; break; } @@ -4418,7 +4404,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'THERMOSTAT_STATE_NAME' || cmd.generic_type == 'THERMOSTAT_HC_STATE_NAME') { if(cmd.currentValue != undefined && cmd.currentValue != null) { - that.log('debug','----Current State Thermo :',cmd.currentValue.toString().toLowerCase()); + this.log('debug','----Current State Thermo :',cmd.currentValue.toString().toLowerCase()); switch(cmd.currentValue.toString().toLowerCase()) { default: case 'off' : // EN @@ -4481,7 +4467,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(service.thermo.chauf && service.thermo.chauf.mode_label !== undefined) { mode_CHAUF=service.thermo.chauf.mode_label.toString().toLowerCase(); } - that.log('debug','TargetThermo :',mode_CLIM,mode_CHAUF,':',cmd.currentValue.toString().toLowerCase()); + this.log('debug','TargetThermo :',mode_CLIM,mode_CHAUF,':',cmd.currentValue.toString().toLowerCase()); switch(cmd.currentValue.toString().toLowerCase()) { case 'off' : // EN case 'stopped' : // EN @@ -4522,7 +4508,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(service.thermoHC.chauf && service.thermoHC.chauf.mode_label !== undefined) { mode_CHAUF=service.thermoHC.chauf.mode_label.toString().toLowerCase(); } - that.log('debug','TargetThermo :',mode_CLIM,mode_CHAUF,':',cmd.currentValue.toString().toLowerCase()); + this.log('debug','TargetThermo :',mode_CLIM,mode_CHAUF,':',cmd.currentValue.toString().toLowerCase()); switch(cmd.currentValue.toString().toLowerCase()) { case 'off' : // EN case 'stopped' : // EN @@ -4560,7 +4546,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'THERMOSTAT_SETPOINT') { returnValue = cmd.currentValue; - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), setTemp : returnValue, @@ -4618,7 +4604,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } if (DEV_DEBUG) { console.log(customizedValues); - that.log('debug','Target Garage/Barrier Homekit: '+returnValue+' soit en Jeedom:'+cmd.currentValue+" ("+HRreturnValue+")"); + this.log('debug','Target Garage/Barrier Homekit: '+returnValue+' soit en Jeedom:'+cmd.currentValue+" ("+HRreturnValue+")"); } break; } @@ -4655,7 +4641,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } if (DEV_DEBUG) { console.log(customizedValues); - that.log('debug','Etat Garage/Barrier Homekit: '+returnValue+' soit en Jeedom:'+cmd.currentValue+" ("+HRreturnValue+")"); + this.log('debug','Etat Garage/Barrier Homekit: '+returnValue+' soit en Jeedom:'+cmd.currentValue+" ("+HRreturnValue+")"); } break; } @@ -4674,7 +4660,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(returnValue === service.TargetValue) {service.Moving=Characteristic.PositionState.STOPPED;} else if (service.TargetValue !== undefined && service.Moving===Characteristic.PositionState.STOPPED) {service.TargetValue=undefined;} - that.log('debug','---------update Blinds Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); + this.log('debug','---------update Blinds Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); break; } if (cmd.generic_type == 'FLAP_STATE_CLOSING' && cmd.id == service.cmd_id) { @@ -4688,7 +4674,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(returnValue === service.TargetValue) {service.Moving=Characteristic.PositionState.STOPPED;} else if (service.TargetValue !== undefined && service.Moving===Characteristic.PositionState.STOPPED) {service.TargetValue=undefined;} - that.log('debug','---------update Inverted Blinds Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); + this.log('debug','---------update Inverted Blinds Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); break; } if (cmd.generic_type == 'WINDOW_STATE' && cmd.id == service.cmd_id) { @@ -4697,7 +4683,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(returnValue === service.TargetValue) {service.Moving=Characteristic.PositionState.STOPPED;} else if (service.TargetValue !== undefined && service.Moving===Characteristic.PositionState.STOPPED) {service.TargetValue=undefined;} - that.log('debug','---------update WindowMoto Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); + this.log('debug','---------update WindowMoto Value(refresh):',returnValue,'% soit',cmd.currentValue,' / ',service.maxValue,' : ',positionStateLabel(service.Moving)); break; } } @@ -4711,13 +4697,13 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i returnValue = returnValue > (service.maxValue-5) ? service.maxValue : returnValue; // >95% is 100% in home (flaps need yearly tunning) } if(service.FlapType=="Closing" && service.Moving!==Characteristic.PositionState.STOPPED) { - that.log('debug','---------update TargetPosition(Closing)before:',returnValue,'%'); + this.log('debug','---------update TargetPosition(Closing)before:',returnValue,'%'); returnValue=100-returnValue; } } else { returnValue = service.TargetValue; } - that.log('debug','---------update TargetPosition(refresh):',returnValue,'%'); + this.log('debug','---------update TargetPosition(refresh):',returnValue,'%'); break; case Characteristic.PositionState.UUID : if('Moving' in service) { @@ -4725,14 +4711,14 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } else { returnValue = Characteristic.PositionState.STOPPED; } - that.log('debug','---------update PositionState(refresh):',positionStateLabel(returnValue)); + this.log('debug','---------update PositionState(refresh):',positionStateLabel(returnValue)); break; case Characteristic.CurrentHorizontalTiltAngle.UUID : case Characteristic.TargetHorizontalTiltAngle.UUID : for (const cmd of cmdList) { if (cmd.generic_type == 'FLAP_HOR_TILT_STATE') { returnValue = parseInt(cmd.currentValue); - that.log('debug','---------update Blinds HorTilt Value(refresh):',returnValue); + this.log('debug','---------update Blinds HorTilt Value(refresh):',returnValue); break; } } @@ -4742,7 +4728,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i for (const cmd of cmdList) { if (cmd.generic_type == 'FLAP_VER_TILT_STATE') { returnValue = parseInt(cmd.currentValue); - that.log('debug','---------update Blinds VerTilt Value(refresh):',returnValue); + this.log('debug','---------update Blinds VerTilt Value(refresh):',returnValue); break; } } @@ -4753,7 +4739,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if (cmd.generic_type == 'LOCK_STATE') { service.target=cmd.currentValue; if(cmd.eqType == 'nuki' || (cmd.eqType == 'jeelink' && cmd.real_eqType && cmd.real_eqType == 'nuki')) { - if (DEV_DEBUG) {that.log('debug','LockCurrentState (nuki) : ',cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug','LockCurrentState (nuki) : ',cmd.currentValue);} switch(parseInt(cmd.currentValue)) { case 0 : returnValue=Characteristic.LockCurrentState.SECURED; @@ -4769,10 +4755,10 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i break; } // } else if(cmd.eqType == 'thekeys' || (cmd.eqType == 'jeelink' && cmd.real_eqType && cmd.real_eqType == 'thekeys')) { - // if (DEV_DEBUG) that.log('debug','LockCurrentState (thekeys) : ',cmd.currentValue); + // if (DEV_DEBUG) this.log('debug','LockCurrentState (thekeys) : ',cmd.currentValue); // returnValue = toBool(cmd.currentValue) === false ? Characteristic.LockCurrentState.SECURED : Characteristic.LockCurrentState.UNSECURED; } else { - if (DEV_DEBUG) {that.log('debug','LockCurrentState : ',cmd.currentValue);} + if (DEV_DEBUG) {this.log('debug','LockCurrentState : ',cmd.currentValue);} returnValue = toBool(cmd.currentValue) === true ? Characteristic.LockCurrentState.SECURED : Characteristic.LockCurrentState.UNSECURED; } } @@ -4786,13 +4772,13 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i else {service.target=targetVal;} if(cmd.eqType == 'nuki' || (cmd.eqType == 'jeelink' && cmd.real_eqType && cmd.real_eqType == 'nuki')) { - if (DEV_DEBUG) {that.log('debug','LockTargetState (nuki) : ',cmd.currentValue,'service.target : ',service.target);} + if (DEV_DEBUG) {this.log('debug','LockTargetState (nuki) : ',cmd.currentValue,'service.target : ',service.target);} returnValue = toBool(targetVal) === false ? Characteristic.LockTargetState.SECURED : Characteristic.LockTargetState.UNSECURED; // } else if(cmd.eqType == 'thekeys' || (cmd.eqType == 'jeelink' && cmd.real_eqType && cmd.real_eqType == 'thekeys')) { - // if (DEV_DEBUG) {that.log('debug','LockTargetState (thekeys) : ',cmd.currentValue);} + // if (DEV_DEBUG) {this.log('debug','LockTargetState (thekeys) : ',cmd.currentValue);} // returnValue = toBool(cmd.currentValue) === false ? Characteristic.LockTargetState.SECURED : Characteristic.LockTargetState.UNSECURED; } else { - if (DEV_DEBUG) {that.log('debug','LockTargetState : ',cmd.currentValue,'service.target : ',service.target);} + if (DEV_DEBUG) {this.log('debug','LockTargetState : ',cmd.currentValue,'service.target : ',service.target);} returnValue = toBool(targetVal) === true ? Characteristic.LockTargetState.SECURED : Characteristic.LockTargetState.UNSECURED; } } @@ -4915,7 +4901,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i if(service.infos.power && service.infos.power.unite && service.infos.power.unite.toLowerCase() == 'kw') { returnValue = Math.round(cmd.currentValue*1000); } - if(that.fakegato && service.eqLogic && service.eqLogic.hasLogging) { + if(this.fakegato && service.eqLogic && service.eqLogic.hasLogging) { service.eqLogic.loggingService.addEntry({ time: Math.round(new Date().valueOf() / 1000), power: returnValue, @@ -5001,7 +4987,7 @@ JeedomPlatform.prototype.getAccessoryValue = function(characteristic, service, i } } } - that.log('debug','**********GetState ProgrammableSwitchEvent: '+returnValue); + this.log('debug','**********GetState ProgrammableSwitchEvent: '+returnValue); break; case Characteristic.OutletInUse.UUID : for (const cmd of cmdList) { @@ -5141,9 +5127,7 @@ function toBool(val) { // -- Return : nothing JeedomPlatform.prototype.command = function(action, value, service) { try{ - const that = this; - - const cmdList = that.jeedomClient.getDeviceCmdFromCache(service.eqID); + const cmdList = this.jeedomClient.getDeviceCmdFromCache(service.eqID); var cmdId = service.cmd_id; let found=false; @@ -5533,7 +5517,7 @@ JeedomPlatform.prototype.command = function(action, value, service) { break; case 'ALARM_RELEASED' : if(action == 'SetAlarmMode' && value == Characteristic.SecuritySystemTargetState.DISARM) { - that.log('debug',"ALARM_RELEASED","setAlarmMode=",value,cmd.id); + this.log('debug',"ALARM_RELEASED","setAlarmMode=",value,cmd.id); cmdId = cmd.id; cmdFound=cmd.generic_type; found = true; @@ -5541,26 +5525,26 @@ JeedomPlatform.prototype.command = function(action, value, service) { break; case 'ALARM_SET_MODE' : if(action == 'SetAlarmMode' && service.hasAlarmModes) { - that.log('debug',"ALARM_SET_MODE","SetAlarmMode=",action,value); + this.log('debug',"ALARM_SET_MODE","SetAlarmMode=",action,value); cmdFound=cmd.generic_type; if(value == Characteristic.SecuritySystemTargetState.NIGHT_ARM && id_NIGHT != undefined) { cmdId = id_NIGHT; - that.log('debug',"set nuit"); + this.log('debug',"set nuit"); found = true; } else if(value == Characteristic.SecuritySystemTargetState.AWAY_ARM && id_AWAY != undefined) { cmdId = id_AWAY; - that.log('debug',"set absent"); + this.log('debug',"set absent"); found = true; } else if(value == Characteristic.SecuritySystemTargetState.STAY_ARM && id_PRESENT != undefined) { cmdId = id_PRESENT; - that.log('debug',"set present"); + this.log('debug',"set present"); found = true; } } break; case 'ALARM_ARMED' : if(action == 'SetAlarmMode' && value != Characteristic.SecuritySystemTargetState.DISARM && !service.hasAlarmModes) { - that.log('debug',"ALARM_ARMED","SetAlarmMode=",action,cmd.id); + this.log('debug',"ALARM_ARMED","SetAlarmMode=",action,cmd.id); cmdFound=cmd.generic_type; cmdId = cmd.id; found = true; @@ -5600,20 +5584,20 @@ JeedomPlatform.prototype.command = function(action, value, service) { if(action == 'TargetHeatingCoolingState') { if(value == Characteristic.TargetHeatingCoolingState.OFF && id_OFF != undefined) { cmdId = id_OFF; - that.log('debug',"set OFF"); + this.log('debug',"set OFF"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.HEAT && id_CHAUF != undefined) { cmdId = id_CHAUF; - that.log('debug',"set CHAUF"); + this.log('debug',"set CHAUF"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.COOL && id_CLIM != undefined) { cmdId = id_CLIM; - that.log('debug',"set CLIM"); + this.log('debug',"set CLIM"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.AUTO) { cmdId = service.actions.set_setpoint.id; value = service.infos.setpoint.currentValue; - that.log('debug','set AUTO',value); + this.log('debug','set AUTO',value); found = true; } } @@ -5622,20 +5606,20 @@ JeedomPlatform.prototype.command = function(action, value, service) { if(action == 'TargetHeatingCoolingState') { if(value == Characteristic.TargetHeatingCoolingState.OFF && id_OFF != undefined) { cmdId = id_OFF_HC; - that.log('debug',"set OFF"); + this.log('debug',"set OFF"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.HEAT && id_CHAUF != undefined) { cmdId = id_CHAUF_HC; - that.log('debug',"set CHAUF"); + this.log('debug',"set CHAUF"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.COOL && id_CLIM != undefined) { cmdId = id_CLIM_HC; - that.log('debug',"set CLIM"); + this.log('debug',"set CLIM"); found = true; } else if(value == Characteristic.TargetHeatingCoolingState.AUTO) { cmdId = service.actions.set_setpointH.id; value = service.infos.setpointH.currentValue; - that.log('debug','set AUTO',value); + this.log('debug','set AUTO',value); found = true; } } @@ -5646,43 +5630,43 @@ JeedomPlatform.prototype.command = function(action, value, service) { if(needToTemporize===0 && needToTemporizeSec===0) { if(cmdFound=="LIGHT_ON") { - if(that.settingLight) { + if(this.settingLight) { if(service.ignoreOnCommandOnBrightnessChange) { return; } } } - that.jeedomClient.executeDeviceAction(cmdId, action, value).then(function(response) { - that.log('info','[Commande envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'generic:'+cmdFound,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); + this.jeedomClient.executeDeviceAction(cmdId, action, value).then((response) => { + this.log('info','[Commande envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'generic:'+cmdFound,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); if(err && err.stack) { console.error(err.stack); } }); } else if(needToTemporize) { if(service.temporizator) {clearTimeout(service.temporizator);} - service.temporizator = setTimeout(function(){ - if(cmdFound=="LIGHT_SLIDER") {that.settingLight=false;} - if(cmdFound=="FAN_SLIDER" || cmdFound=="FAN_SPEED") {that.settingFan=false;} + service.temporizator = setTimeout(() => { + if(cmdFound=="LIGHT_SLIDER") {this.settingLight=false;} + if(cmdFound=="FAN_SLIDER" || cmdFound=="FAN_SPEED") {this.settingFan=false;} - that.jeedomClient.executeDeviceAction(cmdId, action, value).then(function(response) { - that.log('info','[Commande T envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); + this.jeedomClient.executeDeviceAction(cmdId, action, value).then((response) => { + this.log('info','[Commande T envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); if(err && err.stack) { console.error(err.stack); } }); },needToTemporize); } else if(needToTemporizeSec) { if(service.temporizatorSec) {clearTimeout(service.temporizatorSec);} - service.temporizatorSec = setTimeout(function(){ + service.temporizatorSec = setTimeout(() => { if(cmdFound=="LIGHT_ON") { - if(that.settingLight) { + if(this.settingLight) { if(!service.ignoreOnCommandOnBrightnessChange) { - // if(cmdFound=="LIGHT_ON" && service.infos && service.infos.state_bool && service.infos.state_bool.id) that.jeedomClient.updateModelInfo(service.infos.state_bool.id,true); - setTimeout(function(){ - that.jeedomClient.executeDeviceAction(cmdId, action, value).then(function(response) { - that.log('info','[Commande ON LATE envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); + // if(cmdFound=="LIGHT_ON" && service.infos && service.infos.state_bool && service.infos.state_bool.id) this.jeedomClient.updateModelInfo(service.infos.state_bool.id,true); + setTimeout(() => { + this.jeedomClient.executeDeviceAction(cmdId, action, value).then((response) => { + this.log('info','[Commande ON LATE envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); if(err && err.stack) { console.error(err.stack); } }); },1000); @@ -5691,10 +5675,10 @@ JeedomPlatform.prototype.command = function(action, value, service) { } } - that.jeedomClient.executeDeviceAction(cmdId, action, value).then(function(response) { - that.log('info','[Commande T envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); - }).catch(function(err) { - that.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); + this.jeedomClient.executeDeviceAction(cmdId, action, value).then((response) => { + this.log('info','[Commande T envoyée à Jeedom]','cmdId:' + cmdId,'action:' + action,'value: '+value,'response:'+JSON.stringify(response)); + }).catch((err) => { + this.log('error','Erreur à l\'envoi de la commande ' + action + ' vers ' + service.cmd_id , err); if(err && err.stack) { console.error(err.stack); } }); @@ -5712,55 +5696,54 @@ JeedomPlatform.prototype.command = function(action, value, service) { // -- Params -- // -- Return : nothing JeedomPlatform.prototype.startPollingUpdate = function() { - const that = this; - if(that.pollingUpdateRunning) {return;} - that.pollingUpdateRunning = true; - that.jeedomClient.refreshStates().then(function(updates) { - that.lastPoll = updates.datetime; + if(this.pollingUpdateRunning) {return;} + this.pollingUpdateRunning = true; + this.jeedomClient.refreshStates().then((updates) => { + this.lastPoll = updates.datetime; if (updates.result) { - updates.result.map(function(update) { + updates.result.map((update) => { if (update.name == 'cmd::update' && update.option.value != undefined && update.option.cmd_id) { - if(that.jeedomClient.updateModelInfo(update.option.cmd_id,update.option.value)){ // Update cachedModel - that.updateSubscribers(update);// Update subscribers + if(this.jeedomClient.updateModelInfo(update.option.cmd_id,update.option.value)){ // Update cachedModel + this.updateSubscribers(update);// Update subscribers } } else if(update.name == 'scenario::update' && update.option.state != undefined && update.option.scenario_id) { - if(that.jeedomClient.updateModelScenario(update.option.scenario_id,update.option.state)){ // Update cachedModel - that.updateSubscribers(update);// Update subscribers + if(this.jeedomClient.updateModelScenario(update.option.scenario_id,update.option.state)){ // Update cachedModel + this.updateSubscribers(update);// Update subscribers } } else if(DEV_DEBUG && update.name == 'eqLogic::update' && update.option.eqLogic_id) { - const cacheState = that.jeedomClient.getDevicePropertiesFromCache(update.option.eqLogic_id); - that.jeedomClient.getDeviceProperties(update.option.eqLogic_id).then(function(eqLogic){ + const cacheState = this.jeedomClient.getDevicePropertiesFromCache(update.option.eqLogic_id); + this.jeedomClient.getDeviceProperties(update.option.eqLogic_id).then((eqLogic) => { if(cacheState && eqLogic && cacheState.isEnable != eqLogic.isEnable) { - that.log('debug',"Changing Enable in",update.option.eqLogic_id,'from',cacheState.isEnable,'to',eqLogic.isEnable); - that.jeedomClient.updateModelEq(update.option.eqLogic_id,eqLogic); + this.log('debug',"Changing Enable in",update.option.eqLogic_id,'from',cacheState.isEnable,'to',eqLogic.isEnable); + this.jeedomClient.updateModelEq(update.option.eqLogic_id,eqLogic); } }).catch((e) => { - that.log('error','Erreur :',e); + this.log('error','Erreur :',e); }); - that.log('debug','[Reçu Type non géré]',update.name+' contenu: '+JSON.stringify(update).replace("\n","")); + this.log('debug','[Reçu Type non géré]',update.name+' contenu: '+JSON.stringify(update).replace("\n","")); } else if(DEV_DEBUG) { - that.log('debug','[Reçu Type non géré]',update.name+' ou contenu invalide: '+JSON.stringify(update).replace("\n","")); + this.log('debug','[Reçu Type non géré]',update.name+' ou contenu invalide: '+JSON.stringify(update).replace("\n","")); } }); } - }).then(function(){ - that.pollingUpdateRunning = false; - that.pollingID = setImmediate(() => that.startPollingUpdate()); - }).catch(function(err) { - that.log('error','Erreur de récupération des évènements de mise à jour: ', err); + }).then(() => { + this.pollingUpdateRunning = false; + this.pollingID = setImmediate(() => this.startPollingUpdate()); + }).catch((err) => { + this.log('error','Erreur de récupération des évènements de mise à jour: ', err); if(err && err.stack) { console.error(err.stack); } - that.pollingUpdateRunning = false; - that.pollingID = setTimeout(function(){ that.log('debug','!!RESTART POLLING AFTER ERROR!!');that.startPollingUpdate(); }, that.pollerPeriod * 2 * 1000); + this.pollingUpdateRunning = false; + this.pollingID = setTimeout(() => { this.log('debug','!!RESTART POLLING AFTER ERROR!!');this.startPollingUpdate(); }, this.pollerPeriod * 2 * 1000); }); }; @@ -5770,16 +5753,15 @@ JeedomPlatform.prototype.startPollingUpdate = function() { // -- update : the update received from Jeedom // -- Return : nothing JeedomPlatform.prototype.updateSubscribers = function(update) { - const that = this; const updateID = update.option.scenario_id || update.option.cmd_id; - for (let i = 0; i < that.updateSubscriptions.length; i++) { - const {characteristic: subCharact, service: subService} = that.updateSubscriptions[i]; + for (let i = 0; i < this.updateSubscriptions.length; i++) { + const {characteristic: subCharact, service: subService} = this.updateSubscriptions[i]; - // that.log('debug',"update :",updateID,JSON.stringify(subService.infos),JSON.stringify(subService.statusArr),subCharact.UUID); + // this.log('debug',"update :",updateID,JSON.stringify(subService.infos),JSON.stringify(subService.statusArr),subCharact.UUID); const infoFound = findMyID(subService.infos,updateID); const statusFound = findMyID(subService.statusArr,updateID); if(infoFound !== -1 || statusFound !== -1) { - let returnValue = that.getAccessoryValue(subCharact, subService, (infoFound !== -1?infoFound:statusFound)); + let returnValue = this.getAccessoryValue(subCharact, subService, (infoFound !== -1?infoFound:statusFound)); if (returnValue === 'no_response') { subCharact.updateValue(new Error('no_response'), undefined, 'fromJeedom'); @@ -5787,17 +5769,17 @@ JeedomPlatform.prototype.updateSubscribers = function(update) { returnValue = sanitizeValue(returnValue,subCharact); const logMessage = 'Cause de modif: "' + (infoFound && infoFound.name ? infoFound.name + '" (' + updateID + ')' : '') + (statusFound && statusFound.name ? statusFound.name + '" (' + updateID + ')' : '') + ' Envoi valeur:' + returnValue + ' dans ' + subCharact.displayName; if(infoFound !== -1 && infoFound.generic_type=="LIGHT_STATE") { // if it's a LIGHT_STATE - if(!that.settingLight) { // and it's not currently being modified - that.log('info','[Commande envoyée à HomeKit]',logMessage); + if(!this.settingLight) { // and it's not currently being modified + this.log('info','[Commande envoyée à HomeKit]',logMessage); subCharact.updateValue(returnValue, undefined, 'fromJeedom'); - } else if(DEV_DEBUG) {that.log('debug','//Commande NON envoyée à HomeKit',logMessage);} + } else if(DEV_DEBUG) {this.log('debug','//Commande NON envoyée à HomeKit',logMessage);} } else if(infoFound !== -1 && (infoFound.generic_type=="FAN_STATE" || infoFound.generic_type=="FAN_SPEED_STATE")) { // if it's a FAN_STATE - if(!that.settingFan) { // and it's not currently being modified - that.log('info','[Commande envoyée à HomeKit]',logMessage); + if(!this.settingFan) { // and it's not currently being modified + this.log('info','[Commande envoyée à HomeKit]',logMessage); subCharact.updateValue(returnValue, undefined, 'fromJeedom'); - } else if(DEV_DEBUG) {that.log('debug','//Commande NON envoyée à HomeKit',logMessage);} + } else if(DEV_DEBUG) {this.log('debug','//Commande NON envoyée à HomeKit',logMessage);} } else { - that.log('info','[Commande envoyée à HomeKit]',logMessage); + this.log('info','[Commande envoyée à HomeKit]',logMessage); subCharact.updateValue(returnValue, undefined, 'fromJeedom'); } } else {return;} @@ -5863,13 +5845,11 @@ JeedomPlatform.prototype.updateHomeKitColorFromJeedom = function(color, service) // -- service : service to set color to // -- Return : nothing JeedomPlatform.prototype.syncColorCharacteristics = function(rgb, service) { - const that = this; - clearTimeout(service.timeoutIdColorCharacteristics); - service.timeoutIdColorCharacteristics = setTimeout(function() { + service.timeoutIdColorCharacteristics = setTimeout(() => { const rgbColor = rgbToHex(rgb.r, rgb.g, rgb.b); - if (DEV_DEBUG) {that.log('debug',"---------setRGB : ",rgbColor);} - that.command('setRGB', rgbColor, service); + if (DEV_DEBUG) {this.log('debug',"---------setRGB : ",rgbColor);} + this.command('setRGB', rgbColor, service); }, 500); }; @@ -6662,7 +6642,12 @@ function RGBtoHSV(r, g, b) { // -- Params -- // -- id : id to find // -- Return : Object found -function findMyID(obj, id) { - if (!obj) {return -1;} - return Object.values(obj).find((item) => item && item.id == id) || -1; +function findMyID(obj,id) { + if (!obj) return -1; + for(const key in obj) { + if( obj.hasOwnProperty(key) && obj[key] && obj[key].id==id) { + return obj[key]; + } + } + return -1; }