Skip to content

Commit

Permalink
Merge pull request #7 from bbr111/dev
Browse files Browse the repository at this point in the history
Fix error HVM Tower not shown
  • Loading branch information
bbr111 authored Nov 30, 2024
2 parents 1bfec84 + 849b785 commit a47b19e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 50 deletions.
15 changes: 11 additions & 4 deletions bydhvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def __init__(self, ip_address: str, port: int = 8080) -> None:
self.hvs_eta = 0.0
self.hvs_batt_type_from_serial = ""
self.hvs_batt_type = ""
self.hvs_batt_type_string = ""
self.hvs_inv_type = ""
self.hvs_num_cells = 0
self.hvs_num_temps = 0
Expand Down Expand Up @@ -369,12 +370,13 @@ def parse_packet2(self, data: bytes) -> None:

# Map battery type to module and cell counts
batt_type_map = {
0: {'cell_count': 0, 'temp_count': 0},
1: {'cell_count': 16, 'temp_count': 8},
2: {'cell_count': 32, 'temp_count': 12},
0: {'string': 'LVM', 'cell_count': 0, 'temp_count': 0},
1: {'string': 'HVM', 'cell_count': 16, 'temp_count': 8},
2: {'string': 'HVS', 'cell_count': 32, 'temp_count': 12},
}

batt_info = batt_type_map.get(self.hvs_batt_type, {})
self.hvs_batt_type_string = batt_info.get('string', '')
self.hvs_module_cell_count = batt_info.get('cell_count', 0)
self.hvs_module_cell_temp_count = batt_info.get('temp_count', 0)
self.hvs_num_cells = self.hvs_modules * self.hvs_module_cell_count
Expand Down Expand Up @@ -661,7 +663,11 @@ async def state10_send_request8(self) -> None:
if self.hvs_num_cells > 128:
self.my_state = 11
else:
self.my_state = 0 # Polling completed
if self.current_tower + 1 < self.hvs_towers:
self.current_tower += 1
self.my_state = 5
else:
self.my_state = 0 # Polling completed
else:
_LOGGER.error("Invalid or no data received in state 10")
self.my_state = 0
Expand Down Expand Up @@ -769,6 +775,7 @@ def get_data(self) -> dict:
"eta": self.hvs_eta,
"battery_type_from_serial": self.hvs_batt_type_from_serial,
"battery_type": self.hvs_batt_type,
"battery_type_string": self.hvs_batt_type_string,
"inverter_type": self.hvs_inv_type_string,
"number_of_cells": self.hvs_num_cells,
"number_of_temperatures": self.hvs_num_temps,
Expand Down
96 changes: 50 additions & 46 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ async def main():
"""Main func"""
# Replace with IP address of your BYD HVS battery system
battery_ip = '192.168.16.254'
battery = BYDHVS(ip_address=battery_ip)
battery_port = '8080'

battery = BYDHVS(ip_address=battery_ip, port=battery_port)

try:
# Perform the polling to retrieve data
Expand All @@ -18,34 +20,35 @@ async def main():

