blob: 24dceee9bd02670ce3dfe6b4db028a02c2d42976 [file] [log] [blame]
Matthew Barth4f0d3b72020-08-27 14:32:15 -05001/**
2 * Copyright © 2020 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "zone.hpp"
17
18#include <nlohmann/json.hpp>
19#include <phosphor-logging/log.hpp>
20#include <sdbusplus/bus.hpp>
21
22namespace phosphor::fan::control::json
23{
24
25using json = nlohmann::json;
26using namespace phosphor::logging;
27
28Zone::Zone(sdbusplus::bus::bus& bus, const json& jsonObj) :
29 ConfigBase(jsonObj), _incDelay(0)
30{
31 if (jsonObj.contains("profiles"))
32 {
33 for (const auto& profile : jsonObj["profiles"])
34 {
35 _profiles.emplace_back(profile.get<std::string>());
36 }
37 }
38 // Speed increase delay is optional, defaults to 0
39 if (jsonObj.contains("increase_delay"))
40 {
41 _incDelay = jsonObj["increase_delay"].get<uint64_t>();
42 }
43 setFullSpeed(jsonObj);
44 setDefaultFloor(jsonObj);
45 setDecInterval(jsonObj);
46}
47
48void Zone::setFullSpeed(const json& jsonObj)
49{
50 if (!jsonObj.contains("full_speed"))
51 {
52 log<level::ERR>("Missing required zone's full speed",
53 entry("JSON=%s", jsonObj.dump().c_str()));
54 throw std::runtime_error("Missing required zone's full speed");
55 }
56 _fullSpeed = jsonObj["full_speed"].get<uint64_t>();
57}
58
59void Zone::setDefaultFloor(const json& jsonObj)
60{
61 if (!jsonObj.contains("default_floor"))
62 {
63 log<level::ERR>("Missing required zone's default floor speed",
64 entry("JSON=%s", jsonObj.dump().c_str()));
65 throw std::runtime_error("Missing required zone's default floor speed");
66 }
67 _defaultFloor = jsonObj["default_floor"].get<uint64_t>();
68}
69
70void Zone::setDecInterval(const json& jsonObj)
71{
72 if (!jsonObj.contains("decrease_interval"))
73 {
74 log<level::ERR>("Missing required zone's decrease interval",
75 entry("JSON=%s", jsonObj.dump().c_str()));
76 throw std::runtime_error("Missing required zone's decrease interval");
77 }
78 _decInterval = jsonObj["decrease_interval"].get<uint64_t>();
79}
80
81} // namespace phosphor::fan::control::json