Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame^] | 1 | #!/usr/bin/python -u |
| 2 | |
| 3 | import sys |
| 4 | #from gi.repository import GObject |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import Openbmc |
| 10 | |
| 11 | DBUS_NAME = 'org.openbmc.control.Fans' |
| 12 | OBJ_PATH = '/org/openbmc/control/fans' |
| 13 | IFACE_NAME = 'org.openbmc.control.Fans' |
| 14 | |
| 15 | FAN_BUS = 'org.openbmc.sensors.hwmon' |
| 16 | FAN_OBJS = [ |
| 17 | '/org/openbmc/sensors/speed/fan1', |
| 18 | '/org/openbmc/sensors/speed/fan2', |
| 19 | '/org/openbmc/sensors/speed/fan3', |
| 20 | '/org/openbmc/sensors/speed/fan4', |
| 21 | '/org/openbmc/sensors/speed/fan5', |
| 22 | '/org/openbmc/sensors/speed/fan6', |
| 23 | ] |
| 24 | FAN_IFACE = 'org.openbmc.SensorValue' |
| 25 | |
| 26 | class FanControl(Openbmc.DbusProperties): |
| 27 | def __init__(self,bus,name): |
| 28 | Openbmc.DbusProperties.__init__(self) |
| 29 | dbus.service.Object.__init__(self,bus,name) |
| 30 | self.ObjectAdded(name,IFACE_NAME) |
| 31 | self.Set(IFACE_NAME,"floor",250) |
| 32 | self.Set(IFACE_NAME,"ceiling",255) |
| 33 | self.fan_intf = [] |
| 34 | ## create interface proxies to all fans |
| 35 | for fan in FAN_OBJS: |
| 36 | print "Initializing fan: "+fan |
| 37 | obj = bus.get_object(FAN_BUS,fan) |
| 38 | fan_intf.append(dbus.Interface(obj,FAN_IFACE)) |
| 39 | |
| 40 | def setMax(self): |
| 41 | print "Setting fans to max" |
| 42 | for intf in self.fan_intf: |
| 43 | intf.setValue(dbus.UInt32(255)) |
| 44 | |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | |
| 48 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 49 | bus = Openbmc.getDBus() |
| 50 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 51 | fan_control = FanControl(bus,OBJ_PATH) |
| 52 | mainloop = gobject.MainLoop() |
| 53 | |
| 54 | print "Starting fan control" |
| 55 | fan_control.setMax() |
| 56 | mainloop.run() |
| 57 | |