mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-20 13:23:24 -07:00
Get Pushbullet devices automatically using API
This commit is contained in:
parent
c042d9e39a
commit
6e62ffdd22
2 changed files with 50 additions and 12 deletions
|
@ -84,15 +84,8 @@ from plexpy import helpers
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
$('#osxnotifyregister').click(function () {
|
|
||||||
var osx_notify_app = $("#osx_notify_app").val();
|
|
||||||
$.get("/osxnotifyregister", { 'app': osx_notify_app }, function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); });
|
|
||||||
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
|
||||||
})
|
|
||||||
|
|
||||||
$('#save-notification-item').click(function() {
|
function reloadModal() {
|
||||||
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
|
||||||
// Reload modal to update certain fields
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'get_notification_agent_config',
|
url: 'get_notification_agent_config',
|
||||||
data: { config_id: '${config_id}' },
|
data: { config_id: '${config_id}' },
|
||||||
|
@ -102,6 +95,18 @@ from plexpy import helpers
|
||||||
$("#notification-config-modal").html(xhr.responseText);
|
$("#notification-config-modal").html(xhr.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#osxnotifyregister').click(function () {
|
||||||
|
var osx_notify_app = $("#osx_notify_app").val();
|
||||||
|
$.get("/osxnotifyregister", { 'app': osx_notify_app }, function (data) { $('#ajaxMsg').html("<i class='fa fa-check'></i> " + data); });
|
||||||
|
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#save-notification-item').click(function () {
|
||||||
|
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
||||||
|
// Reload modal to update certain fields
|
||||||
|
reloadModal();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -127,8 +132,14 @@ from plexpy import helpers
|
||||||
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
$('#ajaxMsg').addClass('success').fadeIn().delay(3000).fadeOut();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#pushbullet_apikey').on('change', function () {
|
||||||
|
doAjaxCall('set_notification_config', $(this), 'tabs', true);
|
||||||
|
reloadModal();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
// Never send checkbox values directly, always substitute value in hidden input.
|
// Never send checkbox values directly, always substitute value in hidden input.
|
||||||
$('.checkboxes').click(function() {
|
$('.checkboxes').click(function () {
|
||||||
var configToggle = $(this).data('id');
|
var configToggle = $(this).data('id');
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(":checked")) {
|
||||||
$("#"+configToggle).val(1);
|
$("#"+configToggle).val(1);
|
||||||
|
|
|
@ -824,6 +824,31 @@ class PUSHBULLET(object):
|
||||||
|
|
||||||
self.notify('Main Screen Activate', 'Test Message')
|
self.notify('Main Screen Activate', 'Test Message')
|
||||||
|
|
||||||
|
def get_devices(self):
|
||||||
|
if plexpy.CONFIG.PUSHBULLET_APIKEY:
|
||||||
|
http_handler = HTTPSConnection("api.pushbullet.com")
|
||||||
|
http_handler.request("GET", "/v2/devices",
|
||||||
|
headers={'Content-type': "application/json",
|
||||||
|
'Authorization': 'Basic %s' % base64.b64encode(plexpy.CONFIG.PUSHBULLET_APIKEY + ":")})
|
||||||
|
response = http_handler.getresponse()
|
||||||
|
request_status = response.status
|
||||||
|
|
||||||
|
if request_status == 200:
|
||||||
|
data = json.loads(response.read())
|
||||||
|
devices = data.get('devices', [])
|
||||||
|
devices = {d['iden']: d['nickname'] for d in devices if d['active']}
|
||||||
|
devices.update({'': ''})
|
||||||
|
return devices
|
||||||
|
elif request_status >= 400 and request_status < 500:
|
||||||
|
logger.info(u"Unable to retrieve Pushbullet devices list: %s" % response.reason)
|
||||||
|
return {'': ''}
|
||||||
|
else:
|
||||||
|
logger.info(u"Unable to retrieve Pushbullet devices list.")
|
||||||
|
return {'': ''}
|
||||||
|
|
||||||
|
else:
|
||||||
|
return {'': ''}
|
||||||
|
|
||||||
def return_config_options(self):
|
def return_config_options(self):
|
||||||
config_option = [{'label': 'Pushbullet API Key',
|
config_option = [{'label': 'Pushbullet API Key',
|
||||||
'value': self.apikey,
|
'value': self.apikey,
|
||||||
|
@ -831,11 +856,13 @@ class PUSHBULLET(object):
|
||||||
'description': 'Your Pushbullet API key.',
|
'description': 'Your Pushbullet API key.',
|
||||||
'input_type': 'text'
|
'input_type': 'text'
|
||||||
},
|
},
|
||||||
{'label': 'Device ID',
|
{'label': 'Device',
|
||||||
'value': self.deviceid,
|
'value': self.deviceid,
|
||||||
'name': 'pushbullet_deviceid',
|
'name': 'pushbullet_deviceid',
|
||||||
'description': 'A device ID (optional). If set, will override channel tag.',
|
'description': 'Set your Pushbullet device. If set, will override channel tag. ' \
|
||||||
'input_type': 'text'
|
'Leave blank to notify on all devices.',
|
||||||
|
'input_type': 'select',
|
||||||
|
'select_options': self.get_devices()
|
||||||
},
|
},
|
||||||
{'label': 'Channel',
|
{'label': 'Channel',
|
||||||
'value': self.channel_tag,
|
'value': self.channel_tag,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue