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 0b30d04 commit 8872165
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions custom_components/eltako/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,20 @@ async def async_service_send_message(self, event) -> None:
LOGGER.error(f"[Service: Send Message] No valid sender id defined. (Given sender id: {sender_id_str})")
return

def filter_event_data(data: dict, eep_kwargs):
import inspect
sig = inspect.signature(eep_kwargs)
filter_keys = [param.name for param in sig.parameters.values() if param.kind == param.POSITIONAL_OR_KEYWORD]
filtered_dict = {filter_key:data[filter_key] for filter_key in filter_keys if filter_key in data}
filtered_dict.update({filter_key:0 for filter_key in filter_keys if filter_key not in data})
return filtered_dict

eep:EEP = sender_eep(**filter_event_data(event.data), sender_eep.__init__)
for k in eep.__dict__.keys():
if k in event.data.keys():
setattr(eep, k, event.data.get(k[1:])) # key k starts always with '_' because it is a private attribute
else:
LOGGER.warn(f"[Service: Send Message] Argument {k} is not provided for sending {eep.eep_string} message. Set default value: {k}=0")
setattr(eep, k, 0)
# 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]
filtered_data = {filter_key:event.data[filter_key] for filter_key in eep_init_args if filter_key in event.data}
filtered_data.update({filter_key:0 for filter_key in eep_init_args if filter_key not in event.data})

eep:EEP = sender_eep(**filtered_data)
# for k in eep.__dict__.keys():
# if k in event.data.keys():
# setattr(eep, k, event.data.get(k[1:])) # key k starts always with '_' because it is a private attribute
# else:
# LOGGER.warn(f"[Service: Send Message] Argument {k} is not provided for sending {eep.eep_string} message. Set default value: {k}=0")
# setattr(eep, k, 0)

try:
message = eep.encode_message(sender_id)
Expand Down

0 comments on commit 8872165

Please sign in to comment.