Skip to content

Commit

Permalink
Refactor client to only have a single callback call
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsaxon committed Mar 14, 2020
1 parent d9d4074 commit 6c91f65
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions pysonofflanr3/client.py
Expand Up @@ -202,6 +202,8 @@ def add_service(self, zeroconf, type, name):

def update_service(self, zeroconf, type, name):

data = None

# This is needed for zeroconfg 0.24.1
# onwards as updates come to the parent node
if self.my_service_name != name:
Expand Down Expand Up @@ -243,7 +245,6 @@ def update_service(self, zeroconf, type, name):
self.logger.error(
"Missing api_key for encrypted device: %s", name
)
data = None

else:
self.encrypted = True
Expand All @@ -258,12 +259,6 @@ def update_service(self, zeroconf, type, name):

self.properties = info.properties

# process the events on an event loop
# this method is on a background thread called from zeroconf
asyncio.run_coroutine_threadsafe(
self.event_handler(data), self.loop
)

except ValueError as ex:
self.logger.error(
"Error updating service for device %s: %s"
Expand All @@ -272,10 +267,6 @@ def update_service(self, zeroconf, type, name):
format(ex),
)

asyncio.run_coroutine_threadsafe(
self.event_handler(None), self.loop
)

except TypeError as ex:
self.logger.error(
"Error updating service for device %s: %s"
Expand All @@ -284,10 +275,6 @@ def update_service(self, zeroconf, type, name):
format(ex),
)

asyncio.run_coroutine_threadsafe(
self.event_handler(None), self.loop
)

except Exception as ex:
self.logger.error(
"Error updating service for device %s: %s, %s",
Expand All @@ -296,8 +283,11 @@ def update_service(self, zeroconf, type, name):
traceback.format_exc(),
)

finally:
# process the events on an event loop
# this method is on a background thread called from zeroconf
asyncio.run_coroutine_threadsafe(
self.event_handler(None), self.loop
self.event_handler(data), self.loop
)

def retry_connection(self):
Expand Down

0 comments on commit 6c91f65

Please sign in to comment.