2018-01-29 15:48:32 +00:00
|
|
|
class MessageSender:
|
2019-07-05 13:25:59 +00:00
|
|
|
def __init__(self, uplink):
|
|
|
|
self.uplink = uplink
|
2018-01-29 15:48:32 +00:00
|
|
|
|
2019-08-07 07:49:05 +00:00
|
|
|
def send(self, message, originator=None):
|
2019-05-26 16:26:33 +00:00
|
|
|
message = {
|
2019-08-07 07:49:05 +00:00
|
|
|
'key': 'message.send',
|
|
|
|
'message': message
|
2019-05-26 16:26:33 +00:00
|
|
|
}
|
2019-08-07 07:49:05 +00:00
|
|
|
if originator:
|
|
|
|
message['originator'] = originator
|
2019-06-28 15:34:22 +00:00
|
|
|
self.uplink.send_message(message)
|
2018-06-27 13:48:32 +00:00
|
|
|
|
2019-08-07 07:49:05 +00:00
|
|
|
def queue_messages(self, messages, originator=None):
|
|
|
|
message_queue = {
|
|
|
|
'key': 'message.queue',
|
|
|
|
'value': []
|
2019-05-26 16:26:33 +00:00
|
|
|
}
|
2019-08-07 07:49:05 +00:00
|
|
|
for message in messages:
|
|
|
|
next_message = {'message': message}
|
|
|
|
if originator:
|
|
|
|
next_message['originator'] = originator
|
|
|
|
message_queue['value'].append(next_message)
|
|
|
|
self.uplink.send_message(message_queue)
|
2018-07-13 12:09:13 +00:00
|
|
|
|
2019-08-07 07:49:05 +00:00
|
|
|
def set_originator(self, originator):
|
|
|
|
self.uplink.send_message({
|
|
|
|
'key': 'message.config',
|
|
|
|
'originator': originator
|
|
|
|
})
|
2019-08-07 09:24:56 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def generate_messages_from_queue(queue_message):
|
|
|
|
for message in queue_message['value']:
|
|
|
|
yield {
|
|
|
|
'key': 'message.send',
|
|
|
|
**message
|
|
|
|
}
|