Restart modem: pause Smart Power auto power-cycle until the modem is back #61

Merged
jared merged 1 commits from smart-power-pause into main 2026-11-24 00:16:57 -05:00
Owner

Why

UniFi Smart Power on RPDU outlet 13, "AT&T Modem", has auto power-cycle on. When the modem reboots on purpose, Smart Power sees the internet down and cuts the modem's power mid-boot:

  • once during the 2026-11-20 restart
  • twice (04:03 and 04:09) after the 2026-11-24 AT&T-app reboot

One restart becomes two or three. UniFi exposes auto power-cycle only as on or off (cycle_enabled), with no delay setting. So the Restart modem button now pauses it, and the monitor turns it back on.

What changes

  • Restart modem button. After Kuma and the Gandalf silence, and before the restart, it turns off auto power-cycle on every outlet that has it on. Today that's just RPDU outlet 13.
    • If the pause fails, the restart still goes ahead; Smart Power may cycle the modem once more, as it does today.
    • If the restart fails, auto power-cycle is turned straight back on.
  • Monitor (_finish_modem_restart). It turns auto power-cycle back on when the restart ends, whether the modem is back or the 30-minute limit passes.
    • If that fails, it retries every cycle, even after the restart is marked finished.
    • Until it succeeds, Needs attention shows "Smart Power auto power-cycle is still off after the modem restart" as broken, with the last error. Auto-recovery must never be left off silently.
  • UnifiClient.auto_power_cycle_outlets() / set_auto_power_cycle().
    • The PUT sends the device's full outlet_overrides back with only that outlet's cycle_enabled changed; relay states are copied untouched.
    • It then reads the settings again to confirm the change.
    • It sends nothing if the flag is already set.
    • This is the only UniFi setting Gandalf ever writes.
  • UI.
    • The confirm text and the in-progress note mention the pause.
    • A red note appears if auto power-cycle is still off after the restart.

Checked on prod

I sent the RPDU's 20 outlet entries back unchanged with Gandalf's API key, using the same PUT the code uses: 200 {"meta":{"rc":"ok"}}, and a read afterwards matched exactly. So the key can write, and the device _id works in rest/device. Nothing was changed.

Not covered

Reboots from the AT&T app: Gandalf can't see them coming. Use the Restart modem button instead.

Tests

651 passed. flake8, bandit and eslint are clean, and there are no em or en dashes.

  • TestSmartPowerWrites:
    • lists outlets
    • changes only that flag
    • already set sends nothing
    • unconfirmed change raises
    • unknown outlet raises
    • pause and restore
    • pause failure is reported
  • TestFinishModemRestart:
    • back turns it on again
    • retried after the restart finished
    • a restored state is left alone
  • TestModemRestart (app):
    • pauses and stores the outlets
    • a pause failure doesn't stop the restart
    • a failed restart restores it
    • a failed restart plus a failed restore is remembered for the retry loop
  • TestSmartPowerLeftOff (attention).

🤖 Generated with Claude Code

## Why UniFi Smart Power on RPDU outlet 13, "AT&T Modem", has auto power-cycle on. When the modem reboots on purpose, Smart Power sees the internet down and cuts the modem's power mid-boot: - once during the 2026-11-20 restart - twice (04:03 and 04:09) after the 2026-11-24 AT&T-app reboot One restart becomes two or three. UniFi exposes auto power-cycle only as on or off (`cycle_enabled`), with no delay setting. So the Restart modem button now pauses it, and the monitor turns it back on. ## What changes - **Restart modem button.** After Kuma and the Gandalf silence, and before the restart, it turns off auto power-cycle on every outlet that has it on. Today that's just RPDU outlet 13. - If the pause fails, the restart still goes ahead; Smart Power may cycle the modem once more, as it does today. - If the restart fails, auto power-cycle is turned straight back on. - **Monitor (`_finish_modem_restart`).** It turns auto power-cycle back on when the restart ends, whether the modem is back or the 30-minute limit passes. - If that fails, it retries every cycle, even after the restart is marked finished. - Until it succeeds, Needs attention shows "Smart Power auto power-cycle is still off after the modem restart" as broken, with the last error. Auto-recovery must never be left off silently. - **`UnifiClient.auto_power_cycle_outlets()` / `set_auto_power_cycle()`.** - The PUT sends the device's full `outlet_overrides` back with only that outlet's `cycle_enabled` changed; relay states are copied untouched. - It then reads the settings again to confirm the change. - It sends nothing if the flag is already set. - This is the only UniFi setting Gandalf ever writes. - **UI.** - The confirm text and the in-progress note mention the pause. - A red note appears if auto power-cycle is still off after the restart. ## Checked on prod I sent the RPDU's 20 outlet entries back unchanged with Gandalf's API key, using the same PUT the code uses: `200 {"meta":{"rc":"ok"}}`, and a read afterwards matched exactly. So the key can write, and the device `_id` works in `rest/device`. Nothing was changed. ## Not covered Reboots from the AT&T app: Gandalf can't see them coming. Use the Restart modem button instead. ## Tests 651 passed. flake8, bandit and eslint are clean, and there are no em or en dashes. - **`TestSmartPowerWrites`:** - lists outlets - changes only that flag - already set sends nothing - unconfirmed change raises - unknown outlet raises - pause and restore - pause failure is reported - **`TestFinishModemRestart`:** - back turns it on again - retried after the restart finished - a restored state is left alone - **`TestModemRestart` (app):** - pauses and stores the outlets - a pause failure doesn't stop the restart - a failed restart restores it - a failed restart plus a failed restore is remembered for the retry loop - **`TestSmartPowerLeftOff` (attention).** 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-24 00:14:04 -05:00
Restart modem: pause Smart Power auto power-cycle until the modem is back
Lint / JS (eslint) (push) Successful in 14s
Lint / Python (flake8) (push) Successful in 1m5s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m13s
Lint / Python (flake8) (pull_request) Successful in 1m14s
Test / Python Tests (pytest) (push) Successful in 1m51s
Security / Python Security (bandit) (pull_request) Successful in 1m25s
Lint / JS (eslint) (pull_request) Successful in 19s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Test / Python Tests (pytest) (pull_request) Successful in 1m32s
a5d4fc3156
UniFi Smart Power on the RPDU's modem outlet saw the internet down while
the modem rebooted and cut its power mid-boot: once during the 11-20
restart and twice after the 11-24 AT&T-app reboot. UniFi only exposes
auto power-cycle as on or off, so the button now turns it off for every
outlet that has it on, and the monitor turns it back on when the restart
ends (back, or after 30 minutes).

- UnifiClient.auto_power_cycle_outlets / set_auto_power_cycle: sends the
  device's outlet_overrides back with only cycle_enabled changed, then
  reads them again to confirm. The only UniFi setting Gandalf changes.
- A failed pause doesn't stop the restart; a failed restart turns it back
  on. A failed restore is retried every cycle and shown as broken in
  Needs attention until it works.
- The panel note and confirm text mention the pause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared scheduled this pull request to auto merge when all checks succeed 2026-11-24 00:16:33 -05:00
jared merged commit 48420a5698 into main 2026-11-24 00:16:57 -05:00
jared deleted branch smart-power-pause 2026-11-24 00:17:13 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/gandalf#61