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 |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 9 | from obmc.dbuslib.bindings import get_dbus, DbusProperties, DbusObjectManager |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 10 | |
| 11 | DBUS_NAME = 'org.openbmc.control.Fans' |
| 12 | OBJ_PATH = '/org/openbmc/control/fans' |
| 13 | IFACE_NAME = 'org.openbmc.control.Fans' |
| 14 | |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 15 | FAN_BUS = 'org.openbmc.Sensors' |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 16 | FAN_OBJS = [ |
Norman James | 8005a64 | 2015-11-10 13:18:23 -0600 | [diff] [blame] | 17 | '/org/openbmc/sensors/speed/fan0', |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 18 | '/org/openbmc/sensors/speed/fan1', |
| 19 | '/org/openbmc/sensors/speed/fan2', |
| 20 | '/org/openbmc/sensors/speed/fan3', |
| 21 | '/org/openbmc/sensors/speed/fan4', |
| 22 | '/org/openbmc/sensors/speed/fan5', |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 23 | ] |
| 24 | FAN_IFACE = 'org.openbmc.SensorValue' |
| 25 | |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 26 | class FanControl(DbusProperties,DbusObjectManager): |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 27 | def __init__(self,bus,name): |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 28 | DbusProperties.__init__(self) |
| 29 | DbusObjectManager.__init__(self) |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 30 | dbus.service.Object.__init__(self,bus,name) |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 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 |
Norman James | 85f050b | 2015-12-18 14:58:20 -0600 | [diff] [blame] | 37 | obj = bus.get_object(FAN_BUS,fan,introspect=False) |
Norman James | e3de229 | 2015-11-17 08:58:28 -0600 | [diff] [blame] | 38 | self.fan_intf.append(dbus.Interface(obj,FAN_IFACE)) |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 39 | self.InterfacesAdded(name,self.properties) |
Norman James | e3de229 | 2015-11-17 08:58:28 -0600 | [diff] [blame] | 40 | |
| 41 | @dbus.service.method(DBUS_NAME, |
| 42 | in_signature='', out_signature='') |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 43 | def setMax(self): |
| 44 | print "Setting fans to max" |
| 45 | for intf in self.fan_intf: |
| 46 | intf.setValue(dbus.UInt32(255)) |
| 47 | |
| 48 | |
| 49 | if __name__ == '__main__': |
| 50 | |
| 51 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 52 | bus = get_dbus() |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 53 | fan_control = FanControl(bus,OBJ_PATH) |
| 54 | mainloop = gobject.MainLoop() |
| 55 | |
| 56 | print "Starting fan control" |
| 57 | fan_control.setMax() |
Brad Bishop | 70852a3 | 2016-06-29 22:58:51 -0400 | [diff] [blame^] | 58 | name = dbus.service.BusName(DBUS_NAME,bus) |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 59 | mainloop.run() |
| 60 | |