DEV: Always process state.enter event  in new event queue run
@@ -839,10 +839,6 @@ Device::Device(DeviceKey key, deCONZ::ApsController *apsCtrl, QObject *parent) :
addItem(DataTypeString, RAttrModelId);
d->setState(DEV_InitStateHandler);
-
- static int initTimer = 1000;
- d->startStateTimer(initTimer, StateLevel0);
- initTimer += 300; // hack for the first round init, so that each device will start 300ms later
}
Device::~Device()
@@ -885,14 +881,20 @@ bool Device::managed() const
}
void Device::handleEvent(const Event &event, DEV_StateLevel level)
+{
+ if (event.what() == REventStateEnter || event.what() == REventStateLeave)
+ {
+ Q_ASSERT(event.num() >= StateLevel0);
+ Q_ASSERT(event.num() < StateLevelMax);
+ d->state[event.num()](this, event);
+ }
+ else if (d->state[level])
{
if (event.what() == REventAwake && level == StateLevel0)
{
d->awake.start();
}
- if (d->state[level])
- {
d->state[level](this, event);
}
}
@@ -910,17 +912,8 @@ void DevicePrivate::setState(DeviceStateHandler newState, DEV_StateLevel level)
if (state[level])
{
- if (level == StateLevel0)
- {
- // invoke the handler in the next event loop iteration
emit q->eventNotify(Event(q->prefix(), REventStateEnter, level, q->key()));
}
- else
- {
- // invoke sub-states directly
- state[level](q, Event(q->prefix(), REventStateEnter, level, q->key()));
- }
- }
}
}
