/**************************************************************************** * This file is part of the project AqHome. * AqHome (c) by 2025 Martin Preuss, all rights reserved. * * The license for this file can be found in the file COPYING which you * should have received along with this file. ****************************************************************************/ #ifdef HAVE_CONFIG_H # include #endif #include "./mdevices_valuesgraph.h" #include "./mdevices_index.h" #include "aqhome-cgi/service/module.h" #include "aqhome-cgi/modules/mdataclient.h" #include #include #include /* ------------------------------------------------------------------------------------------------ * defs and enums * ------------------------------------------------------------------------------------------------ */ #define GBAS GWEN_Buffer_AppendString #define GBAA GWEN_Buffer_AppendArgs /* ------------------------------------------------------------------------------------------------ * forward declarations * ------------------------------------------------------------------------------------------------ */ static void _writeValueListToTable(const char *sDeviceName, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *dbuf); static void _writeValueToTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf); static void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf); /* ------------------------------------------------------------------------------------------------ * code * ------------------------------------------------------------------------------------------------ */ void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf) { GWEN_DB_NODE *dbQuery; const char *sDeviceName; dbQuery=AQCGI_Request_GetDbQuery(rq); sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL); if (!(sDeviceName && *sDeviceName)) AQH_ModDevices_RunIndex(m, rq, session, dc, dbuf); else { AQH_VALUE_LIST *valueList; valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0); if (valueList && AQH_Value_List_GetCount(valueList)) { GBAA(dbuf,"

Values for Device %s

\n", sDeviceName); _writeValueListToTable(sDeviceName, valueList, dbuf); GBAS(dbuf, "\n"); } else { GBAS(dbuf,"

No values.

\n"); } AQH_Value_List_free(valueList); } } void _writeValueListToTable(const char *sDeviceName, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *dbuf) { const AQH_VALUE *value; GBAS(dbuf, "\n"); value=AQH_Value_List_First(valueList); while(value) { if (AQH_Value_GetValueType(value)==AQH_ValueType_Sensor) _writeValueToTable(sDeviceName, value, dbuf); value=AQH_Value_List_Next(value); } GBAS(dbuf, "
\n"); } void _writeValueToTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf) { const char *sValueName; /* name */ sValueName=AQH_Value_GetName(value); GBAS(dbuf, ""); _addGraphLink(sDeviceName, sValueName, "1d", dbuf); GBAS(dbuf, ""); _addGraphLink(sDeviceName, sValueName, "1w", dbuf); GBAS(dbuf, "\n"); } void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf) { GBAS(dbuf, "\"%s\""); }