blob: e1eac7d94004e8a32c9181d13d024ebb12a77e4f [file] [log] [blame]
Norman James0ca72fb2015-11-10 10:39:36 -06001#!/usr/bin/python -u
2
3import sys
4#from gi.repository import GObject
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
Brad Bishop84e73b52016-05-12 15:57:52 -04009from obmc.dbuslib.bindings import get_dbus, DbusProperties, DbusObjectManager
Norman James0ca72fb2015-11-10 10:39:36 -060010
11DBUS_NAME = 'org.openbmc.control.Fans'
12OBJ_PATH = '/org/openbmc/control/fans'
13IFACE_NAME = 'org.openbmc.control.Fans'
14
Norman James323ed972015-12-09 09:06:37 -060015FAN_BUS = 'org.openbmc.Sensors'
Norman James0ca72fb2015-11-10 10:39:36 -060016FAN_OBJS = [
Norman James8005a642015-11-10 13:18:23 -060017 '/org/openbmc/sensors/speed/fan0',
Norman James0ca72fb2015-11-10 10:39:36 -060018 '/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 James0ca72fb2015-11-10 10:39:36 -060023]
24FAN_IFACE = 'org.openbmc.SensorValue'
25
Brad Bishop84e73b52016-05-12 15:57:52 -040026class FanControl(DbusProperties,DbusObjectManager):
Norman James0ca72fb2015-11-10 10:39:36 -060027 def __init__(self,bus,name):
Brad Bishop84e73b52016-05-12 15:57:52 -040028 DbusProperties.__init__(self)
29 DbusObjectManager.__init__(self)
Norman James0ca72fb2015-11-10 10:39:36 -060030 dbus.service.Object.__init__(self,bus,name)
Norman James0ca72fb2015-11-10 10:39:36 -060031 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 James85f050b2015-12-18 14:58:20 -060037 obj = bus.get_object(FAN_BUS,fan,introspect=False)
Norman Jamese3de2292015-11-17 08:58:28 -060038 self.fan_intf.append(dbus.Interface(obj,FAN_IFACE))
39
40 @dbus.service.method(DBUS_NAME,
41 in_signature='', out_signature='')
Norman James0ca72fb2015-11-10 10:39:36 -060042 def setMax(self):
43 print "Setting fans to max"
44 for intf in self.fan_intf:
45 intf.setValue(dbus.UInt32(255))
46
47
48if __name__ == '__main__':
49
50 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -040051 bus = get_dbus()
Norman James0ca72fb2015-11-10 10:39:36 -060052 fan_control = FanControl(bus,OBJ_PATH)
53 mainloop = gobject.MainLoop()
54
55 print "Starting fan control"
56 fan_control.setMax()
Brad Bishopf0f3efe2016-06-29 23:20:24 -040057
58 fan_control.unmask_signals()
Brad Bishop70852a32016-06-29 22:58:51 -040059 name = dbus.service.BusName(DBUS_NAME,bus)
Norman James0ca72fb2015-11-10 10:39:36 -060060 mainloop.run()
61