Point PowerSupplyRedundancySensor to new interface

The PowerSupplyRedundancy sensor is used by the Host to know
whether the system has redundant power supply support.
The sensor is implemented under the legacy openbmc/pyphosphor
repo which does not persist it's values. This commit will
move this sensor into the official phosphor settings repo
(which does have persistency support) but also keep the legacy
interfaces in place for backwards compatibility.

The PowerSupplyRedundancySensor should look at the new
PowerSupplyRedundancy interface for its value and when
setting the PowerSupplyRedundancySensor, set the new value.

Resolves openbmc/openbmc#2833

Change-Id: I490d385efba70f26b1a3eac87074b1fa0f8cd907
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/obmc/sensors.py b/obmc/sensors.py
index fba7a91..b8c26ed 100644
--- a/obmc/sensors.py
+++ b/obmc/sensors.py
@@ -110,7 +110,48 @@
 class PowerSupplyRedundancySensor(VirtualSensor):
     def __init__(self, bus, name):
         VirtualSensor.__init__(self, bus, name)
-        self.setValue("Enabled")
+        self.bus = bus
+        self.bus_name = 'xyz.openbmc_project.Settings'
+        self.obj_path = '/xyz/openbmc_project/control/power_supply_redundancy'
+        self.iface = 'xyz.openbmc_project.Control.PowerSupplyRedundancy'
+        self.prop_iface = 'org.freedesktop.DBus.Properties'
+        self.property_name = 'PowerSupplyRedundancyEnabled'
+        super(PowerSupplyRedundancySensor, self).setValue(self.getValue())
+
+    # Override setValue method
+    @dbus.service.method(
+        SensorValue.IFACE_NAME, in_signature='v', out_signature='')
+    def setValue(self, value):
+        if (value == "Enabled"):
+            intf = self.getPowerSupplyInterface()
+            intf.Set(self.iface, self.property_name, True)
+        elif (value == "Disabled"):
+            intf = self.getPowerSupplyInterface()
+            intf.Set(self.iface, self.property_name, False)
+        else:
+            print "Invalid Power Supply Redundancy value"
+            return
+        super(PowerSupplyRedundancySensor, self).setValue(value)
+
+    # Override getValue method
+    @dbus.service.method(
+        SensorValue.IFACE_NAME, in_signature='', out_signature='v')
+    def getValue(self):
+        intf = self.getPowerSupplyInterface()
+        value = intf.Get(self.iface, self.property_name)
+        if (value == 1):
+            return "Enabled"
+        elif (value == 0):
+            return "Disabled"
+        else:
+            print "Unable to determine Power Supply Redundancy value"
+            return ""
+
+    def getPowerSupplyInterface(self):
+        obj = self.bus.get_object(self.bus_name, self.obj_path,
+                                  introspect=True)
+        return dbus.Interface(obj, self.prop_iface)
+
 
 class PowerSupplyDeratingSensor(VirtualSensor):
     def __init__(self, bus, name):