gbmcweb: Base Systems PowerState on host power instead of POST complete

PowerState was derived from os_state, which only tracks the post_complete
GPIO, so it reported "Off" while the host was powered and still in POST.
Derive it from host_state.power_state() instead, which already tracks the
power_ok (PWRGD) GPIO via PowerOkHandler.

Google-Bug-Id:555436812
PiperOrigin-RevId: 995467861
Change-Id: I94b40788ba1c7d8e6288528ba3cd539c2c35be34
diff --git a/tlbmc/redfish/routes/system.cc b/tlbmc/redfish/routes/system.cc
index 535f977..75a2610 100644
--- a/tlbmc/redfish/routes/system.cc
+++ b/tlbmc/redfish/routes/system.cc
@@ -141,11 +141,32 @@
   if (power_control != nullptr) {
     HostState host_state = power_control->GetHostState();
 
+    // PowerState reflects host power (the power_ok / PWRGD GPIO), not POST
+    // complete. The transition states below still have power_ok asserted,
+    // so they must report "On" to avoid a false "Off" during a warm reset
+    // or while a force-off pulse is still in flight.
+    switch (host_state.power_state()) {
+      case PowerState::POWER_STATE_ON:
+      case PowerState::POWER_STATE_CHECK_FOR_WARM_RESET:
+      case PowerState::POWER_STATE_TRANSITION_TO_OFF:
+      case PowerState::POWER_STATE_GRACEFUL_TRANSITION_TO_OFF:
+      case PowerState::POWER_STATE_TRANSITION_TO_CYCLE_OFF:
+      case PowerState::POWER_STATE_GRACEFUL_TRANSITION_TO_CYCLE_OFF:
+        json["PowerState"] = "On";
+        break;
+      case PowerState::POWER_STATE_OFF:
+      case PowerState::POWER_STATE_CYCLE_OFF:
+      case PowerState::POWER_STATE_WAIT_FOR_POWER_OK:
+        json["PowerState"] = "Off";
+        break;
+      default:  // POWER_STATE_UNSPECIFIED: leave PowerState untouched.
+        break;
+    }
+
+    // Status/State keeps tracking POST complete (OS state).
     if (host_state.os_state() == OSState::OS_STATE_STANDBY) {
-      json["PowerState"] = "On";
       json["Status"]["State"] = "Enabled";
     } else if (host_state.os_state() == OSState::OS_STATE_INACTIVE) {
-      json["PowerState"] = "Off";
       json["Status"]["State"] = "Disabled";
     }