diff --git a/libnymea-core/integrations/thingmanagerimplementation.cpp b/libnymea-core/integrations/thingmanagerimplementation.cpp index 0c858a83..43655e68 100644 --- a/libnymea-core/integrations/thingmanagerimplementation.cpp +++ b/libnymea-core/integrations/thingmanagerimplementation.cpp @@ -647,6 +647,7 @@ ThingPairingInfo *ThingManagerImplementation::confirmPairing(const PairingTransa qCDebug(dcThingManager()) << "Thing added:" << info->thing(); m_configuredThings.insert(info->thing()->id(), info->thing()); emit thingAdded(info->thing()); + connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered); } else { emit thingChanged(info->thing()); } @@ -728,9 +729,10 @@ ThingSetupInfo* ThingManagerImplementation::addConfiguredThingInternal(const Thi qCDebug(dcThingManager) << "Thing setup complete."; m_configuredThings.insert(info->thing()->id(), info->thing()); storeConfiguredThings(); - postSetupThing(info->thing()); emit thingAdded(info->thing()); + connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered); + postSetupThing(info->thing()); }); return info; @@ -1560,6 +1562,8 @@ void ThingManagerImplementation::loadConfiguredThings() m_configuredThings.insert(thing->id(), thing); emit thingAdded(thing); + + connect(thing, &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered); } settings.endGroup(); @@ -1710,7 +1714,7 @@ void ThingManagerImplementation::onAutoThingsAppeared(const ThingDescriptors &th storeConfiguredThings(); emit thingAdded(info->thing()); - + connect(info->thing(), &Thing::eventTriggered, this, &ThingManagerImplementation::onEventTriggered); postSetupThing(info->thing()); }); } diff --git a/libnymea/integrations/thing.cpp b/libnymea/integrations/thing.cpp index 0ec62516..296f1916 100644 --- a/libnymea/integrations/thing.cpp +++ b/libnymea/integrations/thing.cpp @@ -385,6 +385,12 @@ QString Thing::setupDisplayMessage() const return m_setupDisplayMessage; } +/*! Emits an event from this thing to the system. */ +void Thing::emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms) +{ + emit eventTriggered(Event(eventTypeId, m_id, params)); +} + /*! Returns true if this thing has been auto-created (not created by the user) */ bool Thing::autoCreated() const { diff --git a/libnymea/integrations/thing.h b/libnymea/integrations/thing.h index 18393e6b..e8f03ab3 100644 --- a/libnymea/integrations/thing.h +++ b/libnymea/integrations/thing.h @@ -37,6 +37,7 @@ #include "types/thingclass.h" #include "types/state.h" #include "types/param.h" +#include "types/event.h" #include "types/browseritem.h" #include @@ -127,10 +128,10 @@ public: bool hasState(const StateTypeId &stateTypeId) const; void setStates(const States &states); - QVariant stateValue(const StateTypeId &stateTypeId) const; - void setStateValue(const StateTypeId &stateTypeId, const QVariant &value); + Q_INVOKABLE QVariant stateValue(const StateTypeId &stateTypeId) const; + Q_INVOKABLE void setStateValue(const StateTypeId &stateTypeId, const QVariant &value); - State state(const StateTypeId &stateTypeId) const; + Q_INVOKABLE State state(const StateTypeId &stateTypeId) const; ThingId parentId() const; void setParentId(const ThingId &parentId); @@ -143,11 +144,15 @@ public: ThingError setupError() const; QString setupDisplayMessage() const; +public slots: + void emitEvent(const EventTypeId &eventTypeId, const ParamList ¶ms = ParamList()); + signals: void stateValueChanged(const StateTypeId &stateTypeId, const QVariant &value); void settingChanged(const ParamTypeId ¶mTypeId, const QVariant &value); void nameChanged(); void setupStatusChanged(); + void eventTriggered(const Event &event); private: friend class ThingManager; diff --git a/plugins/mock/integrationpluginmock.cpp b/plugins/mock/integrationpluginmock.cpp index 731b4135..ef584c44 100644 --- a/plugins/mock/integrationpluginmock.cpp +++ b/plugins/mock/integrationpluginmock.cpp @@ -853,10 +853,8 @@ void IntegrationPluginMock::triggerEvent(const EventTypeId &id) Thing *device = m_daemons.key(daemon); - Event event(id, device->id()); - - qCDebug(dcMock) << "Emitting event " << event.eventTypeId(); - emit emitEvent(event); + qCDebug(dcMock) << "Emitting event " << id; + device->emitEvent(id); } void IntegrationPluginMock::onDisappear()