mirror of https://github.com/nymea/nymea.git
add basic construction of time management
parent
80e7d289f7
commit
affcb1ddf6
|
|
@ -462,11 +462,15 @@ void GuhCore::guhTimeout()
|
|||
{
|
||||
m_deviceManager->timeTick();
|
||||
|
||||
// TODO: evaluate special times
|
||||
|
||||
// Minute based time -> only evaluate time based rules if the minute changed
|
||||
if (m_currentDateTime.time().minute() != QDateTime::currentDateTime().time().minute()) {
|
||||
qCDebug(dcApplication) << "Guh time changed" << QDateTime::currentDateTime().time().toString("hh:mm:ss");
|
||||
m_currentDateTime = QDateTime::currentDateTime();
|
||||
|
||||
// TODO: evaluate timeDescriptor based rules
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,6 +283,8 @@ void JsonTypes::init()
|
|||
s_logEntry.insert("o:eventType", loggingEventTypeRef());
|
||||
s_logEntry.insert("o:errorCode", basicTypeToString(String));
|
||||
|
||||
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
|
||||
|
|
@ -930,6 +932,9 @@ QString JsonTypes::basicTypeToString(const QVariant::Type &type)
|
|||
case QVariant::Color:
|
||||
return "Color";
|
||||
break;
|
||||
case QVariant::Time:
|
||||
return "Time";
|
||||
break;
|
||||
default:
|
||||
return QVariant::typeToName(type);
|
||||
break;
|
||||
|
|
@ -1472,6 +1477,9 @@ QPair<bool, QString> JsonTypes::validateBasicType(const QVariant &variant)
|
|||
if (variant.canConvert(QVariant::Color) && QVariant(variant).convert(QVariant::Color)) {
|
||||
return report(true, "");
|
||||
}
|
||||
if (variant.canConvert(QVariant::Time) && QVariant(variant).convert(QVariant::Time)) {
|
||||
return report(true, "");
|
||||
}
|
||||
return report(false, QString("Error validating basic type %1.").arg(variant.toString()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public:
|
|||
Bool,
|
||||
Variant,
|
||||
Color,
|
||||
Time,
|
||||
Object
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,9 +22,15 @@
|
|||
|
||||
namespace guhserver {
|
||||
|
||||
CalendarItem::CalendarItem(const QTime startTime, const QTime duration) :
|
||||
CalendarItem::CalendarItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CalendarItem::CalendarItem(const QTime &startTime, const QTime &duration, const RepeatingOption &repeatingOption) :
|
||||
m_startTime(startTime),
|
||||
m_duration(duration)
|
||||
m_duration(duration),
|
||||
m_repeatingOption(repeatingOption)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -39,4 +45,18 @@ QTime CalendarItem::duration() const
|
|||
return m_duration;
|
||||
}
|
||||
|
||||
bool CalendarItem::isValid() const
|
||||
{
|
||||
return !m_startTime.isNull() && !m_duration.isNull();
|
||||
}
|
||||
|
||||
bool CalendarItem::evaluate(const QDateTime &dateTime) const
|
||||
{
|
||||
Q_UNUSED(dateTime)
|
||||
|
||||
// TODO: evaluate the calendar item, return true if the current time matches the calendar item, otherwise false
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,20 +23,30 @@
|
|||
|
||||
#include <QTime>
|
||||
|
||||
#include "repeatingoption.h"
|
||||
|
||||
namespace guhserver {
|
||||
|
||||
class CalendarItem
|
||||
{
|
||||
public:
|
||||
CalendarItem(const QTime startTime, const QTime duration);
|
||||
CalendarItem();
|
||||
CalendarItem(const QTime &startTime, const QTime &duration, const RepeatingOption &repeatingOption);
|
||||
|
||||
QTime startTime() const;
|
||||
QTime duration() const;
|
||||
|
||||
RepeatingOption repeatingOption() const;
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
bool evaluate(const QDateTime &dateTime) const;
|
||||
|
||||
private:
|
||||
QTime m_startTime;
|
||||
QTime m_duration;
|
||||
|
||||
RepeatingOption m_repeatingOption;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,38 @@
|
|||
|
||||
namespace guhserver {
|
||||
|
||||
RepeatingOption::RepeatingOption()
|
||||
RepeatingOption::RepeatingOption() :
|
||||
m_mode(RepeatingModeNone)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RepeatingOption::RepeatingOption(const RepeatingMode &mode, const QList<int> &weekDays, const QList<int> &monthDays) :
|
||||
m_mode(mode),
|
||||
m_weekDays(weekDays),
|
||||
m_monthDays(monthDays)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RepeatingOption::RepeatingMode RepeatingOption::mode() const
|
||||
{
|
||||
return m_mode;
|
||||
}
|
||||
|
||||
QList<int> RepeatingOption::weekDays() const
|
||||
{
|
||||
return m_weekDays;
|
||||
}
|
||||
|
||||
QList<int> RepeatingOption::monthDays() const
|
||||
{
|
||||
return m_monthDays;
|
||||
}
|
||||
|
||||
bool RepeatingOption::isEmtpy() const
|
||||
{
|
||||
return m_mode == RepeatingModeNone && m_weekDays.isEmpty() && m_monthDays.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#ifndef REPEATINGOPTION_H
|
||||
#define REPEATINGOPTION_H
|
||||
|
||||
#include <QList>
|
||||
#include <QMetaType>
|
||||
|
||||
namespace guhserver {
|
||||
|
|
@ -40,9 +41,20 @@ public:
|
|||
};
|
||||
|
||||
RepeatingOption();
|
||||
RepeatingOption(const RepeatingMode &mode, const QList<int> &weekDays = QList<int>(), const QList<int> &monthDays = QList<int>());
|
||||
|
||||
RepeatingMode mode() const;
|
||||
|
||||
QList<int> weekDays() const;
|
||||
QList<int> monthDays() const;
|
||||
|
||||
bool isEmtpy() const;
|
||||
|
||||
private:
|
||||
RepeatingMode m_mode;
|
||||
|
||||
QList<int> m_weekDays;
|
||||
QList<int> m_monthDays;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -27,4 +27,29 @@ TimeDescriptor::TimeDescriptor()
|
|||
|
||||
}
|
||||
|
||||
QList<TimeEventItem> TimeDescriptor::timeEventItems() const
|
||||
{
|
||||
return m_timeEventItems;
|
||||
}
|
||||
|
||||
void TimeDescriptor::setTimeEventItems(const QList<TimeEventItem> &timeEventItems)
|
||||
{
|
||||
m_timeEventItems = timeEventItems;
|
||||
}
|
||||
|
||||
QList<CalendarItem> TimeDescriptor::calendarItems() const
|
||||
{
|
||||
return m_calendarItems;
|
||||
}
|
||||
|
||||
void TimeDescriptor::setCalendarItems(const QList<CalendarItem> &calendarItems)
|
||||
{
|
||||
m_calendarItems = calendarItems;
|
||||
}
|
||||
|
||||
bool TimeDescriptor::isValid() const
|
||||
{
|
||||
return !m_timeEventItems.isEmpty() || !m_calendarItems.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
#ifndef TIMEDESCRIPTOR_H
|
||||
#define TIMEDESCRIPTOR_H
|
||||
|
||||
#include "timeeventitem.h"
|
||||
#include "calendaritem.h"
|
||||
|
||||
namespace guhserver {
|
||||
|
||||
class TimeDescriptor
|
||||
|
|
@ -28,6 +31,17 @@ class TimeDescriptor
|
|||
public:
|
||||
explicit TimeDescriptor();
|
||||
|
||||
QList<TimeEventItem> timeEventItems() const;
|
||||
void setTimeEventItems(const QList<TimeEventItem> &timeEventItems);
|
||||
|
||||
QList<CalendarItem> calendarItems() const;
|
||||
void setCalendarItems(const QList<CalendarItem> &calendarItems);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
QList<TimeEventItem> m_timeEventItems;
|
||||
QList<CalendarItem> m_calendarItems;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,39 @@ TimeEventItem::TimeEventItem()
|
|||
|
||||
}
|
||||
|
||||
QDateTime TimeEventItem::dateTime() const
|
||||
{
|
||||
return m_dateTimer;
|
||||
}
|
||||
|
||||
void TimeEventItem::setDateTimer(const int &timeStamp)
|
||||
{
|
||||
m_dateTimer = QDateTime::fromTime_t(timeStamp);
|
||||
}
|
||||
|
||||
QTime TimeEventItem::time() const
|
||||
{
|
||||
return m_time;
|
||||
}
|
||||
|
||||
void TimeEventItem::setTimer(const QTime &time)
|
||||
{
|
||||
m_time = time;
|
||||
}
|
||||
|
||||
RepeatingOption TimeEventItem::repatingOption() const
|
||||
{
|
||||
return m_repeatingOption;
|
||||
}
|
||||
|
||||
void TimeEventItem::setRepeatingOption(const RepeatingOption &repeatingOption)
|
||||
{
|
||||
m_repeatingOption = repeatingOption;
|
||||
}
|
||||
|
||||
bool TimeEventItem::isValid() const
|
||||
{
|
||||
return !m_dateTimer.isNull() || !m_time.isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@
|
|||
#ifndef TIMEEVENTITEM_H
|
||||
#define TIMEEVENTITEM_H
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
#include "repeatingoption.h"
|
||||
|
||||
namespace guhserver {
|
||||
|
||||
class TimeEventItem
|
||||
|
|
@ -28,6 +32,25 @@ class TimeEventItem
|
|||
public:
|
||||
TimeEventItem();
|
||||
|
||||
QDateTime dateTime() const;
|
||||
void setDateTimer(const int &timeStamp);
|
||||
|
||||
QTime time() const;
|
||||
void setTimer(const QTime &time);
|
||||
|
||||
RepeatingOption repatingOption() const;
|
||||
void setRepeatingOption(const RepeatingOption &repeatingOption);
|
||||
|
||||
// TODO spectioalDayTime
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
QDateTime m_dateTimer;
|
||||
QTime m_time;
|
||||
|
||||
RepeatingOption m_repeatingOption;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue