From 4f3ac55cf832db54ff1868a300d6e3d4a83a087e Mon Sep 17 00:00:00 2001 From: Raoul Hecky Date: Thu, 12 Dec 2024 10:43:41 +0000 Subject: [PATCH] Fix issue with same_as action where IO has delayed state update --- src/bin/calaos_server/IO/OutputAnalog.cpp | 2 ++ src/bin/calaos_server/IO/OutputAnalog.h | 3 +++ src/bin/calaos_server/IO/OutputFake.h | 2 ++ src/bin/calaos_server/IO/OutputLight.cpp | 2 ++ src/bin/calaos_server/IO/OutputLight.h | 4 ++++ src/bin/calaos_server/IO/OutputLightDimmer.cpp | 9 +++++++++ src/bin/calaos_server/IO/OutputLightDimmer.h | 2 ++ src/bin/calaos_server/IO/OutputLightRGB.cpp | 7 +++++-- src/bin/calaos_server/IO/OutputLightRGB.h | 2 ++ src/bin/calaos_server/IO/OutputString.cpp | 2 ++ src/bin/calaos_server/IO/OutputString.h | 7 +++++-- src/bin/calaos_server/IO/Scenario.h | 8 +++++--- src/bin/calaos_server/IOBase.h | 4 +++- src/bin/calaos_server/Rules/ActionStd.cpp | 15 ++++++--------- 14 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/bin/calaos_server/IO/OutputAnalog.cpp b/src/bin/calaos_server/IO/OutputAnalog.cpp index df3c732f..6713f904 100644 --- a/src/bin/calaos_server/IO/OutputAnalog.cpp +++ b/src/bin/calaos_server/IO/OutputAnalog.cpp @@ -84,6 +84,8 @@ bool OutputAnalog::set_value(double val) readConfig(); + cmd_state = val; + //send computed value to device set_value_real(val * coeff_a + coeff_b); diff --git a/src/bin/calaos_server/IO/OutputAnalog.h b/src/bin/calaos_server/IO/OutputAnalog.h index 03c6918a..06105aea 100644 --- a/src/bin/calaos_server/IO/OutputAnalog.h +++ b/src/bin/calaos_server/IO/OutputAnalog.h @@ -34,6 +34,7 @@ class OutputAnalog : public IOBase double value; double coeff_a = 1.0; double coeff_b = 0.0; + double cmd_state = 0.0; void readConfig(); @@ -52,6 +53,8 @@ class OutputAnalog : public IOBase virtual bool set_value(double val); virtual double get_value_double(); virtual bool set_value(string val); + + virtual double get_command_double() { return cmd_state; } }; } diff --git a/src/bin/calaos_server/IO/OutputFake.h b/src/bin/calaos_server/IO/OutputFake.h index a9d39abd..cee58c1b 100644 --- a/src/bin/calaos_server/IO/OutputFake.h +++ b/src/bin/calaos_server/IO/OutputFake.h @@ -40,6 +40,8 @@ class OutputFake : public IOBase bool set_value(bool val); bool get_value_bool() { return value; } + + virtual bool get_command_bool() { return value; } }; } diff --git a/src/bin/calaos_server/IO/OutputLight.cpp b/src/bin/calaos_server/IO/OutputLight.cpp index 3a0c325b..d59acd27 100644 --- a/src/bin/calaos_server/IO/OutputLight.cpp +++ b/src/bin/calaos_server/IO/OutputLight.cpp @@ -81,6 +81,8 @@ bool OutputLight::_set_value(bool val) { cInfoDom("output") << get_param("id") << ": got action, " << ((val)?"True":"False"); + cmd_state = val; + if (set_value_real(val)) { if (!useRealState) diff --git a/src/bin/calaos_server/IO/OutputLight.h b/src/bin/calaos_server/IO/OutputLight.h index b0bbd5b1..da067fd3 100644 --- a/src/bin/calaos_server/IO/OutputLight.h +++ b/src/bin/calaos_server/IO/OutputLight.h @@ -35,6 +35,8 @@ class OutputLight : public IOBase vector blinks; int current_blink; + bool cmd_state = false; + void TimerImpulse(); void TimerImpulseExtended(); @@ -69,6 +71,8 @@ class OutputLight : public IOBase virtual bool set_value(bool val); virtual bool get_value_bool() { return value; } virtual bool set_value(string val); + + virtual bool get_command_bool() { return cmd_state; } }; } diff --git a/src/bin/calaos_server/IO/OutputLightDimmer.cpp b/src/bin/calaos_server/IO/OutputLightDimmer.cpp index 763c1cf0..e325430b 100644 --- a/src/bin/calaos_server/IO/OutputLightDimmer.cpp +++ b/src/bin/calaos_server/IO/OutputLightDimmer.cpp @@ -97,6 +97,7 @@ bool OutputLightDimmer::set_value(std::string val) set_on_real(); cmd_state = "on"; + cmd_state_bool = true; } } else if (val == "off" || val == "false") @@ -107,6 +108,7 @@ bool OutputLightDimmer::set_value(std::string val) set_off_real(); cmd_state = "off"; + cmd_state_bool = false; } } else if (val == "toggle") @@ -125,6 +127,7 @@ bool OutputLightDimmer::set_value(std::string val) if (percent > 100) percent = 100; cmd_state = "set off " + Utils::to_string(percent); + cmd_state_bool = false; if (value > 0) { @@ -145,6 +148,7 @@ bool OutputLightDimmer::set_value(std::string val) if (percent > 100) percent = 100; cmd_state = "set " + Utils::to_string(percent); + cmd_state_bool = percent > 0 ? true : false; set_value_real(percent); value = percent; @@ -158,6 +162,7 @@ bool OutputLightDimmer::set_value(std::string val) set_dim_up_real(percent); cmd_state = "up " + val; + cmd_state_bool = true; } else if (val.compare(0, 5, "down ") == 0) { @@ -166,6 +171,7 @@ bool OutputLightDimmer::set_value(std::string val) Utils::from_string(val, percent); cmd_state = "down " + val; + cmd_state_bool = true; set_dim_down_real(percent); } @@ -223,12 +229,14 @@ bool OutputLightDimmer::set_value(std::string val) { value = old_value; cmd_state = "on"; + cmd_state_bool = true; } else if (val == "false") { old_value = value; value = 0; cmd_state = "off"; + cmd_state_bool = false; } else if (is_of_type(val)) { @@ -238,6 +246,7 @@ bool OutputLightDimmer::set_value(std::string val) if (percent > 100) percent = 100; cmd_state = "set " + Utils::to_string(percent); + cmd_state_bool = percent > 0 ? true : false; value = percent; } } diff --git a/src/bin/calaos_server/IO/OutputLightDimmer.h b/src/bin/calaos_server/IO/OutputLightDimmer.h index 0e8736b8..7a962610 100644 --- a/src/bin/calaos_server/IO/OutputLightDimmer.h +++ b/src/bin/calaos_server/IO/OutputLightDimmer.h @@ -41,6 +41,7 @@ class OutputLightDimmer : public IOBase int current_blink; std::string cmd_state; + bool cmd_state_bool = false; bool press_detected; bool press_sens; bool stop_after_press; @@ -84,6 +85,7 @@ class OutputLightDimmer : public IOBase bool get_value_bool() { if (value == 0) return false; else return true; } virtual std::string get_command_string() { return cmd_state; } + virtual bool get_command_bool() { return cmd_state_bool; } virtual bool check_condition_value(std::string cvalue, bool equal); }; diff --git a/src/bin/calaos_server/IO/OutputLightRGB.cpp b/src/bin/calaos_server/IO/OutputLightRGB.cpp index 57854a81..2597de7b 100644 --- a/src/bin/calaos_server/IO/OutputLightRGB.cpp +++ b/src/bin/calaos_server/IO/OutputLightRGB.cpp @@ -84,6 +84,7 @@ bool OutputLightRGB::set_value(std::string val) color = ColorValue::fromRgb(255, 255, 255); setColor(color, true); cmd_state = "on"; + cmd_state_bool = true; state = true; } @@ -96,6 +97,7 @@ bool OutputLightRGB::set_value(std::string val) { setColor(ColorValue::fromRgb(0, 0, 0), false); cmd_state = "off"; + cmd_state_bool = false; state = false; } @@ -113,6 +115,7 @@ bool OutputLightRGB::set_value(std::string val) setColor(color, state); cmd_state = "set off " + color.toString(); + cmd_state_bool = false; DELETE_NULL(timer_auto); } @@ -133,8 +136,6 @@ bool OutputLightRGB::set_value(std::string val) setColor(color, state); - cmd_state = "set " + color.toString(); - DELETE_NULL(timer_auto); } } @@ -299,6 +300,7 @@ void OutputLightRGB::setColor(const ColorValue &c, bool s) cInfo() << "New color: " << c.toString() << " state: " << s; cmd_state = "set " + color.toString(); + cmd_state_bool = s; state = s; setColorReal(c, s); @@ -325,6 +327,7 @@ void OutputLightRGB::stateUpdated(const ColorValue &c, bool s) state = s; color = c; cmd_state = "set " + get_value_string(); + cmd_state_bool = state; EmitSignalIO(); if (hasChanged) diff --git a/src/bin/calaos_server/IO/OutputLightRGB.h b/src/bin/calaos_server/IO/OutputLightRGB.h index 9371f8cb..c034bc30 100644 --- a/src/bin/calaos_server/IO/OutputLightRGB.h +++ b/src/bin/calaos_server/IO/OutputLightRGB.h @@ -36,6 +36,7 @@ class OutputLightRGB : public IOBase ColorValue color; std::string cmd_state; + bool cmd_state_bool = false; Timer *timer_auto; void TimerAutoChange(); @@ -67,6 +68,7 @@ class OutputLightRGB : public IOBase bool get_value_bool() { return state; } virtual std::string get_command_string() { return cmd_state; } + virtual bool get_command_bool() { return cmd_state_bool; } virtual bool check_condition_value(string cvalue, bool equal); }; diff --git a/src/bin/calaos_server/IO/OutputString.cpp b/src/bin/calaos_server/IO/OutputString.cpp index ac8f6dd4..c3786684 100644 --- a/src/bin/calaos_server/IO/OutputString.cpp +++ b/src/bin/calaos_server/IO/OutputString.cpp @@ -56,6 +56,8 @@ bool OutputString::set_value(string val) readConfig(); + cmd_state = val; + set_value_real(val); value = val; diff --git a/src/bin/calaos_server/IO/OutputString.h b/src/bin/calaos_server/IO/OutputString.h index 92cee2d2..f257244b 100644 --- a/src/bin/calaos_server/IO/OutputString.h +++ b/src/bin/calaos_server/IO/OutputString.h @@ -31,6 +31,7 @@ class OutputString : public IOBase { protected: string value; + string cmd_state; void readConfig(); @@ -41,9 +42,11 @@ class OutputString : public IOBase OutputString(Params &p); ~OutputString(); - DATA_TYPE get_type() { return TSTRING; } + virtual DATA_TYPE get_type() override { return TSTRING; } - bool set_value(string val); + virtual bool set_value(string val) override; + + virtual string get_command_string() override { return cmd_state; } }; } diff --git a/src/bin/calaos_server/IO/Scenario.h b/src/bin/calaos_server/IO/Scenario.h index 070d0173..51fccb34 100644 --- a/src/bin/calaos_server/IO/Scenario.h +++ b/src/bin/calaos_server/IO/Scenario.h @@ -41,13 +41,15 @@ class Scenario : public IOBase Scenario(Params &p); ~Scenario(); - virtual DATA_TYPE get_type() { return TBOOL; } + virtual DATA_TYPE get_type() override { return TBOOL; } - virtual bool get_value_bool() { return value; } - virtual bool set_value(bool val); + virtual bool get_value_bool() override { return value; } + virtual bool set_value(bool val) override; AutoScenario *getAutoScenario() { return auto_scenario; } + virtual bool get_command_bool() override { return value; } + json_t *toJson(); }; diff --git a/src/bin/calaos_server/IOBase.h b/src/bin/calaos_server/IOBase.h index 179d4ce6..60eaf536 100644 --- a/src/bin/calaos_server/IOBase.h +++ b/src/bin/calaos_server/IOBase.h @@ -106,8 +106,10 @@ class IOBase virtual bool set_value(double val) { return false; } virtual bool set_value(std::string val) { return false; } - //used to retreive the last state command of the TSTRING output + //used to retreive the last state command of the output virtual std::string get_command_string() { return ""; } + virtual bool get_command_bool() { return false; } + virtual double get_command_double() { return 0.0; } //used to get a better condition value in ConditionOutput rules //like if shutter is open or is light on diff --git a/src/bin/calaos_server/Rules/ActionStd.cpp b/src/bin/calaos_server/Rules/ActionStd.cpp index 0b864494..cf68c261 100644 --- a/src/bin/calaos_server/Rules/ActionStd.cpp +++ b/src/bin/calaos_server/Rules/ActionStd.cpp @@ -64,14 +64,11 @@ bool ActionStd::Execute() { std::string var_id = params_var[outputs[i]->get_param("id")]; IOBase *out = ListeRoom::Instance().get_io(var_id); - if (out && out->get_type() == TBOOL) + if (out && + (out->get_type() == TBOOL || + out->get_type() == TSTRING)) { - bval = out->get_value_bool(); - ovar = true; - } - else if (out && out->get_type() == TSTRING) - { - bval = out->get_value_bool(); + bval = out->get_command_bool(); ovar = true; } } @@ -102,7 +99,7 @@ bool ActionStd::Execute() IOBase *out = ListeRoom::Instance().get_io(var_id); if (out && out->get_type() == TINT) { - dval = out->get_value_double(); + dval = out->get_command_double(); ovar = true; } } @@ -137,7 +134,7 @@ bool ActionStd::Execute() } else if (out && out->get_type() == TBOOL) { - sval = out->get_value_bool() ? "true" : "false"; + sval = out->get_command_bool() ? "true" : "false"; ovar = true; } }