Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 2 | |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 3 | import gobject |
| 4 | import dbus |
| 5 | import dbus.service |
| 6 | import dbus.mainloop.glib |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 7 | from obmc.dbuslib.bindings import get_dbus, DbusProperties, DbusObjectManager |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 8 | |
| 9 | DBUS_NAME = 'org.openbmc.control.Fans' |
| 10 | OBJ_PATH = '/org/openbmc/control/fans' |
| 11 | IFACE_NAME = 'org.openbmc.control.Fans' |
| 12 | |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 13 | FAN_BUS = 'org.openbmc.Sensors' |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 14 | FAN_OBJS = [ |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 15 | '/org/openbmc/sensors/speed/fan0', |
| 16 | '/org/openbmc/sensors/speed/fan1', |
| 17 | '/org/openbmc/sensors/speed/fan2', |
| 18 | '/org/openbmc/sensors/speed/fan3', |
| 19 | '/org/openbmc/sensors/speed/fan4', |
| 20 | '/org/openbmc/sensors/speed/fan5', |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 21 | ] |
| 22 | FAN_IFACE = 'org.openbmc.SensorValue' |
| 23 | |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 24 | |
| 25 | class FanControl(DbusProperties, DbusObjectManager): |
| 26 | def __init__(self, bus, name): |
Brad Bishop | f47f5fa | 2016-09-08 22:29:01 -0400 | [diff] [blame] | 27 | super(FanControl, self).__init__( |
| 28 | conn=bus, |
| 29 | object_path=name) |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 30 | self.Set(IFACE_NAME, "floor", 250) |
| 31 | self.Set(IFACE_NAME, "ceiling", 255) |
| 32 | self.fan_intf = [] |
| 33 | ## create interface proxies to all fans |
| 34 | for fan in FAN_OBJS: |
| 35 | print "Initializing fan: "+fan |
| 36 | obj = bus.get_object(FAN_BUS, fan, introspect=False) |
| 37 | self.fan_intf.append(dbus.Interface(obj, FAN_IFACE)) |
| 38 | |
| 39 | @dbus.service.method(DBUS_NAME, in_signature='', out_signature='') |
| 40 | def setMax(self): |
| 41 | print "Setting fans to max" |
| 42 | for intf in self.fan_intf: |
| 43 | intf.setValue(dbus.UInt32(255)) |
| 44 | |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 45 | |
| 46 | if __name__ == '__main__': |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 47 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 48 | bus = get_dbus() |
| 49 | fan_control = FanControl(bus, OBJ_PATH) |
| 50 | mainloop = gobject.MainLoop() |
Brad Bishop | f0f3efe | 2016-06-29 23:20:24 -0400 | [diff] [blame] | 51 | |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 52 | print "Starting fan control" |
| 53 | fan_control.setMax() |
Norman James | 0ca72fb | 2015-11-10 10:39:36 -0600 | [diff] [blame] | 54 | |
Brad Bishop | 056b26e | 2016-08-25 23:01:47 -0400 | [diff] [blame] | 55 | fan_control.unmask_signals() |
| 56 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 57 | mainloop.run() |
Brad Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 58 | |
| 59 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |