-
Notifications
You must be signed in to change notification settings - Fork 26
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
Nexarian/re work proxy #130
base: main
Are you sure you want to change the base?
Conversation
# and always use those if available (required for Docker) | ||
# Configuration - Environment variables | ||
type PROXY_CONFIG = Dict[CONFIG_TYPE, str | int | bool | None] | ||
type PROXY_STATS = Dict[PROXY_STATS_TYPE, str | int | bool | None | PROXY_CONFIG | Dict[str, int]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type
constructs make this Python 3.12+ only. How difficult would it be to make it backward compatible for Python 3? I can update the library to be >= 3.12 but that seems like a big lift. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but I think if we do that we should move this to a class. Look at how unwieldy the type is... A dataclass type would be better and still backwards compatible.
proxy/server.py
Outdated
content = b"Error during proxy" | ||
content_type = "text/plain" | ||
|
||
if self.configuration['PW_BROWSER_CACHE'] > 0 and content_type in ['text/css', 'application/javascript', 'image/png']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be:
if self.configuration[CONFIG_TYPE.PW_BROWSER_CACHE] > 0 and content_type in ['text/css', 'application/javascript', 'image/png']:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
proxy/server.py
Outdated
VERSION=status.get("version", ""), | ||
HASH=status.get("git_hash", ""), | ||
EMAIL=self.configuration[CONFIG_TYPE.PW_EMAIL], | ||
STYLE=self.configuration[CONFIG_TYPE.PW_STYLE], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to get the proxy to render the animation e.g. http://localhost:9999/example.html and it is throwing an error here:
File "/Users/jason/Code/pypowerwall/proxy/server.py", line 824, in handle_static_content
content = content.decode(UTF_8).format(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: '\n "configuration"'
----------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format doesn't work, but replace does? I'm not sure why. I've switched it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonacox Is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that the opentype files are not getting served - need to debug a bit more....
Old / Existing server.py
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /favicon.ico type text/plain
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /example.html type text/html
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /index.html type text/html
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /app.css type text/css
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /vendor.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /app.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /clear.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /40.17c71172308436a079d1.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /39.17c71172308436a079d1.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /1.17c71172308436a079d1.js type application/javascript
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /eca1317ee8a99162d0d0e2df77330cec.otf type font/opentype
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /230aeae00823cd3b622d093948d9c433.png type image/png
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /012955c70685614a5639d326f41890bd.png type image/png
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /4e28cc8f2bdf3ba640331daa2c453341.png type image/png
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /cb0da8a8999c06735455bf5056a5cd78.png type image/png
01/14/2025 08:02:32 PM [proxy] [DEBUG] Served from local web root: /e19c20e966bde501f94e41cd0322dbe8.otf type font/opentype
New server.py
01/14/2025 08:07:11 PM [proxy] [DEBUG] Served from local web root: /favicon.ico type text/plain
01/14/2025 08:07:13 PM [proxy] [DEBUG] Served from local web root: /example.html type text/html
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /index.html type text/html
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /app.css type text/css
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /vendor.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /app.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /clear.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /40.17c71172308436a079d1.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /1.17c71172308436a079d1.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /39.17c71172308436a079d1.js type application/javascript
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /012955c70685614a5639d326f41890bd.png type image/png
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /230aeae00823cd3b622d093948d9c433.png type image/png
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /4e28cc8f2bdf3ba640331daa2c453341.png type image/png
01/14/2025 08:07:14 PM [proxy] [DEBUG] Served from local web root: /cb0da8a8999c06735455bf5056a5cd78.png type image/png
The logging behavior is a bit odd... seems like the way we have the initializer, it is creating a new powerwall instance with each call:
|
It's not creating a new powerwall instance, but init for the handler object is being called repeatedly... That is very weird. |
The problem appears to be this line: It's not doing what I expect, which is create one server and serve forever. Instead, it's constantly creating new threads. |
I pushed some changes that I think help, but they still don't fix the static content render. I'll keep digging. Feel free to look more, too if you'd like. |
proxy/server.py
Outdated
elif path in DISABLED: | ||
result = self.send_json_response( | ||
{"status": "404 Response - API Disabled"}, | ||
status_code=HTTPStatus.NOT_FOUND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status code needs to be 200 for this API. The Powerflow animation code looks for it. The payload can be as it shows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bit counterintuitive that DISABLED
still returns 200. However, I think I sorta understand. It's not NOT FOUND in the proxy itself, it's simply disabled for use in when being called THROUGH the proxy.
Ah... maybe this is the issue:
Notice that two Content-type's are being set. I'll see if I can find where it is doing that in the code. |
Yes, that was it. I'll flag where you need to remove that. |
proxy/server.py
Outdated
def handle_static_content(self, path) -> str: | ||
self.proxystats[PROXY_STATS_TYPE.GETS] += 1 | ||
self.send_response(HTTPStatus.OK) | ||
self.send_header('Content-type', 'text/html') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't sent this here. The static content could be of a differen type. Just remove this and allow the content type to be set later on after the static content is determined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
# Logging | ||
DISABLED: Final[Set[str]] = set([ | ||
'/api/customer/registration', | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add '/networks' here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@jasonacox What else should we test? |
I'm trying to get I also have had no luck getting InfluxDB to start up. |
They don't need to be consecutive, but a pattern would make sense. I suggest a 10+ pattern like: 8675, 8685, 8695, 8705, 8715, 8725, 8735, 8745, 8755, 8765, ... It occurs to me that we should verify that there isn't a user provided overlap. We could assign those automatically if no port is provided. Did you get "Powerwall Dashboard" working? In the current configuration, it only pulls data for 8675. I think the next act will be to figure out how to combine all the gateway instances into the Dashboard in a meaningful way. Possibly a custom telegraf.local.conf with name override for the separate powerwalls. |
No description provided.