Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NebzHB authored Jan 28, 2024
1 parent c26940f commit 450d4fc
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function JeedomPlatform(logger, config, api) {
}
if (api) {
this.api = api;
this.api.on('didFinishLaunching',function(){
this.api.on('didFinishLaunching',() => {
/** Listen **/
let port=0;
if(fs.existsSync('/homebridge/')) { port=8582; } // if docker, use the port next to homebridge-config-ui
Expand All @@ -128,7 +128,7 @@ function JeedomPlatform(logger, config, api) {
this.jeedomClient.daemonIsReady(this.server.address().port);
});
this.addAccessories();
}.bind(this));
});
}
}
catch (e) {
Expand Down Expand Up @@ -3045,10 +3045,10 @@ JeedomPlatform.prototype.addAccessory = function(jeedomAccessory) {
this.log('│ OK : Mise à jour de l\'accessoire (' + jeedomAccessory.name + ')');
this.api.updatePlatformAccessories([HBAccessory]);
}
HBAccessory.on('identify', function(paired, callback) {
HBAccessory.on('identify', (paired, callback) => {
this.log(HBAccessory.displayName, "->Identifié!!!");
if(typeof callback === 'function') {callback();}
}.bind(this));
});
HBAccessory.reviewed = true;
}
catch(e){
Expand All @@ -3066,15 +3066,13 @@ JeedomPlatform.prototype.addAccessory = function(jeedomAccessory) {
// -- UUID : UUID to find
// -- silence : flag for logging or not
// -- Return : nothing
JeedomPlatform.prototype.existingAccessory = function(UUID,silence) {
JeedomPlatform.prototype.existingAccessory = function(UUID,silence=false) {
try{
silence = silence || false;
for (const a in this.accessories) {
if (this.accessories.hasOwnProperty(a)) {
if (this.accessories[a].UUID == UUID) {
if(!silence) {this.log('debug',' Accessoire déjà existant dans le cache Homebridge');}
return this.accessories[a];
}
for (const key of Object.keys(this.accessories)) {
const accessory = this.accessories[key];
if (accessory.UUID == UUID) {
if(!silence) {this.log('debug',' Accessoire déjà existant dans le cache Homebridge');}
return accessory;
}
}
if(!silence) {this.log('debug',' Accessoire non existant dans le cache Homebridge');}
Expand Down Expand Up @@ -3135,25 +3133,19 @@ JeedomPlatform.prototype.configureAccessory = function(accessory) {
// -- Return : nothing
JeedomPlatform.prototype.bindCharacteristicEvents = function(characteristic, service) {
try{
var readOnly = true;
for (var i = 0; i < characteristic.props.perms.length; i++) {
if (characteristic.props.perms[i] == 'pw') {
readOnly = false;
}
}
this.updateSubscriptions.push({ service, characteristic });

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space after '{'

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (18.x)

There should be no space before '}'

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space after '{'

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (20.x)

There should be no space before '}'

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (21.x)

There should be no space after '{'

Check failure on line 3136 in index.js

View workflow job for this annotation

GitHub Actions / build (21.x)

There should be no space before '}'
if (!readOnly) {
characteristic.on('set', function(value, callback, context) {
if (characteristic.props.perms.includes('pw')) {
characteristic.on('set', (value, callback, context) => {
if (context !== 'fromJeedom' && context !== 'fromSetValue') { // from Homekit
this.log('info','[Commande d\'Homekit]','Nom:'+characteristic.displayName+'('+characteristic.UUID+'):'+characteristic.value+'->'+value,'\t\t\t\t\t|||characteristic:'+JSON.stringify(characteristic));
this.setAccessoryValue(value,characteristic,service);
} else {
this.log('info','[Commande de Jeedom]','Nom:'+characteristic.displayName+'('+characteristic.UUID+'):'+value,'\t\t\t\t\t|||context:'+JSON.stringify(context),'characteristic:'+JSON.stringify(characteristic));
}
callback();
}.bind(this));
});
}
characteristic.on('get', function(callback) {
characteristic.on('get', (callback) => {
let returnValue = this.getAccessoryValue(characteristic, service);
if(returnValue !== undefined && returnValue !== 'no_response') {
returnValue = sanitizeValue(returnValue,characteristic);
Expand All @@ -3164,12 +3156,12 @@ JeedomPlatform.prototype.bindCharacteristicEvents = function(characteristic, ser
} else {
callback();
}
}.bind(this));
});

if (this.fakegato) {
characteristic.on('change', function(_callback) {
characteristic.on('change', (_callback) => {
this.changeAccessoryValue(characteristic, service);
}.bind(this));
});
}
}
catch(e){
Expand Down

0 comments on commit 450d4fc

Please sign in to comment.