Update script api
This commit is contained in:
parent
0b5284d5f5
commit
a894d27a18
@ -47,7 +47,7 @@ ScriptAction::ScriptAction(QObject *parent) : QObject(parent)
|
||||
|
||||
void ScriptAction::classBegin()
|
||||
{
|
||||
m_deviceManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("deviceManager").toULongLong());
|
||||
m_thingManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("thingManager").toULongLong());
|
||||
}
|
||||
|
||||
void ScriptAction::componentComplete()
|
||||
@ -55,16 +55,16 @@ void ScriptAction::componentComplete()
|
||||
|
||||
}
|
||||
|
||||
QString ScriptAction::deviceId() const
|
||||
QString ScriptAction::thingId() const
|
||||
{
|
||||
return m_thingId;
|
||||
}
|
||||
|
||||
void ScriptAction::setDeviceId(const QString &deviceId)
|
||||
void ScriptAction::setThingId(const QString &thingId)
|
||||
{
|
||||
if (m_thingId != deviceId) {
|
||||
m_thingId = deviceId;
|
||||
emit deviceIdChanged();
|
||||
if (m_thingId != thingId) {
|
||||
m_thingId = thingId;
|
||||
emit thingIdChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,9 +96,9 @@ void ScriptAction::setActionName(const QString &actionName)
|
||||
|
||||
void ScriptAction::execute(const QVariantMap ¶ms)
|
||||
{
|
||||
Thing *thing = m_deviceManager->configuredThings().findById(ThingId(m_thingId));
|
||||
Thing *thing = m_thingManager->configuredThings().findById(ThingId(m_thingId));
|
||||
if (!thing) {
|
||||
qCWarning(dcScriptEngine) << "No device with id" << m_thingId;
|
||||
qCWarning(dcScriptEngine) << "No thing with id" << m_thingId;
|
||||
return;
|
||||
}
|
||||
ActionType actionType;
|
||||
@ -129,7 +129,7 @@ void ScriptAction::execute(const QVariantMap ¶ms)
|
||||
paramList << Param(paramType.id(), params.value(paramNameOrId));
|
||||
}
|
||||
action.setParams(paramList);
|
||||
m_deviceManager->executeAction(action);
|
||||
m_thingManager->executeAction(action);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,7 +42,8 @@ class ScriptAction : public QObject, public QQmlParserStatus
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QQmlParserStatus)
|
||||
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||
Q_PROPERTY(QString thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||
Q_PROPERTY(QString deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged) // DEPRECATED
|
||||
Q_PROPERTY(QString actionTypeId READ actionTypeId WRITE setActionTypeId NOTIFY actionTypeIdChanged)
|
||||
Q_PROPERTY(QString actionName READ actionName WRITE setActionName NOTIFY actionNameChanged)
|
||||
public:
|
||||
@ -50,8 +51,8 @@ public:
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
|
||||
QString deviceId() const;
|
||||
void setDeviceId(const QString &deviceId);
|
||||
QString thingId() const;
|
||||
void setThingId(const QString &thingId);
|
||||
|
||||
QString actionTypeId() const;
|
||||
void setActionTypeId(const QString &actionTypeId);
|
||||
@ -63,12 +64,12 @@ public slots:
|
||||
void execute(const QVariantMap ¶ms);
|
||||
|
||||
signals:
|
||||
void deviceIdChanged();
|
||||
void thingIdChanged();
|
||||
void actionTypeIdChanged();
|
||||
void actionNameChanged();
|
||||
|
||||
public:
|
||||
ThingManager *m_deviceManager = nullptr;
|
||||
ThingManager *m_thingManager = nullptr;
|
||||
QString m_thingId;
|
||||
QString m_actionTypeId;
|
||||
QString m_actionName;
|
||||
|
||||
@ -44,7 +44,6 @@ QTime ScriptAlarm::time() const
|
||||
|
||||
void ScriptAlarm::setTime(const QTime &time)
|
||||
{
|
||||
qCDebug(dcScriptEngine()) << "Blablabla" << time;
|
||||
if (m_time != time) {
|
||||
m_time = time;
|
||||
emit timeChanged();
|
||||
|
||||
@ -60,10 +60,13 @@ ScriptEngine::ScriptEngine(ThingManager *deviceManager, QObject *parent) : QObje
|
||||
qmlRegisterType<ScriptEvent>("nymea", 1, 0, "DeviceEvent");
|
||||
qmlRegisterType<ScriptAction>("nymea", 1, 0, "DeviceAction");
|
||||
qmlRegisterType<ScriptState>("nymea", 1, 0, "DeviceState");
|
||||
qmlRegisterType<ScriptEvent>("nymea", 1, 0, "ThingEvent");
|
||||
qmlRegisterType<ScriptAction>("nymea", 1, 0, "ThingAction");
|
||||
qmlRegisterType<ScriptState>("nymea", 1, 0, "ThingState");
|
||||
qmlRegisterType<ScriptAlarm>("nymea", 1, 0, "Alarm");
|
||||
|
||||
m_engine = new QQmlEngine(this);
|
||||
m_engine->setProperty("deviceManager", reinterpret_cast<quint64>(m_deviceManager));
|
||||
m_engine->setProperty("thingManager", reinterpret_cast<quint64>(m_deviceManager));
|
||||
|
||||
// Don't automatically print script warnings (that is, runtime errors, *not* console.warn() messages)
|
||||
// to stdout as they'd end up on the "default" logging category.
|
||||
|
||||
@ -41,8 +41,8 @@ ScriptEvent::ScriptEvent(QObject *parent) : QObject(parent)
|
||||
|
||||
void ScriptEvent::classBegin()
|
||||
{
|
||||
m_deviceManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("deviceManager").toULongLong());
|
||||
connect(m_deviceManager, &ThingManager::eventTriggered, this, &ScriptEvent::onEventTriggered);
|
||||
m_thingManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("thingManager").toULongLong());
|
||||
connect(m_thingManager, &ThingManager::eventTriggered, this, &ScriptEvent::onEventTriggered);
|
||||
}
|
||||
|
||||
void ScriptEvent::componentComplete()
|
||||
@ -50,16 +50,16 @@ void ScriptEvent::componentComplete()
|
||||
|
||||
}
|
||||
|
||||
QString ScriptEvent::deviceId() const
|
||||
QString ScriptEvent::thingId() const
|
||||
{
|
||||
return m_thingId;
|
||||
}
|
||||
|
||||
void ScriptEvent::setDeviceId(const QString &deviceId)
|
||||
void ScriptEvent::setThingId(const QString &thingId)
|
||||
{
|
||||
if (m_thingId != deviceId) {
|
||||
m_thingId = deviceId;
|
||||
emit deviceIdChanged();
|
||||
if (m_thingId != thingId) {
|
||||
m_thingId = thingId;
|
||||
emit thingIdChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ void ScriptEvent::onEventTriggered(const Event &event)
|
||||
return;
|
||||
}
|
||||
|
||||
Thing *thing = m_deviceManager->findConfiguredThing(event.thingId());
|
||||
Thing *thing = m_thingManager->findConfiguredThing(event.thingId());
|
||||
if (!m_eventName.isEmpty() && thing->thingClass().eventTypes().findByName(m_eventName).id() != event.eventTypeId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -46,7 +46,8 @@ class ScriptEvent: public QObject, public QQmlParserStatus
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QQmlParserStatus)
|
||||
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||
Q_PROPERTY(QString thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||
Q_PROPERTY(QString deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged) // DEPRECATED
|
||||
Q_PROPERTY(QString eventTypeId READ eventTypeId WRITE setEventTypeId NOTIFY eventTypeIdChanged)
|
||||
Q_PROPERTY(QString eventName READ eventName WRITE setEventName NOTIFY eventNameChanged)
|
||||
public:
|
||||
@ -54,8 +55,8 @@ public:
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
|
||||
QString deviceId() const;
|
||||
void setDeviceId(const QString &deviceId);
|
||||
QString thingId() const;
|
||||
void setThingId(const QString &thingId);
|
||||
|
||||
QString eventTypeId() const;
|
||||
void setEventTypeId(const QString &eventTypeId);
|
||||
@ -67,7 +68,7 @@ private slots:
|
||||
void onEventTriggered(const Event &event);
|
||||
|
||||
signals:
|
||||
void deviceIdChanged();
|
||||
void thingIdChanged();
|
||||
void eventTypeIdChanged();
|
||||
void eventNameChanged();
|
||||
|
||||
@ -75,7 +76,7 @@ signals:
|
||||
void triggered(const QVariantMap ¶ms);
|
||||
|
||||
private:
|
||||
ThingManager *m_deviceManager = nullptr;
|
||||
ThingManager *m_thingManager = nullptr;
|
||||
|
||||
QString m_thingId;
|
||||
QString m_eventTypeId;
|
||||
|
||||
@ -45,8 +45,8 @@ ScriptState::ScriptState(QObject *parent) : QObject(parent)
|
||||
|
||||
void ScriptState::classBegin()
|
||||
{
|
||||
m_deviceManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("deviceManager").toULongLong());
|
||||
connect(m_deviceManager, &ThingManager::thingStateChanged, this, &ScriptState::onThingStateChanged);
|
||||
m_thingManager = reinterpret_cast<ThingManager*>(qmlEngine(this)->property("thingManager").toULongLong());
|
||||
connect(m_thingManager, &ThingManager::thingStateChanged, this, &ScriptState::onThingStateChanged);
|
||||
}
|
||||
|
||||
void ScriptState::componentComplete()
|
||||
@ -54,16 +54,16 @@ void ScriptState::componentComplete()
|
||||
|
||||
}
|
||||
|
||||
QString ScriptState::deviceId() const
|
||||
QString ScriptState::thingId() const
|
||||
{
|
||||
return m_thingId;
|
||||
}
|
||||
|
||||
void ScriptState::setDeviceId(const QString &deviceId)
|
||||
void ScriptState::setThingId(const QString &thingId)
|
||||
{
|
||||
if (m_thingId != deviceId) {
|
||||
m_thingId = deviceId;
|
||||
emit deviceIdChanged();
|
||||
if (m_thingId != thingId) {
|
||||
m_thingId = thingId;
|
||||
emit thingIdChanged();
|
||||
store();
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,7 @@ void ScriptState::setStateName(const QString &stateName)
|
||||
|
||||
QVariant ScriptState::value() const
|
||||
{
|
||||
Thing* thing = m_deviceManager->findConfiguredThing(ThingId(m_thingId));
|
||||
Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId));
|
||||
if (!thing) {
|
||||
return QVariant();
|
||||
}
|
||||
@ -112,15 +112,14 @@ QVariant ScriptState::value() const
|
||||
|
||||
void ScriptState::setValue(const QVariant &value)
|
||||
{
|
||||
qCDebug(dcScriptEngine()) << "setValueCalled1" << value;
|
||||
if (m_pendingActionInfo) {
|
||||
m_valueCache = value;
|
||||
return;
|
||||
}
|
||||
|
||||
Thing* thing = m_deviceManager->findConfiguredThing(ThingId(m_thingId));
|
||||
Thing* thing = m_thingManager->findConfiguredThing(ThingId(m_thingId));
|
||||
if (!thing) {
|
||||
qCWarning(dcScriptEngine()) << "No device with id" << m_thingId << "found.";
|
||||
qCWarning(dcScriptEngine()) << "No thing with id" << m_thingId << "found.";
|
||||
return;
|
||||
}
|
||||
|
||||
@ -128,13 +127,13 @@ void ScriptState::setValue(const QVariant &value)
|
||||
if (!m_stateTypeId.isNull()) {
|
||||
actionTypeId = thing->thingClass().stateTypes().findById(StateTypeId(m_stateTypeId)).id();
|
||||
if (actionTypeId.isNull()) {
|
||||
qCWarning(dcScriptEngine) << "Device" << thing->name() << "does not have a state with type id" << m_stateTypeId;
|
||||
qCWarning(dcScriptEngine) << "Thing" << thing->name() << "does not have a state with type id" << m_stateTypeId;
|
||||
}
|
||||
}
|
||||
if (actionTypeId.isNull()) {
|
||||
actionTypeId = thing->thingClass().stateTypes().findByName(stateName()).id();
|
||||
if (actionTypeId.isNull()) {
|
||||
qCWarning(dcScriptEngine) << "Device" << thing->name() << "does not have a state named" << m_stateName;
|
||||
qCWarning(dcScriptEngine) << "Thing" << thing->name() << "does not have a state named" << m_stateName;
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +149,7 @@ void ScriptState::setValue(const QVariant &value)
|
||||
action.setParams(params);
|
||||
|
||||
m_valueCache = QVariant();
|
||||
m_pendingActionInfo = m_deviceManager->executeAction(action);
|
||||
m_pendingActionInfo = m_thingManager->executeAction(action);
|
||||
connect(m_pendingActionInfo, &ThingActionInfo::finished, this, [this](){
|
||||
m_pendingActionInfo = nullptr;
|
||||
if (!m_valueCache.isNull()) {
|
||||
@ -161,7 +160,7 @@ void ScriptState::setValue(const QVariant &value)
|
||||
|
||||
QVariant ScriptState::minimumValue() const
|
||||
{
|
||||
Thing *thing = m_deviceManager->configuredThings().findById(ThingId(m_thingId));
|
||||
Thing *thing = m_thingManager->configuredThings().findById(ThingId(m_thingId));
|
||||
if (!thing) {
|
||||
return QVariant();
|
||||
}
|
||||
@ -174,7 +173,7 @@ QVariant ScriptState::minimumValue() const
|
||||
|
||||
QVariant ScriptState::maximumValue() const
|
||||
{
|
||||
Thing *thing = m_deviceManager->configuredThings().findById(ThingId(m_thingId));
|
||||
Thing *thing = m_thingManager->configuredThings().findById(ThingId(m_thingId));
|
||||
if (!thing) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@ -44,7 +44,8 @@ class ScriptState : public QObject, public QQmlParserStatus
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QQmlParserStatus)
|
||||
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||
Q_PROPERTY(QString thingId READ thingId WRITE setThingId NOTIFY thingIdChanged)
|
||||
Q_PROPERTY(QString deviceId READ thingId WRITE setThingId NOTIFY thingIdChanged) // DEPRECATED
|
||||
Q_PROPERTY(QString stateTypeId READ stateTypeId WRITE setStateTypeId NOTIFY stateTypeChanged)
|
||||
Q_PROPERTY(QString stateName READ stateName WRITE setStateName NOTIFY stateTypeChanged)
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
|
||||
@ -56,8 +57,8 @@ public:
|
||||
void classBegin() override;
|
||||
void componentComplete() override;
|
||||
|
||||
QString deviceId() const;
|
||||
void setDeviceId(const QString &deviceId);
|
||||
QString thingId() const;
|
||||
void setThingId(const QString &thingId);
|
||||
|
||||
QString stateTypeId() const;
|
||||
void setStateTypeId(const QString &stateTypeId);
|
||||
@ -76,7 +77,7 @@ public slots:
|
||||
void restore();
|
||||
|
||||
signals:
|
||||
void deviceIdChanged();
|
||||
void thingIdChanged();
|
||||
void stateTypeChanged();
|
||||
void valueChanged();
|
||||
|
||||
@ -84,7 +85,7 @@ private slots:
|
||||
void onThingStateChanged(Thing *thing, const StateTypeId &stateTypeId);
|
||||
|
||||
private:
|
||||
ThingManager *m_deviceManager = nullptr;
|
||||
ThingManager *m_thingManager = nullptr;
|
||||
|
||||
QString m_thingId;
|
||||
QString m_stateTypeId;
|
||||
|
||||
Reference in New Issue
Block a user