More work on aqhome-react.

- added some units
- added some types
This commit is contained in:
Martin Preuss
2024-03-10 20:15:21 +01:00
parent 656c9cf66f
commit d3a6256c8c
35 changed files with 1159 additions and 80 deletions

View File

@@ -11,6 +11,10 @@
#endif
#include "./aqhome_react_p.h"
#include "aqhome-react/units/u_or.h"
#include "aqhome-react/units/u_valuefilter.h"
#include "aqhome-react/units/u_hold.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
@@ -22,6 +26,8 @@ AQHOME_REACT *AqHomeReact_new()
AQHOME_REACT *aqh;
GWEN_NEW_OBJECT(AQHOME_REACT, aqh);
aqh->unitNetList=AQHREACT_UnitNet_List_new();
aqh->unitList=AQHREACT_Unit_List_new();
return aqh;
}
@@ -31,6 +37,8 @@ AQHOME_REACT *AqHomeReact_new()
void AqHomeReact_free(AQHOME_REACT *aqh)
{
if (aqh) {
AQHREACT_UnitNet_List_free(aqh->unitNetList);
AQHREACT_Unit_List_free(aqh->unitList);
GWEN_MsgEndpoint_free(aqh->brokerEndpoint);
GWEN_DB_Group_free(aqh->dbArgs);
free(aqh->pidFile);
@@ -80,6 +88,103 @@ int AqHomeReact_GetTimeout(const AQHOME_REACT *aqh)
AQHREACT_UNIT *AqHomeReact_GetTimerUnit(const AQHOME_REACT *aqh)
{
return aqh?aqh->timerUnit:NULL;
}
AQHREACT_UNIT *AqHomeReact_GetVarChangeUnit(const AQHOME_REACT *aqh)
{
return aqh?aqh->varChangeUnit:NULL;
}
AQHREACT_UNIT_NET_LIST *AqHomeReact_GetUnitNetList(const AQHOME_REACT *aqh)
{
return aqh?aqh->unitNetList:NULL;
}
void AqHomeReact_AddUnitNet(AQHOME_REACT *aqh, AQHREACT_UNIT_NET *unitNet)
{
if (aqh)
AQHREACT_UnitNet_List_Add(unitNet, aqh->unitNetList);
}
AQHREACT_UNIT_NET *AqHomeReact_GetUnitNetByName(const AQHOME_REACT *aqh, const char *s)
{
return (aqh && s && *s)?AQHREACT_UnitNet_List_GetByName(aqh->unitNetList, s):NULL;
}
AQHREACT_UNIT *AqHomeReact_FindUnitByNetNameAndUnitId(const AQHOME_REACT *aqh, const char *netName, const char *unitId)
{
if (aqh && unitId && *unitId) {
AQHREACT_UNIT_LIST *unitList=NULL;
if (netName && *netName) {
AQHREACT_UNIT_NET *unitNet;
unitNet=AQHREACT_UnitNet_List_GetByName(aqh->unitNetList, netName);
if (unitNet)
unitList=AQHREACT_UnitNet_GetUnitList(unitNet);
else {
DBG_ERROR(NULL, "Unit net \"%s\" not found", netName);
return NULL;
}
}
else
unitList=aqh->unitList;
if (unitList) {
AQHREACT_UNIT *unit;
unit=AQHREACT_Unit_List_GetById(unitList, unitId);
if (unit==NULL) {
DBG_ERROR(NULL, "Unit \"%s/%s\" not found", netName, unitId);
return NULL;
}
return unit;
}
}
return NULL;
}
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 */
if (aqh && unitType && *unitType) {
if (strcasecmp(unitType, "or")==0)
return AqHomeReact_UnitOr_new();
else if (strcasecmp(unitType, "valueFilter")==0)
return AqHomeReact_UnitValueFilter_new();
else if (strcasecmp(unitType, "hold")==0)
return AqHomeReact_UnitHold_new();
else {
DBG_ERROR(NULL, "Unknown unit type \"%s\"", unitType);
return NULL;
}
}
return NULL;
}