Skip to content

Commit

Permalink
debugging tcp gateway problems
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Oct 16, 2024
1 parent a88d4a6 commit 3ce9a1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion custom_components/eltako/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

SIGNAL_RECEIVE_MESSAGE: Final = "receive_message"
SIGNAL_SEND_MESSAGE: Final = "send_message"
SIGNAL_SEND_MESSAGE_SERVICE: Final = "send_message_service"
EVENT_BUTTON_PRESSED: Final = "btn_pressed"
EVENT_CONTACT_CLOSED: Final = "contact_closed"
GOBAL_EVENT_BUS_ID: Final = "eltako_global_event_bus"
GLOBAL_EVENT_BUS_ID: Final = "eltako_global_event_bus"

LOGGER: Final = logging.getLogger(DOMAIN)

Expand Down
17 changes: 13 additions & 4 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ async def async_setup(self):

# receive messages from HA event bus
event_id = config_helpers.get_bus_event_type(self.dev_id, SIGNAL_SEND_MESSAGE)
LOGGER.debug("[Gateway] [Id: %d] Register gateway bus for message event_id %s", event_id)
self.dispatcher_disconnect_handle = async_dispatcher_connect(
self.hass, event_id, self._callback_send_message_to_serial_bus
)
Expand All @@ -292,7 +293,8 @@ async def async_setup(self):
# The service will be registered for each gateway, as the user
# might have different gateways that cause the eltako relays
# only to react on them.
service_name = f"gateway_{self.dev_id}_send_message"
service_name = config_helpers.get_bus_event_type(self.dev_id, SIGNAL_SEND_MESSAGE_SERVICE)
LOGGER.debug("[Gateway] [Id: %d] Register send message service event_id %s", event_id)
self.hass.services.async_register(DOMAIN, service_name, self.async_service_send_message)


Expand Down Expand Up @@ -345,7 +347,7 @@ def send_message(self, msg: ESP2Message):
"""Put message on RS485 bus. First the message is put onto HA event bus so that other automations can react on messages."""
event_id = config_helpers.get_bus_event_type(self.dev_id, SIGNAL_SEND_MESSAGE)
dispatcher_send(self.hass, event_id, msg)
dispatcher_send(self.hass, GOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': msg})
dispatcher_send(self.hass, GLOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': msg})


def unload(self):
Expand All @@ -368,7 +370,7 @@ def _callback_send_message_to_serial_bus(self, msg):
self.hass.create_task(
self._bus.send(msg)
)
dispatcher_send(self.hass, GOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': msg})
dispatcher_send(self.hass, GLOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': msg})
else:
LOGGER.warning("[Gateway] [Id: %d] Serial port %s is not available!!! message (%s) was not sent.", self.dev_id, self.serial_path, msg)

Expand All @@ -389,10 +391,17 @@ def _callback_receive_message_from_serial_bus(self, message:ESP2Message):
self._attr_base_id = AddressExpression( (message.body[2:6], None) )
self._fire_base_id_change_handlers(self.base_id)


if self.base_id != b'\x00\x00\x00\x00' and isinstance(message, ESP2Message):
event_id = config_helpers.get_bus_event_type(self.dev_id, SIGNAL_RECEIVE_MESSAGE)
dispatcher_send(self.hass, event_id, message)
dispatcher_send(self.hass, GOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': message})

global_msg = ESP2Message(message.body)
address = message.body[6:10]
if address[0] == b'\x00' and address[1] == b'\x00':
global_msg.address = bytes((a + b) & 0xFF for a, b in zip(self.base_id[0], address))

dispatcher_send(self.hass, GLOBAL_EVENT_BUS_ID, {'gateway':self, 'esp2_msg': message})


@property
Expand Down
4 changes: 2 additions & 2 deletions custom_components/eltako/virtual_network_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from .const import *
from . import config_helpers
from .gateway import EnOceanGateway, GOBAL_EVENT_BUS_ID
from .gateway import EnOceanGateway, GLOBAL_EVENT_BUS_ID

VIRT_GW_PORT = 12345
VIRT_GW_DEVICE_NAME = "ESP2 Netowrk Reverse Bridge"
Expand Down Expand Up @@ -239,7 +239,7 @@ async def async_setup(self):

# register for all incoming and outgoing messages from all gateways
self.dispatcher_disconnect_handle = async_dispatcher_connect(
self.hass, GOBAL_EVENT_BUS_ID, self._forward_message
self.hass, GLOBAL_EVENT_BUS_ID, self._forward_message
)

self.zeroconf:Zeroconf = await zeroconf.async_get_instance(self.hass)
Expand Down

0 comments on commit 3ce9a1f

Please sign in to comment.