mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 09:42:57 -07:00
Fix reviewed items by JonnyWong16
This commit is contained in:
parent
f7166f37f5
commit
e17c551555
1 changed files with 10 additions and 25 deletions
|
@ -21,6 +21,7 @@ from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
import email.utils
|
import email.utils
|
||||||
from httplib import HTTPSConnection
|
from httplib import HTTPSConnection
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
@ -137,6 +138,10 @@ def available_notification_agents():
|
||||||
'name': 'nma',
|
'name': 'nma',
|
||||||
'id': AGENT_IDS['nma']
|
'id': AGENT_IDS['nma']
|
||||||
},
|
},
|
||||||
|
{'label': 'MQTT',
|
||||||
|
'name': 'mqtt',
|
||||||
|
'id': AGENT_IDS['mqtt']
|
||||||
|
},
|
||||||
{'label': 'Plex Home Theater',
|
{'label': 'Plex Home Theater',
|
||||||
'name': 'plex',
|
'name': 'plex',
|
||||||
'id': AGENT_IDS['plex']
|
'id': AGENT_IDS['plex']
|
||||||
|
@ -185,11 +190,6 @@ def available_notification_agents():
|
||||||
'name': 'osx',
|
'name': 'osx',
|
||||||
'id': AGENT_IDS['osx']
|
'id': AGENT_IDS['osx']
|
||||||
})
|
})
|
||||||
if MQTT().validate():
|
|
||||||
agents.append({'label': 'MQTT',
|
|
||||||
'name': 'mqtt',
|
|
||||||
'id': AGENT_IDS['mqtt']
|
|
||||||
})
|
|
||||||
|
|
||||||
return agents
|
return agents
|
||||||
|
|
||||||
|
@ -3199,27 +3199,12 @@ class MQTT(Notifier):
|
||||||
self.retain = False
|
self.retain = False
|
||||||
self.client_id = 'plexpy'
|
self.client_id = 'plexpy'
|
||||||
logger.info(u"PlexPy Notifiers :: MQTT init.")
|
logger.info(u"PlexPy Notifiers :: MQTT init.")
|
||||||
|
self.mqtt_client = mqtt.Client(protocol=self.config['protocol'])
|
||||||
try:
|
self.mqtt_client.username_pw_set(self.config['username'], self.config['password'])
|
||||||
self.mqtt = __import__("paho.mqtt.client", globals(), locals(), ['client'], 0)
|
self.mqtt_client.on_connect = self.on_connect
|
||||||
self.mqtt_client = self.mqtt.Client(None, True, None, config['protocol'])
|
self.mqtt_client.on_publish = self.on_publish
|
||||||
self.mqtt_client.username_pw_set(config['username'], config['password'])
|
|
||||||
self.mqtt_client.on_connect = self.on_connect
|
|
||||||
self.mqtt_client.on_publish = self.on_publish
|
|
||||||
except:
|
|
||||||
logger.error(u"PlexPy Notifiers :: Cannot load MQTT Notifications agent.")
|
|
||||||
pass
|
|
||||||
|
|
||||||
logger.info(u"PlexPy Notifiers :: MQTT initialized.")
|
logger.info(u"PlexPy Notifiers :: MQTT initialized.")
|
||||||
|
|
||||||
|
|
||||||
def validate(self):
|
|
||||||
try:
|
|
||||||
self.mqtt = __import__("paho.mqtt.client", globals(), locals(), ['client'], 0)
|
|
||||||
return True
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def on_connect(self, client, userdata, flags, rc):
|
def on_connect(self, client, userdata, flags, rc):
|
||||||
logger.info(u"PlexPy Notifiers :: MQTT notification: connect")
|
logger.info(u"PlexPy Notifiers :: MQTT notification: connect")
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
|
@ -3240,7 +3225,7 @@ class MQTT(Notifier):
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
logger.info(u"PlexPy Notifiers :: MQTT connection: %s.", status)
|
logger.info(u"PlexPy Notifiers :: MQTT connection: %s.", status)
|
||||||
logger.info(u"PlexPy Notifiers :: MQTT notification: Publishing message.")
|
logger.info(u"PlexPy Notifiers :: MQTT notification: Publishing message.")
|
||||||
(rc, mid) = self.mqtt_client.publish(self.topic, json.dumps(self.data), self.qos, self.retain)
|
(rc, mid) = self.mqtt_client.publish(self.config['topic'], json.dumps(self.data), self.qos, self.retain)
|
||||||
else:
|
else:
|
||||||
logger.warn(u"PlexPy Notifiers :: MQTT connection: %s.", status)
|
logger.warn(u"PlexPy Notifiers :: MQTT connection: %s.", status)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue