fix pack polling
This commit is contained in:
1 parent
c3bfad0ea6
commit
6be2abaaf2
10 files changed
+16
-41
No files matched your search
@@ -45,7 +45,7 @@ class BluettiDevice:
|
||||
|
||||
@property
|
||||
def pack_num_field(self) -> List[ReadHoldingRegisters]:
|
||||
"""The address 'range' of the pack num"""
|
||||
"""The address 'range' of the pack num result. Matches pack_num_result"""
|
||||
return []
|
||||
|
||||
def has_field(self, field: str):
|
||||
|
||||
@@ -60,5 +60,5 @@ class ProtocolV1Device(BluettiDevice):
|
||||
@property
|
||||
def pack_num_field(self) -> List[ReadHoldingRegisters]:
|
||||
return [
|
||||
ReadHoldingRegisters(3006, 1),
|
||||
ReadHoldingRegisters(96, 1),
|
||||
]
|
||||
@@ -106,36 +106,11 @@ class DeviceReader:
|
||||
command = self.bluetti_device.build_setter_command(
|
||||
"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)
|
||||
|
||||
# Check pack number
|
||||
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
|
||||
|
||||
except ParseError:
|
||||
_LOGGER.warning("Got a pack parse exception, Skipping pack")
|
||||
continue
|
||||
body = command.parse_response(
|
||||
await self._async_send_command(command)
|
||||
)
|
||||
_LOGGER.debug("Raw data set: %s", body)
|
||||
# b'\x00\x02' b'\x00\x03' here (seems like result)
|
||||
|
||||
for command in pack_commands:
|
||||
# Request & parse result for each pack
|
||||
@@ -198,9 +173,9 @@ class DeviceReader:
|
||||
return cast(bytes, res)
|
||||
|
||||
except TimeoutError:
|
||||
_LOGGER.warning("Polling single command timed out")
|
||||
_LOGGER.debug("Polling single command timed out")
|
||||
except ModbusError as err:
|
||||
_LOGGER.warning(
|
||||
_LOGGER.debug(
|
||||
"Got an invalid request error for %s: %s",
|
||||
command,
|
||||
err,
|
||||
|
||||
@@ -24,7 +24,7 @@ class AC200L(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -24,7 +24,7 @@ class AC200M(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -30,7 +30,7 @@ class AC300(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -30,7 +30,7 @@ class AC500(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -30,7 +30,7 @@ class EP500(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -30,7 +30,7 @@ class EP500P(ProtocolV1Device):
|
||||
# Battery packs
|
||||
self.struct.add_uint_field("pack_num_max", 91) # internal
|
||||
self.struct.add_decimal_field("total_battery_voltage", 92, 1)
|
||||
self.struct.add_uint_field("pack_num", 96) # internal
|
||||
self.struct.add_uint_field("pack_num_result", 96) # internal
|
||||
self.struct.add_decimal_field("pack_voltage", 98, 2) # Full pack voltage
|
||||
self.struct.add_uint_field("pack_battery_percent", 99)
|
||||
self.struct.add_decimal_array_field("cell_voltages", 105, 16, 2) # internal
|
||||
|
||||
@@ -156,7 +156,7 @@ class BluettiSensor(CoordinatorEntity, SensorEntity):
|
||||
|
||||
response_data = self.coordinator.data.get(self._response_key)
|
||||
if response_data is None:
|
||||
_LOGGER.warning("No data for available for (%s)", self._response_key)
|
||||
_LOGGER.debug("No data for available for (%s)", self._response_key)
|
||||
self._attr_available = False
|
||||
self.async_write_ha_state()
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user