Fix occ-control terminations

1. Ensure PowerMode object created before attempting to use
2. Only call setChassisAssociation after getting successful temperature
reading.

Tested on Everest hw

Change-Id: I308c072cf5ab0235086c136ba7644125de0a8c6a
Signed-off-by: Chris Cain <cjcain@us.ibm.com>
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 2245a3f..ee8575d 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -133,6 +133,13 @@
 {
     auto path = fs::path(OCC_CONTROL_ROOT) / occ;
 
+#ifdef POWER10
+    if (!pmode)
+    {
+        pmode = std::make_unique<open_power::occ::powermode::PowerMode>(*this);
+    }
+#endif
+
     statusObjects.emplace_back(std::make_unique<Status>(
         event, path.c_str(), *this,
 #ifdef POWER10
@@ -163,12 +170,8 @@
         }
 
 #ifdef POWER10
-        // Create the power mode object for master OCC
-        if (!pmode)
-        {
-            pmode = std::make_unique<open_power::occ::powermode::PowerMode>(
-                *this, path.c_str());
-        }
+        // Set the master OCC on the PowerMode object
+        pmode->setMasterOcc(path);
 #endif
     }
 
@@ -289,8 +292,9 @@
     pcap = std::make_unique<open_power::occ::powercap::PowerCap>(
         *statusObjects.front(), occMasterName);
 #ifdef POWER10
-    pmode = std::make_unique<open_power::occ::powermode::PowerMode>(
-        *this, path.c_str());
+    pmode = std::make_unique<open_power::occ::powermode::PowerMode>(*this);
+    // Set the master OCC on the PowerMode object
+    pmode->setMasterOcc(path);
 #endif
 }
 #endif
@@ -651,13 +655,6 @@
             continue;
         }
 
-        // At this point, the sensor will be created for sure.
-        if (existingSensors.find(sensorPath) == existingSensors.end())
-        {
-            open_power::occ::dbus::OccDBusSensors::getOccDBus()
-                .setChassisAssociation(sensorPath);
-        }
-
         if (faultValue != 0)
         {
             open_power::occ::dbus::OccDBusSensors::getOccDBus().setValue(
@@ -690,6 +687,13 @@
         open_power::occ::dbus::OccDBusSensors::getOccDBus()
             .setOperationalStatus(sensorPath, true);
 
+        // At this point, the sensor will be created for sure.
+        if (existingSensors.find(sensorPath) == existingSensors.end())
+        {
+            open_power::occ::dbus::OccDBusSensors::getOccDBus()
+                .setChassisAssociation(sensorPath);
+        }
+
         existingSensors[sensorPath] = id;
     }
     return;
@@ -971,9 +975,9 @@
 #ifdef POWER10
 void Manager::occsNotAllRunning()
 {
-    // Function will also gets called when occ-control app gets restarted.
-    // (occ active sensors do not change, so the Status object does not
-    //  call Manager back for all OCCs)
+    // Function will also gets called when occ-control app gets
+    // restarted. (occ active sensors do not change, so the Status
+    // object does not call Manager back for all OCCs)
 
     if (activeCount != statusObjects.size())
     {