Regression fix: use pwm number from configuration

pwm number is specified in fan sensor configuration
Use this number to construct pwm fs path that is used
to create pwm sensor. No pwm sensor is created if pwm
field is not specified in configuration.

This fixes the regression introduced in the below CL, which
incorrectly assume pwm* and fan*_input always use the same
index number.

commit 77b3add2db57918b3f425ca6e147e9505563b867
Author: Yong Zhao <yozhao@google.com>
Date:   Sat Jan 9 04:25:18 2021 +0000

    Fan: Optimize the pwm sensor creation


Tested:
pwm sensors are successfully created and mapped with the
following configuration:
(note: number in configuration is zero based)
{
            "Name": "System Fan connector 7",
            "Pwm": 12,
            "Tachs": [
                6
            ],
            "Type": "IntelFanConnector"
        },

ipmitool sensor output
Pwm 13           | 49.784     | unspecified | ok    | na        | na        | na        | na        | na        | na
Fan 7            | 12382.000  | RPM        | ok    | na        | 1722.000  | 1968.000  | na        | na        | na

Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Signed-off-by: Yong Zhao <yozhao@google.com>
Change-Id: Ie5b44317285378a3e59951deeacd35108c71500d
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 25e5739..0b598d9 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -171,7 +171,6 @@
                 std::string indexStr = *(match.begin() + 1);
 
                 fs::path directory = path.parent_path();
-                fs::path pwmPath = directory / ("pwm" + indexStr);
                 FanTypes fanType = getFanType(directory);
 
                 size_t bus = 0;
@@ -366,6 +365,7 @@
 
                 std::optional<std::string> led;
                 std::string pwmName;
+                fs::path pwmPath;
 
                 if (connector != sensorData->end())
                 {
@@ -375,6 +375,7 @@
 
                         size_t pwm = std::visit(VariantToUnsignedIntVisitor(),
                                                 findPwm->second);
+                        pwmPath = directory / ("pwm" + std::to_string(pwm + 1));
                         /* use pwm name override if found in configuration else
                          * use default */
                         auto findOverride = connector->second.find("PwmName");
@@ -418,7 +419,8 @@
                     std::move(sensorThresholds), *interfacePath, limits,
                     powerState, led);
 
-                if (fs::exists(pwmPath) && !pwmSensors.count(pwmPath))
+                if (!pwmPath.empty() && fs::exists(pwmPath) &&
+                    !pwmSensors.count(pwmPath))
                 {
                     pwmSensors[pwmPath] = std::make_unique<PwmSensor>(
                         pwmName, pwmPath, dbusConnection, objectServer,