Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial working Apprise integration, needs testing and verification. #124

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,12 @@ def settings_page(action=None):
if request.method == 'POST' and action == 'notify':
response = request.form

if _is_checked(response, 'apprise_enabled'):
settings['apprise']['enabled'] = True
else:
settings['apprise']['enabled'] = False
if 'appriselocations' in response:
settings['apprise']['locations'] = response.getlist('appriselocations')
if _is_checked(response, 'ifttt_enabled'):
settings['ifttt']['enabled'] = True
else:
Expand Down
1 change: 1 addition & 0 deletions auto-install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ $SUDO pip3 install gpiozero
$SUDO pip3 install redis
$SUDO pip3 install uuid
$SUDO pip3 install influxdb-client[ciso]
$SUDO pip3 install apprise

# Setup config.txt to enable busses
clear
Expand Down
5 changes: 5 additions & 0 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def default_settings():
'first_time_setup' : True, # Set to True on first setup, to run wizard on load
}

settings['apprise'] = {
'enabled': False,
'locations': {} # list of locations
}

settings['ifttt'] = {
'enabled': False,
'APIKey': '' # API Key for WebMaker IFTTT App notification
Expand Down
22 changes: 22 additions & 0 deletions notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import time
import requests
import json
import apprise
from common import write_event, write_settings, write_control


Expand Down Expand Up @@ -216,6 +217,8 @@ def _build_notification(notify_event, control, settings, pelletdb):
query_args = {"value1": 'Unknown Notification issue'}
write_event(settings, body_message)

if settings['apprise']['locations'] != '' and settings['apprise']['enabled']:
_send_apprise_notifications(settings, title_message, body_message)
if settings['ifttt']['APIKey'] != '' and settings['ifttt']['enabled']:
_send_ifttt_notification(settings, notify_event, query_args)
if settings['pushbullet']['APIKey'] != '' and settings['pushbullet']['enabled']:
Expand All @@ -227,6 +230,25 @@ def _build_notification(notify_event, control, settings, pelletdb):
_send_onesignal_notification(settings, title_message, body_message, channel)


def _send_apprise_notifications(settings, title_message, body_message):
"""
Send Apprise Notifications

:param settings: Settings
:param title_message: Message Title
:param body_message: Message Body
"""
appriseHandler = apprise.Apprise()

for location in settings['apprise']['locations']:
appriseHandler.add(location)

result = appriseHandler.notify(
title=title_message,
body=body_message,
)


def _send_pushover_notification(settings, title_message, body_message):
"""
Send Pushover Notifications
Expand Down
19 changes: 19 additions & 0 deletions static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,4 +746,23 @@ $(document).ready(function() {
}
});

$('button[name=addAppriseLocation]').click(function(e) {
e.preventDefault();
$('.appriselocation').last().clone(true) //set withDataAndEvents to true in .clone to include event handlers
.find("input:text").val("").end()
.insertAfter($('.appriselocation').last());
});

$('button[name=appriseDeleteRow]').click(function(e) {
e.preventDefault();
if($(this).parent().parent().find("input:text").val().length > 0) {
if(confirm('Row is not empty, are you sure?')) {
$(this).parent().parent().remove();
}
}
else {
$(this).parent().parent().remove();
}
});

}); // End of document ready function
37 changes: 37 additions & 0 deletions templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,43 @@ <h5>
</h5>
</div>
<div class="card-body">
<!-- Apprise Notifications -->
<div class="card shadow-sm">
<div class="card-header">
<h5>Apprise Notifications</h5>
</div>
<div class="card-body">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="apprise_enabled" name="apprise_enabled" {% if settings['apprise']['enabled'] == True %}checked{% endif %}>
<label class="custom-control-label" for="apprise_enabled">Apprise Enabled</label>
</div>
<br>
{% if settings['apprise']['locations']|length %}
{% for location in settings['apprise']['locations'] %}<div class="input-group mb-3 appriselocation">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="fas fa-link"></i>&nbsp; Location</span>
</div>
<input id="appriselocations" type="text" class="form-control" name="appriselocations" value="{{location}}">
<div class="input-group-append">
<button type="button" name="appriseDeleteRow" class="btn btn-danger"><i class="fas fa-minus"></i></button>
</div>
</div>{% endfor %}
{% else %}<div class="input-group mb-3 appriselocation">
<div class="input-group-prepend">
<span class="input-group-text">
<i class="fas fa-link"></i>&nbsp; Location</span>
</div>
<input id="appriselocations" type="text" class="form-control" name="appriselocations" value="">
</div>{% endif %}
<div class="mb-3 text-right">
<button type="button" name="addAppriseLocation" class="btn btn-primary"><i class="fas fa-plus"></i> Add Location</button>
</div>
</div>
<!-- End of card body -->
</div>
<!-- End of Card -->
<br>
<!-- IFTTT WebHooks -->
<div class="card shadow-sm">
<div class="card-header">
Expand Down