Skip to content

Commit

Permalink
Fix issue with same_as action where IO has delayed state update
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Dec 12, 2024
1 parent 44caffb commit 4f3ac55
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/bin/calaos_server/IO/OutputAnalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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; }
};

}
Expand Down
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputFake.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

}
Expand Down
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/bin/calaos_server/IO/OutputLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 35,8 @@ class OutputLight : public IOBase
vector<BlinkInfo> blinks;
int current_blink;

bool cmd_state = false;

void TimerImpulse();
void TimerImpulseExtended();

Expand Down Expand Up @@ -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; }
};

}
Expand Down
9 changes: 9 additions & 0 deletions src/bin/calaos_server/IO/OutputLightDimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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);
}
Expand Down Expand Up @@ -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<int>(val))
{
Expand All @@ -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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputLightDimmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
Expand Down
7 changes: 5 additions & 2 deletions src/bin/calaos_server/IO/OutputLightRGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
}
Expand All @@ -133,8 136,6 @@ bool OutputLightRGB::set_value(std::string val)

setColor(color, state);

cmd_state = "set " color.toString();

DELETE_NULL(timer_auto);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputLightRGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 36,7 @@ class OutputLightRGB : public IOBase
ColorValue color;

std::string cmd_state;
bool cmd_state_bool = false;

Timer *timer_auto;
void TimerAutoChange();
Expand Down Expand Up @@ -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);
};
Expand Down
2 changes: 2 additions & 0 deletions src/bin/calaos_server/IO/OutputString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 56,8 @@ bool OutputString::set_value(string val)

readConfig();

cmd_state = val;

set_value_real(val);

value = val;
Expand Down
7 changes: 5 additions & 2 deletions src/bin/calaos_server/IO/OutputString.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 31,7 @@ class OutputString : public IOBase
{
protected:
string value;
string cmd_state;

void readConfig();

Expand All @@ -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; }
};

}
Expand Down
8 changes: 5 additions & 3 deletions src/bin/calaos_server/IO/Scenario.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
4 changes: 3 additions & 1 deletion src/bin/calaos_server/IOBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions src/bin/calaos_server/Rules/ActionStd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 4f3ac55

Please sign in to comment.