Skip to content

Commit

Permalink
feat #57: Expose more low level information of discrete batteries (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrester authored Jan 15, 2024
1 parent abd7cbb commit a643f31
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## [0.5.1]

- Use orjson for parsing json
- Use orjson for parsing json (https://github.com/jrester/tesla_powerwall/pull/59)
- Expose low level information for each battery pack (https://github.com/jrester/tesla_powerwall/pull/60)

## [0.5.0]

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ batteries[0].energy_discharged
#=> 4659550 (Wh)
batteries[0].wobble_detected
#=> False
batteries[0].p_out
#=> 260
batteries[0].q_out
#=> -1080
batteries[0].v_out
#=> 245.70
batteries[0].f_out
#=> 49.953
batteries[0].i_out
#=> -7.4
batteries[0].grid_state
#=> GridState.COMPLIANT
```

### Powerwall Status
Expand Down
20 changes: 19 additions & 1 deletion tesla_powerwall/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from datetime import datetime, timedelta
from typing import Any, Dict, List, Optional

from .const import DEFAULT_KW_ROUND_PERSICION, DeviceType, MeterType, Roles
from .const import (
DEFAULT_KW_ROUND_PERSICION,
DeviceType,
GridState,
MeterType,
Roles,
)
from .error import MeterNotAvailableError
from .helpers import convert_to_kw

Expand Down Expand Up @@ -273,6 +279,12 @@ class BatteryResponse(ResponseBase):
energy_remaining: int
capacity: int
wobble_detected: bool
p_out: int
q_out: int
v_out: float
f_out: float
i_out: float
grid_state: GridState

@staticmethod
def from_dict(src: dict) -> "BatteryResponse":
Expand All @@ -285,4 +297,10 @@ def from_dict(src: dict) -> "BatteryResponse":
energy_remaining=src["nominal_energy_remaining"],
capacity=src["nominal_full_pack_energy"],
wobble_detected=src["wobble_detected"],
p_out=src["p_out"],
q_out=src["q_out"],
v_out=src["v_out"],
f_out=src["f_out"],
i_out=src["i_out"],
grid_state=GridState(src["pinv_grid_state"]),
)
9 changes: 8 additions & 1 deletion tests/unit/test_powerwall.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tesla_powerwall import (
API,
DeviceType,
GridState,
GridStatus,
IslandMode,
MeterDetailsReadings,
Expand All @@ -18,12 +19,12 @@
MetersAggregatesResponse,
MeterType,
MissingAttributeError,
OperationMode,
Powerwall,
SiteMasterResponse,
assert_attribute,
convert_to_kw,
)
from tesla_powerwall.const import OperationMode
from tests.unit import (
ENDPOINT,
ENDPOINT_HOST,
Expand Down Expand Up @@ -249,6 +250,12 @@ async def test_system_status(self):
self.assertEqual(batteries[0].energy_charged, 5525740)
self.assertEqual(batteries[0].energy_discharged, 4659550)
self.assertEqual(batteries[0].wobble_detected, False)
self.assertEqual(batteries[0].p_out, -1830)
self.assertEqual(batteries[0].i_out, 39)
self.assertEqual(batteries[0].f_out, 50.067)
self.assertEqual(batteries[0].q_out, 30)
self.assertEqual(batteries[0].v_out, 226.60000000000002)
self.assertEqual(batteries[0].grid_state, GridState.COMPLIANT)
self.aresponses.assert_plan_strictly_followed()

async def test_islanding_mode_offgrid(self):
Expand Down

0 comments on commit a643f31

Please sign in to comment.