Skip to content

Commit

Permalink
Allow no cache option with pwcacheexpire = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Dec 26, 2023
1 parent 36a08ac commit 0bce44e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pypowerwall/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def get_battery(self):
return None
# Check to see if we have cached data
if 'get_battery' in self.pwcache:
if self.pwcachetime['get_battery'] > time.time() - self.pwcacheexpire - 1:
ttl = self.pwcacheexpire + 1 if self.pwcacheexpire > 0 else 0
if self.pwcachetime['get_battery'] > time.time() - ttl:
return self.pwcache['get_battery']
# GET api/1/energy_sites/{site_id}/site_status
response = self.site.api("SITE_SUMMARY",language="en")
Expand Down Expand Up @@ -358,7 +359,8 @@ def get_site_config(self):
return None
# Check to see if we have cached data
if 'get_site_config' in self.pwcache:
if self.pwcachetime['get_site_config'] > time.time() - SITE_CONFIG_TTL:
ttl = SITE_CONFIG_TTL if self.pwcacheexpire > 0 else 0
if self.pwcachetime['get_site_config'] > time.time() - ttl:
return self.pwcache['get_site_config']
# GET api/1/energy_sites/{site_id}/site_info
response = self.site.api("SITE_CONFIG",language="en")
Expand All @@ -376,7 +378,8 @@ def get_time_remaining(self):
return None
# Check to see if we have cached data
if 'get_time_remaining' in self.pwcache:
if self.pwcachetime['get_time_remaining'] > time.time() - self.pwcacheexpire - 3:
ttl = self.pwcacheexpire + 3 if self.pwcacheexpire > 0 else 0
if self.pwcachetime['get_time_remaining'] > time.time() - ttl:
return self.pwcache['get_time_remaining']
# GET api/1/energy_sites/{site_id}/backup_time_remaining
response = self.site.api("ENERGY_SITE_BACKUP_TIME_REMAINING")
Expand Down

0 comments on commit 0bce44e

Please sign in to comment.