[request] The action name can be specified either on action or name.

This is for UI compatibility purposes.
This commit is contained in:
Fabio Manganiello 2024-09-10 19:49:16 +02:00
parent 05b1fcd43a
commit 5a7068501a
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 5 additions and 3 deletions

View file

@ -64,12 +64,13 @@ class Request(Message):
msg = super().parse(msg)
args = {
'target': msg.get('target', Config.get('device_id')),
'action': msg['action'],
'action': msg.get('action', msg.get('name')),
'args': msg.get('args', {}),
'id': msg['id'] if 'id' in msg else cls._generate_id(),
'timestamp': msg['_timestamp'] if '_timestamp' in msg else time.time(),
}
assert args.get('action'), 'No action specified in the request'
if 'origin' in msg:
args['origin'] = msg['origin']
if 'token' in msg:

View file

@ -286,9 +286,10 @@ class ProceduresPlugin(RunnablePlugin, ProcedureEntityManager):
@classmethod
def _serialize_action(cls, data: Union[Iterable, Dict]) -> Union[Dict, List]:
if isinstance(data, dict):
if data.get('action'):
name = data.get('action', data.get('name'))
if name:
return {
'action': data['action'],
'action': name,
**({'args': data['args']} if data.get('args') else {}),
}