|
|
@ -204,10 +204,15 @@ class NotifyMQTT(NotifyBase): |
|
|
|
'type': 'bool', |
|
|
|
'type': 'bool', |
|
|
|
'default': False, |
|
|
|
'default': False, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
'retain': { |
|
|
|
|
|
|
|
'name': _('Retain Messages'), |
|
|
|
|
|
|
|
'type': 'bool', |
|
|
|
|
|
|
|
'default': False, |
|
|
|
|
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, targets=None, version=None, qos=None, |
|
|
|
def __init__(self, targets=None, version=None, qos=None, |
|
|
|
client_id=None, session=None, **kwargs): |
|
|
|
client_id=None, session=None, retain=None, **kwargs): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Initialize MQTT Object |
|
|
|
Initialize MQTT Object |
|
|
|
""" |
|
|
|
""" |
|
|
@ -230,6 +235,10 @@ class NotifyMQTT(NotifyBase): |
|
|
|
if session is None or not self.client_id \ |
|
|
|
if session is None or not self.client_id \ |
|
|
|
else parse_bool(session) |
|
|
|
else parse_bool(session) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Our Retain Message Flag |
|
|
|
|
|
|
|
self.retain = self.template_args['retain']['default'] \ |
|
|
|
|
|
|
|
if retain is None else parse_bool(retain) |
|
|
|
|
|
|
|
|
|
|
|
# Set up our Quality of Service (QoS) |
|
|
|
# Set up our Quality of Service (QoS) |
|
|
|
try: |
|
|
|
try: |
|
|
|
self.qos = self.template_args['qos']['default'] \ |
|
|
|
self.qos = self.template_args['qos']['default'] \ |
|
|
@ -376,7 +385,7 @@ class NotifyMQTT(NotifyBase): |
|
|
|
self.logger.debug('MQTT Payload: %s' % str(body)) |
|
|
|
self.logger.debug('MQTT Payload: %s' % str(body)) |
|
|
|
|
|
|
|
|
|
|
|
result = self.client.publish( |
|
|
|
result = self.client.publish( |
|
|
|
topic, payload=body, qos=self.qos, retain=False) |
|
|
|
topic, payload=body, qos=self.qos, retain=self.retain) |
|
|
|
|
|
|
|
|
|
|
|
if result.rc != mqtt.MQTT_ERR_SUCCESS: |
|
|
|
if result.rc != mqtt.MQTT_ERR_SUCCESS: |
|
|
|
# Toggle our status |
|
|
|
# Toggle our status |
|
|
@ -456,6 +465,7 @@ class NotifyMQTT(NotifyBase): |
|
|
|
'version': self.version, |
|
|
|
'version': self.version, |
|
|
|
'qos': str(self.qos), |
|
|
|
'qos': str(self.qos), |
|
|
|
'session': 'yes' if self.session else 'no', |
|
|
|
'session': 'yes' if self.session else 'no', |
|
|
|
|
|
|
|
'retain': 'yes' if self.retain else 'no', |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if self.client_id: |
|
|
|
if self.client_id: |
|
|
@ -535,6 +545,10 @@ class NotifyMQTT(NotifyBase): |
|
|
|
if 'session' in results['qsd'] and len(results['qsd']['session']): |
|
|
|
if 'session' in results['qsd'] and len(results['qsd']['session']): |
|
|
|
results['session'] = parse_bool(results['qsd']['session']) |
|
|
|
results['session'] = parse_bool(results['qsd']['session']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Message Retain Flag |
|
|
|
|
|
|
|
if 'retain' in results['qsd'] and len(results['qsd']['retain']): |
|
|
|
|
|
|
|
results['retain'] = parse_bool(results['qsd']['retain']) |
|
|
|
|
|
|
|
|
|
|
|
# The MQTT Quality of Service to use |
|
|
|
# The MQTT Quality of Service to use |
|
|
|
if 'qos' in results['qsd'] and len(results['qsd']['qos']): |
|
|
|
if 'qos' in results['qsd'] and len(results['qsd']['qos']): |
|
|
|
results['qos'] = \ |
|
|
|
results['qos'] = \ |
|
|
|