|
14 | 14 | * the two kitchen helpers cannot both drive the relay |
15 | 15 | * the IR phone charges below 21% on every path, and is re-checked |
16 | 16 | * irbridge_send_candidate honours idx 0 |
| 17 | + * the weekly MeterBots session check says why whenever it fails |
17 | 18 |
|
18 | 19 | Same approach as check_dtek_templates.py: just enough of HA's template |
19 | 20 | environment to render these templates, not an HA emulator. |
@@ -185,5 +186,31 @@ def walk(node): |
185 | 186 | check("no idx -> the input_number", render(tpl, states=held), "47") |
186 | 187 | check("empty idx -> the input_number", render(tpl, states=held, idx=""), "47") |
187 | 188 |
|
| 189 | +# --- MeterBots session ------------------------------------------------------- |
| 190 | +print("\n8. MeterBots session: weekly, and every failure says why") |
| 191 | +pkg = yaml.load((CONFIG / "packages" / "meterbots_session.yaml").read_text(encoding="utf-8"), |
| 192 | + HaLoader) |
| 193 | +auto = pkg["automation"][0] |
| 194 | +check("Mondays at 12:00", |
| 195 | + (auto["trigger"][0]["at"], auto["condition"][0]["weekday"]), ("12:00:00", "mon")) |
| 196 | +call, var_step, notify_step = auto["action"] |
| 197 | +check("a MeterBots that is down does not stop the run", call.get("continue_on_error"), True) |
| 198 | +ok_tpl, why_tpl = var_step["variables"]["ok"], var_step["variables"]["why"] |
| 199 | +cases = [ |
| 200 | + ("logged in", {"status": 200, "content": {"ok": True, "authorized": True}}, "True", ""), |
| 201 | + ("logged out", {"status": 200, "content": {"ok": False, |
| 202 | + "error": "Telegram session is not logged in"}}, |
| 203 | + "False", "Telegram session is not logged in"), |
| 204 | + ("wrong token", {"status": 401, "content": {"error": "unauthorised"}}, "False", "unauthorised"), |
| 205 | + ("not JSON", {"status": 502, "content": "Bad Gateway"}, "False", "MeterBots answered 502"), |
| 206 | +] |
| 207 | +for label, sess, want_ok, want_why in cases: |
| 208 | + check("%s -> ok %s" % (label, want_ok), render(ok_tpl, sess=sess), want_ok) |
| 209 | + check("%s -> why" % label, render(why_tpl, sess=sess, ok=want_ok == "True"), want_why) |
| 210 | +check("no answer at all -> not ok", render(ok_tpl), "False") |
| 211 | +check("no answer at all -> why", |
| 212 | + render(why_tpl, ok=False), "MeterBots did not answer, or refused (see the HA log)") |
| 213 | +check("only a failure notifies", notify_step["if"][0]["value_template"], "{{ not ok }}") |
| 214 | + |
188 | 215 | print("\n%s" % ("FAILED: " + ", ".join(FAILED) if FAILED else "all checks passed")) |
189 | 216 | sys.exit(1 if FAILED else 0) |
0 commit comments