control: Make decrease interval optional

The `decrease_interval` configuration attribute should be optional where
it defaults to 0 when not given. A decrease interval of 0 disables the
decrease timer.

Change-Id: Ie88d94edb286870c7b8965a4ee778c89c08cc00e
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/zone.cpp b/control/json/zone.cpp
index 45157ae..1054a44 100644
--- a/control/json/zone.cpp
+++ b/control/json/zone.cpp
@@ -49,8 +49,8 @@
 
 Zone::Zone(const json& jsonObj, const sdeventplus::Event& event, Manager* mgr) :
     ConfigBase(jsonObj), _dbusZone{}, _manager(mgr), _defaultFloor(0),
-    _incDelay(0), _floor(0), _target(0), _incDelta(0), _decDelta(0),
-    _requestTargetBase(0), _isActive(true),
+    _incDelay(0), _decInterval(0), _floor(0), _target(0), _incDelta(0),
+    _decDelta(0), _requestTargetBase(0), _isActive(true),
     _incTimer(event, std::bind(&Zone::incTimerExpired, this)),
     _decTimer(event, std::bind(&Zone::decTimerExpired, this))
 {
@@ -81,7 +81,13 @@
         _floor = _defaultFloor;
     }
 
-    setDecInterval(jsonObj);
+    // Decrease interval is optional, defaults to 0
+    // A decrease interval of 0sec disables the decrease timer
+    if (jsonObj.contains("decrease_interval"))
+    {
+        _decInterval =
+            std::chrono::seconds(jsonObj["decrease_interval"].get<uint64_t>());
+    }
 
     // Setting properties on interfaces to be served are optional
     if (jsonObj.contains("interfaces"))
@@ -112,8 +118,12 @@
     // Emit object added for this zone's associated dbus object
     _dbusZone->emit_object_added();
 
-    // Start timer for fan target decreases
-    _decTimer.restart(_decInterval);
+    // A decrease interval of 0sec disables the decrease timer
+    if (_decInterval != std::chrono::seconds::zero())
+    {
+        // Start timer for fan target decreases
+        _decTimer.restart(_decInterval);
+    }
 }
 
 void Zone::addFan(std::unique_ptr<Fan> fan)
@@ -276,18 +286,6 @@
     _target = _poweronTarget;
 }
 
-void Zone::setDecInterval(const json& jsonObj)
-{
-    if (!jsonObj.contains("decrease_interval"))
-    {
-        log<level::ERR>("Missing required zone's decrease interval",
-                        entry("JSON=%s", jsonObj.dump().c_str()));
-        throw std::runtime_error("Missing required zone's decrease interval");
-    }
-    _decInterval =
-        std::chrono::seconds(jsonObj["decrease_interval"].get<uint64_t>());
-}
-
 void Zone::setInterfaces(const json& jsonObj)
 {
     for (const auto& interface : jsonObj["interfaces"])
diff --git a/control/json/zone.hpp b/control/json/zone.hpp
index 50d8718..f209b4a 100644
--- a/control/json/zone.hpp
+++ b/control/json/zone.hpp
@@ -369,7 +369,7 @@
     /* Zone's increase delay(in seconds) (OPTIONAL) */
     std::chrono::seconds _incDelay;
 
-    /* Zone's decrease interval(in seconds) */
+    /* Zone's decrease interval(in seconds) (OPTIONAL) */
     std::chrono::seconds _decInterval;
 
     /* The floor target to not go below */
@@ -436,16 +436,6 @@
     void setPowerOnTarget(const json& jsonObj);
 
     /**
-     * @brief Parse and set the zone's decrease interval(in seconds)
-     *
-     * @param[in] jsonObj - JSON object for the zone
-     *
-     * Sets the decrease interval(in seconds) for the zone from the JSON
-     * configuration object
-     */
-    void setDecInterval(const json& jsonObj);
-
-    /**
      * @brief Parse and set the interfaces served by the zone(OPTIONAL)
      *
      * @param[in] jsonObj - JSON object for the zone