Update remote app notification agent platform specific settings

This commit is contained in:
JonnyWong16 2021-06-30 18:01:39 -07:00
parent 15c7212031
commit b4598dca20
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# This file is part of Tautulli. # This file is part of Tautulli.
# #
@ -21,6 +21,7 @@ from future.builtins import object
import base64 import base64
import bleach import bleach
from collections import defaultdict
import json import json
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -3308,19 +3309,10 @@ class TAUTULLIREMOTEAPP(Notifier):
try: try:
query = 'SELECT * FROM mobile_devices WHERE official = 1 ' \ query = 'SELECT * FROM mobile_devices WHERE official = 1 ' \
'AND onesignal_id IS NOT NULL AND onesignal_id != ""' 'AND onesignal_id IS NOT NULL AND onesignal_id != ""'
result = db.select(query=query) return db.select(query=query)
except Exception as e: except Exception as e:
logger.warn("Tautulli Notifiers :: Unable to retrieve Tautulli Remote app devices list: %s." % e) logger.warn("Tautulli Notifiers :: Unable to retrieve Tautulli Remote app devices list: %s." % e)
return {'': ''} return []
devices = {}
for device in result:
if device['friendly_name']:
devices[device['device_id']] = device['friendly_name']
else:
devices[device['device_id']] = device['device_name']
return devices
def _return_config_options(self): def _return_config_options(self):
config_option = [] config_option = []
@ -3336,21 +3328,21 @@ class TAUTULLIREMOTEAPP(Notifier):
'https://github.com/%s/%s/wiki/Frequently-Asked-Questions#notifications-pycryptodome' 'https://github.com/%s/%s/wiki/Frequently-Asked-Questions#notifications-pycryptodome'
% (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO)) + '" target="_blank">FAQ</a>.' , % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO)) + '" target="_blank">FAQ</a>.' ,
'input_type': 'help' 'input_type': 'help'
}) })
else: else:
config_option.append({ config_option.append({
'label': 'Note', 'label': 'Note',
'description': 'The PyCryptodome library was found. ' 'description': 'The PyCryptodome library was found. '
'The content of your notifications will be sent encrypted!', 'The content of your notifications will be sent encrypted!',
'input_type': 'help' 'input_type': 'help'
}) })
config_option[-1]['description'] += '<br><br>Notifications are sent using the ' \ config_option[-1]['description'] += ('<br><br>Notifications are sent using '
'<a href="' + helpers.anon_url('https://onesignal.com') + '" target="_blank">' \ '<a href="' + helpers.anon_url('https://onesignal.com') + '" target="_blank">'
'OneSignal</a>. Some user data is collected and cannot be encrypted. ' \ 'OneSignal</a>. Some user data is collected and cannot be encrypted.<br>'
'Please read the <a href="' + helpers.anon_url( 'Please read the <a href="' + helpers.anon_url(
'https://onesignal.com/privacy_policy') + '" target="_blank">' \ 'https://onesignal.com/privacy_policy') + '" target="_blank">'
'OneSignal Privacy Policy</a> for more details.' 'OneSignal Privacy Policy</a> for more details.')
devices = self.get_devices() devices = self.get_devices()
@ -3362,8 +3354,19 @@ class TAUTULLIREMOTEAPP(Notifier):
'Get the Tautulli Remote App</a> and register a device.<br>' 'Get the Tautulli Remote App</a> and register a device.<br>'
'Note: Only devices registered with a valid OneSignal ID will appear in the list.', 'Note: Only devices registered with a valid OneSignal ID will appear in the list.',
'input_type': 'help' 'input_type': 'help'
}) })
else: else:
if len({d['platform'] for d in devices}) <= 1:
device_select = {d['device_id']: d['friendly_name'] or d['device_name'] for d in devices}
else:
device_select = defaultdict(list)
for d in devices:
platform = 'iOS' if d['platform'] == 'ios' else d['platform'].capitalize()
device_select[platform].append({
'value': d['device_id'],
'text': d['friendly_name'] or d['device_name']
})
config_option.append({ config_option.append({
'label': 'Device', 'label': 'Device',
'value': self.config['device_id'], 'value': self.config['device_id'],
@ -3373,27 +3376,37 @@ class TAUTULLIREMOTEAPP(Notifier):
'register a new device</a> with Tautulli.<br>' 'register a new device</a> with Tautulli.<br>'
'Note: Only devices registered with a valid OneSignal ID will appear in the list.', 'Note: Only devices registered with a valid OneSignal ID will appear in the list.',
'input_type': 'select', 'input_type': 'select',
'select_options': devices 'select_options': device_select,
}) 'refresh': True
config_option.append({
'label': 'Priority',
'value': self.config['priority'],
'name': 'remoteapp_priority',
'description': 'Set the notification priority.',
'input_type': 'select',
'select_options': {1: 'Minimum', 2: 'Low', 3: 'Normal', 4: 'High'}
}) })
config_option.append({
'label': 'Notification Image Type', platform = next((d['platform'] for d in devices if d['device_id'] == self.config['device_id']), None)
'value': self.config['notification_type'],
'name': 'remoteapp_notification_type', if platform == 'android':
'description': 'Set the notification image type.', config_option.append({
'input_type': 'select', 'label': 'Priority',
'select_options': {0: 'No notification image', 'value': self.config['priority'],
1: 'Small image (Expandable text)', 'name': 'remoteapp_priority',
2: 'Large image (Non-expandable text)' 'description': 'Set the notification priority.',
} 'input_type': 'select',
'select_options': {
1: 'Minimum',
2: 'Low',
3: 'Normal',
4: 'High'
}
})
config_option.append({
'label': 'Notification Image Type',
'value': self.config['notification_type'],
'name': 'remoteapp_notification_type',
'description': 'Set the notification image type.',
'input_type': 'select',
'select_options': {
0: 'No notification image',
1: 'Small image (Expandable text)',
2: 'Large image (Non-expandable text)'
}
}) })
return config_option return config_option