From 2e1ca73554f671698b410c813355f774bb5cf1e6 Mon Sep 17 00:00:00 2001 From: Nebz <28622481+NebzHB@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:50:05 +0100 Subject: [PATCH] Update jeedom-api.js --- lib/jeedom-api.js | 1150 +++++++-------------------------------------- 1 file changed, 158 insertions(+), 992 deletions(-) diff --git a/lib/jeedom-api.js b/lib/jeedom-api.js index ebb441f..f31c6c4 100755 --- a/lib/jeedom-api.js +++ b/lib/jeedom-api.js @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see . */ -/* jshint esversion: 6,node: true */ +/* jshint esversion: 11,node: true */ 'use strict'; const axios = require('axios'); const async = require('async'); @@ -346,499 +346,198 @@ JeedomClient.prototype.refreshStates = function() { }); }; +function initServ(result_cmd, serviceType, property, value, isPush = false) { + result_cmd.services[serviceType] ??= []; + const service = {}; + if (isPush) { + service[property] ??= []; + service[property].push(value); + } else { + service[property] = value; + } + result_cmd.services[serviceType].push(service); +} + JeedomClient.prototype.ParseGenericType = function(EqLogic, cmds) { - var result_cmd = {}; - result_cmd = EqLogic; - result_cmd.services = {}; - result_cmd.numSwitches=0; - result_cmd.numDetector=0; - for (var i in cmds) { - if (isset(cmds[i].generic_type)) { - if (cmds[i].generic_type) { - switch(cmds[i].generic_type) { + const result_cmd = {...EqLogic, services: {}, numSwitches: 0, numDetector: 0}; + + cmds.forEach((cmd) => { + if (cmd.generic_type !== null) { + switch(cmd.generic_type) { case 'SHOCK' : case 'RAIN_CURRENT' : case 'RAIN_TOTAL' : case 'WIND_SPEED' : case 'WIND_DIRECTION' : case 'GENERIC_INFO': - if (!result_cmd.services.generic) { - result_cmd.services.generic = []; - } - if (!result_cmd.services.generic[i]) { - result_cmd.services.generic[i] = {}; - } - result_cmd.services.generic[i].state = cmds[i]; + initServ(result_cmd,'generic','state',cmd); break; /** *************** MODE ***********************/ case 'MODE_STATE' : - if (!result_cmd.services.mode) { - result_cmd.services.mode = []; - } - if (!result_cmd.services.mode[i]) { - result_cmd.services.mode[i] = {}; - } - result_cmd.services.mode[i].state = cmds[i]; + initServ(result_cmd,'mode','state',cmd); break; case 'MODE_SET_STATE' : - if(cmds[i].logicalId=="returnPreviousMode") { - if (!result_cmd.services.mode) { - result_cmd.services.mode = []; - } - if (!result_cmd.services.mode[i]) { - result_cmd.services.mode[i] = {}; - } - result_cmd.services.mode[i].set_state_previous = cmds[i]; + if(cmd.logicalId=="returnPreviousMode") { + initServ(result_cmd,'mode','set_state_previous',cmd); } else { - if (!result_cmd.services.mode) { - result_cmd.services.mode = []; - } - if (!result_cmd.services.mode[i]) { - result_cmd.services.mode[i] = {}; - } - if (!result_cmd.services.mode[i].set_state) { - result_cmd.services.mode[i].set_state = []; - } - result_cmd.services.mode[i].set_state.push(cmds[i]); + initServ(result_cmd,'mode','set_state',cmd,true); } break; /** *************** LIGHT ***********************/ case 'LIGHT_STATE' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].state = cmds[i]; + initServ(result_cmd,'light','state',cmd); break; case 'LIGHT_BRIGHTNESS' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].brightness = cmds[i]; + initServ(result_cmd,'light','brightness',cmd); break; case 'LIGHT_STATE_BOOL' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].state_bool = cmds[i]; + initServ(result_cmd,'light','state_bool',cmd); break; case 'LIGHT_ON' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].on = cmds[i]; + initServ(result_cmd,'light','on',cmd); break; case 'LIGHT_OFF' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].off = cmds[i]; + initServ(result_cmd,'light','off',cmd); break; case 'LIGHT_SLIDER' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].slider = cmds[i]; + initServ(result_cmd,'light','slider',cmd); break; case 'LIGHT_COLOR' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].color = cmds[i]; + initServ(result_cmd,'light','color',cmd); break; case 'LIGHT_COLOR_TEMP' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].color_temp = cmds[i]; + initServ(result_cmd,'light','color_temp',cmd); break; case 'LIGHT_SET_COLOR' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].setcolor = cmds[i]; + initServ(result_cmd,'light','setcolor',cmd); break; case 'LIGHT_SET_COLOR_TEMP' : - if (!result_cmd.services.light) { - result_cmd.services.light = []; - } - if (!result_cmd.services.light[i]) { - result_cmd.services.light[i] = {}; - } - result_cmd.services.light[i].setcolor_temp = cmds[i]; + initServ(result_cmd,'light','setcolor_temp',cmd); break; /** *************** WEATHER ***********************/ case 'WEATHER_TEMPERATURE' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].temperature = cmds[i]; + initServ(result_cmd,'weather','temperature',cmd); break; case 'WEATHER_HUMIDITY' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].humidity = cmds[i]; + initServ(result_cmd,'weather','humidity',cmd); break; case 'WEATHER_PRESSURE' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].pressure = cmds[i]; + initServ(result_cmd,'weather','pressure',cmd); break; case 'WEATHER_WIND_SPEED' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].wind_speed = cmds[i]; + initServ(result_cmd,'weather','wind_speed',cmd); break; case 'WEATHER_WIND_DIRECTION' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].wind_direction = cmds[i]; + initServ(result_cmd,'weather','wind_direction',cmd); break; case 'WEATHER_CONDITION' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].condition = cmds[i]; + initServ(result_cmd,'weather','condition',cmd); break; case 'WEATHER_UVINDEX' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].UVIndex = cmds[i]; + initServ(result_cmd,'weather','UVIndex',cmd); break; case 'WEATHER_VISIBILITY' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].visibility = cmds[i]; + initServ(result_cmd,'weather','visibility',cmd); break; case 'WEATHER_RAIN' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].rain = cmds[i]; + initServ(result_cmd,'weather','rain',cmd); break; case 'WEATHER_SNOW' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].snow = cmds[i]; + initServ(result_cmd,'weather','snow',cmd); break; case 'WEATHER_TEMPERATURE_MIN' : - if (!result_cmd.services.weather) { - result_cmd.services.weather = []; - } - if (!result_cmd.services.weather[i]) { - result_cmd.services.weather[i] = {}; - } - result_cmd.services.weather[i].temperature_min = cmds[i]; + initServ(result_cmd,'weather','temperature_min',cmd); break; /** *************** SIREN ***********************/ case 'SIREN_STATE' : - if (!result_cmd.services.siren) { - result_cmd.services.siren = []; - } - if (!result_cmd.services.siren[i]) { - result_cmd.services.siren[i] = {}; - } - result_cmd.services.siren[i].state = cmds[i]; + initServ(result_cmd,'siren','state',cmd); break; /* case 'SIREN_ON' : - if (!result_cmd.services.siren) { - result_cmd.services.siren = []; - } - if (!result_cmd.services.siren[i]) { - result_cmd.services.siren[i] = {}; - } - result_cmd.services.siren[i].on = cmds[i]; + initServ(result_cmd,'siren','on',cmd); break; case 'SIREN_OFF' : - if (!result_cmd.services.siren) { - result_cmd.services.siren = []; - } - if (!result_cmd.services.siren[i]) { - result_cmd.services.siren[i] = {}; - } - result_cmd.services.siren[i].off = cmds[i]; + initServ(result_cmd,'siren','off',cmd); break; */ /** *************** ENERGY ***********************/ case 'ENERGY_STATE' : - if (!result_cmd.services.energy) { - result_cmd.services.energy = []; - } - if (!result_cmd.services.energy[i]) { - result_cmd.services.energy[i] = {}; - } - result_cmd.services.energy[i].state = cmds[i]; + initServ(result_cmd,'energy','state',cmd); break; case 'ENERGY_ON' : - if (!result_cmd.services.energy) { - result_cmd.services.energy = []; - } - if (!result_cmd.services.energy[i]) { - result_cmd.services.energy[i] = {}; - } - result_cmd.services.energy[i].on = cmds[i]; + initServ(result_cmd,'energy','on',cmd); break; case 'ENERGY_OFF' : - if (!result_cmd.services.energy) { - result_cmd.services.energy = []; - } - if (!result_cmd.services.energy[i]) { - result_cmd.services.energy[i] = {}; - } - result_cmd.services.energy[i].off = cmds[i]; + initServ(result_cmd,'energy','off',cmd); break; case 'ENERGY_INUSE' : - if (!result_cmd.services.energy) { - result_cmd.services.energy = []; - } - if (!result_cmd.services.energy[i]) { - result_cmd.services.energy[i] = {}; - } - result_cmd.services.energy[i].inuse = cmds[i]; + initServ(result_cmd,'energy','inuse',cmd); break; /** *************** VALVES ***********************/ case 'FAUCET_STATE' : - if (!result_cmd.services.faucet) { - result_cmd.services.faucet = []; - } - if (!result_cmd.services.faucet[i]) { - result_cmd.services.faucet[i] = {}; - } - result_cmd.services.faucet[i].state = cmds[i]; + initServ(result_cmd,'faucet','state',cmd); break; case 'FAUCET_ON' : - if (!result_cmd.services.faucet) { - result_cmd.services.faucet = []; - } - if (!result_cmd.services.faucet[i]) { - result_cmd.services.faucet[i] = {}; - } - result_cmd.services.faucet[i].on = cmds[i]; + initServ(result_cmd,'faucet','on',cmd); break; case 'FAUCET_OFF' : - if (!result_cmd.services.faucet) { - result_cmd.services.faucet = []; - } - if (!result_cmd.services.faucet[i]) { - result_cmd.services.faucet[i] = {}; - } - result_cmd.services.faucet[i].off = cmds[i]; + initServ(result_cmd,'faucet','off',cmd); break; case 'IRRIG_STATE' : - if (!result_cmd.services.irrigation) { - result_cmd.services.irrigation = []; - } - if (!result_cmd.services.irrigation[i]) { - result_cmd.services.irrigation[i] = {}; - } - result_cmd.services.irrigation[i].state = cmds[i]; + initServ(result_cmd,'irrigation','state',cmd); break; case 'IRRIG_ON' : - if (!result_cmd.services.irrigation) { - result_cmd.services.irrigation = []; - } - if (!result_cmd.services.irrigation[i]) { - result_cmd.services.irrigation[i] = {}; - } - result_cmd.services.irrigation[i].on = cmds[i]; + initServ(result_cmd,'irrigation','on',cmd); break; case 'IRRIG_OFF' : - if (!result_cmd.services.irrigation) { - result_cmd.services.irrigation = []; - } - if (!result_cmd.services.irrigation[i]) { - result_cmd.services.irrigation[i] = {}; - } - result_cmd.services.irrigation[i].off = cmds[i]; + initServ(result_cmd,'irrigation','off',cmd); break; case 'VALVE_STATE' : - if (!result_cmd.services.valve) { - result_cmd.services.valve = []; - } - if (!result_cmd.services.valve[i]) { - result_cmd.services.valve[i] = {}; - } - result_cmd.services.valve[i].state = cmds[i]; + initServ(result_cmd,'valve','state',cmd); break; case 'VALVE_ON' : - if (!result_cmd.services.valve) { - result_cmd.services.valve = []; - } - if (!result_cmd.services.valve[i]) { - result_cmd.services.valve[i] = {}; - } - result_cmd.services.valve[i].on = cmds[i]; + initServ(result_cmd,'valve','on',cmd); break; case 'VALVE_OFF' : - if (!result_cmd.services.valve) { - result_cmd.services.valve = []; - } - if (!result_cmd.services.valve[i]) { - result_cmd.services.valve[i] = {}; - } - result_cmd.services.valve[i].off = cmds[i]; + initServ(result_cmd,'valve','off',cmd); break; case 'VALVE_SET_DURATION' : - if (!result_cmd.services.valve) { - result_cmd.services.valve = []; - } - if (!result_cmd.services.valve[i]) { - result_cmd.services.valve[i] = {}; - } - result_cmd.services.valve[i].setDuration = cmds[i]; + initServ(result_cmd,'valve','setDuration',cmd); break; case 'VALVE_REMAINING_DURATION' : - if (!result_cmd.services.valve) { - result_cmd.services.valve = []; - } - if (!result_cmd.services.valve[i]) { - result_cmd.services.valve[i] = {}; - } - result_cmd.services.valve[i].remainingDuration = cmds[i]; + initServ(result_cmd,'valve','remainingDuration',cmd); break; /** *************** FAN ***********************/ case 'FAN_STATE' : case 'FAN_SPEED_STATE' : - if (!result_cmd.services.fan) { - result_cmd.services.fan = []; - } - if (!result_cmd.services.fan[i]) { - result_cmd.services.fan[i] = {}; - } - result_cmd.services.fan[i].state = cmds[i]; + initServ(result_cmd,'fan','state',cmd); break; case 'FAN_ON' : - if (!result_cmd.services.fan) { - result_cmd.services.fan = []; - } - if (!result_cmd.services.fan[i]) { - result_cmd.services.fan[i] = {}; - } - result_cmd.services.fan[i].on = cmds[i]; + initServ(result_cmd,'fan','on',cmd); break; case 'FAN_OFF' : - if (!result_cmd.services.fan) { - result_cmd.services.fan = []; - } - if (!result_cmd.services.fan[i]) { - result_cmd.services.fan[i] = {}; - } - result_cmd.services.fan[i].off = cmds[i]; + initServ(result_cmd,'fan','off',cmd); break; case 'FAN_SLIDER' : case 'FAN_SPEED' : - if (!result_cmd.services.fan) { - result_cmd.services.fan = []; - } - if (!result_cmd.services.fan[i]) { - result_cmd.services.fan[i] = {}; - } - result_cmd.services.fan[i].slider = cmds[i]; + initServ(result_cmd,'fan','slider',cmd); break; /** *************** SWITCH ***********************/ case 'SWITCH_STATE' : case 'CAMERA_RECORD_STATE' : - if (!result_cmd.services.Switch) { - result_cmd.services.Switch = []; - } - if (!result_cmd.services.Switch[i]) { - result_cmd.services.Switch[i] = {}; - } - result_cmd.services.Switch[i].state = cmds[i]; + initServ(result_cmd,'Switch','state',cmd); result_cmd.numSwitches++; break; case 'SWITCH_ON' : case 'CAMERA_RECORD' : - if (!result_cmd.services.Switch) { - result_cmd.services.Switch = []; - } - if (!result_cmd.services.Switch[i]) { - result_cmd.services.Switch[i] = {}; - } - result_cmd.services.Switch[i].on = cmds[i]; + initServ(result_cmd,'Switch','on',cmd); break; case 'SWITCH_OFF' : case 'CAMERA_STOP' : - if (!result_cmd.services.Switch) { - result_cmd.services.Switch = []; - } - if (!result_cmd.services.Switch[i]) { - result_cmd.services.Switch[i] = {}; - } - result_cmd.services.Switch[i].off = cmds[i]; + initServ(result_cmd,'Switch','off',cmd); break; /** *************** SWITCH ***********************/ case 'GENERIC_ACTION' : - if(cmds[i].subType=="other") { - if (!result_cmd.services.Push) { - result_cmd.services.Push = []; - } - if (!result_cmd.services.Push[i]) { - result_cmd.services.Push[i] = {}; - } - result_cmd.services.Push[i].Push = cmds[i]; + if(cmd.subType=="other") { + initServ(result_cmd,'Push','Push',cmd); } break; case 'PUSH_BUTTON' : @@ -849,818 +548,285 @@ JeedomClient.prototype.ParseGenericType = function(EqLogic, cmds) { case 'CAMERA_ZOOM' : case 'CAMERA_DEZOOM' : case 'CAMERA_PRESET' : - if (!result_cmd.services.Push) { - result_cmd.services.Push = []; - } - if (!result_cmd.services.Push[i]) { - result_cmd.services.Push[i] = {}; - } - result_cmd.services.Push[i].Push = cmds[i]; + initServ(result_cmd,'Push','Push',cmd); break; /** *************** BARRIER/GARAGE**************/ case "BARRIER_STATE" : case "GARAGE_STATE" : - if (!result_cmd.services.GarageDoor) { - result_cmd.services.GarageDoor = []; - } - if (!result_cmd.services.GarageDoor[i]) { - result_cmd.services.GarageDoor[i] = {}; - } - result_cmd.services.GarageDoor[i].state = cmds[i]; + initServ(result_cmd,'GarageDoor','state',cmd); break; case "GB_OPEN" : // should not be used - if (!result_cmd.services.GarageDoor) { - result_cmd.services.GarageDoor = []; - } - if (!result_cmd.services.GarageDoor[i]) { - result_cmd.services.GarageDoor[i] = {}; - } - result_cmd.services.GarageDoor[i].on = cmds[i]; + initServ(result_cmd,'GarageDoor','on',cmd); break; case "GB_CLOSE" : // should not be used - if (!result_cmd.services.GarageDoor) { - result_cmd.services.GarageDoor = []; - } - if (!result_cmd.services.GarageDoor[i]) { - result_cmd.services.GarageDoor[i] = {}; - } - result_cmd.services.GarageDoor[i].off = cmds[i]; + initServ(result_cmd,'GarageDoor','off',cmd); break; case "GB_TOGGLE" : - if (!result_cmd.services.GarageDoor) { - result_cmd.services.GarageDoor = []; - } - if (!result_cmd.services.GarageDoor[i]) { - result_cmd.services.GarageDoor[i] = {}; - } - result_cmd.services.GarageDoor[i].toggle = cmds[i]; + initServ(result_cmd,'GarageDoor','toggle',cmd); break; /** *************** LOCK ***********************/ case 'LOCK_STATE' : - if (!result_cmd.services.lock) { - result_cmd.services.lock = []; - } - if (!result_cmd.services.lock[i]) { - result_cmd.services.lock[i] = {}; - } - result_cmd.services.lock[i].state = cmds[i]; + initServ(result_cmd,'lock','state',cmd); break; case 'LOCK_OPEN' : - if (!result_cmd.services.lock) { - result_cmd.services.lock = []; - } - if (!result_cmd.services.lock[i]) { - result_cmd.services.lock[i] = {}; - } - result_cmd.services.lock[i].on = cmds[i]; + initServ(result_cmd,'lock','on',cmd); break; case 'LOCK_CLOSE' : - if (!result_cmd.services.lock) { - result_cmd.services.lock = []; - } - if (!result_cmd.services.lock[i]) { - result_cmd.services.lock[i] = {}; - } - result_cmd.services.lock[i].off = cmds[i]; + initServ(result_cmd,'lock','off',cmd); break; /** *************** StatelessSwitch ******************/ case 'SWITCH_STATELESS_ALLINONE' : - if (!result_cmd.services.StatelessSwitch) { - result_cmd.services.StatelessSwitch = []; - } - if (!result_cmd.services.StatelessSwitch[i]) { - result_cmd.services.StatelessSwitch[i] = {}; - } - result_cmd.services.StatelessSwitch[i].eventType = cmds[i]; + initServ(result_cmd,'StatelessSwitch','eventType',cmd); break; case 'SWITCH_STATELESS_SINGLE' : - if (!result_cmd.services.StatelessSwitchMono) { - result_cmd.services.StatelessSwitchMono = []; - } - if (!result_cmd.services.StatelessSwitchMono[i]) { - result_cmd.services.StatelessSwitchMono[i] = {}; - } - result_cmd.services.StatelessSwitchMono[i].Single = cmds[i]; + initServ(result_cmd,'StatelessSwitchMono','Single',cmd); break; case 'SWITCH_STATELESS_DOUBLE' : - if (!result_cmd.services.StatelessSwitchMono) { - result_cmd.services.StatelessSwitchMono = []; - } - if (!result_cmd.services.StatelessSwitchMono[i]) { - result_cmd.services.StatelessSwitchMono[i] = {}; - } - result_cmd.services.StatelessSwitchMono[i].Double = cmds[i]; + initServ(result_cmd,'StatelessSwitchMono','Double',cmd); break; case 'SWITCH_STATELESS_LONG' : - if (!result_cmd.services.StatelessSwitchMono) { - result_cmd.services.StatelessSwitchMono = []; - } - if (!result_cmd.services.StatelessSwitchMono[i]) { - result_cmd.services.StatelessSwitchMono[i] = {}; - } - result_cmd.services.StatelessSwitchMono[i].Long = cmds[i]; + initServ(result_cmd,'StatelessSwitchMono','Long',cmd); break; /** *************** FLAP ***********************/ case 'FLAP_STATE' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].state = cmds[i]; + initServ(result_cmd,'flap','state',cmd); break; case 'FLAP_STATE_CLOSING' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].stateClosing = cmds[i]; + initServ(result_cmd,'flap','stateClosing',cmd); break; case 'FLAP_UP' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].up = cmds[i]; + initServ(result_cmd,'flap','up',cmd); break; case 'FLAP_DOWN' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].down = cmds[i]; + initServ(result_cmd,'flap','down',cmd); break; case 'FLAP_SLIDER' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].slider = cmds[i]; + initServ(result_cmd,'flap','slider',cmd); break; case 'FLAP_STOP' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].stop = cmds[i]; + initServ(result_cmd,'flap','stop',cmd); break; case 'FLAP_MOVING' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].moving = cmds[i]; + initServ(result_cmd,'flap','moving',cmd); break; case 'FLAP_HOR_TILT_STATE' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].HorTiltState = cmds[i]; + initServ(result_cmd,'flap','HorTiltState',cmd); break; case 'FLAP_HOR_TILT_SLIDER' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].HorTiltSlider = cmds[i]; + initServ(result_cmd,'flap','HorTiltSlider',cmd); break; case 'FLAP_VER_TILT_STATE' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].VerTiltState = cmds[i]; + initServ(result_cmd,'flap','VerTiltState',cmd); break; case 'FLAP_VER_TILT_SLIDER' : - if (!result_cmd.services.flap) { - result_cmd.services.flap = []; - } - if (!result_cmd.services.flap[i]) { - result_cmd.services.flap[i] = {}; - } - result_cmd.services.flap[i].VerTiltSlider = cmds[i]; + initServ(result_cmd,'flap','VerTiltSlider',cmd); break; /** *************** WINDOW ***********************/ case 'WINDOW_STATE' : - if (!result_cmd.services.windowMoto) { - result_cmd.services.windowMoto = []; - } - if (!result_cmd.services.windowMoto[i]) { - result_cmd.services.windowMoto[i] = {}; - } - result_cmd.services.windowMoto[i].state = cmds[i]; + initServ(result_cmd,'windowMoto','state',cmd); break; case 'WINDOW_UP' : - if (!result_cmd.services.windowMoto) { - result_cmd.services.windowMoto = []; - } - if (!result_cmd.services.windowMoto[i]) { - result_cmd.services.windowMoto[i] = {}; - } - result_cmd.services.windowMoto[i].up = cmds[i]; + initServ(result_cmd,'windowMoto','up',cmd); break; case 'WINDOW_DOWN' : - if (!result_cmd.services.windowMoto) { - result_cmd.services.windowMoto = []; - } - if (!result_cmd.services.windowMoto[i]) { - result_cmd.services.windowMoto[i] = {}; - } - result_cmd.services.windowMoto[i].down = cmds[i]; + initServ(result_cmd,'windowMoto','down',cmd); break; case 'WINDOW_SLIDER' : - if (!result_cmd.services.windowMoto) { - result_cmd.services.windowMoto = []; - } - if (!result_cmd.services.windowMoto[i]) { - result_cmd.services.windowMoto[i] = {}; - } - result_cmd.services.windowMoto[i].slider = cmds[i]; + initServ(result_cmd,'windowMoto','slider',cmd); break; case 'WINDOW_MOVING' : - if (!result_cmd.services.windowMoto) { - result_cmd.services.windowMoto = []; - } - if (!result_cmd.services.windowMoto[i]) { - result_cmd.services.windowMoto[i] = {}; - } - result_cmd.services.windowMoto[i].moving = cmds[i]; + initServ(result_cmd,'windowMoto','moving',cmd); break; /** ************* THERMOSTAT ***********************/ case 'THERMOSTAT_STATE' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].state = cmds[i]; + initServ(result_cmd,'thermostat','state',cmd); break; case 'THERMOSTAT_STATE_NAME' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].state_name = cmds[i]; + initServ(result_cmd,'thermostat','state_name',cmd); break; case 'THERMOSTAT_TEMPERATURE' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].temperature = cmds[i]; + initServ(result_cmd,'thermostat','temperature',cmd); break; case 'THERMOSTAT_SET_SETPOINT' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].set_setpoint = cmds[i]; + initServ(result_cmd,'thermostat','set_setpoint',cmd); break; case 'THERMOSTAT_SETPOINT' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].setpoint = cmds[i]; + initServ(result_cmd,'thermostat','setpoint',cmd); break; case 'THERMOSTAT_SET_MODE' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].set_mode = cmds[i]; + initServ(result_cmd,'thermostat','set_mode',cmd); break; case 'THERMOSTAT_MODE' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].mode = cmds[i]; + initServ(result_cmd,'thermostat','mode',cmd); break; case 'THERMOSTAT_LOCK' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].lock = cmds[i]; + initServ(result_cmd,'thermostat','lock',cmd); break; case 'THERMOSTAT_SET_LOCK' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].set_lock = cmds[i]; + initServ(result_cmd,'thermostat','set_lock',cmd); break; case 'THERMOSTAT_SET_UNLOCK' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].set_unlock = cmds[i]; + initServ(result_cmd,'thermostat','set_unlock',cmd); break; case 'THERMOSTAT_TEMPERATURE_OUTDOOR' : - if (!result_cmd.services.thermostat) { - result_cmd.services.thermostat = []; - } - if (!result_cmd.services.thermostat[i]) { - result_cmd.services.thermostat[i] = {}; - } - result_cmd.services.thermostat[i].temperature_outdoor = cmds[i]; + initServ(result_cmd,'thermostat','temperature_outdoor',cmd); break; /** ************* THERMOSTAT_HC ***********************/ case 'THERMOSTAT_HC_STATE' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].state = cmds[i]; + initServ(result_cmd,'thermostatHC','state',cmd); break; case 'THERMOSTAT_HC_STATE_NAME' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].state_name = cmds[i]; + initServ(result_cmd,'thermostatHC','state_name',cmd); break; case 'THERMOSTAT_HC_TEMPERATURE' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].temperature = cmds[i]; + initServ(result_cmd,'thermostatHC','temperature',cmd); break; case 'THERMOSTAT_HC_SET_SETPOINT_H' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].set_setpointH = cmds[i]; + initServ(result_cmd,'thermostatHC','set_setpointH',cmd); break; case 'THERMOSTAT_HC_SET_SETPOINT_C' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].set_setpointC = cmds[i]; + initServ(result_cmd,'thermostatHC','set_setpointC',cmd); break; case 'THERMOSTAT_HC_SETPOINT_H' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].setpointH = cmds[i]; + initServ(result_cmd,'thermostatHC','setpointH',cmd); break; case 'THERMOSTAT_HC_SETPOINT_C' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].setpointC = cmds[i]; + initServ(result_cmd,'thermostatHC','setpointC',cmd); break; case 'THERMOSTAT_HC_SET_MODE' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].set_mode = cmds[i]; + initServ(result_cmd,'thermostatHC','set_mode',cmd); break; case 'THERMOSTAT_HC_MODE' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].mode = cmds[i]; + initServ(result_cmd,'thermostatHC','mode',cmd); break; case 'THERMOSTAT_HC_LOCK' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].lock = cmds[i]; + initServ(result_cmd,'thermostatHC','lock',cmd); break; case 'THERMOSTAT_HC_SET_LOCK' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].set_lock = cmds[i]; + initServ(result_cmd,'thermostatHC','set_lock',cmd); break; case 'THERMOSTAT_HC_SET_UNLOCK' : - if (!result_cmd.services.thermostatHC) { - result_cmd.services.thermostatHC = []; - } - if (!result_cmd.services.thermostatHC[i]) { - result_cmd.services.thermostatHC[i] = {}; - } - result_cmd.services.thermostatHC[i].set_unlock = cmds[i]; + initServ(result_cmd,'thermostatHC','set_unlock',cmd); break; /** ************* ALARME ***********************/ case 'ALARM_STATE' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].state = cmds[i]; + initServ(result_cmd,'alarm','state',cmd); break; case 'ALARM_MODE' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].mode = cmds[i]; + initServ(result_cmd,'alarm','mode',cmd); break; case 'ALARM_ENABLE_STATE' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].enable_state = cmds[i]; + initServ(result_cmd,'alarm','enable_state',cmd); break; case 'ALARM_ARMED' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].armed = cmds[i]; + initServ(result_cmd,'alarm','armed',cmd); break; case 'ALARM_RELEASED' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].released = cmds[i]; + initServ(result_cmd,'alarm','released',cmd); break; case 'ALARM_SET_MODE' : - if (!result_cmd.services.alarm) { - result_cmd.services.alarm = []; - } - if (!result_cmd.services.alarm[i]) { - result_cmd.services.alarm[i] = {}; - } - result_cmd.services.alarm[i].set_mode = cmds[i]; + initServ(result_cmd,'alarm','set_mode',cmd); break; /** *************** GENERIC ***********************/ case 'AIRQUALITY_INDEX' : - if (!result_cmd.services.AirQuality) { - result_cmd.services.AirQuality = []; - } - if (!result_cmd.services.AirQuality[i]) { - result_cmd.services.AirQuality[i] = {}; - } - result_cmd.services.AirQuality[i].Index = cmds[i]; + initServ(result_cmd,'AirQuality','Index',cmd); break; case 'AIRQUALITY_PM25' : - if (!result_cmd.services.AirQuality) { - result_cmd.services.AirQuality = []; - } - if (!result_cmd.services.AirQuality[i]) { - result_cmd.services.AirQuality[i] = {}; - } - result_cmd.services.AirQuality[i].PM25 = cmds[i]; + initServ(result_cmd,'AirQuality','PM25',cmd); break; case 'AIRQUALITY_CUSTOM' : - if (!result_cmd.services.AirQualityCustom) { - result_cmd.services.AirQualityCustom = []; - } - if (!result_cmd.services.AirQualityCustom[i]) { - result_cmd.services.AirQualityCustom[i] = {}; - } - result_cmd.services.AirQualityCustom[i].Index = cmds[i]; + initServ(result_cmd,'AirQualityCustom','Index',cmd); break; case 'NOISE' : - if (!result_cmd.services.Noise) { - result_cmd.services.Noise = []; - } - if (!result_cmd.services.Noise[i]) { - result_cmd.services.Noise[i] = {}; - } - result_cmd.services.Noise[i].Noise = cmds[i]; + initServ(result_cmd,'Noise','Noise',cmd); break; case 'CO2' : - if (!result_cmd.services.CO2) { - result_cmd.services.CO2 = []; - } - if (!result_cmd.services.CO2[i]) { - result_cmd.services.CO2[i] = {}; - } - result_cmd.services.CO2[i].CO2 = cmds[i]; + initServ(result_cmd,'CO2','CO2',cmd); break; case 'CO' : - if (!result_cmd.services.CO) { - result_cmd.services.CO = []; - } - if (!result_cmd.services.CO[i]) { - result_cmd.services.CO[i] = {}; - } - result_cmd.services.CO[i].CO = cmds[i]; + initServ(result_cmd,'CO','CO',cmd); break; case 'OPENING_WINDOW' : case 'OPENING' : - if (!result_cmd.services.opening) { - result_cmd.services.opening = []; - } - if (!result_cmd.services.opening[i]) { - result_cmd.services.opening[i] = {}; - } - result_cmd.services.opening[i].opening = cmds[i]; + initServ(result_cmd,'opening','opening',cmd); break; case 'BATTERY' : - if (!result_cmd.services.battery) { - result_cmd.services.battery = []; - } - if (!result_cmd.services.battery[i]) { - result_cmd.services.battery[i] = {}; - } - result_cmd.services.battery[i].battery = cmds[i]; + initServ(result_cmd,'battery','battery',cmd); break; case 'BATTERY_CHARGING' : // not existing yet - if (!result_cmd.services.battery) { - result_cmd.services.battery = []; - } - if (!result_cmd.services.battery[i]) { - result_cmd.services.battery[i] = {}; - } - result_cmd.services.battery[i].batteryCharging = cmds[i]; + initServ(result_cmd,'battery','batteryCharging',cmd); break; case 'DEFECT' : - if (!result_cmd.services.defect) { - result_cmd.services.defect = []; - } - if (!result_cmd.services.defect[i]) { - result_cmd.services.defect[i] = {}; - } - result_cmd.services.defect[i].defect = cmds[i]; + initServ(result_cmd,'defect','defect',cmd); break; case 'PRESENCE' : - if (!result_cmd.services.presence) { - result_cmd.services.presence = []; - } - if (!result_cmd.services.presence[i]) { - result_cmd.services.presence[i] = {}; - } - result_cmd.services.presence[i].presence = cmds[i]; + initServ(result_cmd,'presence','presence',cmd); result_cmd.numDetector++; break; case 'OCCUPANCY' : - if (!result_cmd.services.occupancy) { - result_cmd.services.occupancy = []; - } - if (!result_cmd.services.occupancy[i]) { - result_cmd.services.occupancy[i] = {}; - } - result_cmd.services.occupancy[i].occupancy = cmds[i]; + initServ(result_cmd,'occupancy','occupancy',cmd); result_cmd.numDetector++; break; case 'TEMPERATURE' : - if (!result_cmd.services.temperature) { - result_cmd.services.temperature = []; - } - if (!result_cmd.services.temperature[i]) { - result_cmd.services.temperature[i] = {}; - } - result_cmd.services.temperature[i].temperature = cmds[i]; + initServ(result_cmd,'temperature','temperature',cmd); break; case 'BRIGHTNESS' : - if (!result_cmd.services.brightness) { - result_cmd.services.brightness = []; - } - if (!result_cmd.services.brightness[i]) { - result_cmd.services.brightness[i] = {}; - } - result_cmd.services.brightness[i].brightness = cmds[i]; + initServ(result_cmd,'brightness','brightness',cmd); break; case 'SMOKE' : - if (!result_cmd.services.smoke) { - result_cmd.services.smoke = []; - } - if (!result_cmd.services.smoke[i]) { - result_cmd.services.smoke[i] = {}; - } - result_cmd.services.smoke[i].smoke = cmds[i]; + initServ(result_cmd,'smoke','smoke',cmd); break; case 'UV' : // via custom - if (!result_cmd.services.uv) { - result_cmd.services.uv = []; - } - if (!result_cmd.services.uv[i]) { - result_cmd.services.uv[i] = {}; - } - result_cmd.services.uv[i].uv = cmds[i]; + initServ(result_cmd,'uv','uv',cmd); break; case 'HUMIDITY' : - if (!result_cmd.services.humidity) { - result_cmd.services.humidity = []; - } - if (!result_cmd.services.humidity[i]) { - result_cmd.services.humidity[i] = {}; - } - result_cmd.services.humidity[i].humidity = cmds[i]; + initServ(result_cmd,'humidity','humidity',cmd); break; case 'SABOTAGE' : - if (!result_cmd.services.sabotage) { - result_cmd.services.sabotage = []; - } - if (!result_cmd.services.sabotage[i]) { - result_cmd.services.sabotage[i] = {}; - } - result_cmd.services.sabotage[i].sabotage = cmds[i]; + initServ(result_cmd,'sabotage','sabotage',cmd); break; case 'FLOOD' : case 'WATER_LEAK' : - if (!result_cmd.services.flood) { - result_cmd.services.flood = []; - } - if (!result_cmd.services.flood[i]) { - result_cmd.services.flood[i] = {}; - } - result_cmd.services.flood[i].flood = cmds[i]; + initServ(result_cmd,'flood','flood',cmd); break; case 'POWER' : // via custom - if (!result_cmd.services.power) { - result_cmd.services.power = []; - } - if (!result_cmd.services.power[i]) { - result_cmd.services.power[i] = {}; - } - result_cmd.services.power[i].power = cmds[i]; + initServ(result_cmd,'power','power',cmd); break; case 'CONSUMPTION' : // via custom - if (!result_cmd.services.consumption) { - result_cmd.services.consumption = []; - } - if (!result_cmd.services.consumption[i]) { - result_cmd.services.consumption[i] = {}; - } - result_cmd.services.consumption[i].consumption = cmds[i]; + initServ(result_cmd,'consumption','consumption',cmd); break; case 'ACTIVE' : - if (!result_cmd.services.status_active) { - result_cmd.services.status_active = []; - } - if (!result_cmd.services.status_active[i]) { - result_cmd.services.status_active[i] = {}; - } - result_cmd.services.status_active[i].status_active = cmds[i]; + initServ(result_cmd,'status_active','status_active',cmd); break; case 'SPEAKER_VOLUME' : case 'VOLUME' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].volume = cmds[i]; + initServ(result_cmd,'speaker','volume',cmd); break; case 'SPEAKER_SET_VOLUME' : case 'SET_VOLUME' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].set_volume = cmds[i]; + initServ(result_cmd,'speaker','set_volume',cmd); break; case 'SPEAKER_MUTE' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].mute = cmds[i]; + initServ(result_cmd,'speaker','mute',cmd); break; case 'SPEAKER_MUTE_TOGGLE' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].mute_toggle = cmds[i]; + initServ(result_cmd,'speaker','mute_toggle',cmd); break; case 'SPEAKER_MUTE_ON' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].mute_on = cmds[i]; + initServ(result_cmd,'speaker','mute_on',cmd); break; case 'SPEAKER_MUTE_OFF' : - if (!result_cmd.services.speaker) { - result_cmd.services.speaker = []; - } - if (!result_cmd.services.speaker[i]) { - result_cmd.services.speaker[i] = {}; - } - result_cmd.services.speaker[i].mute_off = cmds[i]; + initServ(result_cmd,'speaker','mute_off',cmd); break; case 'PRESSURE' : - if (!result_cmd.services.pressure) { - result_cmd.services.pressure = []; - } - if (!result_cmd.services.pressure[i]) { - result_cmd.services.pressure[i] = {}; - } - result_cmd.services.pressure[i].pressure = cmds[i]; + initServ(result_cmd,'pressure','pressure',cmd); break; - } } } - } + }); return result_cmd; }; -function isset() { - var a = arguments, l = a.length, i = 0; - - if (l === 0) { - throw new Error('Empty isset'); - } - - while (i !== l) { - if (!a[i]) { - return false; - } - i++; - } - return true; -} - module.exports.createClient = function(url, apikey, Plateform,myPlugin) { return new JeedomClient(url, apikey, Plateform,myPlugin); };