Skip to content

Commit

Permalink
v0.1.4 - Battery Level Percentage Scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Jan 9, 2022
1 parent c2e2fac commit 1519cd4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# RELEASE NOTES

## v0.1.4 - TBD (unreleased)
## v0.1.4 - Battery Level Percentage Scaling

* Added Tesla App style Battery Level Conversion option to `level()`
* PyPI 0.1.4
* Changed "Network Scan" default timeout to 400ms for better detection.
* Added Tesla App style "Battery Level Percentage" Conversion option to `level()` to convert the level reading to the 95% scale used by the App. Ths converts the battery level percentage to be consistent with the Tesla App:

```python
>>> pw.level(appvalue=True)
>>> pw.level(scale=True)
39.971429212508326
>>> pw.level()
42.972857751882906
Expand Down
8 changes: 4 additions & 4 deletions pypowerwall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import sys
from . import tesla_pb2 # Protobuf definition for vitals

version_tuple = (0, 1, 3)
version_tuple = (0, 1, 4)
version = __version__ = '%d.%d.%d' % version_tuple
__author__ = 'jasonacox'

Expand Down Expand Up @@ -180,20 +180,20 @@ def poll(self, api='/api/site_info/site_name', jsonformat=False, raw=False, recu
else:
return payload

def level(self, appvalue=False):
def level(self, scale=False):
"""
Battery Level Percentage
Args:
appvalue = If True, convert battery level to app scale value
scale = If True, convert battery level to app scale value
Note: Tesla App reserves 5% of battery = ( (batterylevel / 0.95) - (5 / 0.95) )
"""
# Return power level percentage for battery
level = 0
payload = self.poll('/api/system_status/soe', jsonformat=True)
if(payload is not None and 'percentage' in payload):
level = payload['percentage']
if appvalue:
if scale:
return ((level / 0.95) - (5 / 0.95))
else:
return level
Expand Down

0 comments on commit 1519cd4

Please sign in to comment.