use std::map for fantype 'compatible' string checks

Switches to using a map of valid 'compatible'
strings + fanTypes instead of individual 'compatible'
string ==  conditionals

Tested: confirmed that HPE's GXP fans appear in webUI
with this change + appropriate entity-manager config entries

Change was made based on Andrew J's comment @
https://gerrit.openbmc.org/c/openbmc/dbus-sensors/+/62008/comment/cf2f99d8_a3d1d111/

Change-Id: Ia74b1617d95148a9e6a08865146d000c06a65b47
Signed-off-by: Chris Sides <christopher.sides@hpe.com>
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 6dccee5..f888e17 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -62,6 +62,13 @@
 // todo: power supply fan redundancy
 std::optional<RedundancySensor> systemRedundancy;
 
+static const std::map<std::string, FanTypes> compatibleFanTypes = {
+    {"aspeed,ast2400-pwm-tacho", FanTypes::aspeed},
+    {"aspeed,ast2500-pwm-tacho", FanTypes::aspeed},
+    {"nuvoton,npcm750-pwm-fan", FanTypes::nuvoton}
+    // add compatible string here for new fan type
+};
+
 FanTypes getFanType(const fs::path& parentPath)
 {
     fs::path linkPath = parentPath / "of_node";
@@ -70,30 +77,26 @@
     std::string compatiblePath = canonical + "/compatible";
     std::ifstream compatibleStream(compatiblePath);
 
-    if (!compatibleStream.is_open())
+    if (!compatibleStream)
     {
         std::cerr << "Error opening " << compatiblePath << "\n";
-        return FanTypes::i2c; // Should this throw an exception instead?
+        return FanTypes::i2c;
     }
 
     std::string compatibleString;
-    while (compatibleStream.peek() != EOF)
+    while (std::getline(compatibleStream, compatibleString))
     {
-        std::getline(compatibleStream, compatibleString);
         compatibleString.pop_back(); // trim EOL before comparisons
 
-        if (compatibleString == "aspeed,ast2400-pwm-tacho" ||
-            compatibleString == "aspeed,ast2500-pwm-tacho")
+        std::map<std::string, FanTypes>::const_iterator compatibleIterator =
+            compatibleFanTypes.find(compatibleString);
+
+        if (compatibleIterator != compatibleFanTypes.end())
         {
-            return FanTypes::aspeed;
-        }
-        if (compatibleString == "nuvoton,npcm750-pwm-fan")
-        {
-            return FanTypes::nuvoton;
+            return compatibleIterator->second;
         }
     }
 
-    // todo: will we need to support other types?
     return FanTypes::i2c;
 }
 void enablePwm(const fs::path& filePath)
@@ -316,8 +319,8 @@
                 }
                 if (fanType == FanTypes::aspeed || fanType == FanTypes::nuvoton)
                 {
-                    // there will be only 1 aspeed or nuvoton sensor object
-                    // in sysfs, we found the fan
+                    // there will be only 1 aspeed or nuvoton
+                    // object in sysfs, we found the fan
                     sensorData = &cfgData;
                     break;
                 }