-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamped WebView to use watched Variables instead of DataToUI
- Loading branch information
Showing
6 changed files
with
26 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,23 @@ | ||
document.addEventListener("DOMContentLoaded", function(){ | ||
C4.subscribeToDataToUi(true); | ||
C4.subscribeToDataToUi(false); | ||
C4.subscribeToVariable("PRODUCTION_KW"); | ||
C4.subscribeToVariable("CONSUMPTION_KW"); | ||
C4.subscribeToVariable("GRID_POWER_KW"); | ||
C4.subscribeToVariable("DAILY_ENERGY_PRODUCTION_KWH"); | ||
C4.subscribeToVariable("DAILY_ENERGY_CONSUMPTION_KWH"); | ||
C4.subscribeToVariable("EXCESS_SOLAR_KW"); | ||
}); | ||
|
||
function updateData(variable, value) { | ||
console.log("updateData: " + variable + value) | ||
document.getElementById(variable).textContent=value; | ||
} | ||
|
||
function onDataToUi(value) { | ||
console.log("DATA_TO_UI: " + value); | ||
var response = JSON.parse(value); | ||
if (!response || typeof response !== "object") { | ||
console.log("DATA_TO_UI: onDataToUi called with invalid or no JSON"); | ||
return; | ||
} | ||
console.log("DATA_TO_UI: successfully parsed response."); | ||
var data = response.data; | ||
console.log(data); | ||
for (var property in data) { | ||
if (data.hasOwnProperty(property)) { | ||
console.log(data[property]); | ||
updateData(property, data[property]); | ||
} | ||
} | ||
function onVariable(variable, value) { | ||
console.log("Received variable: " + variable + value); | ||
updateData(variable, value); | ||
} | ||
|
||
function onSubscribeToDataToUi(message) { | ||
alert("Error subscribing to data to ui: " + message); | ||
} | ||
function onSubscribeToVariableError(variable, message) { | ||
alert("Error subscribing to variable: " + variable + "," + message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters