empierre / MyDomoAtHome

MyDomoAtHome - REST interface for ImperoHome with Domoticz (ISS)
http://domoticz.com/wiki/ImperiHome
GNU General Public License v3.0
32 stars 22 forks source link

Selector Switch - LevelNames - BASE64 string has to be decoded first #175

Closed theduf59 closed 5 years ago

theduf59 commented 5 years ago

my env : pi3 raspbian + domoticz v4.10393

In domoticz reply to http://192.168.1.11:8080/json.htm?type=devices&filter=all&used=true&order=Name, LevelNames is base64 encoded for Select Switch devices :

  "LevelNames" : "T2ZmfFF1aWV0fEJhbGFuY2VkfFR1cmJvfE1heA==",
         "SubType" : "Selector Switch",
         "SwitchType" : "Selector",
         "Type" : "Light/Switch",

so I had this issue :

{ MaxDimLevel: null,
  Action: null,
  graph: null,
  Selector: [ 'T2ZmfFF1aWV0fEJhbGFuY2VkfFR1cmJvfE1heA==' ] }
4
/home/pi/node_modules/node-mydomoathome/mdah.js:433
    params.push({"key": "Value", "value": ret[lvl].toString()});
                                                   ^

TypeError: Cannot read property 'toString' of undefined
    at DevMultiSwitch (/home/pi/node_modules/node-mydomoathome/mdah.js:433:52)
    at Request._callback (/home/pi/node_modules/node-mydomoathome/mdah.js:2449:45)
    at Request.self.callback (/home/pi/node_modules/node-mydomoathome/node_modules/request/request.js:185:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (/home/pi/node_modules/node-mydomoathome/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:189:13)
    at IncomingMessage.<anonymous> (/home/pi/node_modules/node-mydomoathome/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1103:12)

my correction proposal in function DevMultiSwitch(data) :

//decode base64 data.LevelNames
let buff = new Buffer(data.LevelNames, 'base64');  
let lvlNames = buff.toString('ascii');
// know use lvlNames instead of data.LevelNames.
var res = lvlNames.split('|').join(',');
        if(data.LevelOffHidden) {
                res = res.replace ("Off,","");
        }
var ret = lvlNames.split('|');

now console.log(mydev); shows :

{ MaxDimLevel: null,
  Action: null,
  graph: null,
  Selector: [ 'Off', 'Quiet', 'Balanced', 'Turbo', 'Max' ] }
theduf59 commented 5 years ago

already solved here , it's not the same code I got from npm