fix daily calendaritem evaluation
This commit is contained in:
parent
625109f550
commit
78f17180a5
@ -319,7 +319,7 @@ void GuhCore::executeRuleActions(const QList<RuleAction> ruleActions)
|
|||||||
{
|
{
|
||||||
foreach (const RuleAction &ruleAction, ruleActions) {
|
foreach (const RuleAction &ruleAction, ruleActions) {
|
||||||
Action action = ruleAction.toAction();
|
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);
|
DeviceManager::DeviceError status = executeAction(action);
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case DeviceManager::DeviceErrorNoError:
|
case DeviceManager::DeviceErrorNoError:
|
||||||
@ -464,6 +464,9 @@ void GuhCore::init() {
|
|||||||
|
|
||||||
m_logger->logSystemEvent(m_timeManager->currentDateTime(), true);
|
m_logger->logSystemEvent(m_timeManager->currentDateTime(), true);
|
||||||
emit initialized();
|
emit initialized();
|
||||||
|
|
||||||
|
// Evaluate rules on current time
|
||||||
|
onDateTimeChanged(m_timeManager->currentDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Connected to the DeviceManager's emitEvent signal. Events received in
|
/*! Connected to the DeviceManager's emitEvent signal. Events received in
|
||||||
@ -643,14 +646,18 @@ void GuhCore::deviceManagerLoaded()
|
|||||||
m_logger->removeDeviceLogs(deviceId);
|
m_logger->removeDeviceLogs(deviceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
|
|
||||||
if (!m_deviceManager->findConfiguredDevice(deviceId)) {
|
// FIXME: this removes all timedescriptors
|
||||||
qCDebug(dcApplication()) << "Cleaning stale rule entries for device id" << deviceId;
|
|
||||||
foreach (const RuleId &ruleId, m_ruleEngine->findRules(deviceId)) {
|
// foreach (const DeviceId &deviceId, m_ruleEngine->devicesInRules()) {
|
||||||
m_ruleEngine->removeDeviceFromRule(ruleId, deviceId);
|
// 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.";
|
qCDebug(dcApplication()) << "Housekeeping done in" << startTime.msecsTo(QDateTime::currentDateTime()) << "ms.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -377,6 +377,8 @@ void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &data)
|
|||||||
handler->setProperty("clientId", clientId);
|
handler->setProperty("clientId", clientId);
|
||||||
handler->setProperty("token", message.value("token").toByteArray());
|
handler->setProperty("token", message.value("token").toByteArray());
|
||||||
|
|
||||||
|
qCDebug(dcJsonRpc()) << "Got method" << method.toLatin1().data();
|
||||||
|
|
||||||
JsonReply *reply;
|
JsonReply *reply;
|
||||||
QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params));
|
QMetaObject::invokeMethod(handler, method.toLatin1().data(), Q_RETURN_ARG(JsonReply*, reply), Q_ARG(QVariantMap, params));
|
||||||
if (reply->type() == JsonReply::TypeAsync) {
|
if (reply->type() == JsonReply::TypeAsync) {
|
||||||
|
|||||||
@ -133,7 +133,7 @@ RuleEngine::RuleEngine(QObject *parent) :
|
|||||||
bool enabled = settings.value("enabled", true).toBool();
|
bool enabled = settings.value("enabled", true).toBool();
|
||||||
bool executable = settings.value("executable", true).toBool();
|
bool executable = settings.value("executable", true).toBool();
|
||||||
|
|
||||||
qCDebug(dcRuleEngine) << "Load rule" << name << idString;
|
qCDebug(dcRuleEngine) << "Loading rule" << name << idString;
|
||||||
|
|
||||||
// Load timeDescriptor
|
// Load timeDescriptor
|
||||||
TimeDescriptor timeDescriptor;
|
TimeDescriptor timeDescriptor;
|
||||||
|
|||||||
@ -57,7 +57,7 @@ TcpServer::TcpServer(const ServerConfiguration &configuration, const QSslConfigu
|
|||||||
/*! Destructor of this \l{TcpServer}. */
|
/*! Destructor of this \l{TcpServer}. */
|
||||||
TcpServer::~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();
|
stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -154,17 +154,26 @@ bool CalendarItem::evaluateDaily(const QDateTime &dateTime) const
|
|||||||
if (duration() >= 1440)
|
if (duration() >= 1440)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// get todays startTime
|
// Get todays startTime
|
||||||
QDateTime startDateTime = QDateTime(dateTime.date(), startTime());
|
QDateTime startDateTime = dateTime;
|
||||||
|
startDateTime.setTime(startTime());
|
||||||
QDateTime endDateTime = startDateTime.addSecs(duration() * 60);
|
QDateTime endDateTime = startDateTime.addSecs(duration() * 60);
|
||||||
|
|
||||||
// get todays startTime
|
// Get yesterdays startTime for day overlapping clendaritems
|
||||||
QDateTime startDateTimeYesterday = QDateTime(dateTime.date().addDays(-1), startTime());
|
QDateTime startDateTimeYesterday = dateTime.addDays(-1);
|
||||||
|
startDateTimeYesterday.setTime(startTime());
|
||||||
QDateTime endDateTimeYesterday = startDateTimeYesterday.addSecs(duration() * 60);
|
QDateTime endDateTimeYesterday = startDateTimeYesterday.addSecs(duration() * 60);
|
||||||
|
|
||||||
bool todayValid = dateTime >= startDateTime && dateTime < endDateTime;
|
bool todayValid = dateTime >= startDateTime && dateTime < endDateTime;
|
||||||
bool yesterdayValid = dateTime >= startDateTimeYesterday && dateTime < endDateTimeYesterday;
|
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;
|
return todayValid || yesterdayValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,8 @@ WebServer::WebServer(const WebServerConfiguration &configuration, const QSslConf
|
|||||||
/*! Destructor of this \l{WebServer}. */
|
/*! Destructor of this \l{WebServer}. */
|
||||||
WebServer::~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();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ WebSocketServer::WebSocketServer(const ServerConfiguration &configuration, const
|
|||||||
/*! Destructor of this \l{WebSocketServer}. */
|
/*! Destructor of this \l{WebSocketServer}. */
|
||||||
WebSocketServer::~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();
|
stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -213,9 +213,6 @@ void TestTimeManager::loadSaveTimeDescriptor()
|
|||||||
|
|
||||||
QVariantMap timeDescriptorMapLoaded = response.toMap().value("params").toMap().value("rule").toMap().value("timeDescriptor").toMap();
|
QVariantMap timeDescriptorMapLoaded = response.toMap().value("params").toMap().value("rule").toMap().value("timeDescriptor").toMap();
|
||||||
|
|
||||||
qDebug() << timeDescriptorMapLoaded;
|
|
||||||
qDebug() << timeDescriptorMap;
|
|
||||||
|
|
||||||
QCOMPARE(timeDescriptorMap, timeDescriptorMapLoaded);
|
QCOMPARE(timeDescriptorMap, timeDescriptorMapLoaded);
|
||||||
|
|
||||||
// REMOVE rule
|
// REMOVE rule
|
||||||
|
|||||||
Reference in New Issue
Block a user