|
1 | | -///////// <version>1.0.2</version> |
| 1 | +///////// <version>1.0.3</version> |
2 | 2 | ///////// GOODWE1 ///////////// |
3 | 3 | ///////// Plugin to extract Goodwe Solar data for Toon /////////////// |
4 | 4 | ///////// By Oepi-Loepi /////////////// |
|
19 | 19 | http.onreadystatechange = function() { // Call a function when the state changes. |
20 | 20 | if (http.readyState === 4) { |
21 | 21 | if (http.status === 200) { |
22 | | - if (debugOutput) console.log("*********SolarPanel http.responseText : " + http.responseText) |
23 | | - var JsonString = http.responseText |
24 | | - var JsonObject= JSON.parse(JsonString) |
25 | | - var uid = JsonObject.data.uid |
26 | | - var token = JsonObject.data.token |
27 | | - var timestamp = JsonObject.data.timestamp |
28 | | - if (debugOutput) console.log("*********SolarPanel uid : " + uid) |
29 | | - if (debugOutput) console.log("*********SolarPanel token : " + token) |
30 | | - getStep2(uid,token, timestamp) |
| 22 | + try { |
| 23 | + var JsonString = http.responseText |
| 24 | + var JsonObject= JSON.parse(JsonString) |
| 25 | + var uid = JsonObject.data.uid |
| 26 | + var token = JsonObject.data.token |
| 27 | + var timestamp = JsonObject.data.timestamp |
| 28 | + if (debugOutput) console.log("*********SolarPanel uid : " + uid) |
| 29 | + if (debugOutput) console.log("*********SolarPanel token : " + token) |
| 30 | + getStep2(uid,token, timestamp) |
| 31 | + } |
| 32 | + catch (e){ |
| 33 | + currentPower = 0 |
| 34 | + parseReturnData(0,totalValue,todayValue,0,0,0,0, http.status,"error") |
| 35 | + } |
31 | 36 | } else { |
32 | 37 | if (debugOutput) console.log("*********SolarPanel error: " + http.status) |
33 | 38 | parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error") |
|
53 | 58 | http.onreadystatechange = function() { // Call a function when the state changes. |
54 | 59 | if (http.readyState === 4) { |
55 | 60 | if (http.status === 200) { |
56 | | - if (debugOutput) console.log("*********SolarPanel http.responseText : " + http.responseText) |
57 | | - var JsonString = http.responseText |
58 | | - var JsonObject= JSON.parse(JsonString) |
59 | | - var hasError = JsonObject.hasError |
60 | | - var succes = JsonObject.msg |
61 | | - var today2 |
62 | | - if (debugOutput) console.log ("*********SolarPanel JsonObject.hasError : " + JsonObject.hasError) |
63 | | - if(!hasError){ |
64 | | - currentPower = parseInt(JsonObject.data[0].pac) |
65 | | - today2 = Math.floor((JsonObject.data[0].eday)*1000) |
66 | | - totalValue = Math.floor((JsonObject.data[0].etotal)*1000) |
67 | | - if (debugOutput) console.log ("*********SolarPanel currentPower: " + currentPower) |
68 | | - if (debugOutput) console.log ("*********SolarPanel totalValue: " + totalValue) |
69 | | - parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes") |
70 | | - } else { |
71 | | - if (debugOutput) console.log("*********SolarPanel Plugin error") |
72 | | - parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error") |
| 61 | + try { |
| 62 | + var JsonString = http.responseText |
| 63 | + var JsonObject= JSON.parse(JsonString) |
| 64 | + var hasError = JsonObject.hasError |
| 65 | + var succes = JsonObject.msg |
| 66 | + var today2 |
| 67 | + if (debugOutput) console.log ("*********SolarPanel JsonObject.hasError : " + JsonObject.hasError) |
| 68 | + if(!hasError){ |
| 69 | + currentPower = parseInt(JsonObject.data[0].pac) |
| 70 | + today2 = Math.floor((JsonObject.data[0].eday)*1000) |
| 71 | + totalValue = Math.floor((JsonObject.data[0].etotal)*1000) |
| 72 | + if (debugOutput) console.log ("*********SolarPanel currentPower: " + currentPower) |
| 73 | + if (debugOutput) console.log ("*********SolarPanel totalValue: " + totalValue) |
| 74 | + parseReturnData(currentPower,totalValue,today2,0,0,0,0,http.status,"succes") |
| 75 | + } else { |
| 76 | + if (debugOutput) console.log("*********SolarPanel Plugin error") |
| 77 | + parseReturnData(0,totalValue,0,0,0,0,0, http.status,"error") |
| 78 | + } |
| 79 | + } |
| 80 | + catch (e){ |
| 81 | + currentPower = 0 |
| 82 | + parseReturnData(0,totalValue,todayValue,0,0,0,0, http.status,"error") |
73 | 83 | } |
74 | 84 | } else { |
75 | 85 | if (debugOutput) console.log("*********SolarPanel error: " + http.status) |
|
0 commit comments