Refactor some notifiers code

This commit is contained in:
JonnyWong16 2020-04-18 19:59:30 -07:00
parent 231d439ef8
commit fb5d97a627
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -66,7 +66,6 @@ import users
BROWSER_NOTIFIERS = {} BROWSER_NOTIFIERS = {}
AGENT_IDS = {'growl': 0, AGENT_IDS = {'growl': 0,
'prowl': 1, 'prowl': 1,
'xbmc': 2, 'xbmc': 2,
@ -103,131 +102,157 @@ def available_notification_agents():
agents = [{'label': 'Tautulli Remote Android App', agents = [{'label': 'Tautulli Remote Android App',
'name': 'androidapp', 'name': 'androidapp',
'id': AGENT_IDS['androidapp'], 'id': AGENT_IDS['androidapp'],
'class': ANDROIDAPP,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Boxcar', {'label': 'Boxcar',
'name': 'boxcar', 'name': 'boxcar',
'id': AGENT_IDS['boxcar'], 'id': AGENT_IDS['boxcar'],
'class': BOXCAR,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Browser', {'label': 'Browser',
'name': 'browser', 'name': 'browser',
'id': AGENT_IDS['browser'], 'id': AGENT_IDS['browser'],
'class': BROWSER,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Discord', {'label': 'Discord',
'name': 'discord', 'name': 'discord',
'id': AGENT_IDS['discord'], 'id': AGENT_IDS['discord'],
'class': DISCORD,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Email', {'label': 'Email',
'name': 'email', 'name': 'email',
'id': AGENT_IDS['email'], 'id': AGENT_IDS['email'],
'class': EMAIL,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Facebook', {'label': 'Facebook',
'name': 'facebook', 'name': 'facebook',
'id': AGENT_IDS['facebook'], 'id': AGENT_IDS['facebook'],
'class': FACEBOOK,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'GroupMe', {'label': 'GroupMe',
'name': 'groupme', 'name': 'groupme',
'id': AGENT_IDS['groupme'], 'id': AGENT_IDS['groupme'],
'class': GROUPME,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Growl', {'label': 'Growl',
'name': 'growl', 'name': 'growl',
'id': AGENT_IDS['growl'], 'id': AGENT_IDS['growl'],
'class': GROWL,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Hipchat', {'label': 'Hipchat',
'name': 'hipchat', 'name': 'hipchat',
'id': AGENT_IDS['hipchat'], 'id': AGENT_IDS['hipchat'],
'class': HIPCHAT,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'IFTTT', {'label': 'IFTTT',
'name': 'ifttt', 'name': 'ifttt',
'id': AGENT_IDS['ifttt'], 'id': AGENT_IDS['ifttt'],
'class': IFTTT,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Join', {'label': 'Join',
'name': 'join', 'name': 'join',
'id': AGENT_IDS['join'], 'id': AGENT_IDS['join'],
'class': JOIN,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Kodi', {'label': 'Kodi',
'name': 'xbmc', 'name': 'xbmc',
'id': AGENT_IDS['xbmc'], 'id': AGENT_IDS['xbmc'],
'class': XBMC,
'action_types': ('all',) 'action_types': ('all',)
}, },
# {'label': 'Notify My Android', # {'label': 'Notify My Android',
# 'name': 'nma', # 'name': 'nma',
# 'id': AGENT_IDS['nma'], # 'id': AGENT_IDS['nma'],
# 'class': NMA,
# 'action_types': ('all',) # 'action_types': ('all',)
# }, # },
{'label': 'MQTT', {'label': 'MQTT',
'name': 'mqtt', 'name': 'mqtt',
'id': AGENT_IDS['mqtt'], 'id': AGENT_IDS['mqtt'],
'class': MQTT,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Plex Home Theater', {'label': 'Plex Home Theater',
'name': 'plex', 'name': 'plex',
'id': AGENT_IDS['plex'], 'id': AGENT_IDS['plex'],
'class': PLEX,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Plex Mobile App', {'label': 'Plex Mobile App',
'name': 'plexmobileapp', 'name': 'plexmobileapp',
'id': AGENT_IDS['plexmobileapp'], 'id': AGENT_IDS['plexmobileapp'],
'class': PLEXMOBILEAPP,
'action_types': ('on_play', 'on_created', 'on_newdevice') 'action_types': ('on_play', 'on_created', 'on_newdevice')
}, },
{'label': 'Prowl', {'label': 'Prowl',
'name': 'prowl', 'name': 'prowl',
'id': AGENT_IDS['prowl'], 'id': AGENT_IDS['prowl'],
'class': PROWL,
'action_types': ('all',) 'action_types': ('all',)
}, },
# {'label': 'Pushalot', # {'label': 'Pushalot',
# 'name': 'pushalot', # 'name': 'pushalot',
# 'id': AGENT_IDS['pushalot'], # 'id': AGENT_IDS['pushalot'],
# 'class': PUSHALOT,
# 'action_types': ('all',) # 'action_types': ('all',)
# }, # },
{'label': 'Pushbullet', {'label': 'Pushbullet',
'name': 'pushbullet', 'name': 'pushbullet',
'id': AGENT_IDS['pushbullet'], 'id': AGENT_IDS['pushbullet'],
'class': PUSHBULLET,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Pushover', {'label': 'Pushover',
'name': 'pushover', 'name': 'pushover',
'id': AGENT_IDS['pushover'], 'id': AGENT_IDS['pushover'],
'class': PUSHOVER,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Script', {'label': 'Script',
'name': 'scripts', 'name': 'scripts',
'id': AGENT_IDS['scripts'], 'id': AGENT_IDS['scripts'],
'class': SCRIPTS,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Slack', {'label': 'Slack',
'name': 'slack', 'name': 'slack',
'id': AGENT_IDS['slack'], 'id': AGENT_IDS['slack'],
'class': SLACK,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Telegram', {'label': 'Telegram',
'name': 'telegram', 'name': 'telegram',
'id': AGENT_IDS['telegram'], 'id': AGENT_IDS['telegram'],
'class': TELEGRAM,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Twitter', {'label': 'Twitter',
'name': 'twitter', 'name': 'twitter',
'id': AGENT_IDS['twitter'], 'id': AGENT_IDS['twitter'],
'class': TWITTER,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Webhook', {'label': 'Webhook',
'name': 'webhook', 'name': 'webhook',
'id': AGENT_IDS['webhook'], 'id': AGENT_IDS['webhook'],
'class': WEBHOOK,
'action_types': ('all',) 'action_types': ('all',)
}, },
{'label': 'Zapier', {'label': 'Zapier',
'name': 'zapier', 'name': 'zapier',
'id': AGENT_IDS['zapier'], 'id': AGENT_IDS['zapier'],
'class': ZAPIER,
'action_types': ('all',) 'action_types': ('all',)
} }
] ]
@ -237,6 +262,7 @@ def available_notification_agents():
agents.append({'label': 'macOS Notification Center', agents.append({'label': 'macOS Notification Center',
'name': 'osx', 'name': 'osx',
'id': AGENT_IDS['osx'], 'id': AGENT_IDS['osx'],
'class': OSX,
'action_types': ('all',) 'action_types': ('all',)
}) })
@ -382,8 +408,8 @@ def available_notification_actions(agent_id=None):
} }
] ]
if agent_id: if str(agent_id).isdigit():
action_types = get_notify_agents(return_dict=True).get(agent_id, {}).get('action_types', []) action_types = get_notify_agents(return_dict=True).get(int(agent_id), {}).get('action_types', [])
if 'all' not in action_types: if 'all' not in action_types:
actions = [a for a in actions if a['name'] in action_types] actions = [a for a in actions if a['name'] in action_types]
@ -392,64 +418,8 @@ def available_notification_actions(agent_id=None):
def get_agent_class(agent_id=None, config=None): def get_agent_class(agent_id=None, config=None):
if str(agent_id).isdigit(): if str(agent_id).isdigit():
agent_id = int(agent_id) agent = get_notify_agents(return_dict=True).get(int(agent_id), {}).get('class', Notifier)
return agent(config=config)
if agent_id == 0:
return GROWL(config=config)
elif agent_id == 1:
return PROWL(config=config)
elif agent_id == 2:
return XBMC(config=config)
elif agent_id == 3:
return PLEX(config=config)
elif agent_id == 4:
return NMA(config=config)
elif agent_id == 5:
return PUSHALOT(config=config)
elif agent_id == 6:
return PUSHBULLET(config=config)
elif agent_id == 7:
return PUSHOVER(config=config)
elif agent_id == 8:
return OSX(config=config)
elif agent_id == 9:
return BOXCAR(config=config)
elif agent_id == 10:
return EMAIL(config=config)
elif agent_id == 11:
return TWITTER(config=config)
elif agent_id == 12:
return IFTTT(config=config)
elif agent_id == 13:
return TELEGRAM(config=config)
elif agent_id == 14:
return SLACK(config=config)
elif agent_id == 15:
return SCRIPTS(config=config)
elif agent_id == 16:
return FACEBOOK(config=config)
elif agent_id == 17:
return BROWSER(config=config)
elif agent_id == 18:
return JOIN(config=config)
elif agent_id == 19:
return HIPCHAT(config=config)
elif agent_id == 20:
return DISCORD(config=config)
elif agent_id == 21:
return ANDROIDAPP(config=config)
elif agent_id == 22:
return GROUPME(config=config)
elif agent_id == 23:
return MQTT(config=config)
elif agent_id == 24:
return ZAPIER(config=config)
elif agent_id == 25:
return WEBHOOK(config=config)
elif agent_id == 26:
return PLEXMOBILEAPP(config=config)
else:
return Notifier(config=config)
else: else:
return None return None