entity-manager: extract addValueToDbus

Based on the type and if it's an array or not the json data will be
exposed. There are 2 template functions 'addProperty' and
'addArrayToDbus' which can be called.

Extract that branch into another function to avoid the duplication
there.

Tested: on Tyan s8030 board

Inventory is properly exposed and object paths appear as expected.

```
root@s8030-bmc-30303035c0c1:~# busctl tree xyz.openbmc_project.EntityManager
`- /xyz
  `- /xyz/openbmc_project
    |- /xyz/openbmc_project/EntityManager
    `- /xyz/openbmc_project/inventory
      `- /xyz/openbmc_project/inventory/system
        |- /xyz/openbmc_project/inventory/system/board
        | `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Power_Consumption
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Temp
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/GARBO_SENSOR
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_18_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_CORE_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_ABCD
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_EFGH
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_SOC_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_12_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_DUAL
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_RUN
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_DUAL
        |   |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_RUN
        |   `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/X550
```

DBus interfaces appear as expected

```
root@s8030-bmc-30303035c0c1:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
NAME                                              TYPE      SIGNATURE RESULT/VALUE     FLAGS
org.freedesktop.DBus.Introspectable               interface -         -                -
.Introspect                                       method    -         s                -
org.freedesktop.DBus.Peer                         interface -         -                -
.GetMachineId                                     method    -         s                -
.Ping                                             method    -         -                -
org.freedesktop.DBus.Properties                   interface -         -                -
.Get                                              method    ss        v                -
.GetAll                                           method    s         a{sv}            -
.Set                                              method    ssv       -                -
.PropertiesChanged                                signal    sa{sv}as  -                -
xyz.openbmc_project.Configuration.ADC             interface -         -                -
.Index                                            property  t         10               emits-change
.Name                                             property  s         "VBAT_33"        emits-change
.PowerState                                       property  s         "Always"         emits-change
.ScaleFactor                                      property  d         0.3333           emits-change
.Type                                             property  s         "ADC"            emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds0 interface -         -                -
.Delete                                           method    -         -                -
.Direction                                        property  s         "greater than"   emits-change
.Name                                             property  s         "upper critical" emits-change
.Severity                                         property  d         1                emits-change
.Value                                            property  d         3.507            emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds1 interface -         -                -
.Delete                                           method    -         -                -
.Direction                                        property  s         "less than"      emits-change
.Name                                             property  s         "lower critical" emits-change
.Severity                                         property  d         1                emits-change
.Value                                            property  d         2.688            emits-change
```

Change-Id: I3ee614847bed92ae5015d7ecb585cdfda54e3ea2
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index 72f67f4..45e4f6d 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -194,63 +194,26 @@
             }
             case (nlohmann::json::value_t::number_integer):
             {
-                if (array)
-                {
-                    addArrayToDbus<int64_t>(key, value, iface.get(), permission,
-                                            systemConfiguration, path);
-                }
-                else
-                {
-                    addProperty(key, value.get<int64_t>(), iface.get(),
-                                systemConfiguration, path,
-                                sdbusplus::asio::PropertyPermission::readOnly);
-                }
+                addValueToDBus<int64_t>(key, value, *iface, permission,
+                                        systemConfiguration, path);
                 break;
             }
             case (nlohmann::json::value_t::number_unsigned):
             {
-                if (array)
-                {
-                    addArrayToDbus<uint64_t>(key, value, iface.get(),
-                                             permission, systemConfiguration,
-                                             path);
-                }
-                else
-                {
-                    addProperty(key, value.get<uint64_t>(), iface.get(),
-                                systemConfiguration, path,
-                                sdbusplus::asio::PropertyPermission::readOnly);
-                }
+                addValueToDBus<uint64_t>(key, value, *iface, permission,
+                                         systemConfiguration, path);
                 break;
             }
             case (nlohmann::json::value_t::number_float):
             {
-                if (array)
-                {
-                    addArrayToDbus<double>(key, value, iface.get(), permission,
-                                           systemConfiguration, path);
-                }
-
-                else
-                {
-                    addProperty(key, value.get<double>(), iface.get(),
-                                systemConfiguration, path, permission);
-                }
+                addValueToDBus<double>(key, value, *iface, permission,
+                                       systemConfiguration, path);
                 break;
             }
             case (nlohmann::json::value_t::string):
             {
-                if (array)
-                {
-                    addArrayToDbus<std::string>(key, value, iface.get(),
-                                                permission, systemConfiguration,
-                                                path);
-                }
-                else
-                {
-                    addProperty(key, value.get<std::string>(), iface.get(),
-                                systemConfiguration, path, permission);
-                }
+                addValueToDBus<std::string>(key, value, *iface, permission,
+                                            systemConfiguration, path);
                 break;
             }
             default:
diff --git a/src/entity_manager/dbus_interface.hpp b/src/entity_manager/dbus_interface.hpp
index 35ea742..5e6609d 100644
--- a/src/entity_manager/dbus_interface.hpp
+++ b/src/entity_manager/dbus_interface.hpp
@@ -99,6 +99,25 @@
         });
 }
 
+template <typename PropertyType>
+void addValueToDBus(const std::string& key, const nlohmann::json& value,
+                    sdbusplus::asio::dbus_interface& iface,
+                    sdbusplus::asio::PropertyPermission permission,
+                    nlohmann::json& systemConfiguration,
+                    const std::string& path)
+{
+    if (value.is_array())
+    {
+        addArrayToDbus<PropertyType>(key, value, &iface, permission,
+                                     systemConfiguration, path);
+    }
+    else
+    {
+        addProperty(key, value.get<PropertyType>(), &iface, systemConfiguration,
+                    path, sdbusplus::asio::PropertyPermission::readOnly);
+    }
+}
+
 void createDeleteObjectMethod(
     const std::string& jsonPointerPath,
     const std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,