From 89a281c3f3a25d49deb0495fff8500330866fe19 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Mon, 13 May 2024 12:02:00 +0200 Subject: [PATCH] test fire_last_message_received --- custom_components/eltako/gateway.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/custom_components/eltako/gateway.py b/custom_components/eltako/gateway.py index 04714d01..7a35e227 100644 --- a/custom_components/eltako/gateway.py +++ b/custom_components/eltako/gateway.py @@ -20,7 +20,7 @@ from homeassistant.core import HomeAssistant from homeassistant.const import CONF_MAC -from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send +from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send, dispatcher_connect from homeassistant.helpers import device_registry as dr from homeassistant.helpers.device_registry import DeviceRegistry, DeviceInfo from homeassistant.config_entries import ConfigEntry @@ -120,6 +120,9 @@ def _fire_received_message_count_event(self): self._received_message_count_handler( self._received_message_count ) ) + def process_messages(self): + LOGGER.info("GATEWAY: HANDLE MESSAGES") + def _init_bus(self): self._received_message_count = 0 @@ -129,7 +132,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: @@ -143,6 +146,11 @@ def _register_device(self) -> None: model=self.model, ) + # Register callbacks. + event_id = config_helpers.get_bus_event_type(self.gateway.base_id, SIGNAL_RECEIVE_MESSAGE) + dispatcher_connect(self.hass, event_id, self.process_messages) + + ### address validation functions def validate_sender_id(self, sender_id: AddressExpression, device_name: str = "") -> bool: