#!/usr/bin/env python

import dbus

dbus_objects = {
    "power": {
        "bus_name": "org.openbmc.control.Power",
        "object_name": "/org/openbmc/control/power0",
        "interface_name": "org.openbmc.control.Power",
    },
    "occstatus0": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/cpu0/OccStatus",
        "interface_name": "org.openbmc.SensorValue",
    },
    "occstatus1": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/cpu1/OccStatus",
        "interface_name": "org.openbmc.SensorValue",
    },
    "bootprogress": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/BootProgress",
        "interface_name": "org.openbmc.SensorValue",
    },
    "host": {
        "bus_name": "xyz.openbmc_project.State.Host",
        "object_name": "/xyz/openbmc_project/state/host0",
        "interface_name": "xyz.openbmc_project.State.Host",
    },
    "settings": {
        "bus_name": "org.openbmc.settings.Host",
        "object_name": "/org/openbmc/settings/host0",
        "interface_name": "org.freedesktop.DBus.Properties",
    },
    "system": {
        "bus_name": "org.openbmc.managers.System",
        "object_name": "/org/openbmc/managers/System",
        "interface_name": "org.freedesktop.DBus.Properties",
    },
    "powersupplyredundancy": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/PowerSupplyRedundancy",
        "interface_name": "org.openbmc.SensorValue",
    },
    "turboallowed": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/TurboAllowed",
        "interface_name": "org.openbmc.SensorValue",
    },
    "powersupplyderating": {
        "bus_name": "org.openbmc.Sensors",
        "object_name": "/org/openbmc/sensors/host/PowerSupplyDerating",
        "interface_name": "org.openbmc.SensorValue",
    },
}


def getInterface(bus, objs, key):
    obj = bus.get_object(
        objs[key]["bus_name"], objs[key]["object_name"], introspect=False
    )
    return dbus.Interface(obj, objs[key]["interface_name"])


def getProperty(bus, objs, key, prop):
    obj = bus.get_object(
        objs[key]["bus_name"], objs[key]["object_name"], introspect=False
    )
    intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
    return intf.Get(objs[key]["interface_name"], prop)


def setProperty(bus, objs, key, prop, prop_value):
    obj = bus.get_object(objs[key]["bus_name"], objs[key]["object_name"])
    intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
    return intf.Set(objs[key]["interface_name"], prop, prop_value)


bus = dbus.SystemBus()
pgood = getProperty(bus, dbus_objects, "power", "pgood")

if pgood == 1:
    intf = getInterface(bus, dbus_objects, "bootprogress")
    intf.setValue("FW Progress, Starting OS")
    intf = getInterface(bus, dbus_objects, "occstatus0")
    intf.setValue("Enabled")
    intf = getInterface(bus, dbus_objects, "occstatus1")
    intf.setValue("Enabled")
else:
    # Power is off, so check power policy
    settings_intf = getInterface(bus, dbus_objects, "settings")
    system_intf = getInterface(bus, dbus_objects, "system")
    system_last_state = system_intf.Get(
        "org.openbmc.managers.System", "system_last_state"
    )
    power_policy = settings_intf.Get(
        "org.openbmc.settings.Host", "power_policy"
    )
    print(
        "Last System State:"
        + system_last_state
        + "Power Policy:"
        + power_policy
    )

    if power_policy == "ALWAYS_POWER_ON" or (
        power_policy == "RESTORE_LAST_STATE"
        and system_last_state == "HOST_POWERED_ON"
    ):
        setProperty(
            bus,
            dbus_objects,
            "host",
            "RequestedHostTransition",
            "xyz.openbmc_project.State.Host.Transition.On",
        )

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
