generic action handler

This commit is contained in:
John Lancaster
2023-11-24 16:34:38 -06:00
parent f4c73c5ef7
commit 964b7fa0b0

View File

@@ -19,15 +19,15 @@ class AqaraCube(Mqtt):
if action == '': if action == '':
return return
elif (handler := getattr(self, f'handle_{action}', None)):
if (arg := self.args.get(action, None)) is not None: if (arg := self.args.get(action, None)) is not None:
self.action_handler(action_description=arg) self.action_handler(action=action, description=arg)
elif (handler := getattr(self, f'handle_{action}', None)):
handler(payload) handler(payload)
else: else:
self.log(f'Unhandled cube action: {action}') self.log(f'Unhandled cube action: {action}')
def action_handler(self, action_description): def action_handler(self, action: str , description: str):
self.log(f'{self.args["cube"]}: generic action handler: {action_description}') self.log(f'{self.args["cube"]}: {action}: {description}')
def handle_rotate_right(self, payload): def handle_rotate_right(self, payload):
self.log(f'{self.args["cube"]}: Rotate right') self.log(f'{self.args["cube"]}: Rotate right')