fix(cli): filter outage schedule by selected bill
All checks were successful
Test blackout notifier / test (push) Successful in 4s
Hourly blackout check / check (push) Successful in 4s

This commit is contained in:
2026-07-27 17:25:38 +03:30
parent b44d6dd3cb
commit 0b24d544d3
3 changed files with 21 additions and 14 deletions

View File

@@ -215,7 +215,7 @@ minute interval with `-i`/`--interval`:
./main.sh --interval 5 ./main.sh --interval 5
``` ```
Select one bill for the large countdown with `-b`/`--bill-id`: Select one bill for the countdown and outage schedule with `-b`/`--bill-id`:
```sh ```sh
./main.sh --bill-id 7356609804429 ./main.sh --bill-id 7356609804429
@@ -223,10 +223,10 @@ Select one bill for the large countdown with `-b`/`--bill-id`:
The dashboard uses Tehran time to show a large `HH : mm : ss` countdown for the The dashboard uses Tehran time to show a large `HH : mm : ss` countdown for the
selected bill's ongoing or nearest upcoming outage. The compact schedule below selected bill's ongoing or nearest upcoming outage. The compact schedule below
continues to list active current and future events for every bill, including is also limited to that bill's active current and future events, including
emergency outages. If the selected bill has no qualifying outage, the countdown emergency outages. If the selected bill has no qualifying outage, the dashboard
area says so while the full schedule remains visible. Without `--bill-id`, the shows `ALL CLEAR`. Without `--bill-id`, the countdown and schedule include all
countdown retains the original behavior and selects across all bills. bills.
The terminal output uses English-only labels and omits the stored address and The terminal output uses English-only labels and omits the stored address and
reason text. When there are no qualifying events for any bill it prints an `ALL reason text. When there are no qualifying events for any bill it prints an `ALL

View File

@@ -68,7 +68,7 @@ repository state. The countdown updates every second.
Options: Options:
-i, --interval MINUTES Refetch state at this interval (default: 10) -i, --interval MINUTES Refetch state at this interval (default: 10)
-b, --bill-id BILL_ID Use only this bill for the large countdown -b, --bill-id BILL_ID Show the countdown and schedule for this bill only
-h, --help Show this help -h, --help Show this help
Environment: Environment:
@@ -334,6 +334,9 @@ build_schedule() {
while IFS= read -r record; do while IFS= read -r record; do
record_fields "$record" fields record_fields "$record" fields
if [[ -n "$countdown_bill_id" && "${fields[0]}" != "$countdown_bill_id" ]]; then
continue
fi
if [[ "${fields[2]}" != "active" ]]; then if [[ "${fields[2]}" != "active" ]]; then
continue continue
fi fi

View File

@@ -143,8 +143,8 @@ assert_contains "${SCHEDULE[2]}" '"outage_number":"5"' \
"later events should remain in the schedule" "later events should remain in the schedule"
build_schedule "$FIXTURE" "$NOW_EPOCH" "222" build_schedule "$FIXTURE" "$NOW_EPOCH" "222"
assert_equal "3" "${#SCHEDULE[@]}" \ assert_equal "1" "${#SCHEDULE[@]}" \
"selecting a countdown bill should not filter the schedule" "selecting a bill should filter the schedule"
assert_equal "UPCOMING" "${HERO%%$'\t'*}" \ assert_equal "UPCOMING" "${HERO%%$'\t'*}" \
"the countdown should ignore another bill's ongoing outage" "the countdown should ignore another bill's ongoing outage"
assert_contains "$HERO" '"bill_id":"222"' \ assert_contains "$HERO" '"bill_id":"222"' \
@@ -152,17 +152,21 @@ assert_contains "$HERO" '"bill_id":"222"' \
SELECTED_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "222")" SELECTED_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "222")"
assert_contains "$SELECTED_OUTPUT" "COUNTDOWN FOR BILL 222" \ assert_contains "$SELECTED_OUTPUT" "COUNTDOWN FOR BILL 222" \
"the selected countdown bill should be labeled" "the selected countdown bill should be labeled"
assert_contains "$SELECTED_OUTPUT" "OUTAGE SCHEDULE (3)" \ assert_contains "$SELECTED_OUTPUT" "OUTAGE SCHEDULE (1)" \
"the selected countdown bill should not hide other bills from the list" "the schedule should contain only the selected bill"
if [[ "$SELECTED_OUTPUT" == *"Bill 111"* ]]; then
printf 'FAIL: selected bill output contains another bill\n' >&2
exit 1
fi
build_schedule "$FIXTURE" "$NOW_EPOCH" "333" build_schedule "$FIXTURE" "$NOW_EPOCH" "333"
assert_equal "" "$HERO" \ assert_equal "" "$HERO" \
"a bill without upcoming outages should not borrow another bill's countdown" "a bill without upcoming outages should not borrow another bill's countdown"
assert_equal "0" "${#SCHEDULE[@]}" \
"a bill without upcoming outages should have an empty schedule"
NO_HERO_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "333")" NO_HERO_OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH" 80 "333")"
assert_contains "$NO_HERO_OUTPUT" "NO CURRENT OR UPCOMING OUTAGE" \ assert_contains "$NO_HERO_OUTPUT" "ALL CLEAR" \
"a selected bill without outages should have a clear countdown status" "a selected bill without outages should render the all-clear screen"
assert_contains "$NO_HERO_OUTPUT" "OUTAGE SCHEDULE (3)" \
"all bills should remain listed when the selected bill has no outage"
build_schedule "$FIXTURE" "$NOW_EPOCH" build_schedule "$FIXTURE" "$NOW_EPOCH"
OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH")" OUTPUT="$(NO_COLOR=1 COLUMNS=80 render_dashboard "$NOW_EPOCH")"