Skip to content

Commit

Permalink
correct fix for #31
Browse files Browse the repository at this point in the history
  • Loading branch information
patman15 committed Jul 3, 2024
1 parent 972d77b commit c532dae
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/bms_ble/plugins/ogt_bms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, ble_device: BLEDevice, reconnect: bool = False) -> None:
self._ble_device.name[10:],
self._key,
)
self._values: BMSsample = {} # dictionary of BMS return values
self._values: BMSsample # dictionary of BMS return values
self._REGISTERS: dict[int, tuple[str, int, Callable[[int], int | float] | None]]
if self._type == "A":
self._REGISTERS = {
Expand Down Expand Up @@ -98,7 +98,13 @@ def __init__(self, ble_device: BLEDevice, reconnect: bool = False) -> None:
23: (ATTR_CYCLES, 2, None),
}
# add cell voltage registers, note need to be last!
self._REGISTERS.update({63-reg: (f"{KEY_CELL_VOLTAGE}{reg+1}", 2, lambda x: float(x)/1000) for reg in range(16)})
self._REGISTERS.update(
{
63
- reg: (f"{KEY_CELL_VOLTAGE}{reg+1}", 2, lambda x: float(x) / 1000)
for reg in range(16)
}
)
self._HEADER = "+R16"
else:
self._REGISTERS = {}
Expand Down Expand Up @@ -134,7 +140,7 @@ async def async_update(self) -> BMSsample:

await self._connect()

self._values.clear()
self._values = {}
for key in list(self._REGISTERS):
await self._read(key)
try:
Expand All @@ -145,7 +151,8 @@ async def async_update(self) -> BMSsample:
break

self.calc_values(
self._values, {ATTR_CYCLE_CAP, ATTR_POWER, ATTR_BATTERY_CHARGING, ATTR_DELTA_VOLTAGE}
self._values,
{ATTR_CYCLE_CAP, ATTR_POWER, ATTR_BATTERY_CHARGING, ATTR_DELTA_VOLTAGE},
)

if self._reconnect:
Expand Down

0 comments on commit c532dae

Please sign in to comment.