updated pack polling
This commit is contained in:
1 parent
6e433e3551
commit
b548528085
3 files changed
+42
-20
No files matched your search
@@ -43,6 +43,11 @@ class BluettiDevice:
|
|||||||
"""The address ranges that are writable"""
|
"""The address ranges that are writable"""
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pack_num_field(self) -> List[ReadHoldingRegisters]:
|
||||||
|
"""The address 'range' of the pack num"""
|
||||||
|
return []
|
||||||
|
|
||||||
def has_field(self, field: str):
|
def has_field(self, field: str):
|
||||||
return any(f.name == field for f in self.struct.fields)
|
return any(f.name == field for f in self.struct.fields)
|
||||||
|
|
||||||
|
|||||||
@@ -56,3 +56,9 @@ class ProtocolV1Device(BluettiDevice):
|
|||||||
@property
|
@property
|
||||||
def writable_ranges(self) -> List[range]:
|
def writable_ranges(self) -> List[range]:
|
||||||
return [range(3006, 3009)]
|
return [range(3006, 3009)]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pack_num_field(self) -> List[ReadHoldingRegisters]:
|
||||||
|
return [
|
||||||
|
ReadHoldingRegisters(3006, 1),
|
||||||
|
]
|
||||||
@@ -97,20 +97,45 @@ class DeviceReader:
|
|||||||
_LOGGER.warning("Got a parse exception")
|
_LOGGER.warning("Got a parse exception")
|
||||||
|
|
||||||
# Execute pack polling commands
|
# Execute pack polling commands
|
||||||
if len(pack_commands) > 0:
|
if len(pack_commands) > 0 and len(self.bluetti_device.pack_num_field) == 1:
|
||||||
_LOGGER.debug("Polling battery packs")
|
_LOGGER.debug("Polling battery packs")
|
||||||
for pack in range(1, self.bluetti_device.pack_num_max + 1):
|
for pack in range(1, self.bluetti_device.pack_num_max + 1):
|
||||||
|
_LOGGER.debug("Setting pack_num to %i", pack)
|
||||||
|
|
||||||
# Set current pack number
|
# Set current pack number
|
||||||
await self._async_send_command(
|
command = self.bluetti_device.build_setter_command(
|
||||||
self.bluetti_device.build_setter_command(
|
|
||||||
"pack_num", pack
|
"pack_num", pack
|
||||||
)
|
)
|
||||||
|
await self._async_send_command(command)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Read pack_num field
|
||||||
|
command = self.bluetti_device.pack_num_field[0]
|
||||||
|
body = command.parse_response(
|
||||||
|
await self._async_send_command(command)
|
||||||
)
|
)
|
||||||
|
_LOGGER.debug("Raw data: %s", body)
|
||||||
|
parsed = self.bluetti_device.parse(
|
||||||
|
command.starting_address, body
|
||||||
|
)
|
||||||
|
_LOGGER.debug("Parsed data: %s", parsed)
|
||||||
|
|
||||||
# We need to wait after switching packs for the data to be available
|
# Check pack number
|
||||||
await asyncio.sleep(5)
|
pack_number = parsed.get("pack_num")
|
||||||
|
if (
|
||||||
|
not isinstance(pack_number, int)
|
||||||
|
or pack_number != pack
|
||||||
|
):
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Parsed pack_num(%s) does not match expected '%s', Skipping pack (maybe you don't have this connected)",
|
||||||
|
pack_number,
|
||||||
|
pack,
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
pack_ok = False
|
except ParseError:
|
||||||
|
_LOGGER.warning("Got a pack parse exception, Skipping pack")
|
||||||
|
continue
|
||||||
|
|
||||||
for command in pack_commands:
|
for command in pack_commands:
|
||||||
# Request & parse result for each pack
|
# Request & parse result for each pack
|
||||||
@@ -123,20 +148,6 @@ class DeviceReader:
|
|||||||
)
|
)
|
||||||
_LOGGER.debug("Parsed data: %s", parsed)
|
_LOGGER.debug("Parsed data: %s", parsed)
|
||||||
|
|
||||||
if not pack_ok: # Only check this once
|
|
||||||
pack_number = parsed.get("pack_num")
|
|
||||||
if (
|
|
||||||
not isinstance(pack_number, int)
|
|
||||||
or pack_number != pack
|
|
||||||
):
|
|
||||||
_LOGGER.debug(
|
|
||||||
"Parsed pack_num(%s) does not match expected '%s'",
|
|
||||||
pack_number,
|
|
||||||
pack,
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
pack_ok = True
|
|
||||||
|
|
||||||
for key, value in parsed.items():
|
for key, value in parsed.items():
|
||||||
parsed_data.update({key + str(pack): value})
|
parsed_data.update({key + str(pack): value})
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user