Skip to content

Commit

Permalink
test thread sync
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed May 14, 2024
1 parent 6cb66fd commit 8c671e0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def set_connection_state_changed_handler(self, handler):

def _fire_connection_state_changed_event(self, status):
if self._connection_state_handler:
asyncio.ensure_future(
asyncio.run_coroutine_threadsafe(
self._connection_state_handler(status),
loop= self._loop
loop = self._loop
)


Expand All @@ -105,9 +105,9 @@ def set_last_message_received_handler(self, handler):

def _fire_last_message_received_event(self):
if self._last_message_received_handler:
asyncio.ensure_future(
self._last_message_received_handler( datetime.utcnow().replace(tzinfo=pytz.utc) ),
loop= self._loop
asyncio.run_coroutine_threadsafe(
self._last_message_received_handler( datetime.now(datetime.UTC).replace(tzinfo=pytz.UTC) ),
loop = self._loop
)


Expand All @@ -118,9 +118,9 @@ def set_received_message_count_handler(self, handler):
def _fire_received_message_count_event(self):
self._received_message_count += 1
if self._received_message_count_handler:
asyncio.ensure_future(
asyncio.run_coroutine_threadsafe(
self._received_message_count_handler( self._received_message_count ),
loop= self._loop
loop = self._loop
)

def process_messages(self, data=None):
Expand Down Expand Up @@ -293,7 +293,11 @@ def _callback_send_message_to_serial_bus(self, msg):
LOGGER.debug("[Gateway] [Id: %d] Send message: %s - Serialized: %s", self.dev_id, msg, msg.serialize().hex())

# put message on serial bus
asyncio.ensure_future(self._bus.send(msg), loop=self._loop)
# asyncio.ensure_future(self._bus.send(msg), loop=self._loop)
asyncio.run_coroutine_threadsafe(
self._bus.send(msg),
loop = self._loop
)
else:
LOGGER.warn("[Gateway] [Id: %d] Serial port %s is not available!!! message (%s) was not sent.", self.dev_id, self.serial_path, msg)

Expand Down

0 comments on commit 8c671e0

Please sign in to comment.