sensor: Refactor get sensor reading command

Use the functor in the generated yaml to get the sensor reading
for analog sensors.

Change-Id: I2535cd5015096c3e1e2baa5f9a865fc6b27e6875
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index e52ab69..f9294eb 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -523,9 +523,6 @@
 
     *data_len=0;
 
-    int64_t raw_value;
-    ipmi::sensor::Info sensor;
-
     switch(type) {
         case 0xC2:
         case 0xC8:
@@ -586,59 +583,6 @@
             resp->indication[1] = 0;
             break;
 
-        case IPMI_SENSOR_TEMP:
-        case IPMI_SENSOR_VOLTAGE:
-        case IPMI_SENSOR_CURRENT:
-        case IPMI_SENSOR_FAN:
-            // Get reading for /xyz/openbmc_project/Sensor/Value.interface
-            if(sensors.find(reqptr->sennum) == sensors.end())
-            {
-                fprintf(stderr, "Failed to find config entry for Sensor 0x%02x\n",
-                        reqptr->sennum);
-                return IPMI_CC_SENSOR_INVALID;
-            }
-
-            sensor = sensors.at(reqptr->sennum);
-            if (ipmi::sensor::Mutability::Read !=
-                  (sensor.mutability & ipmi::sensor::Mutability::Read))
-            {
-                log<level::ERR>("Sensor was not readable.\n");
-                return IPMI_CC_SENSOR_INVALID;
-            }
-
-
-            // Get value
-            r = sd_bus_get_property_trivial(bus,
-                                            a.bus,
-                                            a.path,
-                                            a.interface,
-                                            "Value",
-                                            NULL,
-                                            'x',
-                                            &raw_value);
-            if (r < 0) {
-                fprintf(stderr,
-                        "Failed to call sd_bus_get_property:%d,  %s, 'value'\n",
-                        r,
-                        strerror(-r));
-                fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n",
-                        a.bus, a.path, a.interface);
-                break;
-            }
-
-            // Prevent div0
-            if (sensor.coefficientM == 0) {
-                sensor.coefficientM = 1;
-            };
-
-            resp->value = static_cast<uint8_t>(
-                    (raw_value - sensor.scaledOffset) / sensor.coefficientM);
-            resp->operation = 1 << scanningEnabledBit; // scanning enabled
-            resp->indication[0] = 0; // not a threshold sensor. ignore
-            resp->indication[1] = 0;
-            rc = IPMI_CC_OK;
-            *data_len=sizeof(sensorreadingresp_t);
-            break;
         default:
         {
             const auto iter = sensors.find(reqptr->sennum);
@@ -646,6 +590,11 @@
             {
                 return IPMI_CC_SENSOR_INVALID;
             }
+            if (ipmi::sensor::Mutability::Read !=
+                  (iter->second.mutability & ipmi::sensor::Mutability::Read))
+            {
+                return IPMI_CC_SENSOR_INVALID;
+            }
 
             try
             {