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

0.8.0 Refactoring code #77

Merged
merged 27 commits into from
Mar 26, 2024
Merged

0.8.0 Refactoring code #77

merged 27 commits into from
Mar 26, 2024

Conversation

emptywee
Copy link
Contributor

  • Refactor code
  • Clean up
  • Make code more pythonish

@jasonacox I know it's a little too much to review, but what do you think if we go this way as the first round of refactoring?
It's a little hard to sync it with upstream changes, but if we transition to this structure, it'll be easy to both continue maintaining the current code and refactoring it further.

I noticed that meaning of the jsonformat param was inconsistent across the board, so I fixed that as well, but it might break things for any users of the library if they used the methods directly. Mainly it was the poll() method, which treated the param the other way around.

I also asked about code style guide or anything along those lines, you didn't see it I guess :) So I made it look a bit more Python-ish, if you don't mind.

Please, let me know what you think.

emptywee and others added 4 commits March 17, 2024 20:08
* Refactor code
* Clean up
* Make code more pythonish

Co-authored-by: Igor Cherkaev <igor.cherkaev@copart.com>
@emptywee
Copy link
Contributor Author

Oh, oops, didn't know example.py was required for tests :) I basically renamed it to example-local-mode.py, let me rename it back.

@jasonacox
Copy link
Owner

🤯 !! You did this today?! Amazing @emptywee ! A lot to review but I like the style consistency and the jsonformat change.

So far, I like what I see. As you mention, we should look at the breaking changes and call them out. Also, proxy is not running. I will probably start with that and back in to what is breaking (first pass looks like it is related to missing pw.auth['AuthCookie'].

@jasonacox jasonacox requested a review from mcbirse March 18, 2024 02:15
@emptywee
Copy link
Contributor Author

!! You did this today?! Amazing @emptywee ! A lot to review but I like the style consistency and the jsonformat change.

Yeah :) It's not much, tbh, just moved some code around, so that we can work on it further later.

So far, I like what I see. As you mention, we should look at the breaking changes and call them out. Also, proxy is not running. I will probably start with that and back in to what is breaking (first pass looks like it is related to missing pw.auth['AuthCookie'].

Oopsie, I am not super familiar with the project and all moving parts :( I'll look into the proxy piece, too.

align env vars of the example scripts.
minor bugfixes, linting, etc
@emptywee
Copy link
Contributor Author

emptywee commented Mar 18, 2024

Fixed the proxy piece to be compatible with the new structure of the library. Tested on my local - worked well with both local powerwall and cloud access.

@emptywee
Copy link
Contributor Author

emptywee commented Mar 18, 2024

Also, I saw some kind of an effort to support py2? I think we can remove it unless it's required. We don't mention it on pypi, we don't run any tests with it either. If we have to support py2, I'll have to drop all the type hints I've added with this PR.

@jasonacox what do you think?

@jasonacox
Copy link
Owner

I saw some kind of an effort to support py2?

Yes, we can remove py2 support. That's just legacy code. We also assert Python 3 in our setup.py

"Programming Language :: Python :: 3",
.

@emptywee
Copy link
Contributor Author

Great, I'll remove it then as part of this code refresh. Thanks.

* remove python2 legacy compatibility code from the scanner (`scan.py`)
* make `tessolarcharge.py` look more pythonic
@emptywee
Copy link
Contributor Author

Removed py2 stuff, looks like it was only one script there.

jasonacox and others added 2 commits March 18, 2024 20:46
* getting rid of hundreds of if-elif-elif-elif in the cloud poll function
@emptywee
Copy link
Contributor Author

emptywee commented Mar 19, 2024

@jasonacox what do you think about 1ccfbc3 ? If we get rid of tens of if-elif-elif-elif in the poll function there? Not very cryptic, I hope :)

Comment on lines +92 to +124
"/api/devices/vitals": self.get_api_devices_vitals,
"/api/meters/aggregates": self.get_api_meters_aggregates,
"/api/operation": self.get_api_operation,
"/api/site_info": self.get_api_site_info,
"/api/site_info/site_name": self.get_api_site_info_site_name,
"/api/status": self.get_api_status,
"/api/system_status": self.get_api_system_status,
"/api/system_status/grid_status": self.get_api_system_status_grid_status,
"/api/system_status/soe": self.get_api_system_status_soe,
"/vitals": self.get_vitals,
# Possible Actions
"/api/login/Basic": self.api_login_basic,
"/api/logout": self.api_logout,
# Mock Actions
"/api/auth/toggle/supported": self.get_api_auth_toggle_supported,
"/api/customer": self.get_api_customer,
"/api/customer/registration": self.get_api_customer_registration,
"/api/installer": self.get_api_installer,
"/api/meters": self.get_api_meters,
"/api/meters/readings": self.get_api_unimplemented_timeout,
"/api/meters/site": self.get_api_meters_site,
"/api/meters/solar": self.get_unimplemented_api,
"/api/networks": self.get_api_unimplemented_timeout,
"/api/powerwalls": self.get_api_powerwalls,
"/api/site_info/grid_codes": self.get_api_unimplemented_timeout,
"/api/sitemaster": self.get_api_sitemaster,
"/api/solar_powerwall": self.get_api_solar_powerwall,
"/api/solars": self.get_api_solars,
"/api/solars/brands": self.get_api_solars_brands,
"/api/synchrometer/ct_voltage_references": self.get_api_synchrometer_ct_voltage_references,
"/api/system/update/status": self.get_api_system_update_status,
"/api/system_status/grid_faults": self.get_api_system_status_grid_faults,
"/api/troubleshooting/problems": self.get_api_troubleshooting_problems,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of if/elif/elif/elif/.../else we define a map with api -> function and then use it in the self.poll() function, making it compact and easy to extend.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have mixed feeling about that. I have started using that method for many of my smaller sets and find it cluttered and harder to read, especially for longer lists. I notice CoPilot prefers this.

A better option would be to move to routers (ala flask) and perhaps consider moving to asyncio / uvicorn. That would be a slightly bigger lift. :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continued... To be fair... willing to entertain it. I've been moving to this in other projects. Do we have any performance data or other indicators that this is a preferred path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely, it'll be faster to get a pointer to the required function with a key in the dictionary versus traversing all if and elif, but to me it also looks compact and more readable. As you may have noticed already I like to have small and short functions, I prefer those that fit on one screen :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better option would be to move to routers (ala flask) and perhaps consider moving to asyncio / uvicorn. That would be a slightly bigger lift. :)

Definitely, that's why we should take this big first step to decouple big functions into smaller class methods first, then we'll be able to transition into something else.

Also, once this is all reviewed and ironed out, we'll be able to plug in other tesla libraries if anything better comes into play. All we'll need to do is implement a few required methods. And then let users choose which way to interact with their powerwall/tesla gateway. But first, need to get rid of hard-coded logic here and there and make the whole thing a little bit more flexible, in my opinion.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Adding support for the official Tesla FleetAPI is a perfect example. Sold. ;)

