aqhome-react, aqhome: added units/functions for handling local variables.

This commit is contained in:
Martin Preuss
2024-05-12 17:31:31 +02:00
parent 516ac4e34e
commit 7ce34b0500
13 changed files with 402 additions and 33 deletions

View File

@@ -15,11 +15,13 @@
#include "aqhome-react/units/u_logical.h"
#include "aqhome-react/units/u_valuefilter.h"
#include "aqhome-react/units/u_valueset.h"
#include "aqhome-react/units/u_varset.h"
#include "aqhome-react/units/u_stabilize.h"
#include "aqhome-react/units/u_lowpass.h"
#include "aqhome-react/units/u_highpass.h"
#include "aqhome-react/units/u_zeroposnegstring.h"
#include "aqhome-react/units/u_suntime.h"
#include "aqhome-react/units/u_varchanges.h"
#include <gwenhywfar/misc.h>
@@ -114,9 +116,9 @@ AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh)
AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh)
AQHREACT_UNIT *AqHomeReact_GetServerVarChangeUnit(const AQHOME_REACT *aqh)
{
return aqh?aqh->varChangeUnit:NULL;
return aqh?aqh->serverVarChangeUnit:NULL;
}
@@ -147,6 +149,73 @@ void AqHomeReact_AddUnit(AQHOME_REACT *aqh, AQHREACT_UNIT *unit)
AQH_VARS *AqHomeReact_GetLocalVars(const AQHOME_REACT *aqh)
{
return aqh?aqh->localVars:NULL;
}
int AqHomeReact_SetCharValue(AQHOME_REACT *aqh, const char *path, const char *value)
{
if (aqh && aqh->localVars && path && *path) {
int rv;
uint64_t timestamp;
timestamp=(uint64_t) time(NULL);
rv=AQH_Vars_SetCharValue(aqh->localVars, AQH_VARS_PATHFLAGS_OVERWRITE_VARS, path, value);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
return rv;
}
AqHomeReact_UnitVarChanges_StringVarUpdated(aqh->localVarChangeUnit, path, timestamp, value);
return 0;
}
return GWEN_ERROR_INVALID;
}
const char *AqHomeReact_GetCharValue(AQHOME_REACT *aqh, const char *path, int idx, const char *defaultValue)
{
if (aqh && aqh->localVars && path && *path) {
return AQH_Vars_GetCharValue(aqh->localVars, path, idx, defaultValue);
}
return defaultValue;
}
int AqHomeReact_SetDoubleValue(AQHOME_REACT *aqh, const char *path, double value)
{
if (aqh && aqh->localVars && path && *path) {
int rv;
uint64_t timestamp;
timestamp=(uint64_t) time(NULL);
rv=AQH_Vars_SetDoubleValue(aqh->localVars, AQH_VARS_PATHFLAGS_OVERWRITE_VARS, path, value);
if (rv<0) {
DBG_INFO(NULL, "here (%d)", rv);
return rv;
}
AqHomeReact_UnitVarChanges_DoubleVarUpdated(aqh->localVarChangeUnit, path, timestamp, value);
return 0;
}
return GWEN_ERROR_INVALID;
}
double AqHomeReact_GetDoubleValue(AQHOME_REACT *aqh, const char *path, int idx, double defaultValue)
{
if (aqh && aqh->localVars && path && *path) {
return AQH_Vars_GetDoubleValue(aqh->localVars, path, idx, defaultValue);
}
return defaultValue;
}
AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitType)
{
/* this does not include u_timer and u_varchanges, because those are only created once globally in init.c */
@@ -161,6 +230,8 @@ AQHREACT_UNIT *AqHomeReact_CreateUnitByName(AQHOME_REACT *aqh, const char *unitT
return AqHomeReact_UnitValueFilter_new(aqh);
else if (strcasecmp(unitType, "valueSet")==0)
return AqHomeReact_UnitValueSet_new(aqh);
else if (strcasecmp(unitType, "varSet")==0)
return AqHomeReact_UnitVarSet_new(aqh);
else if (strcasecmp(unitType, "stabilize")==0)
return AqHomeReact_UnitStabilize_new(aqh);
else if (strcasecmp(unitType, "lowPass")==0)