@@ -123,16 +123,16 @@ def __init__(self, ip_address: str, port: int = 8080) -> None:
123123 # Request 2
124124 'read_battery_info' : bytes .fromhex ("010300100003040e" ),
125125 # Request 3 and 10
126- 'start_measurement ' : bytes .fromhex ("0110055000020400018100f853" ),
126+ 'start_measure_box_1 ' : bytes .fromhex ("0110055000020400018100f853" ),
127127 # Request 4 and 11
128128 'read_measurement_status' : bytes .fromhex ("010305510001d517" ),
129129 # Requests 5-8 and 12-15
130130 'read_cell_volt_temp' : bytes .fromhex ("01030558004104e5" ),
131131 # Request 9
132132 'switch_pass' : bytes .fromhex ("01100100000306444542554700176f" ),
133133 # Request 16
134- 'switch_to_box_2 ' : bytes .fromhex ("01100550000204000281000853" ),
135- 'switch_to_box_3 ' : bytes .fromhex ("01100550000204000381005993" ),
134+ 'start_measure_box_2 ' : bytes .fromhex ("01100550000204000281000853" ),
135+ 'start_measure_box_3 ' : bytes .fromhex ("01100550000204000381005993" ),
136136 # BMU
137137 'EVT_MSG_0_0' : bytes .fromhex ("011005a000020400008100A6D7" ),
138138 # BMS tower 1
@@ -526,7 +526,6 @@ async def poll(self) -> None:
526526 13 : self .state13_send_request11 ,
527527 14 : self .state14_send_request12 ,
528528 15 : self .state15_send_request13 ,
529- 16 : self .state16_switch_tower ,
530529 }
531530
532531 while self .my_state != 0 :
@@ -586,7 +585,12 @@ async def state4_send_request2(self) -> None:
586585
587586 async def state5_start_measurement (self ) -> None :
588587 """State 5: Start measurement and proceed with detailed queries."""
589- await self .send_request (self .my_requests ['start_measurement' ])
588+ if self .current_tower == 0 :
589+ await self .send_request (self .my_requests ['start_measure_box_1' ])
590+ elif self .current_tower == 1 :
591+ await self .send_request (self .my_requests ['start_measure_box_2' ])
592+ elif self .current_tower == 2 :
593+ await self .send_request (self .my_requests ['start_measure_box_3' ])
590594 data = await self .receive_response ()
591595 if data and self .check_packet (data ):
592596 # Wait time as per original code (e.g., 8 seconds)
@@ -656,9 +660,6 @@ async def state10_send_request8(self) -> None:
656660 # Check if we have more than 128 cells
657661 if self .hvs_num_cells > 128 :
658662 self .my_state = 11
659- # if x towerconfig has less than 5 modules
660- elif self .hvs_towers - 1 > self .current_tower :
661- self .my_state = 16 # Proceed to second tower
662663 else :
663664 self .my_state = 0 # Polling completed
664665 else :
@@ -670,10 +671,12 @@ async def state10_send_request8(self) -> None:
670671 async def state11_send_request9 (self ) -> None :
671672 """Handle additional cells for more than 128 cells (e.g., 5 modules)"""
672673 # State 11: Send request 9 - Switch to second pass
673- if self .current_tower > 1 :
674- await self .send_request (self .my_requests ['switch_to_box_2' ])
675- else :
676- await self .send_request (self .my_requests ['switch_pass' ])
674+ if self .current_tower == 0 :
675+ await self .send_request (self .my_requests ['start_measure_box_1' ])
676+ elif self .current_tower == 1 :
677+ await self .send_request (self .my_requests ['start_measure_box_2' ])
678+ elif self .current_tower == 2 :
679+ await self .send_request (self .my_requests ['start_measure_box_3' ])
677680 data = await self .receive_response ()
678681 if data and self .check_packet (data ):
679682 self .my_state = 12
@@ -724,27 +727,15 @@ async def state15_send_request13(self) -> None:
724727 data = await self .receive_response ()
725728 if data and self .check_packet (data ):
726729 self .parse_packet13 (data , self .current_tower )
727- if self .hvs_towers - 1 > self .current_tower :
728- self .my_state = 16
730+ if self .current_tower + 1 < self .hvs_towers :
729731 self .current_tower += 1
732+ self .my_state = 5
730733 else :
731- self .my_state = 0 # Polling completed
734+ self .my_state = 0 # Letzter Turm erreicht
732735 else :
733736 _LOGGER .error ("Invalid or no data received in state 15" )
734737 self .my_state = 0
735738
736- async def state16_switch_tower (self ) -> None :
737- """Handle second tower"""
738- await self .send_request (self .my_requests ['switch_to_box_2' ])
739- data = await self .receive_response ()
740- if data and self .check_packet (data ):
741- # Wait time as per original code (e.g., 8 seconds)
742- await asyncio .sleep (self .SLEEP_TIME )
743- self .my_state = 4
744- else :
745- _LOGGER .error ("Invalid or no data received in state 16" )
746- self .my_state = 0
747-
748739 def get_data (self ) -> dict :
749740 """Retrieve the collected data."""
750741 return {
0 commit comments