Skip to content

Commit

Permalink
[Pushsafer] Remove special handling for vibration again
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Mar 12, 2023
1 parent a40efe5 commit b171c1f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 29 deletions.
5 changes: 0 additions & 5 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ in progress

- Pushsafer: Fix to prevent submitting empty parameters to upstream API.

BREAKING CHANGE: This has an impact on the ``vibration`` parameter:
Previously, a Pushsafer notification would always have vibrations turned
on, which is considered to be a bug. Now, you will have to explicitly
configure ``vibration=0``, in order to use the "device-default" vibration.


2023-02-13 0.32.0
=================
Expand Down
7 changes: 2 additions & 5 deletions HANDBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,8 @@ In order to receive pushsafer notifications you need what is called a _private o
targets = {
'nagios' : ['privatekey', 'Device ID', 'Icon', 'Sound', 'Vibration', 'URL', 'Url Title', 'Time2Live', 'Priority', 'Retry', 'Expire', 'Answer'],
'tracking' : ['aliaskey1'],
'extraphone' : ['aliaskey2', '', '', '', '0', '', '', '60', '2', '60', '600', '0'],
'warnme' : ['aliaskey3', '', '', '', '0', '', '', '60', '1', '', '', '1']
'extraphone' : ['aliaskey2', '', '', '', '', '', '', '60', '2', '60', '600', '0'],
'warnme' : ['aliaskey3', '', '', '', '', '', '', '60', '1', '', '', '1']
}
```
Expand All @@ -2472,9 +2472,6 @@ Please note:
- [Retry](https://www.pushsafer.com/en/pushapi_ext#API-RE)
with [Expire](https://www.pushsafer.com/en/pushapi_ext#API-EX):
For configuring delivery retries, you must set both parameters.
- [Vibration](https://www.pushsafer.com/en/pushapi_ext#API-V):
`vibration=0` means "device-default" vibration. This is a special value
used by mqttwarn, it will be translated to an empty `v=` upstream parameter.
| Topic option | M/O | Description |
| ------------- | :----: | -------------------------------------- |
Expand Down
14 changes: 1 addition & 13 deletions mqttwarn/services/pushsafer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ def pushsafer(**kwargs):
def filter_empty_parameters(params: t.Dict[str, str]):
"""
Filter empty parameters.
Also, translate special value `vibration=0` into empty value,
because this currently signals "vibrate with device-default".
"""
effective_parameters = OrderedDict()
for key, value in params.items():
if value != "":
# Special handling for `vibration=0`.
# TODO: Remove after eventual upstream adjustments.
if key == "v" and str(value) == "0":
value = ""
effective_parameters[key] = value
return effective_parameters

Expand Down Expand Up @@ -151,12 +144,7 @@ def encode_v1(self):
params['s'] = addrs[3]

if len(addrs) > 4:
# Special handling for `vibration`.
# With the v1 configuration layout, it should not always trigger a vibration when left empty.
# Therefore, a synthetic value `0` can be used to configure "device-default" vibration.
value = str(addrs[4])
if value != "":
params['v'] = value
params['v'] = addrs[4]

if len(addrs) > 5:
params['u'] = addrs[5]
Expand Down
3 changes: 1 addition & 2 deletions tests/etc/better-addresses.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ targets = {
'device': '52|65|78',
'icon': 64,
'sound': 2,
# Zero means "vibrate with device-default".
'vibration': '0',
'vibration': 1,
'url': 'http://example.org',
'url_title': 'Example Org',
'time_to_live': 60,
Expand Down
3 changes: 1 addition & 2 deletions tests/services/pushsafer/test_pushsafer_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class IoTestItem:
IoTestItem(id="device-id", in_addrs=[TEST_TOKEN, "52|65|78"], out_data={"d": "52|65|78"}),
IoTestItem(id="icon", in_addrs=[TEST_TOKEN, "", "test.ico"], out_data={"i": "test.ico"}),
IoTestItem(id="sound", in_addrs=[TEST_TOKEN, "", "", "test.mp3"], out_data={"s": "test.mp3"}),
IoTestItem(id="vibration-default", in_addrs=[TEST_TOKEN, "", "", "", "0"], out_data={"v": ""}),
IoTestItem(id="vibration-two", in_addrs=[TEST_TOKEN, "", "", "", "2"], out_data={"v": "2"}),
IoTestItem(id="vibration", in_addrs=[TEST_TOKEN, "", "", "", "2"], out_data={"v": "2"}),
IoTestItem(
id="url", in_addrs=[TEST_TOKEN, "", "", "", "", "http://example.org"], out_data={"u": "http://example.org"}
),
Expand Down
3 changes: 1 addition & 2 deletions tests/services/pushsafer/test_pushsafer_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class IoTestItem:
IoTestItem(id="device-id", in_addrs={"private_key": TEST_TOKEN, "device": "52|65|78"}, out_data={"d": "52|65|78"}),
IoTestItem(id="icon", in_addrs={"private_key": TEST_TOKEN, "icon": "test.ico"}, out_data={"i": "test.ico"}),
IoTestItem(id="sound", in_addrs={"private_key": TEST_TOKEN, "sound": "test.mp3"}, out_data={"s": "test.mp3"}),
IoTestItem(id="vibration-default", in_addrs={"private_key": TEST_TOKEN, "vibration": 0}, out_data={"v": ""}),
IoTestItem(id="vibration-two", in_addrs={"private_key": TEST_TOKEN, "vibration": 2}, out_data={"v": "2"}),
IoTestItem(id="vibration", in_addrs={"private_key": TEST_TOKEN, "vibration": 2}, out_data={"v": "2"}),
IoTestItem(
id="url",
in_addrs={"private_key": TEST_TOKEN, "url": "http://example.org"},
Expand Down

0 comments on commit b171c1f

Please sign in to comment.