control:zone: Override floor to current ceiling
When a requested floor is above the currently set ceiling, override the
requested floor value with the current ceiling value. This ensures that
a floor is never above a set ceiling. If a floor is intended to be
higher than a current ceiling, then fan control must be configured to
change the ceiling value prior to the requested floor change being made.
Change-Id: I59daf32140d94a05a32652c4502b4a4ed5cb3fca
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/zone.cpp b/control/json/zone.cpp
index f1c5a44..f484733 100644
--- a/control/json/zone.cpp
+++ b/control/json/zone.cpp
@@ -78,6 +78,15 @@
if (jsonObj.contains("default_floor"))
{
_defaultFloor = jsonObj["default_floor"].get<uint64_t>();
+ if (_defaultFloor > _ceiling)
+ {
+ log<level::ERR>(
+ fmt::format("Configured default_floor({}) above ceiling({}), "
+ "setting default floor to ceiling",
+ _defaultFloor, _ceiling)
+ .c_str());
+ _defaultFloor = _ceiling;
+ }
// Start with the current floor set as the default
_floor = _defaultFloor;
}
@@ -245,6 +254,11 @@
{
using namespace std::string_literals;
+ if (target > _ceiling)
+ {
+ target = _ceiling;
+ }
+
if (!hold)
{
size_t removed = _floorHolds.erase(ident);
@@ -312,7 +326,7 @@
auto pred = [](const auto& entry) { return entry.second; };
if (std::all_of(_floorChange.begin(), _floorChange.end(), pred))
{
- _floor = target;
+ _floor = (target > _ceiling) ? _ceiling : target;
// Floor above target, update target to floor
if (_target < _floor)
{