mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 21:21:15 -07:00
Add onesignal_id to register device API
This commit is contained in:
parent
0272c35047
commit
36324d10dc
6 changed files with 38 additions and 21 deletions
5
API.md
5
API.md
|
@ -2674,11 +2674,12 @@ Registers the Tautulli Android App for notifications.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
device_name (str): The device name of the Tautulli Android App
|
device_id (str): The unique device identifier for the mobile device
|
||||||
device_id (str): The OneSignal device id of the Tautulli Android App
|
device_name (str): The device name of the mobile device
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
friendly_name (str): A friendly name to identify the mobile device
|
friendly_name (str): A friendly name to identify the mobile device
|
||||||
|
onesignal_id (str): The OneSignal id for the mobile device
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<label for="friendly_name">OneSignal Device ID</label>
|
<label for="friendly_name">OneSignal Device ID</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<input type="text" class="form-control" id="device_id" value="${device['device_id']}" size="30" readonly>
|
<input type="text" class="form-control" id="onesignal_id" value="${device['onesignal_id'] or ''}" size="30" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="help-block">Your OneSignal device ID for notifications.</p>
|
<p class="help-block">Your OneSignal device ID for notifications.</p>
|
||||||
|
|
|
@ -743,7 +743,7 @@ def dbcheck():
|
||||||
c_db.execute(
|
c_db.execute(
|
||||||
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT, '
|
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT, '
|
||||||
'last_seen INTEGER, official INTEGER DEFAULT 0)'
|
'onesignal_id TEXT, last_seen INTEGER, official INTEGER DEFAULT 0)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
|
||||||
|
@ -2012,6 +2012,15 @@ def dbcheck():
|
||||||
c_db.execute('UPDATE mobile_devices SET official = ? WHERE device_id = ?',
|
c_db.execute('UPDATE mobile_devices SET official = ? WHERE device_id = ?',
|
||||||
[mobile_app.validate_device_id(device_id), device_id])
|
[mobile_app.validate_device_id(device_id), device_id])
|
||||||
|
|
||||||
|
# Upgrade mobile_devices table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT onesignal_id FROM mobile_devices')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug("Altering database. Updating database table mobile_devices.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE mobile_devices ADD COLUMN onesignal_id TEXT'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade notifiers table from earlier versions
|
# Upgrade notifiers table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT custom_conditions FROM notifiers')
|
c_db.execute('SELECT custom_conditions FROM notifiers')
|
||||||
|
|
|
@ -391,16 +391,17 @@ class API2(object):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def register_device(self, device_id='', device_name='', friendly_name='', **kwargs):
|
def register_device(self, device_id='', device_name='', friendly_name='', onesignal_id='', **kwargs):
|
||||||
""" Registers the Tautulli Android App for notifications.
|
""" Registers the Tautulli Android App for notifications.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
device_name (str): The device name of the Tautulli Android App
|
device_id (str): The unique device identifier for the mobile device
|
||||||
device_id (str): The OneSignal device id of the Tautulli Android App
|
device_name (str): The device name of the mobile device
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
friendly_name (str): A friendly name to identify the mobile device
|
friendly_name (str): A friendly name to identify the mobile device
|
||||||
|
onesignal_id (str): The OneSignal id for the mobile device
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
|
@ -419,7 +420,8 @@ class API2(object):
|
||||||
result = mobile_app.add_mobile_device(device_id=device_id,
|
result = mobile_app.add_mobile_device(device_id=device_id,
|
||||||
device_name=device_name,
|
device_name=device_name,
|
||||||
device_token=self._api_apikey,
|
device_token=self._api_apikey,
|
||||||
friendly_name=friendly_name)
|
friendly_name=friendly_name,
|
||||||
|
onesignal_id=onesignal_id)
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
self._api_msg = 'Device registration successful.'
|
self._api_msg = 'Device registration successful.'
|
||||||
|
|
|
@ -87,13 +87,14 @@ def get_mobile_device_by_token(device_token=None):
|
||||||
return get_mobile_devices(device_token=device_token)
|
return get_mobile_devices(device_token=device_token)
|
||||||
|
|
||||||
|
|
||||||
def add_mobile_device(device_id=None, device_name=None, device_token=None, friendly_name=None):
|
def add_mobile_device(device_id=None, device_name=None, device_token=None, friendly_name=None, onesignal_id=None):
|
||||||
db = database.MonitorDatabase()
|
db = database.MonitorDatabase()
|
||||||
|
|
||||||
keys = {'device_id': device_id}
|
keys = {'device_id': device_id}
|
||||||
values = {'device_name': device_name,
|
values = {'device_name': device_name,
|
||||||
'device_token': device_token,
|
'device_token': device_token,
|
||||||
'official': validate_device_id(device_id=device_id)}
|
'onesignal_id': onesignal_id,
|
||||||
|
'official': validate_onesignal_id(onesignal_id=onesignal_id)}
|
||||||
|
|
||||||
if friendly_name:
|
if friendly_name:
|
||||||
values['friendly_name'] = friendly_name
|
values['friendly_name'] = friendly_name
|
||||||
|
@ -172,11 +173,14 @@ def set_last_seen(device_token=None):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def validate_device_id(device_id):
|
def validate_onesignal_id(onesignal_id):
|
||||||
|
if onesignal_id is None:
|
||||||
|
return False
|
||||||
|
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
payload = {'app_id': _ONESIGNAL_APP_ID}
|
payload = {'app_id': _ONESIGNAL_APP_ID}
|
||||||
|
|
||||||
r = requests.get('https://onesignal.com/api/v1/players/{}'.format(device_id), headers=headers, json=payload)
|
r = requests.get('https://onesignal.com/api/v1/players/{}'.format(onesignal_id), headers=headers, json=payload)
|
||||||
return r.status_code == 200
|
return r.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -929,7 +929,7 @@ class ANDROIDAPP(Notifier):
|
||||||
#logger.debug("Salt (base64): {}".format(base64.b64encode(salt)))
|
#logger.debug("Salt (base64): {}".format(base64.b64encode(salt)))
|
||||||
|
|
||||||
payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
|
payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
|
||||||
'include_player_ids': [self.config['device_id']],
|
'include_player_ids': [device['onesignal_id']],
|
||||||
'contents': {'en': 'Tautulli Notification'},
|
'contents': {'en': 'Tautulli Notification'},
|
||||||
'data': {'encrypted': True,
|
'data': {'encrypted': True,
|
||||||
'cipher_text': base64.b64encode(encrypted_data),
|
'cipher_text': base64.b64encode(encrypted_data),
|
||||||
|
@ -942,7 +942,7 @@ class ANDROIDAPP(Notifier):
|
||||||
"Install the library to encrypt the notifications.")
|
"Install the library to encrypt the notifications.")
|
||||||
|
|
||||||
payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
|
payload = {'app_id': mobile_app._ONESIGNAL_APP_ID,
|
||||||
'include_player_ids': [self.config['device_id']],
|
'include_player_ids': [device['onesignal_id']],
|
||||||
'contents': {'en': 'Tautulli Notification'},
|
'contents': {'en': 'Tautulli Notification'},
|
||||||
'data': {'encrypted': False,
|
'data': {'encrypted': False,
|
||||||
'plain_text': plaintext_data}
|
'plain_text': plaintext_data}
|
||||||
|
@ -958,7 +958,8 @@ class ANDROIDAPP(Notifier):
|
||||||
db = database.MonitorDatabase()
|
db = database.MonitorDatabase()
|
||||||
|
|
||||||
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 != ""'
|
||||||
result = db.select(query=query)
|
result = db.select(query=query)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli Notifiers :: Unable to retrieve Android app devices list: %s." % e)
|
logger.warn("Tautulli Notifiers :: Unable to retrieve Android app devices list: %s." % e)
|
||||||
|
@ -983,9 +984,9 @@ class ANDROIDAPP(Notifier):
|
||||||
'The content of your notifications will be sent unencrypted!</strong><br>'
|
'The content of your notifications will be sent unencrypted!</strong><br>'
|
||||||
'Please install the library to encrypt the notification contents. '
|
'Please install the library to encrypt the notification contents. '
|
||||||
'Instructions can be found in the '
|
'Instructions can be found in the '
|
||||||
'<a href="https://github.com/%s/%s-Wiki/wiki/'
|
'<a href="' + helpers.anon_url(
|
||||||
'Frequently-Asked-Questions#notifications-pycryptodome'
|
'https://github.com/%s/%s-Wiki/wiki/Frequently-Asked-Questions#notifications-pycryptodome'
|
||||||
'" target="_blank">FAQ</a>.' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO),
|
% (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO)) + '" target="_blank">FAQ</a>.' ,
|
||||||
'input_type': 'help'
|
'input_type': 'help'
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
@ -998,7 +999,7 @@ class ANDROIDAPP(Notifier):
|
||||||
|
|
||||||
config_option[-1]['description'] += '<br><br>Notifications are sent using the ' \
|
config_option[-1]['description'] += '<br><br>Notifications are sent using the ' \
|
||||||
'<a href="' + helpers.anon_url('https://onesignal.com') + '" target="_blank">' \
|
'<a href="' + helpers.anon_url('https://onesignal.com') + '" target="_blank">' \
|
||||||
'OneSignal</a> API. Some user data is collected and cannot be encrypted. ' \
|
'OneSignal</a>. Some user data is collected and cannot be encrypted. ' \
|
||||||
'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.'
|
||||||
|
@ -1008,7 +1009,7 @@ class ANDROIDAPP(Notifier):
|
||||||
if not devices:
|
if not devices:
|
||||||
config_option.append({
|
config_option.append({
|
||||||
'label': 'Device',
|
'label': 'Device',
|
||||||
'description': 'No devices registered. '
|
'description': 'No mobile devices registered with OneSignal. '
|
||||||
'<a data-tab-destination="android_app" data-toggle="tab" data-dismiss="modal">'
|
'<a data-tab-destination="android_app" data-toggle="tab" data-dismiss="modal">'
|
||||||
'Get the Android App</a> and register a device.',
|
'Get the Android App</a> and register a device.',
|
||||||
'input_type': 'help'
|
'input_type': 'help'
|
||||||
|
@ -1018,7 +1019,7 @@ class ANDROIDAPP(Notifier):
|
||||||
'label': 'Device',
|
'label': 'Device',
|
||||||
'value': self.config['device_id'],
|
'value': self.config['device_id'],
|
||||||
'name': 'androidapp_device_id',
|
'name': 'androidapp_device_id',
|
||||||
'description': 'Set your Android app device or '
|
'description': 'Set your mobile device or '
|
||||||
'<a data-tab-destination="android_app" data-toggle="tab" data-dismiss="modal">'
|
'<a data-tab-destination="android_app" data-toggle="tab" data-dismiss="modal">'
|
||||||
'register a new device</a> with Tautulli.',
|
'register a new device</a> with Tautulli.',
|
||||||
'input_type': 'select',
|
'input_type': 'select',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue