Skip to content

Commit

Permalink
Better handling with network connection error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajarzyn committed Aug 1, 2022
1 parent 56826fd commit 7bc4c51
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def initialize_connection(self):
return True
except OSError as msg:
self.active_connection.close()
Domoticz.Error(f"Connection failed, check ip. Error: str({msg})")
Domoticz.Error(f"Connection failed, check ip. Error: {str(msg)}")
return False

def send_message(self, command, address, value):
Expand Down Expand Up @@ -480,13 +480,17 @@ def process_socket_message(self, command='READ_PARAMS', address=0, value=0):
address = 0
value = 0

raw_data = command, 0, 0, 0

try:
raw_data = self.send_message(SOCKET_COMMANDS[command], address, value)
except socket.error:
if self.initialize_connection():
raw_data = self.send_message(SOCKET_COMMANDS[command], address, value)

if raw_data is None:
Domoticz.Error(f"Connection error.")
raw_data = command, 0, 0, 0

return raw_data

def update(self, message):
Expand Down

1 comment on commit 7bc4c51

@ajarzyn
Copy link
Owner Author

@ajarzyn ajarzyn commented on 7bc4c51 Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #6 ?

Please sign in to comment.