Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 1 | import dbus |
| 2 | |
| 3 | BUS_PREFIX = 'org.openbmc' |
| 4 | GPIO_DEV = '/sys/class/gpio' |
| 5 | |
| 6 | |
| 7 | FRU_TYPES = { |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame^] | 8 | 'CPU' : 1, |
| 9 | 'DIMM' : 2, |
| 10 | 'BACKPLANE' : 3, |
| 11 | 'RISER_CARD' : 4, |
| 12 | 'FAN' : 5 |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 13 | } |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 14 | ENUMS = { |
| 15 | 'org.openbmc.SensorIntegerThreshold.state' : |
| 16 | ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'], |
| 17 | 'org.openbmc.Fru.type' : |
| 18 | ['NONE','CPU','DIMM','BACKPLANE','RISER_CARD','FAN'] |
| 19 | } |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame^] | 20 | |
| 21 | class DbusProperty: |
| 22 | def __init__(self,name,value): |
| 23 | self.dbusBaseType = { |
| 24 | 'dbus.Byte' : 'int', |
| 25 | 'dbus.Float' : 'float', |
| 26 | 'dbus.Int32' : 'int', |
| 27 | 'dbus.UInt32' : 'long', |
| 28 | 'dbus.String' : 'str', |
| 29 | 'dbus.UInt64' : 'long', |
| 30 | } |
| 31 | self.name = str(name) |
| 32 | self.dbusType = str(type(value)).split("'")[1] |
| 33 | self.value = None |
| 34 | try: |
| 35 | self.value = eval(self.dbusBaseType[self.dbusType]+"(value)") |
| 36 | except: |
| 37 | raise Exception("Unknown dbus type: "+self.dbusType) |
| 38 | |
| 39 | def changeValue(self,value): |
| 40 | try: |
| 41 | self.value = eval(self.dbusBaseType[self.dbusType]+"(value)") |
| 42 | except: |
| 43 | raise Exception("Unknown dbus type: "+self.dbusType) |
| 44 | |
| 45 | |
| 46 | def getName(self): |
| 47 | return self.name |
| 48 | def getValue(self): |
| 49 | e = self.dbusType+"(self.value)" |
| 50 | return eval(e) |
| 51 | |
| 52 | #def __getstate__(self): |
| 53 | # odict = self.__dict__.copy() # copy the dict since we change it |
| 54 | # return odict |
| 55 | |
| 56 | ##def __setstate__(self, dict): |
| 57 | # self.__dict__.update(dict) # update attributes |
| 58 | |
| 59 | def __str__(self): |
| 60 | return self.dbusType+":"+str(self.value) |