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

Add battery percent charged calculation #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ batteries[0].i_out
#=> -7.4
batteries[0].grid_state
#=> GridState.COMPLIANT
batteries[0].percent_charged
#=> 52.58
```

### Powerwall Status
Expand Down
6 changes: 6 additions & 0 deletions tesla_powerwall/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,14 @@ class BatteryResponse(ResponseBase):
f_out: float
i_out: float
grid_state: GridState
percent_charged: float

@staticmethod
def from_dict(src: dict) -> "BatteryResponse":
percent_charged = (
100.0 * src["nominal_energy_remaining"] / src["nominal_full_pack_energy"]
)

return BatteryResponse(
src,
part_number=src["PackagePartNumber"],
Expand All @@ -303,4 +308,5 @@ def from_dict(src: dict) -> "BatteryResponse":
f_out=src["f_out"],
i_out=src["i_out"],
grid_state=GridState(src["pinv_grid_state"]),
percent_charged=percent_charged,
)
1 change: 1 addition & 0 deletions tests/integration/test_powerwall.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async def test_batteries(self) -> None:
battery.capacity
battery.part_number
battery.serial_number
battery.percent_charged

async def test_grid_status(self) -> None:
grid_status = await self.powerwall.get_grid_status()
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_powerwall.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ async def test_system_status(self):
self.assertEqual(batteries[0].q_out, 30)
self.assertEqual(batteries[0].v_out, 226.60000000000002)
self.assertEqual(batteries[0].grid_state, GridState.COMPLIANT)
self.assertEqual(batteries[0].percent_charged, 100.0 * 7378 / 14031)
self.aresponses.assert_plan_strictly_followed()

async def test_islanding_mode_offgrid(self):
Expand Down