mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Add mobile device settings
This commit is contained in:
parent
1ca1f9975c
commit
019787b32d
9 changed files with 343 additions and 173 deletions
|
@ -350,7 +350,7 @@ class API2:
|
|||
|
||||
return data
|
||||
|
||||
def register_device(self, device_id='', device_name='', **kwargs):
|
||||
def register_device(self, device_id='', device_name='', friendly_name='', **kwargs):
|
||||
""" Registers the PlexPy Android App for notifications.
|
||||
|
||||
```
|
||||
|
@ -359,7 +359,7 @@ class API2:
|
|||
device_id (str): The OneSignal device id of the PlexPy Android App
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
friendly_name (str): A friendly name to identify the mobile device
|
||||
|
||||
Returns:
|
||||
None
|
||||
|
@ -377,7 +377,8 @@ class API2:
|
|||
|
||||
result = mobile_app.add_mobile_device(device_id=device_id,
|
||||
device_name=device_name,
|
||||
device_token=self._api_apikey)
|
||||
device_token=self._api_apikey,
|
||||
friendly_name=friendly_name)
|
||||
|
||||
if result:
|
||||
self._api_msg = 'Device registration successful.'
|
||||
|
|
|
@ -49,13 +49,16 @@ def get_mobile_device_by_token(device_token=None):
|
|||
return get_mobile_devices(device_token=device_token)
|
||||
|
||||
|
||||
def add_mobile_device(device_id=None, device_name=None, device_token=None):
|
||||
def add_mobile_device(device_id=None, device_name=None, device_token=None, friendly_name=None):
|
||||
db = database.MonitorDatabase()
|
||||
|
||||
keys = {'device_id': device_id}
|
||||
values = {'device_name': device_name,
|
||||
'device_token': device_token}
|
||||
|
||||
if friendly_name:
|
||||
values['friendly_name'] = friendly_name
|
||||
|
||||
try:
|
||||
result = db.upsert(table_name='mobile_devices', key_dict=keys, value_dict=values)
|
||||
except Exception as e:
|
||||
|
@ -70,12 +73,49 @@ def add_mobile_device(device_id=None, device_name=None, device_token=None):
|
|||
return True
|
||||
|
||||
|
||||
def delete_mobile_device(device_id=None):
|
||||
def get_mobile_device_config(mobile_device_id=None):
|
||||
if str(mobile_device_id).isdigit():
|
||||
mobile_device_id = int(mobile_device_id)
|
||||
else:
|
||||
logger.error(u"PlexPy MobileApp :: Unable to retrieve mobile device config: invalid mobile_device_id %s." % mobile_device_id)
|
||||
return None
|
||||
|
||||
db = database.MonitorDatabase()
|
||||
result = db.select_single('SELECT * FROM mobile_devices WHERE id = ?',
|
||||
args=[mobile_device_id])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def set_mobile_device_config(mobile_device_id=None, **kwargs):
|
||||
if str(mobile_device_id).isdigit():
|
||||
mobile_device_id = int(mobile_device_id)
|
||||
else:
|
||||
logger.error(u"PlexPy MobileApp :: Unable to set exisiting mobile device: invalid mobile_device_id %s." % mobile_device_id)
|
||||
return False
|
||||
|
||||
keys = {'id': mobile_device_id}
|
||||
values = {}
|
||||
|
||||
if kwargs.get('friendly_name'):
|
||||
values['friendly_name'] = kwargs['friendly_name']
|
||||
|
||||
db = database.MonitorDatabase()
|
||||
try:
|
||||
db.upsert(table_name='mobile_devices', key_dict=keys, value_dict=values)
|
||||
logger.info(u"PlexPy MobileApp :: Updated mobile device agent: mobile_device_id %s." % mobile_device_id)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warn(u"PlexPy MobileApp :: Unable to update mobile device: %s." % e)
|
||||
return False
|
||||
|
||||
|
||||
def delete_mobile_device(mobile_device_id=None):
|
||||
db = database.MonitorDatabase()
|
||||
|
||||
if device_id:
|
||||
logger.debug(u"PlexPy MobileApp :: Deleting device_id %s from the database." % device_id)
|
||||
result = db.action('DELETE FROM mobile_devices WHERE device_id = ?', args=[device_id])
|
||||
if mobile_device_id:
|
||||
logger.debug(u"PlexPy MobileApp :: Deleting device_id %s from the database." % mobile_device_id)
|
||||
result = db.action('DELETE FROM mobile_devices WHERE id = ?', args=[mobile_device_id])
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -3066,9 +3066,9 @@ class WebInterface(object):
|
|||
result = notifiers.set_notifier_config(notifier_id=notifier_id, agent_id=agent_id, **kwargs)
|
||||
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'Added notification agent.'}
|
||||
return {'result': 'success', 'message': 'Saved notification agent.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Failed to add notification agent.'}
|
||||
return {'result': 'error', 'message': 'Failed to save notification agent.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
|
@ -3277,16 +3277,49 @@ class WebInterface(object):
|
|||
else:
|
||||
return {'result': 'error', 'message': 'Device not registered.'}
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
@requireAuth(member_of("admin"))
|
||||
def get_mobile_device_config_modal(self, mobile_device_id=None, **kwargs):
|
||||
result = mobile_app.get_mobile_device_config(mobile_device_id=mobile_device_id)
|
||||
|
||||
return serve_template(templatename="mobile_device_config.html", device=result)
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def delete_mobile_device(self, device_id=None, **kwargs):
|
||||
def set_mobile_device_config(self, mobile_device_id=None, **kwargs):
|
||||
""" Configure an exisitng notificaiton agent.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
mobile_device_id (int): The mobile device config to update
|
||||
|
||||
Optional parameters:
|
||||
friendly_name (str): A friendly name to identify the mobile device
|
||||
|
||||
Returns:
|
||||
None
|
||||
```
|
||||
"""
|
||||
result = mobile_app.set_mobile_device_config(mobile_device_id=mobile_device_id, **kwargs)
|
||||
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'Saved mobile device.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Failed to save mobile device.'}
|
||||
|
||||
@cherrypy.expose
|
||||
@cherrypy.tools.json_out()
|
||||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def delete_mobile_device(self, mobile_device_id=None, **kwargs):
|
||||
""" Remove a mobile device from the database.
|
||||
|
||||
```
|
||||
Required parameters:
|
||||
device_id (int): The device to delete
|
||||
mobile_device_id (int): The device id to delete
|
||||
|
||||
Optional parameters:
|
||||
None
|
||||
|
@ -3295,9 +3328,9 @@ class WebInterface(object):
|
|||
None
|
||||
```
|
||||
"""
|
||||
result = mobile_app.delete_mobile_device(device_id=device_id)
|
||||
result = mobile_app.delete_mobile_device(mobile_device_id=mobile_device_id)
|
||||
if result:
|
||||
return {'result': 'success', 'message': 'Device deleted successfully.'}
|
||||
return {'result': 'success', 'message': 'Deleted mobile device.'}
|
||||
else:
|
||||
return {'result': 'error', 'message': 'Failed to delete device.'}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue