Skip to content

Commit

Permalink
test fire_last_message_received
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed May 13, 2024
1 parent 2b4fd79 commit 6e6488b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions custom_components/eltako/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

SIGNAL_RECEIVE_MESSAGE: Final = "receive_message"
SIGNAL_SEND_MESSAGE: Final = "send_message"
SIGNAL_GATEWAY_CONNECTION_STATUS: Final = "gateway_connection_status"
EVENT_BUTTON_PRESSED: Final = "btn_pressed"
EVENT_CONTACT_CLOSED: Final = "contact_closed"

Expand Down
22 changes: 15 additions & 7 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ def __init__(self, general_settings:dict, hass: HomeAssistant,

def set_connection_state_changed_handler(self, handler):
self._connection_state_handler = handler
self._fire_connection_state_changed_event(self._bus and self._bus.is_active())


def _fire_connection_state_changed_event(self, connected:bool):
if self._connection_state_handler:
self.hass.async_create_task(
self._connection_state_handler( connected )
)
event_id = config_helpers.get_bus_event_type(self.base_id, SIGNAL_GATEWAY_CONNECTION_STATUS)
dispatcher_send(self.hass, event_id, None)


def set_last_message_received_handler(self, handler):
Expand All @@ -121,7 +118,15 @@ def _fire_received_message_count_event(self):
)

def process_messages(self, data):
LOGGER.info("GATEWAY: HANDLE MESSAGES")
"""Received message from bus in HA loop. (Actions needs to run outside bus thread!)"""
self._fire_received_message_count_event()
self._fire_last_message_received_event()

def process_connection_status_signal(self, data):
if self._connection_state_handler:
self.hass.async_create_task(
self._connection_state_handler( self._bus.is_active() )
)


def _init_bus(self):
Expand All @@ -132,7 +137,7 @@ def _init_bus(self):
else:
self._bus = ESP3SerialCommunicator(filename=self.serial_path, callback=self._callback_receive_message_from_serial_bus, esp2_translation_enabled=True)

# self._bus.set_status_changed_handler(self._fire_connection_state_changed_event)
self._bus.set_status_changed_handler(self._fire_connection_state_changed_event)


def _register_device(self) -> None:
Expand Down Expand Up @@ -213,6 +218,9 @@ async def async_setup(self):
event_id = config_helpers.get_bus_event_type(self.base_id, SIGNAL_RECEIVE_MESSAGE)
async_dispatcher_connect(self.hass, event_id, self.process_messages)

event_id = config_helpers.get_bus_event_type(self.base_id, SIGNAL_GATEWAY_CONNECTION_STATUS)
async_dispatcher_connect(self.hass, event_id, self.process_connection_status)

# Register home assistant service for sending arbitrary telegrams.
#
# The service will be registered for each gateway, as the user
Expand Down

0 comments on commit 6e6488b

Please sign in to comment.