Get Pushbullet devices automatically using API

This commit is contained in:
Jonathan Wong 2015-12-12 14:08:34 -08:00
commit 6e62ffdd22
2 changed files with 50 additions and 12 deletions

View file

@ -84,15 +84,8 @@ from plexpy import helpers
% endif
<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() {
doAjaxCall('set_notification_config', $(this), 'tabs', true);
// Reload modal to update certain fields
function reloadModal() {
$.ajax({
url: 'get_notification_agent_config',
data: { config_id: '${config_id}' },
@ -102,6 +95,18 @@ from plexpy import helpers
$("#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;
});
@ -127,6 +132,12 @@ from plexpy import helpers
$('#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.
$('.checkboxes').click(function () {
var configToggle = $(this).data('id');

View file

@ -824,6 +824,31 @@ class PUSHBULLET(object):
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):
config_option = [{'label': 'Pushbullet API Key',
'value': self.apikey,
@ -831,11 +856,13 @@ class PUSHBULLET(object):
'description': 'Your Pushbullet API key.',
'input_type': 'text'
},
{'label': 'Device ID',
{'label': 'Device',
'value': self.deviceid,
'name': 'pushbullet_deviceid',
'description': 'A device ID (optional). If set, will override channel tag.',
'input_type': 'text'
'description': 'Set your Pushbullet device. If set, will override channel tag. ' \
'Leave blank to notify on all devices.',
'input_type': 'select',
'select_options': self.get_devices()
},
{'label': 'Channel',
'value': self.channel_tag,