Comment on lines +629 to +648
data = API_METERS_AGGREGATES_STUB
data['site'].update({
"last_communication_time": timestamp,
"instant_power": grid_power,
})
data['battery'].update({
"last_communication_time": timestamp,
"instant_power": battery_power,
"num_meters_aggregated": battery_count,
})
data['load'].update({
"last_communication_time": timestamp,
"instant_power": load_power,

})
data['solar'].update({
"last_communication_time": timestamp,
"instant_power": solar_power,
"num_meters_aggregated": solar_inverters,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved large dictionaries to a separate file with stubs and just update the fields we have information for.


return data

@not_implemented_mock_data
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a decorator here that warns users that fake/mock data is returned

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@@ -20,7 +20,7 @@

# Global Variables
AUTHFILE = ".pypowerwall.auth"
authpath = os.getenv("PW_AUTHPATH", "")
authpath = os.getenv("PW_AUTH_PATH", "")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was it! The setup works now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using: jasonacox/pypowerwall:0.8.0t51-beta2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, my bad, I mechanically replaced it as if that was added by me for local testing =(

@jasonacox
Copy link
Owner

Doing my final testing. @mcbirse if you have time, check to see if jasonacox/pypowerwall:0.8.0t51-beta2 solves the string errors.

@jasonacox
Copy link
Owner

Do we really need this or perhaps move this to DEBUG? This is going to be too noisy for cloud mode users of the proxy.

03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.

@emptywee
Copy link
Contributor Author

Do we really need this or perhaps move this to DEBUG? This is going to be too noisy for cloud mode users of the proxy.

03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:33 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:34 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:40:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.

Hmm, what if we print it once and suppress further?

@emptywee
Copy link
Contributor Author

Why do we feed proxy users in cloud mode with mock data, btw?

@jasonacox
Copy link
Owner

Hmm, what if we print it once and suppress further?

Actually, I think it would be better if it was included in the DEBUG line with the API information. Here is a snapshot of logs with a basic dashboard running (power flow animation):

03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_DATA data
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/system_status/grid_status
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_DATA data
03/24/2024 02:50:35 PM [proxy] [DEBUG] 172.18.0.4 "GET /soe HTTP/1.1" 200 -
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/system_status/soe
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_SUMMARY data
03/24/2024 02:50:35 PM [proxy] [DEBUG] 172.18.0.4 "GET /temps/pw HTTP/1.1" 200 -
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /vitals
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_CONFIG data
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_DATA data
03/24/2024 02:50:35 PM [proxy] [DEBUG] 172.18.0.4 "GET /strings HTTP/1.1" 200 -
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /vitals
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_CONFIG data
03/24/2024 02:50:35 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_DATA data
03/24/2024 02:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/system_status/grid_status HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/system_status/grid_status
03/24/2024 02:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/sitemaster HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/sitemaster
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/meters/aggregates HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/meters/aggregates
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_CONFIG data
03/24/2024 02:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/system_status/soe HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/system_status/soe
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_SUMMARY data
03/24/2024 02:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/powerwalls HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/powerwalls
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Retrieved SITE_DATA data
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Returning cached SITE_DATA data

We could just decorate the DEBUG line with "[mock data]" qualifier and turn

2:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/sitemaster HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/sitemaster
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API is using mock data in cloud mode.

into

2:50:36 PM [proxy] [DEBUG] 192.168.65.1 "GET /api/sitemaster HTTP/1.1" 200 -
03/24/2024 02:50:36 PM [pypowerwall.cloud.pypowerwall_cloud] [DEBUG]  -- cloud: Request for /api/sitemaster [mock data]

Why do we feed proxy users in cloud mode with mock data, btw?

The intent of cloud mode is to simulate local mode as a drop-in replacement. Tools built for local mode access to powerwall can use the same API even if their system doesn't have a local API (e.g. Powerwall 3).

@emptywee
Copy link
Contributor Author

@jasonacox
How about bf5f6ef ?

@jasonacox
Copy link
Owner

jasonacox commented Mar 24, 2024

That works! Proxy logs now using jasonacox/pypowerwall:0.8.0t51-beta3:

03/24/2024 03:31:24 PM [proxy] [INFO] pyPowerwall [0.8.0] Proxy Server [t51] - HTTP Port 8675
03/24/2024 03:31:24 PM [proxy] [INFO] pyPowerwall Proxy Started
03/24/2024 03:31:24 PM [proxy] [INFO] pyPowerwall Proxy Server - Cloud Mode
03/24/2024 03:31:25 PM [proxy] [INFO] Connected to Site ID 35...9 (Tesla Energy Gateway)
03/24/2024 03:31:32 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API [get_api_sitemaster] is using mock data in cloud mode. This message will be printed only once at the warning level.
03/24/2024 03:31:32 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API [get_api_powerwalls] is using mock data in cloud mode. This message will be printed only once at the warning level.
03/24/2024 03:31:32 PM [pypowerwall.cloud.pypowerwall_cloud] [WARNING] This API [get_api_auth_toggle_supported] is using mock data in cloud mode. This message will be printed only once at the warning level.

Tested on:
✅ Win11
✅ MacOS
✅ RPi
✅ Ubuntu Linux

Copy link
Owner

@jasonacox jasonacox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a pre-existing bug. Local systems without vitals would always return None instead of processing the battery blocks from system_status(). I saw this why doing python library tests for all functions in local and cloud mode.

@jasonacox
Copy link
Owner

New proxy container built with latest commit: jasonacox/pypowerwall:0.8.0t51-beta4

Functions tested (local and cloud mode):

import pypowerwall

pw = pypowerwall.Powerwall(host,password,email,timezone)

pw.poll()
pw.level()
pw.power()
pw.site()
pw.solar()
pw.battery()
pw.load()
pw.grid()
pw.home()
pw.vitals()
pw.strings()
pw.din()
pw.uptime()
pw.version()
pw.status()
pw.site_name()
pw.temps()
pw.alerts()
pw.system_status()
pw.battery_blocks()
pw.grid_status()
pw.is_connected()
pw.get_reserve()
pw.get_time_remaining()

@emptywee
Copy link
Contributor Author

Kind like how it's working out :)

@jasonacox
Copy link
Owner

Thanks again for this @emptywee ! - I'm ready to merge unless either of you spot anything.

@mcbirse if you have time, check to see if jasonacox/pypowerwall:0.8.0t51-beta4 solves the string errors. I'll merge tomorrow if all goes well.

@emptywee
Copy link
Contributor Author

Thanks again for this @emptywee ! - I'm ready to merge unless either of you spot anything.

@mcbirse if you have time, check to see if jasonacox/pypowerwall:0.8.0t51-beta4 solves the string errors. I'll merge tomorrow if all goes well.

Happy to help!

Do you want to keep it as something that only polls data? I've already extended the 0.7.x version of your library with a post method to change battery reserve settings, if you are cool with it, I'll open a PR when I adapt it for 0.8.0. Unfortunately, local mode doesn't allow you to control battery reserve threshold anymore (starting from some firmware), but it is what it is.

@jasonacox
Copy link
Owner

post method to change battery reserve settings

Yes! ❤️ We have the external tools (scripts for reserve and mode) but there is no reason we couldn't include it in pypowerwall. It makes more sense with the cloud support now. Also, we can make it work via command line, expanding on your argparse work. ;)

@emptywee
Copy link
Contributor Author

post method to change battery reserve settings

Yes! ❤️ We have the external tools (scripts for reserve and mode) but there is no reason we couldn't include it in pypowerwall. It makes more sense with the cloud support now. Also, we can make it work via command line, expanding on your argparse work. ;)

Sweet! But for now let's focus on merging this in and let folks test it in the wild :)

pypowerwall/__main__.py Outdated Show resolved Hide resolved
@mcbirse
Copy link
Collaborator

mcbirse commented Mar 25, 2024

@mcbirse if you have time, check to see if jasonacox/pypowerwall:0.8.0t51-beta4 solves the string errors. I'll merge tomorrow if all goes well.

@emptywee and @jasonacox - great work on this! I have re-tested and no longer have an exception raised for strings or logging spam from that. Functionally all appears to be working well, in both local and cloud mode.

I did note the following though, and am wondering if it should be handled differently?

On my Powerwall, requests to /api/solar_powerwall return an empty response (not a 404 like requests to /api/devices/vitals). It seems only PW+ owners (and maybe PW3) can utilise /api/solar_powerwall. Strange that I do not get a 404 though.

Perhaps it should be treated like the "vitals" call and give an error once, then get disabled? Not sure.

I did also test the api call directly to the TEG installer WiFi, to see if I get any data, which you can see in the logs below (I have bridged 192.168.91.1 onto my local LAN, no headache of multi-homed host setup 😉 ).

03/25/2024 08:36:38 PM [proxy] [DEBUG] 172.18.0.1 "GET /api/solar_powerwall HTTP/1.1" 200 -
03/25/2024 08:36:38 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 08:36:48 PM [proxy] [DEBUG] 172.18.0.1 "GET /strings HTTP/1.1" 200 -
03/25/2024 08:36:48 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 08:36:58 PM [proxy] [DEBUG] 172.18.0.1 "GET /alerts/pw HTTP/1.1" 200 -
03/25/2024 08:36:58 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall

Not a big issue, but the calls telegraf makes to /strings and /alerts/pw means it will show in the logs all the time if DEBUG is enabled, example below. Kind of seems like an error/notification you would want to see only once like with vitals?

03/25/2024 09:09:08 PM [proxy] [INFO] Connected to Energy Gateway 192.168.91.1 (My home)
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /freq HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /temps/pw HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /strings HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /soe HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /aggregates HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /alerts/pw HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [proxy] [DEBUG] 172.18.0.1 "GET /pod HTTP/1.1" 200 -
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] 404 Powerwall API not found at https://192.168.91.1/api/devices/vitals
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] 404 Powerwall API not found at https://192.168.91.1/api/devices/vitals
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] 404 Powerwall API not found at https://192.168.91.1/api/devices/vitals
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] 404 Powerwall API not found at https://192.168.91.1/api/devices/vitals
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] 404 Powerwall API not found at https://192.168.91.1/api/devices/vitals
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] Firmware 240400 detected - Does not support vitals API - disabling.
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] Firmware 240400 detected - Does not support vitals API - disabling.
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [ERROR] Firmware 240400 detected - Does not support vitals API - disabling.
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 09:09:10 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 09:09:11 PM [pypowerwall.local.pypowerwall_local] [ERROR] Firmware 240400 detected - Does not support vitals API - disabling.
03/25/2024 09:09:11 PM [pypowerwall.local.pypowerwall_local] [ERROR] Firmware 240400 detected - Does not support vitals API - disabling.
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /freq HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /temps/pw HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /strings HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /soe HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /aggregates HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /alerts/pw HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [proxy] [DEBUG] 172.18.0.1 "GET /pod HTTP/1.1" 200 -
03/25/2024 09:09:15 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 09:09:15 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /soe HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /aggregates HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /temps/pw HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /strings HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /alerts/pw HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /freq HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [proxy] [DEBUG] 172.18.0.1 "GET /pod HTTP/1.1" 200 -
03/25/2024 09:09:20 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall
03/25/2024 09:09:20 PM [pypowerwall.local.pypowerwall_local] [DEBUG] Empty response from Powerwall at https://192.168.91.1/api/solar_powerwall

Thoughts?

BTW because of the lack of the solar_powerwalls api, I do not get any alerts in local mode (not even mock alerts like I do in cloud mode such as the SystemConnectedToGrid).

All good to merge either way - seems to be working well. 👍

@emptywee
Copy link
Contributor Author

emptywee commented Mar 25, 2024

@mcbirse your setup seems a lot like mine. I've got a tesla gateway, enphase micro inverters, powerwall2 batteries. I'm getting same empty responses here and there with 200 OK status codes.

I think we could discuss how the library should behave and treat them in the next iteration of changes.

Maybe even introduce a hybrid mode? Where it goes for data to cloud if not available in local, all being automatically and transparent for users?

Just a thought.

@jasonacox
Copy link
Owner

Thanks @mcbirse ! We could definitely add some Alerts. I started an issue jasonacox/Powerwall-Dashboard#457
I almost added to this release but don't want to delay getting this out. Scope for the next dot release. ;-)

Also, in the past, I had a few versions with memory leaks. This release looks good.

image

Past 24 hours.

Here we go... 0.8.0 🚀

@jasonacox jasonacox merged commit 19a277b into jasonacox:main Mar 26, 2024
12 checks passed
@emptywee
Copy link
Contributor Author

Hooray! We finally did it! I'll drink to that!

@jasonacox
Copy link
Owner

Thanks again @emptywee !! Yes, Cheers 🍻

Thanks for the great work. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants