diff --git a/debian/control b/debian/control index 55ef73ce..7ac17bda 100644 --- a/debian/control +++ b/debian/control @@ -61,6 +61,7 @@ Depends: libqt5network5, tar, iputils-tracepath, iputils-ping, + qml-module-qtquick2, dnsutils, nymea-translations, libnymea1 (= ${binary:Version}), diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index 75bd7299..b8e0e380 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -607,6 +607,12 @@ RuleEngine *NymeaCore::ruleEngine() const return m_ruleEngine; } +/*! Returns a pointer to the \l{ScriptEngine} instance owned by NymeaCore.*/ +ScriptEngine *NymeaCore::scriptEngine() const +{ + return m_scriptEngine; +} + /*! Returns a pointer to the \l{TimeManager} instance owned by NymeaCore.*/ TimeManager *NymeaCore::timeManager() const { diff --git a/libnymea-core/nymeacore.h b/libnymea-core/nymeacore.h index 3c8d57a9..938102ad 100644 --- a/libnymea-core/nymeacore.h +++ b/libnymea-core/nymeacore.h @@ -86,6 +86,7 @@ public: JsonRPCServerImplementation *jsonRPCServer() const; DeviceManager *deviceManager() const; RuleEngine *ruleEngine() const; + ScriptEngine *scriptEngine() const; TimeManager *timeManager() const; ServerManager *serverManager() const; BluetoothServer *bluetoothServer() const; diff --git a/libnymea-core/scriptengine/scriptalarm.cpp b/libnymea-core/scriptengine/scriptalarm.cpp index e2facfae..d6525666 100644 --- a/libnymea-core/scriptengine/scriptalarm.cpp +++ b/libnymea-core/scriptengine/scriptalarm.cpp @@ -91,8 +91,10 @@ bool ScriptAlarm::active() const void ScriptAlarm::timerEvent(QTimerEvent *event) { Q_UNUSED(event) + QTime now = QTime::currentTime(); + updateActive(); if (!m_weekDays.testFlag(today())) { diff --git a/libnymea-core/scriptengine/scriptengine.cpp b/libnymea-core/scriptengine/scriptengine.cpp index d75a9239..ddc385dd 100644 --- a/libnymea-core/scriptengine/scriptengine.cpp +++ b/libnymea-core/scriptengine/scriptengine.cpp @@ -371,8 +371,6 @@ bool ScriptEngine::loadScript(Script *script) QString name = jsonDoc.toVariant().toMap().value("name").toString(); - qCWarning(dcScriptEngine()) << "Loading script"; - script->errors.clear(); script->component = new QQmlComponent(m_engine, QUrl::fromLocalFile(fileName), this); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index fbf1e9d6..65057ddb 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -20,4 +20,5 @@ SUBDIRS = versioning \ usermanager \ mqttbroker \ tags \ + scripts \ diff --git a/tests/auto/scripts/testhelper.cpp b/tests/auto/scripts/testhelper.cpp new file mode 100644 index 00000000..5c73bf14 --- /dev/null +++ b/tests/auto/scripts/testhelper.cpp @@ -0,0 +1,26 @@ +#include "testhelper.h" + +TestHelper* TestHelper::s_instance = nullptr; + +TestHelper *TestHelper::instance() +{ + if (!s_instance) { + s_instance = new TestHelper(); + } + return s_instance; +} + +void TestHelper::logEvent(const QString &deviceId, const QString &eventId, const QVariantMap ¶ms) +{ + emit eventLogged(DeviceId(deviceId), eventId, params); +} + +void TestHelper::logStateChange(const QString &deviceId, const QString &stateId, const QVariant &value) +{ + emit stateChangeLogged(DeviceId(deviceId), stateId, value); +} + +TestHelper::TestHelper(QObject *parent) : QObject(parent) +{ + +} diff --git a/tests/auto/scripts/testhelper.h b/tests/auto/scripts/testhelper.h new file mode 100644 index 00000000..3c26816a --- /dev/null +++ b/tests/auto/scripts/testhelper.h @@ -0,0 +1,28 @@ +#ifndef TESTHELPER_H +#define TESTHELPER_H + +#include + +#include "typeutils.h" + +class TestHelper : public QObject +{ + Q_OBJECT +public: + static TestHelper* instance(); + + Q_INVOKABLE void logEvent(const QString &deviceId, const QString &eventId, const QVariantMap ¶ms); + Q_INVOKABLE void logStateChange(const QString &deviceId, const QString &stateId, const QVariant &value); + +signals: + void setState(const QVariant &value); + void executeAction(const QVariantMap ¶ms); + + void eventLogged(const DeviceId &deviceId, const QString &eventId, const QVariantMap ¶ms); + void stateChangeLogged(const DeviceId &deviceId, const QString stateId, const QVariant &value); +private: + explicit TestHelper(QObject *parent = nullptr); + static TestHelper* s_instance; +}; + +#endif // TESTHELPER_H