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 Seplos v2 BMS support #115

Merged
merged 24 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixed tests
  • Loading branch information
patman15 committed Dec 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 56abcf4ecbf1e5da56717d650ee182fccdf60b92
42 changes: 21 additions & 21 deletions custom_components/bms_ble/const.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
ATTR_VOLTAGE,
)

BMS_TYPES: Final = [
BMS_TYPES: Final[list[str]] = [
"cbtpwr_bms",
"daly_bms",
"ective_bms",
@@ -21,29 +21,29 @@
"seplos_bms",
"seplos_v2_bms",
"dpwrcore_bms", # only name filter
# "jbd_bms", # only UUID filter
"jbd_bms", # only UUID filter
] # available BMS types
DOMAIN: Final = "bms_ble"
DOMAIN: Final[str] = "bms_ble"
LOGGER: Final = logging.getLogger(__package__)
UPDATE_INTERVAL: Final = 30 # [s]
UPDATE_INTERVAL: Final[int] = 30 # [s]

# attributes (do not change)
ATTR_CELL_VOLTAGES: Final = "cell_voltages" # [V]
ATTR_CURRENT: Final = "current" # [A]
ATTR_CYCLE_CAP: Final = "cycle_capacity" # [Wh]
ATTR_CYCLE_CHRG: Final = "cycle_charge" # [Ah]
ATTR_CYCLES: Final = "cycles" # [#]
ATTR_DELTA_VOLTAGE: Final = "delta_voltage" # [V]
ATTR_LQ: Final = "link_quality" # [%]
ATTR_POWER: Final = "power" # [W]
ATTR_RSSI: Final = "rssi" # [dBm]
ATTR_RUNTIME: Final = "runtime" # [s]
ATTR_TEMP_SENSORS: Final = "temperature_sensors" # [°C]
ATTR_CELL_VOLTAGES: Final[str] = "cell_voltages" # [V]
ATTR_CURRENT: Final[str] = "current" # [A]
ATTR_CYCLE_CAP: Final[str] = "cycle_capacity" # [Wh]
ATTR_CYCLE_CHRG: Final[str] = "cycle_charge" # [Ah]
ATTR_CYCLES: Final[str] = "cycles" # [#]
ATTR_DELTA_VOLTAGE: Final[str] = "delta_voltage" # [V]
ATTR_LQ: Final[str] = "link_quality" # [%]
ATTR_POWER: Final[str] = "power" # [W]
ATTR_RSSI: Final[str] = "rssi" # [dBm]
ATTR_RUNTIME: Final[str] = "runtime" # [s]
ATTR_TEMP_SENSORS: Final[str] = "temperature_sensors" # [°C]

# temporary dictionary keys (do not change)
KEY_CELL_COUNT: Final = "cell_count" # [#]
KEY_CELL_VOLTAGE: Final = "cell#" # [V]
KEY_DESIGN_CAP: Final = "design_capacity" # [Ah]
KEY_PACK_COUNT: Final = "pack_count" # [#]
KEY_TEMP_SENS: Final = "temp_sensors" # [#]
KEY_TEMP_VALUE: Final = "temp#" # [°C]
KEY_CELL_COUNT: Final[str] = "cell_count" # [#]
KEY_CELL_VOLTAGE: Final[str] = "cell#" # [V]
KEY_DESIGN_CAP: Final[str] = "design_capacity" # [Ah]
KEY_PACK_COUNT: Final[str] = "pack_count" # [#]
KEY_TEMP_SENS: Final[str] = "temp_sensors" # [#]
KEY_TEMP_VALUE: Final[str] = "temp#" # [°C]
11 changes: 4 additions & 7 deletions custom_components/bms_ble/plugins/seplos_v2_bms.py
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ class BMS(BaseBMS):
_CMD_VER: Final[int] = 0x10
_RSP_VER: Final[int] = 0x14
_INFO_LEN: Final[int] = 10 # minimal frame length
_CELLS_POS: Final[int] = 9
_MAX_SUBS: Final[int] = 15
_FIELDS: Final[
list[tuple[str, int, int, int, bool, Callable[[int], int | float]]]
@@ -186,15 +185,13 @@ def _cell_voltages(data: bytearray, offset: int = 0) -> dict[str, float]:
return {
f"{KEY_CELL_VOLTAGE}{idx+offset}": float(
int.from_bytes(
data[
BMS._CELLS_POS + 1 + idx * 2 : BMS._CELLS_POS + 1 + idx * 2 + 2
],
data[10 + idx * 2 : 10 + idx * 2 + 2],
byteorder="big",
signed=False,
)
)
/ 1000
for idx in range(data[BMS._CELLS_POS])
for idx in range(data[9])
}

async def _async_update(self) -> BMSsample:
@@ -207,7 +204,7 @@ async def _async_update(self) -> BMSsample:
if cmd not in self._data_final:
return {}

result = BMS._decode_data(self._data_final)
result: BMSsample = BMS._decode_data(self._data_final)

total_cells: int = 0
for pack in range(int(result.get(KEY_PACK_COUNT, 0) + 1)):
@@ -225,7 +222,7 @@ async def _async_update(self) -> BMSsample:
round(max(pack_cells.values()) - min(pack_cells.values()), 3),
)
}
total_cells += self._data_final[0x61][BMS._CELLS_POS]
total_cells += self._data_final[0x61][9]

self._data_final.clear()

8 changes: 4 additions & 4 deletions tests/test_seplos_v2_bms.py
Original file line number Diff line number Diff line change
@@ -168,13 +168,13 @@ async def test_update(monkeypatch, reconnect_fixture) -> None:
"cell_count": 16,
"temp_sensors": 6,
"voltage": 53.0,
"current": 2.15,
"current": 21.5,
"battery_level": 52.0,
"cycle_charge": 43.72,
"cycle_charge": 437.2,
"cycles": 113,
"temperature": 22.55,
"cycle_capacity": 2317.16,
"power": 113.95,
"cycle_capacity": 23171.6,
"power": 1139.5,
"battery_charging": True,
"cell#0": 3.312,
"cell#1": 3.313,
Loading