jasonacox / pypowerwall

Python API for Tesla Powerwall and Solar Power Data
MIT License
120 stars 21 forks source link

Add Bearer Token Auth #63

Closed jasonacox closed 6 months ago

jasonacox commented 6 months ago

This release adds the ability to use a Bearer Token for auth for local Powerwall gateway API calls. This is selectable by defining authmode='token' in the initialization. The default mode uses the existing AuthCookie and UserRecord method.

import pypowerwall

pw = pypowerwall.Powerwall(HOST, PASSWORD, EMAIL, TIMEZONE, authmode="token")

This could potentially help with Issue #57 (untested)

mcbirse commented 6 months ago

Hi Jason - is it okay if I push some unrelated minor tweaks for pypowerwall as part of this PR before it gets merge? Just a thought to reduce the number of updates that need to pushed to PyPI and Docker Hub.

Mostly very minor - just to neaten up the cloud mode setup output...

mcbirse commented 6 months ago

Oh, I did also have a thought to make a change to the "scan" option however, so that it could accept an additional argument - that being able to pass the users current host IP address.

I was thinking offering a "scan" of the users network during the setup process might be good... but as that would be run using "docker exec" and inside the container, it does not detect the correct network. Could be resolved easily by passing the current IP address of the host from the setup script and base the network detection on that instead.

jasonacox commented 6 months ago

is it okay if I push some unrelated minor tweaks for pypowerwall as part of this PR

Absolutely! Please do.

change to the "scan" option ... offering a "scan" of the users network during the setup process

That's brilliant. Yes please. I never thought of that but you are right, it would be a nice addition.

mcbirse commented 6 months ago

Hope that small addition is okay...

I was looking at the setup script changes for Powerwall-Dashboard, and we could now include something like this to run a network scan:

docker exec -it pypowerwall python -m pypowerwall scan -ip=$(ip route get 8.8.8.8 | awk '{ print $NF }')
jasonacox commented 6 months ago

v0.7.4 Merged and uploaded: