Skip to content

Commit

Permalink
New config receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
NebzHB authored Jan 22, 2024
1 parent 11a62e8 commit 30516c7
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let Access, Accessory, Service, Characteristic, AdaptiveLightingController, UUID
const fs = require('fs');
const inherits = require('util').inherits;
const myLogger = require('./lib/myLogger').myLogger;
const express = require('express');

const debug = {};
debug.DEBUG = 100;
debug.INFO = 200;
Expand Down Expand Up @@ -88,6 +90,15 @@ function JeedomPlatform(logger, config, api) {
} else {
this.log('info',"Adresse Jeedom bien configurée :"+config.url);
}

this.app = express();
this.app.get('/config', this.ConfigCMD.bind(this));
this.app.use((err, req, res, _next) => {
res.type('json');
console.log('error',err);
res.json({'result':'ko','msg':err});
});

this.DEV_DEBUG = DEV_DEBUG; // for passing by
this.jeedomClient = require('./lib/jeedom-api').createClient(config.url, config.apikey, this, config.myPlugin);
this.rooms = {};
Expand All @@ -108,6 +119,11 @@ function JeedomPlatform(logger, config, api) {
if (api) {
this.api = api;
this.api.on('didFinishLaunching',function(){
/** Listen **/
this.server = this.app.listen(0, '0.0.0.0', () => {
this.log('info',"On écoute les messages sur le port "+this.server.address().port);
this.jeedomClient.daemonIsReady(this.server.address().port);
});
this.addAccessories();
}.bind(this));
}
Expand All @@ -118,6 +134,42 @@ function JeedomPlatform(logger, config, api) {
}
}

JeedomPlatform.prototype.ConfigCMD = function(req, res) {
res.type('json');
res.status(202);

this.log('info','Recu une configuration de jeedom :'+JSON.stringify(req.query));

if ('setting' in req.query === false) {
const error="Pour faire une config, le démon a besoin de son nom";
this.log('error',error);
res.json({'result':'ko','msg':error});
return;
}
if ('value' in req.query === false) {
const error="Pour faire une config, le démon a besoin d'une valeur a configurer";
this.log('error',error);
res.json({'result':'ko','msg':error});
return;
}

switch(req.query.setting) {
case 'sendLoglevel':
this.debugLevel = req.query.value;
this.log.changeLevel(this.debugLevel);
break;
default: {
const error = "Configuration inexistante";
this.log('error','ERROR CONFIG: ' + req.query.setting + ' : '+error);
res.json({'result':'ko','msg':error});
return;
}
}
this.log('conf',"Configuration de : "+req.query.setting+" effectuée avec la valeur : "+((typeof req.query.value == "object")?JSON.stringify(req.query.value):req.query.value));
res.json({'result':'ok','value':req.query.value});
};


// -- addAccessories
// -- Desc : Accessories creation, we get a full model from jeedom and put it in local cache
// -- Return : nothing
Expand Down

0 comments on commit 30516c7

Please sign in to comment.