Enhance handling sensor value property type change

From comments resulting in change
https://gerrit.openbmc-project.xyz/29187, simplified the check that both
the type configured and type of the sensor value property are the same
along with doing an assert when the type configured does not match the
supported types of the sensor value property.

A static_assert was not able to be performed within the visitor due to
the type supported by the variant parameter and that the fan
configuration also provides the data type for the properties. Since all
properties configured to be used are ran thru this function, a
static_assert would cause those to fail to compile. This is the best
solution found until the type is removed from being provided in the
configuration.

Tested:
    Configured sensor value property to an unsupported type causing an
assert
    No change to a sensor value being configured as an int with the dbus
interface being int or double
    No change to a sensor value being configured as a double with the
dbus interface being a double

Change-Id: I37955fd60ed23c9d6d198cdce22008258cc00014
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/zone.hpp b/control/zone.hpp
index c949228..8415def 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -6,6 +6,7 @@
 #include <sdbusplus/bus.hpp>
 #include <sdeventplus/event.hpp>
 #include <vector>
+#include <optional>
 #include "fan.hpp"
 #include "types.hpp"
 #include "sdbusplus.hpp"
@@ -237,14 +238,16 @@
             const char* prop,
             PropertyVariantType& variant)
         {
-            T value;
-
             // Handle the transition of the dbus sensor value type from
             // int64 to double which also removed the scale property.
             // https://gerrit.openbmc-project.xyz/11739
             if (strcmp(intf, "xyz.openbmc_project.Sensor.Value") == 0 &&
                 strcmp(prop, "Value") == 0)
             {
+                // Use 'optional' variable to determine if the sensor value
+                // is set within the visitor based on the supported types.
+                // A non-supported type configured will assert.
+                std::optional<T> value;
                 std::visit([&value](auto&& val)
                 {
                     // If the type configured is int64, but the sensor value
@@ -260,23 +263,22 @@
                     // If the type configured matches the sensor value
                     // property's type, just return the value as its
                     // given type.
-                    else if constexpr((std::is_same_v<T, int64_t> &&
-                                       std::is_same_v<V, int64_t>) ||
-                                      (std::is_same_v<T, double> &&
-                                       std::is_same_v<V, double>))
+                    else if constexpr(std::is_same_v<T, V>)
                     {
                         value = val;
                     }
                 }, variant);
 
-                return value;
+                // Unable to return Sensor Value property
+                // as given type configured.
+                assert(value);
+
+                return value.value();
             }
 
             // Default to return the property's value by the data type
             // configured, applying no visitors to the variant.
-            value = std::get<T>(variant);
-
-            return value;
+            return std::get<T>(variant);
         };
 
         /**