>>> asyncio.run(controlpi.test(
... {"Test Alias": {"plugin": "Alias",
... "from": {"id": {"const": 42}},
- ... "to": {"id": "translated"}}},
- ... [{"id": 42, "content": "Test Message"},
- ... {"id": 42, "content": "Second Message"}]))
+ ... "to": {"id": "translated"},
+ ... "translate": [{'from': "old", "to": "new"}]}},
+ ... [{"id": 42, "content": "Test Message", "old": "content"},
+ ... {"id": 42, "content": "Second Message", "old": "content"}]))
... # doctest: +NORMALIZE_WHITESPACE
test(): {'sender': '', 'event': 'registered',
'client': 'Test Alias', 'plugin': 'Alias',
'sends': [{'id': {'const': 'translated'}}],
'receives': [{'id': {'const': 42}}]}
test(): {'sender': 'test()', 'id': 42,
- 'content': 'Test Message'}
+ 'content': 'Test Message', 'old': 'content'}
test(): {'sender': 'Test Alias', 'id': 'translated',
- 'content': 'Test Message'}
+ 'content': 'Test Message', 'new': 'content'}
test(): {'sender': 'test()', 'id': 42,
- 'content': 'Second Message'}
+ 'content': 'Second Message', 'old': 'content'}
test(): {'sender': 'Test Alias', 'id': 'translated',
- 'content': 'Second Message'}
+ 'content': 'Second Message', 'new': 'content'}
The "from" and "to" keys are required:
>>> asyncio.run(controlpi.test(
'from' is a required property
<BLANKLINE>
Failed validating 'required' in schema:
- {'properties': {'from': {'type': 'object'}, 'to': {'type': 'object'}},
+ {'properties': {'from': {'type': 'object'},
+ 'to': {'type': 'object'},
+ 'translate': {'items': {'properties': {'from': {'type': 'string'},
+ 'to': {'type': 'string'}},
+ 'type': 'object'},
+ 'type': 'array'}},
'required': ['from', 'to']}
<BLANKLINE>
On instance:
'to' is a required property
<BLANKLINE>
Failed validating 'required' in schema:
- {'properties': {'from': {'type': 'object'}, 'to': {'type': 'object'}},
+ {'properties': {'from': {'type': 'object'},
+ 'to': {'type': 'object'},
+ 'translate': {'items': {'properties': {'from': {'type': 'string'},
+ 'to': {'type': 'string'}},
+ 'type': 'object'},
+ 'type': 'array'}},
'required': ['from', 'to']}
<BLANKLINE>
On instance:
"""
CONF_SCHEMA = {'properties': {'from': {'type': 'object'},
- 'to': {'type': 'object'}},
+ 'to': {'type': 'object'},
+ 'translate': {'type': 'array',
+ 'items': {'type': 'object',
+ 'properties': {'from': {'type': 'string'},
+ 'to': {'type': 'string'}}}}},
'required': ['from', 'to']}
"""Schema for Alias plugin configuration.
alias_message.update(self.conf['to'])
for key in message:
if key != 'sender' and key not in self.conf['from']:
- alias_message[key] = message[key]
+ if key in self._translate:
+ alias_message[self._translate[key]] = message[key]
+ else:
+ alias_message[key] = message[key]
await self.bus.send(alias_message)
def process_conf(self) -> None:
"""Register plugin as bus client."""
+ self._translate = {}
+ if 'translate' in self.conf:
+ for pair in self.conf['translate']:
+ self._translate[pair['from']] = pair['to']
self.bus.register(self.name, 'Alias',
[MessageTemplate.from_message(self.conf['to'])],
[self.conf['from']],