Skip to content

Commit

Permalink
Add solar.js style for animation
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Mar 4, 2024
1 parent 999c638 commit b54b4ab
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
6 changes: 6 additions & 0 deletions proxy/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## pyPowerwall Proxy Release Notes

### Proxy t42 (3 Mar 2024)

* Add Power Flow Animation style (set `PW_STYLE="solar"`) for Solar-Only display. Removes the Powerwall image and related text to display a Grid + Solar + Home powerflow animation.

<img width="443" alt="image" src="https://github.com/jasonacox/Powerwall-Dashboard/assets/836718/37fa7f7b-d4f9-4240-82bc-a81ba2f798c7">

### Proxy t41 (25 Feb 2024)

* Bug fixes for Solar-Only systems using `cloud mode` (see https://github.com/jasonacox/Powerwall-Dashboard/issues/437).
Expand Down
2 changes: 1 addition & 1 deletion proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import ssl
from transform import get_static, inject_js

BUILD = "t41"
BUILD = "t42"
ALLOWLIST = [
'/api/status', '/api/site_info/site_name', '/api/meters/site',
'/api/meters/solar', '/api/sitemaster', '/api/powerwalls',
Expand Down
104 changes: 104 additions & 0 deletions proxy/web/solar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use strict'

// Clear IndexedDB to prevent auth hangup in the proxied Powerwall web app.
try {
window.indexedDB.databases().then((dbs) => {
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) });
});
} catch (error) {
document.write("Browser blocking indexedDB - Turn off incognito mode.");
}

function injectScriptAndUse() {
return new Promise((resolve, reject) => {
var body = document.getElementsByTagName("body")[0];
var script = document.createElement("script");
script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";
script.onload = function () {
resolve();
};
body.appendChild(script);
});
}

injectScriptAndUse().then(() => {
console.log("Applying SolarOnly customization");
triggerOnMutation(formatPowerwallForSolar);
});

function triggerOnMutation(cb) {
// Create an observer instance
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
var newNodes = mutation.addedNodes; // DOM NodeList
if (newNodes !== null) { // If there are new nodes added
if (cb) cb();
}
});
});

// Configuration of the observer:
var config = {
attributes: true,
childList: true,
subtree: true,
};

var target = $("#root")[0];

// Pass in the target node, as well as the observer options
observer.observe(target, config);
}

function formatPowerwallForSolar() {
// Hide elements.
$('.overview-menu, #logout, .footer, .compact-btn-row, .toast-list, .power-flow-header, .btn, .powerwall-soe, .soe-label').hide();

// Hide Powerwall image
var imgElement = document.querySelector('[data-testid="b3372156-8a9e-4d17-9721-fcc5891d1074"]');
if (imgElement) {
imgElement.style.display = 'none';
}
// Hide the Powerwall text
const divs = document.querySelectorAll('[data-testid="ec7d6a6d-b6d2-411c-a535-c052c00baf62"]');
divs.forEach(div => {
if (div.style.width === '120px' && div.style.top === '200.5px' && div.style.left === '0px' && div.style.right === '0px') {
const paragraph = div.querySelector('p[data-testid="4c6aadb3-7661-4d7f-b1ff-d5a0571fac60"]');
if (paragraph) {
paragraph.style.display = 'none';
}
}
});

// Set alignment
$('.core-layout__viewport').css({
padding: 0,
margin: 0,
});

$('.power-flow-header').css({
"padding-top": 0,
});

$('.power-flow-grid').css({
width: "100%",
left: 0,
right: 0,
margin: 0,
"padding-top": 0,
"position": "fixed",
});

$('.app').css({
"overflow-y": "hidden",
});

// Set colors
$('body').css({
"background-color": "transparent",
});

$('.power-flow-grid.active').css({
"background-color": "transparent",
});
}

0 comments on commit b54b4ab

Please sign in to comment.