# Print the retrieved data
print("Battery Data:")
print(f"Serial Number : {data['serial_number']}")
print(f"BMU Firmware : {data['bmu_firmware']}")
print(f"BMU Firmware_A : {data['bmu_firmware_a']}")
print(f"BMU Firmware_B : {data['bmu_firmware_b']}")
print(f"BMS Firmware : {data['bms_firmware']}")
print(f"Modules : {data['modules']}")
print(f"ModuleCellCount : {data['module_cell_count']}")
print(f"ModuleCellTempCount: {data['module_cell_temp_count']}")
print(f"Towers : {data['towers']}")
print(f"Grid Type : {data['grid_type']}")
print(f"SOC : {data['soc']}%")
print(f"Max Voltage : {data['max_voltage']} V")
print(f"Min Voltage : {data['min_voltage']} V")
print(f"SOH : {data['soh']}%")
print(f"Current : {data['current']} A")
print(f"Battery Voltage : {data['battery_voltage']} V")
print(f"Max Temperature : {data['max_temperature']} °C")
print(f"Min Temperature : {data['min_temperature']} °C")
print(f"Battery Temperature: {data['battery_temperature']} °C")
print(f"Voltage Difference : {data['voltage_difference']} V")
print(f"Power : {data['power']} W")
print(f"Error Number : {data['error_number']}")
print(f"Error String : {data['error_string']}")
print(f"Charge Total : {data['charge_total']} Ah")
print(f"Discharge Total : {data['discharge_total']} Ah")
print(f"ETA : {data['eta']}")
print(f"Battery Type : {data['battery_type']}")
print(f"Inverter Type : {data['inverter_type']}")
print(f"Serial Number : {data['serial_number']}")
print(f"BMU Firmware : {data['bmu_firmware']}")
print(f"BMU Firmware_A : {data['bmu_firmware_a']}")
print(f"BMU Firmware_B : {data['bmu_firmware_b']}")
print(f"BMS Firmware : {data['bms_firmware']}")
print(f"Modules : {data['modules']}")
print(f"ModuleCellCount : {data['module_cell_count']}")
print(f"ModuleCellTempCount : {data['module_cell_temp_count']}")
print(f"Towers : {data['towers']}")
print(f"Grid Type : {data['grid_type']}")
print(f"SOC : {data['soc']}%")
print(f"Max Voltage : {data['max_voltage']} V")
print(f"Min Voltage : {data['min_voltage']} V")
print(f"SOH : {data['soh']}%")
print(f"Current : {data['current']} A")
print(f"Battery Voltage : {data['battery_voltage']} V")
print(f"Max Temperature : {data['max_temperature']} °C")
print(f"Min Temperature : {data['min_temperature']} °C")
print(f"Battery Temperature : {data['battery_temperature']} °C")
print(f"Voltage Difference : {data['voltage_difference']} V")
print(f"Power : {data['power']} W")
print(f"Error Number : {data['error_number']}")
print(f"Error String : {data['error_string']}")
print(f"Charge Total : {data['charge_total']} Ah")
print(f"Discharge Total : {data['discharge_total']} Ah")
print(f"ETA : {data['eta']}")
print(f"Battery Type : {data['battery_type']}")
print(f"Battery Type String : {data['battery_type_string']}")
print(f"Inverter Type : {data['inverter_type']}")
for idx, tower in enumerate(data['tower_attributes']):
print(f"\nTower {idx + 1}:")
print(f""" Max Cell Voltage (mV): {
Expand All @@ -56,26 +59,27 @@ async def main():
tower.get('max_cell_voltage_cell')}""")
print(f""" Min Cell Voltage Cell: No. {
tower.get('min_cell_voltage_cell')}""")
print(f" Max Cell Temp : {tower.get('max_cell_temp')}°C")
print(f" Min Cell Temp : {tower.get('min_cell_temp')}°C")
print(f""" Max Cell Temp Cell : No.{
print(f" Max Cell Temp : {tower.get('max_cell_temp')}°C")
print(f" Min Cell Temp : {tower.get('min_cell_temp')}°C")
print(f""" Max Cell Temp Cell : No.{
tower.get('max_cell_temp_cell')}""")
print(f""" Min Cell Temp Cell : No.{
print(f""" Min Cell Temp Cell : No.{
tower.get('min_cell_temp_cell')}""")
print(f" Balancing Status : {tower.get('balancing_status')}")
print(f" Balancing Count : {tower.get('balancing_count')}")
print(f" Total Charge : {tower['charge_total']}")
print(f" Discharge Total : {tower.get('discharge_total')}")
print(f" ETA : {tower.get('eta')}")
print(f" Battery Volt : {tower.get('battery_volt')}")
print(f" Output Volt : {tower.get('out_volt')}")
print(f""" SOCDiagnosis : {
print(f" Balancing Status : {tower.get('balancing_status')}")
print(f" Balancing Count : {tower.get('balancing_count')}")
print(f" Total Charge : {tower.get('charge_total')}")
print(f" Discharge Total : {tower.get('discharge_total')}")
print(f" ETA : {tower.get('eta')}")
print(f" Battery Volt : {tower.get('battery_volt')}")
print(f" Output Volt : {tower.get('out_volt')}")
print(f""" SOCDiagnosis : {
tower.get('hvs_soc_diagnosis')}%""")
print(f" State of Health : {tower.get('soh')}%")
print(f" State : {tower.get('state')}")
print(f" State_String : {tower.get('state_string')}")
print(f" Cell Voltages : {tower.get('cell_voltages')}")
print(f" Cell Temperatures : {tower.get('cell_temperatures')}")
print(f" State of Health : {tower.get('soh')}%")
print(f" State : {tower.get('state')}")
print(f" State_String : {tower.get('state_string')}")
print(f" Cell Voltages : {tower.get('cell_voltages')}")
print(f""" Cell Temperatures : {
tower.get('cell_temperatures')}""")

except BYDHVSError as e:
print(f"An error occurred: {e}")
Expand Down

0 comments on commit a47b19e

Please sign in to comment.