blob: f6a7dbffe3a4a34d7fd473ed5ba191c4129b3682 [file] [log] [blame]
Brad Bishop670f2552016-08-30 19:12:54 -04001#!/usr/bin/env python
Norman James323ed972015-12-09 09:06:37 -06002
CamVan Nguyend65b2d52018-02-27 15:14:41 -06003# TODO: openbmc/openbmc#2994 remove python 2 support
4try: # python 2
5 import gobject
6except ImportError: # python 3
7 from gi.repository import GObject as gobject
Norman James323ed972015-12-09 09:06:37 -06008import dbus
9import dbus.service
10import dbus.mainloop.glib
Brad Bishopee1b1542016-05-12 16:55:00 -040011import obmc.sensors
Brad Bishop84e73b52016-05-12 15:57:52 -040012from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
Brad Bishop44d4ad92016-08-30 19:14:46 -040013
14try:
15 import obmc_system_config as System
16 has_system = True
17except ImportError:
18 has_system = False
Yi Li54decc82016-05-05 17:42:56 +080019
Norman James323ed972015-12-09 09:06:37 -060020DBUS_NAME = 'org.openbmc.Sensors'
21OBJ_PATH = '/org/openbmc/sensors'
22
23
Brad Bishop670f2552016-08-30 19:12:54 -040024class SensorManager(DbusProperties, DbusObjectManager):
25 def __init__(self, bus, name):
Brad Bishopf47f5fa2016-09-08 22:29:01 -040026 super(SensorManager, self).__init__(
27 conn=bus,
28 object_path=name)
Norman James323ed972015-12-09 09:06:37 -060029
Brad Bishop670f2552016-08-30 19:12:54 -040030 @dbus.service.method(
31 DBUS_NAME, in_signature='ss', out_signature='')
32 def register(self, object_name, obj_path):
33 if obj_path not in self.objects:
CamVan Nguyend65b2d52018-02-27 15:14:41 -060034 print("Register: "+object_name+" : "+obj_path)
Brad Bishop670f2552016-08-30 19:12:54 -040035 sensor = eval('obmc.sensors.'+object_name+'(bus,obj_path)')
36 self.add(obj_path, sensor)
Norman James323ed972015-12-09 09:06:37 -060037
Brad Bishop670f2552016-08-30 19:12:54 -040038 @dbus.service.method(
39 DBUS_NAME, in_signature='s', out_signature='')
40 def delete(self, obj_path):
41 if obj_path in self.objects:
CamVan Nguyend65b2d52018-02-27 15:14:41 -060042 print("Delete: "+obj_path)
Brad Bishop670f2552016-08-30 19:12:54 -040043 self.remove(obj_path)
44
45 def SensorChange(self, value, path=None):
46 if path in self.objects:
47 self.objects[path].setValue(value)
48 else:
CamVan Nguyend65b2d52018-02-27 15:14:41 -060049 print("ERROR: Sensor not found: "+path)
Brad Bishop670f2552016-08-30 19:12:54 -040050
Adriana Kobylak24341f92018-01-26 15:07:23 -060051
Norman James323ed972015-12-09 09:06:37 -060052if __name__ == '__main__':
Brad Bishop670f2552016-08-30 19:12:54 -040053 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
54 bus = get_dbus()
55 root_sensor = SensorManager(bus, OBJ_PATH)
Norman James323ed972015-12-09 09:06:37 -060056
Adriana Kobylak24341f92018-01-26 15:07:23 -060057 # instantiate non-polling sensors
58 # these don't need to be in separate process
Brad Bishop44d4ad92016-08-30 19:14:46 -040059 if has_system:
CamVan Nguyend65b2d52018-02-27 15:14:41 -060060 for (id, the_sensor) in list(System.MISC_SENSORS.items()):
Brad Bishop44d4ad92016-08-30 19:14:46 -040061 sensor_class = the_sensor['class']
62 obj_path = System.ID_LOOKUP['SENSOR'][id]
63 sensor_obj = getattr(obmc.sensors, sensor_class)(bus, obj_path)
64 if 'os_path' in the_sensor:
65 sensor_obj.sysfs_attr = the_sensor['os_path']
66 root_sensor.add(obj_path, sensor_obj)
Norman James323ed972015-12-09 09:06:37 -060067
Brad Bishop670f2552016-08-30 19:12:54 -040068 mainloop = gobject.MainLoop()
Norman James323ed972015-12-09 09:06:37 -060069
Brad Bishop670f2552016-08-30 19:12:54 -040070 root_sensor.unmask_signals()
71 name = dbus.service.BusName(DBUS_NAME, bus)
CamVan Nguyend65b2d52018-02-27 15:14:41 -060072 print("Starting sensor manager")
Brad Bishop670f2552016-08-30 19:12:54 -040073 mainloop.run()
Brad Bishop53066752016-09-21 08:48:04 -040074
75# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4