blob: 256edd82946f7a4a0d497ff523d83452e1a4b2db [file] [log] [blame]
Brad Bishop179b39b2016-05-12 16:45:57 -04001# Contributors Listed Below - COPYRIGHT 2016
2# [+] International Business Machines Corp.
3#
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied. See the License for the specific language governing
15# permissions and limitations under the License.
16
17import os
18import subprocess
19import dbus
20import dbus.service
21from obmc.dbuslib.bindings import DbusProperties
22
23
Brad Bishopaea38c62018-01-30 13:00:26 -050024# Abstract class, must subclass
Brad Bishop179b39b2016-05-12 16:45:57 -040025class SensorValue(DbusProperties):
26 IFACE_NAME = 'org.openbmc.SensorValue'
27
28 def __init__(self, bus, name):
29 self.Set(SensorValue.IFACE_NAME, 'units', "")
30 self.Set(SensorValue.IFACE_NAME, 'error', False)
31
32 @dbus.service.method(
33 IFACE_NAME, in_signature='v', out_signature='')
34 def setValue(self, value):
35 self.Set(SensorValue.IFACE_NAME, 'value', value)
36
37 @dbus.service.method(
38 IFACE_NAME, in_signature='', out_signature='v')
39 def getValue(self):
40 return self.Get(SensorValue.IFACE_NAME, 'value')
41
42
Brad Bishop179b39b2016-05-12 16:45:57 -040043class VirtualSensor(SensorValue):
44 def __init__(self, bus, name):
45 DbusProperties.__init__(self)
46 SensorValue.__init__(self, bus, name)
47 dbus.service.Object.__init__(self, bus, name)
48
49
Brad Bishop179b39b2016-05-12 16:45:57 -040050CONTROL_IFACE = 'org.openbmc.Control'
51
52
Brad Bishop179b39b2016-05-12 16:45:57 -040053class BootCountSensor(VirtualSensor):
54 def __init__(self, bus, name):
55 VirtualSensor.__init__(self, bus, name)
Andrew Geissler9070d1b2017-05-22 14:46:34 -050056 # Default boot count is 2. Add 1 onto this to allow for an
57 # SBE side switch boot attempt
58 self.setValue(3)
59
Brad Bishopaea38c62018-01-30 13:00:26 -050060 # override setValue method for debug purposes
Andrew Geissler9070d1b2017-05-22 14:46:34 -050061 @dbus.service.method(
62 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
63 def setValue(self, value):
CamVan Nguyen9172f3e2018-02-27 15:18:58 -060064 print("Setting boot count to " + str(value))
Brad Bishop10ad8c32017-07-01 00:23:06 -040065 SensorValue.setValue(self, value)
Brad Bishop179b39b2016-05-12 16:45:57 -040066
67
Dhruvaraj Sdc0dc122017-03-21 02:13:29 -050068class PowerSupplyRedundancySensor(VirtualSensor):
69 def __init__(self, bus, name):
70 VirtualSensor.__init__(self, bus, name)
Gunnar Millsdab1c6d2018-01-26 15:28:26 -060071 self.bus = bus
72 self.bus_name = 'xyz.openbmc_project.Settings'
73 self.obj_path = '/xyz/openbmc_project/control/power_supply_redundancy'
74 self.iface = 'xyz.openbmc_project.Control.PowerSupplyRedundancy'
75 self.prop_iface = 'org.freedesktop.DBus.Properties'
76 self.property_name = 'PowerSupplyRedundancyEnabled'
77 super(PowerSupplyRedundancySensor, self).setValue(self.getValue())
78
79 # Override setValue method
80 @dbus.service.method(
81 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
82 def setValue(self, value):
83 if (value == "Enabled"):
84 intf = self.getPowerSupplyInterface()
85 intf.Set(self.iface, self.property_name, True)
86 elif (value == "Disabled"):
87 intf = self.getPowerSupplyInterface()
88 intf.Set(self.iface, self.property_name, False)
89 else:
CamVan Nguyen9172f3e2018-02-27 15:18:58 -060090 print("Invalid Power Supply Redundancy value")
Gunnar Millsdab1c6d2018-01-26 15:28:26 -060091 return
92 super(PowerSupplyRedundancySensor, self).setValue(value)
93
94 # Override getValue method
95 @dbus.service.method(
96 SensorValue.IFACE_NAME, in_signature='', out_signature='v')
97 def getValue(self):
98 intf = self.getPowerSupplyInterface()
99 value = intf.Get(self.iface, self.property_name)
100 if (value == 1):
101 return "Enabled"
102 elif (value == 0):
103 return "Disabled"
104 else:
CamVan Nguyen9172f3e2018-02-27 15:18:58 -0600105 print("Unable to determine Power Supply Redundancy value")
Gunnar Millsdab1c6d2018-01-26 15:28:26 -0600106 return ""
107
108 def getPowerSupplyInterface(self):
109 obj = self.bus.get_object(self.bus_name, self.obj_path,
110 introspect=True)
111 return dbus.Interface(obj, self.prop_iface)
112
Brad Bishop10ad8c32017-07-01 00:23:06 -0400113
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500114class PowerSupplyDeratingSensor(VirtualSensor):
115 def __init__(self, bus, name):
116 VirtualSensor.__init__(self, bus, name)
Deepak Kodihallid67740e2018-02-23 08:05:19 -0600117 super(PowerSupplyDeratingSensor, self).setValue(90)
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500118
Brad Bishopaea38c62018-01-30 13:00:26 -0500119 # override setValue method
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500120 @dbus.service.method(
121 SensorValue.IFACE_NAME, in_signature='v', out_signature='')
122 def setValue(self, value):
CamVan Nguyen9172f3e2018-02-27 15:18:58 -0600123 print("Setting Power Supply Derating is not allowed")
Jayanth Othayoth857e4b82017-03-27 08:25:45 -0500124
Brad Bishop10ad8c32017-07-01 00:23:06 -0400125
Jayanth Othayoth7a57f952017-03-28 07:15:29 -0500126class TurboAllowedSensor(VirtualSensor):
127 def __init__(self, bus, name):
128 VirtualSensor.__init__(self, bus, name)
129 self.setValue(0)
130
Brad Bishopaea38c62018-01-30 13:00:26 -0500131 # override setValue method
Jayanth Othayoth7a57f952017-03-28 07:15:29 -0500132 @dbus.service.method(
133 SensorValue.IFACE_NAME, in_signature='b', out_signature='')
134 def setValue(self, value):
Brad Bishop10ad8c32017-07-01 00:23:06 -0400135 super(TurboAllowedSensor, self).setValue(value)