Skip to content

Commit

Permalink
test Service for sending arbritrary ESP2 messages
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Mar 24, 2024
1 parent e30f746 commit 037f4b0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,30 @@ async def async_setup(self):
# Command Section
async def async_service_send_message(self, event) -> None:
"""Send an arbitrary message with the provided eep."""
LOGGER.debug(f"[Service: Send Message {event.service}] Received event data: {event.data}")
LOGGER.debug(f"[Service Send Message: {event.service}] Received event data: {event.data}")

try:
sender_id_str = event.data.get("id", None)
sender_id:AddressExpression = AddressExpression.parse(sender_id_str)
except:
LOGGER.error(f"[Service: Send Message] No valid sender id defined. (Given sender id: {sender_id_str})")
LOGGER.error(f"[Service Send Message: {event.service}] No valid sender id defined. (Given sender id: {sender_id_str})")
return

try:
sender_eep_str = event.data.get("eep", None)
sender_eep:EEP = EEP.find(sender_eep_str)
except:
LOGGER.error(f"[Service: Send Message] No valid sender id defined. (Given sender id: {sender_id_str})")
LOGGER.error(f"[Service Send Message: {event.service}] No valid sender id defined. (Given sender id: {sender_id_str})")
return

# prepare all arguements for eep constructor
import inspect
sig = inspect.signature(sender_eep.__init__)
eep_init_args = [param.name for param in sig.parameters.values() if param.kind == param.POSITIONAL_OR_KEYWORD]
knargs = {filter_key:event.data[filter_key] for filter_key in eep_init_args if filter_key in event.data and filter_key != 'self'}
LOGGER.debug(f"[Service: Send Message] Provided EEP ({sender_eep.__name__}) args: {knargs})")
LOGGER.debug(f"[Service Send Message: {event.service}] Provided EEP ({sender_eep.__name__}) args: {knargs})")
uknargs = {filter_key:0 for filter_key in eep_init_args if filter_key not in event.data and filter_key != 'self'}
LOGGER.debug(f"[Service: Send Message] Missing EEP ({sender_eep.__name__}) args: {uknargs})")
LOGGER.debug(f"[Service Send Message: {event.service}] Missing EEP ({sender_eep.__name__}) args: {uknargs})")
eep_args = knargs
eep_args.update(uknargs)

Expand All @@ -250,12 +250,12 @@ async def async_service_send_message(self, event) -> None:
try:
# create message
msg = eep.encode_message(sender_id[0])
LOGGER.debug("[Service: Send Message] Generated message: %s Serialized: %s", msg, msg.serialize().hex())
LOGGER.debug("[Service Send Message: {event.service}] Generated message: %s Serialized: %s", msg, msg.serialize().hex())
# send message
event_id = config_helpers.get_bus_event_type(self.base_id, SIGNAL_SEND_MESSAGE)
dispatcher_send(self.hass, event_id, msg)
except:
LOGGER.error(f"[Service: Send Message] Cannot send message.", exc_info=True, stack_info=True)
LOGGER.error(f"[Service Send Message: {event.service}] Cannot send message.", exc_info=True, stack_info=True)



Expand Down

0 comments on commit 037f4b0

Please sign in to comment.