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

v0.12.2 - TEDAPI Cache Expiration Fix #123

Merged
merged 4 commits into from
Dec 31, 2024
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
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# RELEASE NOTES

## v0.12.2 - Cache Expiration Fix

* Fix bug in cache expiration timeout code that was not honoring pwcacheexpire setting. Raised by @erikgiesele in https://github.com/jasonacox/pypowerwall/issues/122 - PW_CACHE_EXPIRE=0 not possible? (Proxy)
* Add WARNING log in proxy for settings below 5s.
* Change TEDAPI config default timeout from 300s to 5s and link to pwcacheexpire setting.

## v0.12.1 - Scanner Update

Expand Down
9 changes: 9 additions & 0 deletions proxy/RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## pyPowerwall Proxy Release Notes

### Proxy t67 (26 Dec 2024)

* pyPowerwall v0.12.2 - Fix bug in cache timeout code that was not honoring pwcacheexpire setting. Raised by @erikgiesele in https://github.com/jasonacox/pypowerwall/issues/122 - PW_CACHE_EXPIRE=0 not possible? (Proxy)
* Add WARNING log in proxy for settings below 5s.

### Proxy t66

* pyPowerwall v0.12.0

### Proxy t65 (22 Nov 2024)

* Add `PW_NEG_SOLAR` config option and logic to remove negative solar values for /aggregates and /csv APIs
Expand Down
2 changes: 1 addition & 1 deletion proxy/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pypowerwall==0.12.1
pypowerwall==0.12.2
bs4==0.0.2
7 changes: 5 additions & 2 deletions proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import pypowerwall
from pypowerwall import parse_version

BUILD = "t66"
BUILD = "t67"
ALLOWLIST = [
'/api/status', '/api/site_info/site_name', '/api/meters/site',
'/api/meters/solar', '/api/sitemaster', '/api/powerwalls',
Expand Down Expand Up @@ -171,13 +171,16 @@
(pypowerwall.version, BUILD, httptype, port))
log.info("pyPowerwall Proxy Started")

# Check for cache expire time limit below 5s
if cache_expire < 5:
log.warning("Cache expiration set below 5s (PW_CACHE_EXPIRE=%d)" % cache_expire)

# Signal handler - Exit on SIGTERM
# noinspection PyUnusedLocal
def sig_term_handle(signum, frame):
raise SystemExit


# Register signal handler
signal.signal(signal.SIGTERM, sig_term_handle)


Expand Down
3 changes: 2 additions & 1 deletion pypowerwall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
from typing import Union, Optional
import time

version_tuple = (0, 12, 1)
version_tuple = (0, 12, 2)
version = __version__ = '%d.%d.%d' % version_tuple
__author__ = 'jasonacox'

Expand Down Expand Up @@ -244,6 +244,7 @@ def connect(self, retry=False) -> bool:
log.debug("TEDAPI ** full **")
self.tedapi_mode = "full"
self.client = PyPowerwallTEDAPI(self.gw_pwd, pwcacheexpire=self.pwcacheexpire,
pwconfigexpire=self.pwcacheexpire,
timeout=self.timeout, host=self.host)
else:
self.tedapi_mode = "hybrid"
Expand Down
4 changes: 2 additions & 2 deletions pypowerwall/tedapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Class:
TEDAPI(gw_pwd: str, debug: bool = False, pwcacheexpire: int = 5, timeout: int = 5,
pwconfigexpire: int = 300, host: str = GW_IP) - Initialize TEDAPI
pwconfigexpire: int = 5, host: str = GW_IP) - Initialize TEDAPI

Parameters:
gw_pwd - Powerwall Gateway Password
Expand Down Expand Up @@ -84,7 +84,7 @@ def lookup(data, keylist):
# TEDAPI Class
class TEDAPI:
def __init__(self, gw_pwd: str, debug: bool = False, pwcacheexpire: int = 5, timeout: int = 5,
pwconfigexpire: int = 300, host: str = GW_IP) -> None:
pwconfigexpire: int = 5, host: str = GW_IP) -> None:
self.debug = debug
self.pwcachetime = {} # holds the cached data timestamps for api
self.pwcacheexpire = pwcacheexpire # seconds to expire status cache
Expand Down
5 changes: 3 additions & 2 deletions pypowerwall/tedapi/pypowerwall_tedapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def compute_LL_voltage(v1n, v2n, v3n=None):
# noinspection PyMethodMayBeStatic
class PyPowerwallTEDAPI(PyPowerwallBase):
def __init__(self, gw_pwd: str, debug: bool = False, pwcacheexpire: int = 5, timeout: int = 5,
pwconfigexpire: int = 300, host: str = GW_IP) -> None:
pwconfigexpire: int = 5, host: str = GW_IP) -> None:
super().__init__("[email protected]")
self.tedapi = None
self.timeout = timeout
Expand All @@ -61,7 +61,8 @@ def __init__(self, gw_pwd: str, debug: bool = False, pwcacheexpire: int = 5, tim
self.auth = {'AuthCookie': 'local', 'UserRecord': 'local'} # Bogus local auth record

# Initialize TEDAPI
self.tedapi = TEDAPI(self.gw_pwd, debug=self.debug, host=self.host, timeout=self.timeout)
self.tedapi = TEDAPI(self.gw_pwd, debug=self.debug, host=self.host, timeout=self.timeout,
pwcacheexpire=self.pwcacheexpire, pwconfigexpire=self.pwconfigexpire)
log.debug(f" -- tedapi: Attempting to connect to {self.host}...")
if not self.tedapi.connect():
raise ConnectionError(f"Unable to connect to Tesla TEDAPI at {self.host}")
Expand Down
Loading