Zefau / ioBroker.jarvis

jarvis - just another remarkable vis
https://forum.iobroker.net/topic/49776
Other
147 stars 38 forks source link

[v3.2.0-beta.14] Datenpunkt-Eigenschaften Warnung wird angezeigt, obwohl korrekt gesetzt #2659

Closed mcuiobroker closed 3 weeks ago

mcuiobroker commented 3 weeks ago

image image

{
  "value": "val=> {let v = JSON.parse(val).params.on; console.log(v); return v;}",
  "on": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":true}}",
  "off": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":false}}"
}
Zefau commented 3 weeks ago

Das Objekt val enhält kein params (bzw. ist dies undefined), daher kommt Cannot read properties of undefined (reading on).

Versuch mal:

{
  "value": "val=> {const v = JSON.parse(val || '{}'); const param = v && v.params && v.params.on; console.log(v); return v;}",

  "on": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":true}}",
  "off": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":false}}"
}
mcuiobroker commented 3 weeks ago
{
  "value": "val=> {const v = JSON.parse(val || '{}'); if( v.params!=undefined && v.params.on!=undefined){ console.log(v); return v.params.on;}}",
  "on": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":true}}",
  "off": "{\"id\": 1,\"src\":\"PlusPlugS-04\",\"method\":\"Switch.Set\",\"params\": {\"id\":0,\"on\":false}}"
}

Damit funktioniert es ohne Warnung. Danke.