Skip to content

Commit

Permalink
Prevent too fast doubled button events when the same event occurs wit…
Browse files Browse the repository at this point in the history
…hin 500ms
  • Loading branch information
manup committed Jul 23, 2018
1 parent 0ed3d17 commit 0f89afe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions de_web_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,18 @@ void DeRestPluginPrivate::checkSensorButtonEvent(Sensor *sensor, const deCONZ::A
ResourceItem *item = sensor->item(RStateButtonEvent);
if (item)
{
if (item->toNumber() == buttonMap->button)
{
QDateTime now = QDateTime::currentDateTime();
const auto dt = item->lastSet().msecsTo(now);

if (dt > 0 && dt < 500)
{
DBG_Printf(DBG_INFO, "button %u %s, discard too fast event (dt = %d)\n", buttonMap->button, buttonMap->name, dt);
break;
}
}

item->setValue(buttonMap->button);

Event e(RSensors, RStateButtonEvent, sensor->id(), item);
Expand Down

0 comments on commit 0f89afe

Please sign in to comment.