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

Enable passing of more Pushover API parameters. #570

Merged
merged 2 commits into from
Aug 21, 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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in progress
- SMTP service plugin: Add support for minimal configuration w/o TLS and AUTH
- Update dependencies: Use Jinja2 3.x; Remove configparser, it is built into Python 3
- Add support for Python 3.11
- Pushover service plugin: Enable passing of parameters ``html``, ``url``, ``url_title``


2021-10-31 0.28.1
Expand Down
15 changes: 15 additions & 0 deletions HANDBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,21 @@ NOTE: `callback` is an optional URL for pushover to [ack messages](https://pusho
| `title` | O | application title (dflt: pushover dflt) |
| `priority` | O | priority. (dflt: pushover setting) |

Users can enable Pushover's [HTML styling](https://pushover.net/api#html) or [Supplementary URLs](https://pushover.net/api#urls) support in messages by adding the `html`, `url`, and `url_title` keys to the data object:

```ini
[config:pushover]
callback = None
alldata = PushoverAllData()
```

```
def PushoverAllData(topic, data, srv=None):
return {
'url': 'https://somedomain/path',
}
```

The pushover service will accept a payload with either a simple text message, or a json payload which contains
a `message` and either an `imageurl` or `imagebase64` encoded image.

Expand Down
5 changes: 5 additions & 0 deletions mqttwarn/services/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def plugin(srv, item):
else:
params['message'] = item.message

# Check for a few more Pushover API parameters
for key in ['html', 'url', 'url_title']:
if key in item.data:
params[key] = item.data[key]

# check if there is an image contained in a JSON payload
# (support either an image URL or base64 encoded image)
image = None
Expand Down
37 changes: 37 additions & 0 deletions tests/services/test_pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,43 @@ def test_pushover_success_with_sound(srv, caplog):
assert "Successfully sent pushover notification" in caplog.text


@responses.activate
def test_pushover_success_with_html_and_url_and_url_title(srv, caplog):

module = load_module_from_file("mqttwarn/services/pushover.py")

item = Item(
config={},
target="test",
addrs=["userkey2", "appkey2"],
message="⚽ Notification message ⚽",
data={
"html": "<p>⚽ Notification message ⚽</p>",
"url": "https://example.org/foo",
"url_title": "Notification group 'foo'",
},
)

with caplog.at_level(logging.DEBUG):

add_successful_mock_response()
outcome = module.plugin(srv, item)

assert (
responses.calls[0].request.body
== "user=userkey2&token=appkey2&retry=60&expire=3600&message=%E2%9A%BD+Notification+message+%E2%9A%BD"
"&html=%3Cp%3E%E2%9A%BD+Notification+message+%E2%9A%BD%3C%2Fp%3E&url=https%3A%2F%2Fexample.org%2Ffoo"
"&url_title=Notification+group+%27foo%27"
)

assert responses.calls[0].response.status_code == 200
assert responses.calls[0].response.text == '{"status": 1}'

assert outcome is True
assert "Sending pushover notification to test" in caplog.text
assert "Successfully sent pushover notification" in caplog.text


@responses.activate
def test_pushover_success_with_devices(srv, caplog):

Expand Down