Solar Array and home energy dashboard.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

85 lines
2.0 KiB

  1. // Interface for testing, provides testing data, and dynamic updates, etc.
  2. // WebSocket emulation class for testing
  3. function WebSocketTest(actions) {
  4. this.actions = actions.slice(); // copy
  5. this.actions.reverse()
  6. this.processNextItem()
  7. }
  8. // WebSocketTest.prototype.send = function ()
  9. // WebSocketTest.prototype.close = function ()
  10. // Internal
  11. WebSocketTest.prototype.processNextItem = function () {
  12. var item = this.actions.pop()
  13. if (item === undefined) {
  14. console.log("WebSocketTest finished running");
  15. return;
  16. }
  17. var wst = this;
  18. setTimeout(function() {
  19. item[1](wst);
  20. wst.processNextItem();
  21. }, item[0]);
  22. return this;
  23. }
  24. fakeData = [
  25. [ 1578544199000, 0.3934 ],
  26. [ 1578544209000, 0.4934 ],
  27. [ 1578544219000, 0.5234 ],
  28. [ 1578544229000, 0.4734 ],
  29. [ 1578544239000, 0.4334 ],
  30. [ 1578544249000, 0.2334 ],
  31. [ 1578544259000, 0.1034 ],
  32. [ 1578544269000, -0.4334 ],
  33. [ 1578544279000, -0.6334 ],
  34. [ 1578544289000, -0.2334 ],
  35. ]
  36. fakeConData = [
  37. [ 1578544199000, 0.3934 ],
  38. [ 1578544209000, 0.4934 ],
  39. [ 1578544219000, 0.5234 ],
  40. [ 1578544229000, 0.4734 ],
  41. [ 1578544239000, 0.4334 ],
  42. [ 1578544249000, 0.2334 ],
  43. [ 1578544259000, 0.1034 ],
  44. [ 1578544269000, 0.4334 ],
  45. [ 1578544279000, 0.6334 ],
  46. [ 1578544289000, 0.2334 ],
  47. ]
  48. fakeOverviewData = {
  49. grid: fakeData,
  50. consumption: fakeConData,
  51. production: fakeConData,
  52. }
  53. // Setup the socket that will be used
  54. var socket = new WebSocketTest([
  55. [ 10, function(a) { a.onopen(new Object()) } ],
  56. [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
  57. data : 'o ' + JSON.stringify(fakeOverviewData)
  58. })) } ],
  59. [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
  60. data : 'p .123'
  61. })) } ],
  62. [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
  63. data : 'c .302'
  64. })) } ],
  65. [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
  66. data : 'ng .758'
  67. })) } ],
  68. [ 2000, function(a) { a.onmessage(new MessageEvent('websockettest', {
  69. data : 'p .234'
  70. })) } ],
  71. [ 10, function(a) { a.onmessage(new MessageEvent('websockettest', {
  72. data : 'ng -.584'
  73. })) } ],
  74. ]);