State Diagram questions
After ESR published the state diagram at A&D, a few questions about certain states can be combined arose:
1) What is the difference between “Power came back after host shut down” and the “Daemon Running” state at the top, other than that the battery was able to keep the SBC running through the outage? Is that difference enough to justify a separate state, or should “Host has shut down” just send the system back to the “Daemon Running” state? If it's assumed that after a host shutdown, UPSide will then power off the load outlets, I don't see any need for a separate state (just a different path to get to "Daemon Running", and the "disable AC outlets" action associated with it). I make this assumption because the fact that a shutdown has been done means the battery is already discharged below the safe threshold. The action node description would be modified thus: Trigger: Poll of mains reports good AC voltage. Means: Host has shut down. Action: Power AC load off. Alarm: CHARGING
2a) The action described as: Trigger: Poll of mains reports bad AC voltage Means: Mains power is off Alarm: DOWN takes the state directly from "Daemon running" to "On battery power", bypassing the reserve-level check done at the "Charge wait" state. This action should instead put the state right back to "Daemon running" for another polling interval, which can bring it through "Charge wait" after mains poll OK.
2b) Similarly, Trigger: Poll of mains reports bad AC voltage Means: Power has dropped takes "Charge wait" directly to "On Battery Power". This is incorrect for the same reason as 2a), an for the same reason should lead to "Daemon running".
3) “On mains power” does not distinguish between whether the host is powered up or not. Is that a relevant distinction? It seems that the only reason to care whether it’s powered down is to determine whether to try to abort the shutdown command if that’s even possible and desirable. KISS Principle suggests that it's not desirable to abort a shutdown once it's initiated, because there is no longer enough battery reserve to safely operate the host. Instead, if the next state after the shutdown is initiated is "Daemon running", we have a far-simpler state diagram, and are Doing The Right Thing as well.
In this case, rather than monitoring for a host shutdown at the "bottom" of the diagram as ASS|U|MEd in 1) above, we do a poll of the host load in the "Charge wait" state, and if it's below the "watchkeeper" level sufficient to listen for "power" button press, Wake on LAN, etc., and disable the outlet at that time, remain in "Charge wait" state and to the other polls that could lead to a different state. This way, when the battery level checks out as OK, and the outlet is enabled, a properly-configured host could be brought back up automatically.