aqhome-cgi: use service code from AqCGI.

This commit is contained in:
Martin Preuss
2026-06-01 15:55:42 +02:00
parent 62741e1c16
commit c262c4a56a
52 changed files with 862 additions and 2119 deletions

View File

@@ -41,6 +41,7 @@ static void _writeValueToDetailedTable(const char *sDeviceName, const AQH_VALUE
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, int withLink);
static void _writeDeviceInfo(const AQH_DEVICE *device, GWEN_BUFFER *dbuf);
@@ -49,7 +50,7 @@ static void _addGraphLink(const char *sDeviceName, const char *sValueName, const
* ------------------------------------------------------------------------------------------------
*/
void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
void AQH_ModDevices_RunValuesAsGraph(AQCGI_MODULE *m, AQCGI_REQUEST *rq, AQCGI_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf)
{
GWEN_DB_NODE *dbQuery;
const char *sDeviceName;
@@ -59,40 +60,70 @@ void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSI
if (!(sDeviceName && *sDeviceName))
AQH_ModDevices_RunIndex(m, rq, session, dc, dbuf);
else {
const char *sValueName;
AQH_DEVICE *device;
sValueName=GWEN_DB_GetCharValue(dbQuery, "value", 0, NULL);
if (sValueName && *sValueName) {
AQH_VALUE *value;
device=AQH_DataClient_GetDeviceByName(dc, sDeviceName);
if (device) {
const char *sValueName;
GBAA(dbuf,"<h1>Value %s/%s</h1>\n", sDeviceName, sValueName);
value=AQH_ModDevices_GetValueForDevice(dc, sDeviceName, sValueName);
if (value) {
_writeValueToDetailedTable(sDeviceName, value, dbuf);
AQH_Value_free(value);
AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 120");
}
}
else {
AQH_VALUE_LIST *valueList;
sValueName=GWEN_DB_GetCharValue(dbQuery, "value", 0, NULL);
if (sValueName && *sValueName) {
AQH_VALUE *value;
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
if (valueList && AQH_Value_List_GetCount(valueList)) {
GBAA(dbuf,"<h1>Values for Device %s</h1>\n", sDeviceName);
_writeValueListToTable(sDeviceName, valueList, dbuf);
GBAS(dbuf, "\n");
GBAA(dbuf,"<h1>Value %s/%s</h1>\n", sDeviceName, sValueName);
_writeDeviceInfo(device, dbuf);
value=AQH_ModDevices_GetValueForDevice(dc, sDeviceName, sValueName);
if (value) {
_writeValueToDetailedTable(sDeviceName, value, dbuf);
AQH_Value_free(value);
AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 120");
}
}
else {
GBAS(dbuf,"<p>No values.</p>\n");
AQH_VALUE_LIST *valueList;
valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0);
if (valueList && AQH_Value_List_GetCount(valueList)) {
GBAA(dbuf,"<h1>Values for Device %s</h1>\n", sDeviceName);
_writeDeviceInfo(device, dbuf);
_writeValueListToTable(sDeviceName, valueList, dbuf);
GBAS(dbuf, "\n");
}
else {
GBAS(dbuf,"<p>No values.</p>\n");
}
AQH_Value_List_free(valueList);
AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 305");
}
AQH_Value_List_free(valueList);
AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 305");
AQH_Device_free(device);
}
}
}
void _writeDeviceInfo(const AQH_DEVICE *device, GWEN_BUFFER *dbuf)
{
const char *s;
int cnt=0;
GBAS(dbuf, "<p>");
s=AQH_Device_GetNameForGui(device);
if (s)
GBAA(dbuf, "%s%s", (cnt++)?", ":"", s?s:"");
s=AQH_Device_GetRoomName(device);
if (s)
GBAA(dbuf, "%s%s", (cnt++)?", ":"", s?s:"");
s=AQH_Device_GetLocation(device);
if (s)
GBAA(dbuf, "%s%s", (cnt++)?", ":"", s?s:"");
s=AQH_Device_GetDescription(device);
if (s)
GBAA(dbuf, "%s%s", (cnt++)?", ":"", s?s:"");
GBAS(dbuf, "</p>");
}
void _writeValueToDetailedTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf)
{