Skip to content

Commit

Permalink
Update APSystemsSocket.py
Browse files Browse the repository at this point in the history
Removed a bug, duplicate code and reintroduced closing en opening of socket inbetween commands to achieve compatibility with the ECU-R with SunSpec logo on the back (containing ECU-R pro firmware).
  • Loading branch information
HAEdwin committed Apr 18, 2022
1 parent 4e84731 commit b3a96fd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/apsystems_ecur/APSystemsSocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,11 @@ def query_ecu(self):

_LOGGER.debug(f"Connecting to ECU on {self.ipaddr} {self.port}")
sock = self.open_socket()
_LOGGER.debug(f"Connecting to ECU on {self.ipaddr} {self.port}")


cmd = self.ecu_query
_LOGGER.debug(f"Sending ECU query to socket {cmd}")
self.ecu_raw_data = self.send_read_from_socket(cmd)

self.process_ecu_data()

try:
self.process_ecu_data()
Expand All @@ -140,16 +138,20 @@ def query_ecu(self):
raise

if self.lifetime_energy == 0:
self.socket_close()
self.close_socket()
error = f"ECU returned 0 for lifetime energy, raw data={self.ecu_raw_data}"
self.add_error(error)
raise APSystemsInvalidData(error)

# Some ECUs likes the socket to be closed and re-opened between commands
self.close_socket()
self.open_socket()
cmd = self.inverter_query_prefix + self.ecu_id + self.inverter_query_suffix
self.inverter_raw_data = self.send_read_from_socket(cmd)

# Some ECUs likes the socket to be closed and re-opened between commands
self.close_socket()
self.open_socket()
cmd = self.inverter_signal_prefix + self.ecu_id + self.inverter_signal_suffix
self.inverter_raw_signal = self.send_read_from_socket(cmd)

Expand Down

0 comments on commit b3a96fd

Please sign in to comment.