fix daily calendaritem evaluation

This commit is contained in:
Simon Stürz 2017-10-03 09:07:27 +02:00 committed by Michael Zanetti
parent 625109f550
commit 78f17180a5
8 changed files with 36 additions and 20 deletions

View File

@ -319,7 +319,7 @@ void GuhCore::executeRuleActions(const QList<RuleAction> ruleActions)
{
foreach (const RuleAction &ruleAction, ruleActions) {
Action action = ruleAction.toAction();
qCDebug(dcRuleEngine) << "executing action" << ruleAction.actionTypeId() << action.params();
qCDebug(dcRuleEngine) << "Executing action" << ruleAction.actionTypeId() << action.params();
DeviceManager::DeviceError status = executeAction(action);
switch(status) {
case DeviceManager::DeviceErrorNoError:
@ -464,6 +464,9 @@ void GuhCore::init() {
m_logger->logSystemEvent(m_timeManager->currentDateTime(), true);
emit initialized();
// Evaluate rules on current time
onDateTimeChanged(m_timeManager->currentDateTime());
}
/*! Connected to the DeviceManager's emitEvent signal. Events received in
@ -643,14 +646,18 @@ void GuhCore::deviceManagerLoaded()
m_logger->removeDeviceLogs(deviceId);
}
}
foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
if (!m_deviceManager->findConfiguredDevice(deviceId)) {
qCDebug(dcApplication()) << "Cleaning stale rule entries for device id" << deviceId;
foreach (const RuleId &ruleId, m_ruleEngine->findRules(deviceId)) {
m_ruleEngine->removeDeviceFromRule(ruleId, deviceId);
}
}
}
// FIXME: this removes all timedescriptors
// foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
// if (!m_deviceManager->findConfiguredDevice(deviceId)) {
// qCDebug(dcApplication()) << "Cleaning stale rule entries for device id" << deviceId;
// foreach (const RuleId &ruleId, m_ruleEngine->findRules(deviceId)) {
// m_ruleEngine->removeDeviceFromRule(ruleId, deviceId);
// }
// }
// }
qCDebug(dcApplication()) << "Housekeeping done in" << startTime.msecsTo(QDateTime::currentDateTime()) << "ms.";
}

View File

@ -377,6 +377,8 @@ void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &data)
handler->setProperty("clientId", clientId);
handler->setProperty("token", message.value("token").toByteArray());
qCDebug(dcJsonRpc()) << "Got method" << method.toLatin1().data();
JsonReply *reply;
QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params));
if (reply->type() == JsonReply::TypeAsync) {

View File

@ -133,7 +133,7 @@ RuleEngine::RuleEngine(QObject *parent) :
bool enabled = settings.value("enabled", true).toBool();
bool executable = settings.value("executable", true).toBool();
qCDebug(dcRuleEngine) << "Load rule" << name << idString;
qCDebug(dcRuleEngine) << "Loading rule" << name << idString;
// Load timeDescriptor
TimeDescriptor timeDescriptor;

View File

@ -57,7 +57,7 @@ TcpServer::TcpServer(const ServerConfiguration &configuration, const QSslConfigu
/*! Destructor of this \l{TcpServer}. */
TcpServer::~TcpServer()
{
qCDebug(dcApplication) << "Shutting down \"TCP Server\"";
qCDebug(dcApplication) << "Shutting down \"TCP Server\"" << QString("%1://%2:%3").arg((configuration().authenticationEnabled ? "guhs" : "guh")).arg(configuration().address.toString()).arg(configuration().port);
stopServer();
}

View File

@ -154,17 +154,26 @@ bool CalendarItem::evaluateDaily(const QDateTime &dateTime) const
if (duration() >= 1440)
return true;
// get todays startTime
QDateTime startDateTime = QDateTime(dateTime.date(), startTime());
// Get todays startTime
QDateTime startDateTime = dateTime;
startDateTime.setTime(startTime());
QDateTime endDateTime = startDateTime.addSecs(duration() * 60);
// get todays startTime
QDateTime startDateTimeYesterday = QDateTime(dateTime.date().addDays(-1), startTime());
// Get yesterdays startTime for day overlapping clendaritems
QDateTime startDateTimeYesterday = dateTime.addDays(-1);
startDateTimeYesterday.setTime(startTime());
QDateTime endDateTimeYesterday = startDateTimeYesterday.addSecs(duration() * 60);
bool todayValid = dateTime >= startDateTime && dateTime < endDateTime;
bool yesterdayValid = dateTime >= startDateTimeYesterday && dateTime < endDateTimeYesterday;
qCDebug(dcRuleEngine()) << "-------------------------------------------------------------------------------";
qCDebug(dcRuleEngine()) << "Evaluate daily: current time" << dateTime.toString("dd:MM:yyyy hh:mm") << dateTime.toTime_t();
qCDebug(dcRuleEngine()) << "Evaluate daily: start time" << startDateTime.toString("dd:MM:yyyy hh:mm") << startDateTime.toTime_t();
qCDebug(dcRuleEngine()) << "Evaluate daily: end time" << endDateTime.toString("dd:MM:yyyy hh:mm") << endDateTime.toTime_t();
qCDebug(dcRuleEngine()) << "Today valid" << todayValid;
qCDebug(dcRuleEngine()) << "Yesterday valid" << yesterdayValid;
return todayValid || yesterdayValid;
}

View File

@ -115,7 +115,8 @@ WebServer::WebServer(const WebServerConfiguration &configuration, const QSslConf
/*! Destructor of this \l{WebServer}. */
WebServer::~WebServer()
{
qCDebug(dcApplication) << "Shutting down \"Webserver\"";
qCDebug(dcApplication) << "Shutting down \"Webserver\"" << QString("%1://%2:%3").arg((m_configuration.authenticationEnabled ? "https" : "http")).arg(m_configuration.address.toString()).arg(m_configuration.port);
this->close();
}

View File

@ -73,7 +73,7 @@ WebSocketServer::WebSocketServer(const ServerConfiguration &configuration, const
/*! Destructor of this \l{WebSocketServer}. */
WebSocketServer::~WebSocketServer()
{
qCDebug(dcApplication) << "Shutting down \"Websocket server\"";
qCDebug(dcApplication) << "Shutting down \"Websocket server\"" << QString("%1://%2:%3").arg((configuration().authenticationEnabled ? "wss" : "ws")).arg(configuration().address.toString()).arg(configuration().port);
stopServer();
}

View File

@ -213,9 +213,6 @@ void TestTimeManager::loadSaveTimeDescriptor()
QVariantMap timeDescriptorMapLoaded = response.toMap().value("params").toMap().value("rule").toMap().value("timeDescriptor").toMap();
qDebug() << timeDescriptorMapLoaded;
qDebug() << timeDescriptorMap;
QCOMPARE(timeDescriptorMap, timeDescriptorMapLoaded);
// REMOVE rule