Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable alarm systems in rules; return alarm systems in full config request #5255

Merged
merged 4 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6009,7 +6009,7 @@ bool DB_LoadSecret(DB_Secret &secret)
return false;
}

return true;
return !secret.secret.empty();
}

static bool initSecretsTable()
Expand Down
4 changes: 4 additions & 0 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17445,6 +17445,10 @@ Resource *DeRestPluginPrivate::getResource(const char *resource, const QString &
{
return &config;
}
else if (resource == RAlarmSystems)
{
return AS_GetAlarmSystem(id.toUInt(), *alarmSystems);
}

return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions ias_ace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ QLatin1String IAS_PanelStatusToString(quint8 panelStatus)
return QLatin1String("");
}

int IAS_PanelStatusFromString(const QString &panelStatus)
{
const auto i = std::find(IAS_PanelStates.cbegin(), IAS_PanelStates.cend(), panelStatus);

if (i != IAS_PanelStates.cend())
{
return std::distance(IAS_PanelStates.cbegin(), i);
}

return -1;
}

static quint8 handleArmCommand(AlarmSystem *alarmSys, quint8 armMode, const QString &pinCode, quint64 srcAddress)
{
if (!alarmSys || armMode > IAS_ACE_ARM_MODE_ARM_ALL_ZONES)
Expand Down
1 change: 1 addition & 0 deletions ias_ace.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class AlarmSystems;
class ApsControllerWrapper;

QLatin1String IAS_PanelStatusToString(quint8 panelStatus);
int IAS_PanelStatusFromString(const QString &panelStatus);
void IAS_IasAceClusterIndication(const deCONZ::ApsDataIndication &ind, deCONZ::ZclFrame &zclFrame, AlarmSystems *alarmSystems, ApsControllerWrapper &apsCtrlWrapper);

#endif // IAS_ACE_H
18 changes: 13 additions & 5 deletions rest_alarmsystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ int AS_handleAlarmSystemsApi(const ApiRequest &req, ApiResponse &rsp, AlarmSyste
return REQ_NOT_HANDLED;
}

QVariantMap AS_AlarmSystemsToMap(const AlarmSystems &alarmSystems)
{
QVariantMap result;

for (const AlarmSystem *alarmSys : alarmSystems.alarmSystems)
{
result[QString::number(alarmSys->id())] = alarmSystemToMap(alarmSys);
}

return result;
}

static int getAllAlarmSystems(const ApiRequest &, ApiResponse &rsp, const AlarmSystems &alarmSystems)
{
rsp.httpStatus = HttpStatusOk;
Expand All @@ -249,11 +261,7 @@ static int getAllAlarmSystems(const ApiRequest &, ApiResponse &rsp, const AlarmS
return REQ_READY_SEND;
}

for (const AlarmSystem *alarmSys : alarmSystems.alarmSystems)
{
QVariantMap map = alarmSystemToMap(alarmSys);
rsp.map[QString::number(alarmSys->id())] = map;
}
rsp.map = AS_AlarmSystemsToMap(alarmSystems);

return REQ_READY_SEND;
}
Expand Down
3 changes: 3 additions & 0 deletions rest_alarmsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#ifndef REST_ALARMSYSTEMS_H
#define REST_ALARMSYSTEMS_H

#include <QVariant>

class ApiRequest;
class ApiResponse;
class EventEmitter;
Expand All @@ -23,5 +25,6 @@ class AlarmSystems;
REQ_NOT_HANDLED
*/
int AS_handleAlarmSystemsApi(const ApiRequest &req, ApiResponse &rsp, AlarmSystems &alarmSystems, EventEmitter *eventEmitter);
QVariantMap AS_AlarmSystemsToMap(const AlarmSystems &alarmSystems);

#endif // REST_ALARMSYSTEMS_H
6 changes: 3 additions & 3 deletions rest_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QVariantMap>
#include <QNetworkInterface>
#include <QProcessEnvironment>
#include "rest_alarmsystems.h"
#include "daylight.h"
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
Expand Down Expand Up @@ -1252,9 +1253,8 @@ int DeRestPluginPrivate::getFullState(const ApiRequest &req, ApiResponse &rsp)
}
}

// scenes
{
}
// alarm systems
rsp.map[QLatin1String("alarmsystems")] = AS_AlarmSystemsToMap(*alarmSystems);

configToMap(req, configMap);

Expand Down