Brad Bishop | 179b39b | 2016-05-12 16:45:57 -0400 | [diff] [blame] | 1 | # 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 | |
| 17 | import os |
| 18 | import subprocess |
| 19 | import dbus |
| 20 | import dbus.service |
| 21 | from obmc.dbuslib.bindings import DbusProperties |
| 22 | |
| 23 | |
Brad Bishop | aea38c6 | 2018-01-30 13:00:26 -0500 | [diff] [blame] | 24 | # Abstract class, must subclass |
Brad Bishop | 179b39b | 2016-05-12 16:45:57 -0400 | [diff] [blame] | 25 | class 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 Bishop | 179b39b | 2016-05-12 16:45:57 -0400 | [diff] [blame] | 43 | class 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 Bishop | 179b39b | 2016-05-12 16:45:57 -0400 | [diff] [blame] | 50 | CONTROL_IFACE = 'org.openbmc.Control' |
| 51 | |
| 52 | |
Jayanth Othayoth | 857e4b8 | 2017-03-27 08:25:45 -0500 | [diff] [blame] | 53 | class PowerSupplyDeratingSensor(VirtualSensor): |
| 54 | def __init__(self, bus, name): |
| 55 | VirtualSensor.__init__(self, bus, name) |
Deepak Kodihalli | d67740e | 2018-02-23 08:05:19 -0600 | [diff] [blame] | 56 | super(PowerSupplyDeratingSensor, self).setValue(90) |
Jayanth Othayoth | 857e4b8 | 2017-03-27 08:25:45 -0500 | [diff] [blame] | 57 | |
Brad Bishop | aea38c6 | 2018-01-30 13:00:26 -0500 | [diff] [blame] | 58 | # override setValue method |
Jayanth Othayoth | 857e4b8 | 2017-03-27 08:25:45 -0500 | [diff] [blame] | 59 | @dbus.service.method( |
| 60 | SensorValue.IFACE_NAME, in_signature='v', out_signature='') |
| 61 | def setValue(self, value): |
CamVan Nguyen | 9172f3e | 2018-02-27 15:18:58 -0600 | [diff] [blame] | 62 | print("Setting Power Supply Derating is not allowed") |
Jayanth Othayoth | 857e4b8 | 2017-03-27 08:25:45 -0500 | [diff] [blame] | 63 | |