mirror of https://github.com/nymea/nymea.git
Allow emitting events from things directly
parent
978cfebe0d
commit
f029184651
|
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 <QObject>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue