pid: add helper methods for thermal controller types

Add helper methods for thermal controller types, such as checking if a
string is a supported thermal type and which type that string
corresponds to.

Change-Id: I3c782f5825e7726f264dd186df583bde0a0dc861
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/pid/builder.cpp b/pid/builder.cpp
index 261a165..8fef528 100644
--- a/pid/builder.cpp
+++ b/pid/builder.cpp
@@ -94,7 +94,7 @@
                                                        info->pidInfo);
                 zone->addFanPID(std::move(pid));
             }
-            else if (info->type == "temp" || info->type == "margin")
+            else if (isThermalType(info->type))
             {
                 for (const auto& i : info->inputs)
                 {
@@ -102,19 +102,9 @@
                     zone->addThermalInput(i);
                 }
 
-                ThermalType type;
-                if (info->type == "temp")
-                {
-                    type = ThermalType::absolute;
-                }
-                else
-                {
-                    type = ThermalType::margin;
-                }
-
                 auto pid = ThermalController::createThermalPid(
                     zone.get(), name, inputs, info->setpoint, info->pidInfo,
-                    type);
+                    getThermalType(info->type));
 
                 zone->addThermalPID(std::move(pid));
             }
diff --git a/pid/thermalcontroller.cpp b/pid/thermalcontroller.cpp
index ff2c7bc..d794525 100644
--- a/pid/thermalcontroller.cpp
+++ b/pid/thermalcontroller.cpp
@@ -20,6 +20,20 @@
 #include "util.hpp"
 #include "zone.hpp"
 
+#include <algorithm>
+
+ThermalType getThermalType(const std::string& typeString)
+{
+    /* Currently it only supports the two types. */
+    return (typeString == "temp") ? ThermalType::absolute : ThermalType::margin;
+}
+
+bool isThermalType(const std::string& typeString)
+{
+    static const std::vector<std::string> thermalTypes = {"temp", "margin"};
+    return std::count(thermalTypes.begin(), thermalTypes.end(), typeString);
+}
+
 std::unique_ptr<PIDController> ThermalController::createThermalPid(
     ZoneInterface* owner, const std::string& id,
     const std::vector<std::string>& inputs, double setpoint,
diff --git a/pid/thermalcontroller.hpp b/pid/thermalcontroller.hpp
index 317219c..1a602a2 100644
--- a/pid/thermalcontroller.hpp
+++ b/pid/thermalcontroller.hpp
@@ -18,6 +18,22 @@
     absolute
 };
 
+/**
+ * Get the ThermalType for a given string.
+ *
+ * @param[in] typeString - a string representation of a type.
+ * @return the ThermalType representation.
+ */
+ThermalType getThermalType(const std::string& typeString);
+
+/**
+ * Is the type specified a thermal type?
+ *
+ * @param[in] typeString - a string representation of a PID type.
+ * @return true if it's a thermal PID type.
+ */
+bool isThermalType(const std::string& typeString);
+
 class ThermalController : public PIDController
 {
   public: