improvement: Automatically build polling commands basing on the fields

This commit is contained in:
Artem Chepurnyi committed 2024-06-29 16:45:59 +03:00
1 parent 0e5c1a0b44
commit a1e9c180b3
10 files changed
+69 -113

No files matched your search

@@ -28,6 +28,7 @@ class AC200M(ProtocolV1Device):
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
self.struct.add_version_field("pack_bms_version", 201)
# Controls
self.struct.add_bool_field("power_off", 3060)
@@ -39,12 +40,9 @@ class AC200M(ProtocolV1Device):
@property
def polling_commands(self) -> List[ReadHoldingRegisters]:
return super().polling_commands + [
ReadHoldingRegisters(70, 5),
ReadHoldingRegisters(86, 3),
ReadHoldingRegisters(92, 1),
ReadHoldingRegisters(3060, 2),
]
return self.struct.get_read_holding_registers(
filter=lambda address: address <= 90 or address >= 256 # pack_polling_commands
)
@property
def writable_ranges(self) -> List[range]:
@@ -53,8 +51,6 @@ class AC200M(ProtocolV1Device):
@property
def pack_polling_commands(self) -> List[ReadHoldingRegisters]:
return [
ReadHoldingRegisters(91, 2),
ReadHoldingRegisters(96, 1),
ReadHoldingRegisters(98, 2),
ReadHoldingRegisters(105, 16)
ReadHoldingRegisters(91, 37),
ReadHoldingRegisters(201, 2),
]