Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localize PowerFlow Animation #58

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# RELEASE NOTES

## v0.6.4 - Power Flow Animation

Proxy t29 Updates
* Default page rendered by proxy (http://pypowerwall/) will render Powerflow Animation
* Animation assets (html, css, js, images, fonts, svg) will render from local filesystem instead of pulling from Powerwall TEG portal.
* Start prep for possible API removals from Powerwall TEG portal (see NOAPI settings)

Powerwall Network Scanner
* Adjust scan timeout default to 1,000ms (1s) to help with more consistent scans.

## v0.6.3 - Powerwall 3 Scan

* Added scan detection for new Powerwall 3 systems. API discovery is still underway so pypowerwall currently does not support Powerwall 3s. See https://github.com/jasonacox/Powerwall-Dashboard/issues/387
Expand Down
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 t29 (16 Dec 2023)

* Default page rendered by proxy (http://pypowerwall/) will render Powerflow Animation
* Animation assets (html, css, js, images, fonts, svg) will render from local filesystem instead of pulling from Powerwall TEG portal.
* Start prep for possible API removals from Powerwall TEG portal (see NOAPI settings)

### Proxy t28 (14 Oct 2023)

* Add a `grafana-dark` style for `PW_STYLE` settings to accommodate placing as iframe in newer Grafana versions (e.g. v9.4.14). See https://github.com/jasonacox/Powerwall-Dashboard/discussions/371.
Expand Down
34 changes: 31 additions & 3 deletions proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import ssl
from transform import get_static, inject_js

BUILD = "t28"
BUILD = "t29"
NOAPI = False # Set to True to serve bogus data for API calls to Powerwall
ALLOWLIST = [
'/api/status', '/api/site_info/site_name', '/api/meters/site',
'/api/meters/solar', '/api/sitemaster', '/api/powerwalls',
Expand Down Expand Up @@ -106,7 +107,14 @@ def get_value(a, key):
return None

# Connect to Powerwall
# TODO: Add support for multiple Powerwalls
# TODO: Add support for solar-only systems
pw = pypowerwall.Powerwall(host,password,email,timezone,cache_expire,timeout,pool_maxsize)
if not pw or NOAPI or not host or host.lower() == "none":
NOAPI = True
log.info("pyPowerwall Proxy Server - NOAPI Mode")
else:
log.info("pyPowerwall Proxy Server - Connected to %s" % host)

class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
daemon_threads = True
Expand Down Expand Up @@ -140,6 +148,9 @@ def do_GET(self):
# Force 95% Scale
level = pw.level(scale=True)
message = json.dumps({"percentage":level})
elif self.path == '/api/system_status/grid_status':
# Grid Status - JSON
message = pw.poll('/api/system_status/grid_status')
elif self.path == '/csv':
# Grid,Home,Solar,Battery,Level - CSV
contenttype = 'text/plain; charset=utf-8'
Expand Down Expand Up @@ -273,15 +284,32 @@ def do_GET(self):
message = message + '\n<p>Page refresh: %s</p>\n</body>\n</html>' % (
str(datetime.datetime.fromtimestamp(time.time())))
elif self.path in ALLOWLIST:
# Allowed API Call
message = pw.poll(self.path)
# Allowed API Calls - Proxy to Powerwall
if NOAPI:
# If we are in NOAPI mode serve up bogus data
filename = "/bogus/" + self.path[1:].replace('/', '.') + ".json"
fcontent, ftype = get_static(web_root, filename)
if not fcontent:
fcontent = bytes("{}", 'utf-8')
log.debug("No offline content found for: {}".format(filename))
else:
log.debug("Served from local filesystem: {}".format(filename))
self.send_header('Content-type','{}'.format(ftype))
self.end_headers()
self.wfile.write(fcontent)
return
else:
# Proxy request to Powerwall
message = pw.poll(self.path)
else:
# Everything else - Set auth headers required for web application
proxystats['gets'] = proxystats['gets'] + 1
self.send_header("Set-Cookie", "AuthCookie={};{}".format(pw.auth['AuthCookie'], cookiesuffix))
self.send_header("Set-Cookie", "UserRecord={};{}".format(pw.auth['UserRecord'], cookiesuffix))

# Serve static assets from web root first, if found.
if self.path == "/" or self.path == "":
self.path = "/index.html"
fcontent, ftype = get_static(web_root, self.path)
if fcontent:
log.debug("Served from local web root: {}".format(self.path))
Expand Down
Binary file added proxy/web/012955c70685614a5639d326f41890bd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
422 changes: 422 additions & 0 deletions proxy/web/1.17c71172308436a079d1.js

Large diffs are not rendered by default.

Binary file added proxy/web/124f233cfa9945f861dcaca7acedd308.otf
Binary file not shown.
Binary file added proxy/web/230aeae00823cd3b622d093948d9c433.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added proxy/web/2bf15a1686c7a1bf7b577337a07d7049.otf
Binary file not shown.
Loading
Loading