xref: /openbmc/phosphor-modbus/rtu/device/reservoir_pump_unit.cpp (revision 7184805ae4ede906935133e3e0f8ee2468bc781b)
1 #include "reservoir_pump_unit.hpp"
2 
3 #include "device_factory.hpp"
4 
5 #include <phosphor-logging/lg2.hpp>
6 
7 namespace phosphor::modbus::rtu::device
8 {
9 
10 PHOSPHOR_LOG2_USING;
11 
12 static constexpr auto ModbusRDF040DSS5193E0ReservoirPumpUnitInterface =
13     "xyz.openbmc_project.Configuration.ModbusRDF040DSS5193E0ReservoirPumpUnit";
14 
15 static const std::unordered_map<std::string_view, config::DeviceModel>
16     validDevices = {{ModbusRDF040DSS5193E0ReservoirPumpUnitInterface,
17                      config::DeviceModel::RDF040DSS5193E0}};
18 
ReservoirPumpUnit(sdbusplus::async::context & ctx,const config::Config & config,PortIntf & serialPort,EventIntf::Events & events)19 ReservoirPumpUnit::ReservoirPumpUnit(
20     sdbusplus::async::context& ctx, const config::Config& config,
21     PortIntf& serialPort, EventIntf::Events& events) :
22     BaseDevice(ctx, config, serialPort, events)
23 {
24     info("Reservoir pump unit {NAME} created successfully", "NAME",
25          config.name);
26 }
27 
getInterfaces()28 auto ReservoirPumpUnit::getInterfaces() -> std::unordered_set<std::string>
29 {
30     return {ModbusRDF040DSS5193E0ReservoirPumpUnitInterface};
31 }
32 
getConfig(sdbusplus::async::context & ctx,const sdbusplus::message::object_path & objectPath,const std::string & interfaceName)33 auto ReservoirPumpUnit::getConfig(
34     sdbusplus::async::context& ctx,
35     const sdbusplus::message::object_path& objectPath,
36     const std::string& interfaceName)
37     -> sdbusplus::async::task<std::optional<config::DeviceFactoryConfig>>
38 {
39     config::DeviceFactoryConfig config{};
40 
41     auto res = co_await config::updateBaseConfig(ctx, objectPath, interfaceName,
42                                                  config);
43     if (!res)
44     {
45         co_return std::nullopt;
46     }
47 
48     for (const auto& [deviceInterface, deviceModel] : validDevices)
49     {
50         if (interfaceName == deviceInterface)
51         {
52             config.deviceModel = deviceModel;
53         }
54     }
55 
56     if (config.deviceModel == config::DeviceModel::unknown)
57     {
58         error("Invalid device model {MODEL} for {NAME}", "MODEL", interfaceName,
59               "NAME", config.name);
60         co_return std::nullopt;
61     }
62 
63     config.deviceType = config::DeviceType::reservoirPumpUnit;
64 
65     co_return config;
66 }
67 
68 } // namespace phosphor::modbus::rtu::device
69