blob: 5970ae24b5f1caf4a923fd142cb1db2ce2e1f177 [file] [log] [blame]
Matthew Barth0c4b1572020-10-22 14:39:46 -05001/**
Matthew Barth41a34082021-01-27 15:31:48 -06002 * Copyright © 2021 IBM Corporation
Matthew Barth0c4b1572020-10-22 14:39:46 -05003 *
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 "default_floor.hpp"
17
Matthew Barth0c4b1572020-10-22 14:39:46 -050018#include "types.hpp"
Matthew Barth41a34082021-01-27 15:31:48 -060019#include "zone.hpp"
Matthew Barth0c4b1572020-10-22 14:39:46 -050020
21#include <nlohmann/json.hpp>
22
Matthew Barth41a34082021-01-27 15:31:48 -060023#include <algorithm>
24#include <tuple>
25
Matthew Barth0c4b1572020-10-22 14:39:46 -050026namespace phosphor::fan::control::json
27{
28
29using json = nlohmann::json;
30
31DefaultFloor::DefaultFloor(const json&) : ActionBase(DefaultFloor::name)
32{
Matthew Barth41a34082021-01-27 15:31:48 -060033 // There are no JSON configuration parameters for this action
Matthew Barth0c4b1572020-10-22 14:39:46 -050034}
35
Matthew Barth41a34082021-01-27 15:31:48 -060036void DefaultFloor::run(Zone& zone, const Group& group)
Matthew Barth0c4b1572020-10-22 14:39:46 -050037{
Matthew Barth41a34082021-01-27 15:31:48 -060038 // Set/update the services of the group
39 zone.setServices(&group);
40 auto services = zone.getGroupServices(&group);
41 auto defFloor =
42 std::any_of(services.begin(), services.end(),
43 [](const auto& s) { return !std::get<hasOwnerPos>(s); });
44 if (defFloor)
45 {
46 zone.setFloor(zone.getDefFloor());
47 }
48 // Update fan control floor change allowed
49 zone.setFloorChangeAllow(&group, !defFloor);
Matthew Barth0c4b1572020-10-22 14:39:46 -050050}
51
52} // namespace phosphor::fan::control::json