Skip to content

Commit 3092029

Browse files
appzeramotl
authored andcommitted
[Pushsafer] Add parameters for Confirm, Answer Options, and Force Answer
The corresponding parameter names are `cr`, `ao`, and `af`.
1 parent f9207eb commit 3092029

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ in progress
88

99
- Pushsafer: Fix to prevent submitting empty parameters to upstream API.
1010
- Pushsafer: Modernize configuration layout for target addresses.
11+
- Pushsafer: Add parameters for "Confirm", "Answer Options", and "Force Answer".
1112

1213

1314
2023-02-13 0.32.0

mqttwarn/services/pushsafer.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def encode_v1(self):
120120
9 (if present) is the Pushsafer retry after which time (in seconds 60-10800) a message should resend
121121
10 (if present) is the Pushsafer expire after which time (in seconds 60-10800) the retry should stopped
122122
11 (if present) is the Pushsafer answer, 1 = Answer, 0 = no possibility to answer
123+
12 (if present) is the Pushsafer answer options seperated by a pipe character e.g. yes|no|maybe
124+
13 (if present) is the Pushsafer force answer, 1 = yes, 0 = no
125+
14 (if present) is the Pushsafer message will be repeated after specified time delay when not confirmed
123126
"""
124127

125128
addrs = self.item.addrs
@@ -166,6 +169,15 @@ def encode_v1(self):
166169
if len(addrs) > 11:
167170
params['a'] = addrs[11]
168171

172+
if len(addrs) > 12:
173+
params['ao'] = addrs[12]
174+
175+
if len(addrs) > 13:
176+
params['af'] = addrs[13]
177+
178+
if len(addrs) > 14:
179+
params['cr'] = addrs[14]
180+
169181
if title is not None:
170182
params['t'] = title
171183

@@ -217,6 +229,9 @@ class PushsaferParameters:
217229
retry: t.Optional[int] = None
218230
expire: t.Optional[int] = None
219231
answer: t.Optional[int] = None
232+
answer_options: t.Optional[str] = None
233+
answer_force: t.Optional[int] = None
234+
confirm_repeat: t.Optional[int] = None
220235

221236
PARAMETER_MAP = {
222237
"device": "d",
@@ -230,6 +245,9 @@ class PushsaferParameters:
230245
"retry": "re",
231246
"expire": "ex",
232247
"answer": "a",
248+
"answer_options": "ao",
249+
"answer_force": "af",
250+
"confirm_repeat": "cr",
233251
}
234252

235253
def to_dict(self) -> t.Dict[str, t.Union[str, int]]:

tests/services/pushsafer/test_pushsafer_v1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ class IoTestItem:
118118
IoTestItem(id="retry", in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "60"], out_data={"re": "60"}),
119119
IoTestItem(id="expire", in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "", "600"], out_data={"ex": "600"}),
120120
IoTestItem(id="answer", in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "", "", "0"], out_data={"a": "0"}),
121+
IoTestItem(
122+
id="answer-options",
123+
in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "", "", "1", "yes|no"],
124+
out_data={"a": "1", "ao": "yes|no"},
125+
),
126+
IoTestItem(
127+
id="answer-force",
128+
in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "", "", "1", "", "1"],
129+
out_data={"a": "1", "af": "1"},
130+
),
131+
IoTestItem(
132+
id="confirm-repeat",
133+
in_addrs=[TEST_TOKEN, "", "", "", "", "", "", "", "", "", "", "1", "", "", "45"],
134+
out_data={"a": "1", "cr": "45"},
135+
),
121136
]
122137

123138

tests/services/pushsafer/test_pushsafer_v2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ class IoTestItem:
120120
IoTestItem(id="retry", in_addrs={"private_key": TEST_TOKEN, "retry": 60}, out_data={"re": "60"}),
121121
IoTestItem(id="expire", in_addrs={"private_key": TEST_TOKEN, "expire": 600}, out_data={"ex": "600"}),
122122
IoTestItem(id="answer", in_addrs={"private_key": TEST_TOKEN, "answer": 1}, out_data={"a": "1"}),
123+
IoTestItem(
124+
id="answer-options",
125+
in_addrs={"private_key": TEST_TOKEN, "answer": 1, "answer_options": "yes|no"},
126+
out_data={"a": "1", "ao": "yes|no"},
127+
),
128+
IoTestItem(
129+
id="answer-force",
130+
in_addrs={"private_key": TEST_TOKEN, "answer": 1, "answer_force": 1},
131+
out_data={"a": "1", "af": "1"},
132+
),
133+
IoTestItem(
134+
id="confirm-repeat",
135+
in_addrs={"private_key": TEST_TOKEN, "answer": 1, "confirm_repeat": 45},
136+
out_data={"a": "1", "cr": "45"},
137+
),
123138
]
124139

125140

0 commit comments

Comments
 (0)