fix postsetup after loading the devices
This commit is contained in:
parent
9ee5eb20a9
commit
e678370ecd
@ -846,9 +846,11 @@ void DeviceManager::loadConfiguredDevices()
|
|||||||
// We always add the device to the list in this case. If its in the storedDevices
|
// We always add the device to the list in this case. If its in the storedDevices
|
||||||
// it means that it was working at some point so lets still add it as there might
|
// it means that it was working at some point so lets still add it as there might
|
||||||
// be rules associated with this device. Device::setupCompleted() will be false.
|
// be rules associated with this device. Device::setupCompleted() will be false.
|
||||||
setupDevice(device);
|
DeviceSetupStatus status = setupDevice(device);
|
||||||
|
|
||||||
m_configuredDevices.append(device);
|
m_configuredDevices.append(device);
|
||||||
|
|
||||||
|
if (status == DeviceSetupStatus::DeviceSetupStatusSuccess)
|
||||||
|
postSetupDevice(device);
|
||||||
}
|
}
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -272,7 +272,7 @@ bool Alarm::checkTimeTypes(const QDateTime &dateTime)
|
|||||||
|
|
||||||
void Alarm::validate(const QDateTime &dateTime)
|
void Alarm::validate(const QDateTime &dateTime)
|
||||||
{
|
{
|
||||||
qCDebug(dcDateTime) << name() << "validate" << dateTime.toString() << "...";
|
qCDebug(dcDateTime) << name() << "validate...";
|
||||||
|
|
||||||
if (!checkDayOfWeek(dateTime))
|
if (!checkDayOfWeek(dateTime))
|
||||||
return;
|
return;
|
||||||
@ -285,7 +285,7 @@ void Alarm::validate(const QDateTime &dateTime)
|
|||||||
if (!checkMinute(dateTime))
|
if (!checkMinute(dateTime))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCDebug(dcDateTime) << name() << "match time" << QTime(hours(), minutes()).toString("hh:mm") << "with offset" << m_offset;
|
qCDebug(dcDateTime) << name() << "time match" << QTime(hours(), minutes()).toString("hh:mm") << "with offset" << m_offset;
|
||||||
emit alarm();
|
emit alarm();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,7 +102,6 @@ DevicePluginDateTime::DevicePluginDateTime() :
|
|||||||
connect(this, &DevicePluginDateTime::minuteChanged, this, &DevicePluginDateTime::onMinuteChanged);
|
connect(this, &DevicePluginDateTime::minuteChanged, this, &DevicePluginDateTime::onMinuteChanged);
|
||||||
connect(this, &DevicePluginDateTime::hourChanged, this, &DevicePluginDateTime::onHourChanged);
|
connect(this, &DevicePluginDateTime::hourChanged, this, &DevicePluginDateTime::onHourChanged);
|
||||||
connect(this, &DevicePluginDateTime::dayChanged, this, &DevicePluginDateTime::onDayChanged);
|
connect(this, &DevicePluginDateTime::dayChanged, this, &DevicePluginDateTime::onDayChanged);
|
||||||
connect(this, &DevicePluginDateTime::timeDataChanged, this, &DevicePluginDateTime::onTimeDataUpdate);
|
|
||||||
connect(this, &DevicePluginDateTime::configValueChanged, this, &DevicePluginDateTime::onConfigValueChanged);
|
connect(this, &DevicePluginDateTime::configValueChanged, this, &DevicePluginDateTime::onConfigValueChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +172,10 @@ DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *devic
|
|||||||
void DevicePluginDateTime::postSetupDevice(Device *device)
|
void DevicePluginDateTime::postSetupDevice(Device *device)
|
||||||
{
|
{
|
||||||
Q_UNUSED(device)
|
Q_UNUSED(device)
|
||||||
qCDebug(dcDateTime) << "post setup";
|
onMinuteChanged();
|
||||||
searchGeoLocation();
|
onHourChanged();
|
||||||
|
onDayChanged();
|
||||||
|
onTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDateTime::deviceRemoved(Device *device)
|
void DevicePluginDateTime::deviceRemoved(Device *device)
|
||||||
@ -334,7 +335,32 @@ void DevicePluginDateTime::processTimesData(const QByteArray &data)
|
|||||||
m_dawn = QDateTime(QDate::currentDate(), QTime::fromString(dawnString, "h:m:s AP"), Qt::UTC).toTimeZone(m_timeZone);
|
m_dawn = QDateTime(QDate::currentDate(), QTime::fromString(dawnString, "h:m:s AP"), Qt::UTC).toTimeZone(m_timeZone);
|
||||||
m_sunset = QDateTime(QDate::currentDate(), QTime::fromString(sunsetString, "h:m:s AP"), Qt::UTC).toTimeZone(m_timeZone);
|
m_sunset = QDateTime(QDate::currentDate(), QTime::fromString(sunsetString, "h:m:s AP"), Qt::UTC).toTimeZone(m_timeZone);
|
||||||
|
|
||||||
emit timeDataChanged();
|
// calculate the times in each alarm
|
||||||
|
qCDebug(dcDateTime) << " dusk :" << m_dusk.toString();
|
||||||
|
qCDebug(dcDateTime) << " sunrise :" << m_sunrise.toString();
|
||||||
|
qCDebug(dcDateTime) << " noon :" << m_noon.toString();
|
||||||
|
qCDebug(dcDateTime) << " sunset :" << m_sunset.toString();
|
||||||
|
qCDebug(dcDateTime) << " dawn :" << m_dawn.toString();
|
||||||
|
qCDebug(dcDateTime) << "---------------------------------------------";
|
||||||
|
|
||||||
|
// alarms
|
||||||
|
foreach (Alarm *alarm, m_alarms.values()) {
|
||||||
|
alarm->setDusk(m_dusk);
|
||||||
|
alarm->setSunrise(m_sunrise);
|
||||||
|
alarm->setNoon(m_noon);
|
||||||
|
alarm->setDawn(m_dawn);
|
||||||
|
alarm->setSunset(m_sunset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// date
|
||||||
|
if (m_todayDevice == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_todayDevice->setStateValue(duskStateTypeId, m_dusk.toTime_t());
|
||||||
|
m_todayDevice->setStateValue(sunriseStateTypeId, m_sunrise.toTime_t());
|
||||||
|
m_todayDevice->setStateValue(noonStateTypeId, m_noon.toTime_t());
|
||||||
|
m_todayDevice->setStateValue(dawnStateTypeId, m_dawn.toTime_t());
|
||||||
|
m_todayDevice->setStateValue(sunsetStateTypeId, m_sunset.toTime_t());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -343,6 +369,8 @@ void DevicePluginDateTime::onTimeout()
|
|||||||
QDateTime zoneTime = QDateTime::currentDateTime().toTimeZone(m_timeZone);
|
QDateTime zoneTime = QDateTime::currentDateTime().toTimeZone(m_timeZone);
|
||||||
//qCDebug(dcDateTime) << m_timeZone.id() << zoneTime.toString();
|
//qCDebug(dcDateTime) << m_timeZone.id() << zoneTime.toString();
|
||||||
|
|
||||||
|
validateTimeTypes(zoneTime);
|
||||||
|
|
||||||
if (zoneTime.date() != m_currentDateTime.date())
|
if (zoneTime.date() != m_currentDateTime.date())
|
||||||
emit dayChanged();
|
emit dayChanged();
|
||||||
|
|
||||||
@ -352,13 +380,6 @@ void DevicePluginDateTime::onTimeout()
|
|||||||
if (zoneTime.time().minute() != m_currentDateTime.time().minute())
|
if (zoneTime.time().minute() != m_currentDateTime.time().minute())
|
||||||
emit minuteChanged();
|
emit minuteChanged();
|
||||||
|
|
||||||
foreach (Device *device, deviceManager()->findConfiguredDevices(alarmDeviceClassId)) {
|
|
||||||
Alarm *alarm = m_alarms.value(device);
|
|
||||||
alarm->validateTimes(zoneTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
validateTimeTypes(zoneTime);
|
|
||||||
|
|
||||||
// just store for compairing
|
// just store for compairing
|
||||||
m_currentDateTime = zoneTime;
|
m_currentDateTime = zoneTime;
|
||||||
}
|
}
|
||||||
@ -373,37 +394,6 @@ void DevicePluginDateTime::onAlarm()
|
|||||||
emit emitEvent(Event(alarmEventTypeId, device->id()));
|
emit emitEvent(Event(alarmEventTypeId, device->id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDateTime::onTimeDataUpdate()
|
|
||||||
{
|
|
||||||
// calculate the times in each alarm
|
|
||||||
qCDebug(dcDateTime) << " dusk :" << m_dusk.toString();
|
|
||||||
qCDebug(dcDateTime) << " sunrise :" << m_sunrise.toString();
|
|
||||||
qCDebug(dcDateTime) << " noon :" << m_noon.toString();
|
|
||||||
qCDebug(dcDateTime) << " dawn :" << m_dawn.toString();
|
|
||||||
qCDebug(dcDateTime) << " sunset :" << m_sunset.toString();
|
|
||||||
qCDebug(dcDateTime) << "---------------------------------------------";
|
|
||||||
|
|
||||||
// alarms
|
|
||||||
foreach (Alarm *alarm, m_alarms.values()) {
|
|
||||||
alarm->setDusk(m_dusk);
|
|
||||||
alarm->setSunrise(m_sunrise);
|
|
||||||
alarm->setNoon(m_noon);
|
|
||||||
alarm->setDawn(m_dawn);
|
|
||||||
alarm->setSunset(m_sunset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// date
|
|
||||||
if (m_todayDevice != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_todayDevice->setStateValue(duskStateTypeId, m_dusk.toTime_t());
|
|
||||||
m_todayDevice->setStateValue(sunriseStateTypeId, m_sunrise.toTime_t());
|
|
||||||
m_todayDevice->setStateValue(noonStateTypeId, m_noon.toTime_t());
|
|
||||||
m_todayDevice->setStateValue(dawnStateTypeId, m_dawn.toTime_t());
|
|
||||||
m_todayDevice->setStateValue(sunsetStateTypeId, m_sunset.toTime_t());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DevicePluginDateTime::onMinuteChanged()
|
void DevicePluginDateTime::onMinuteChanged()
|
||||||
{
|
{
|
||||||
QDateTime zoneTime = QDateTime::currentDateTime().toTimeZone(m_timeZone);
|
QDateTime zoneTime = QDateTime::currentDateTime().toTimeZone(m_timeZone);
|
||||||
@ -467,9 +457,8 @@ void DevicePluginDateTime::onConfigValueChanged(const QString ¶mName, const
|
|||||||
|
|
||||||
void DevicePluginDateTime::validateTimeTypes(const QDateTime &dateTime)
|
void DevicePluginDateTime::validateTimeTypes(const QDateTime &dateTime)
|
||||||
{
|
{
|
||||||
if (m_todayDevice == 0) {
|
if (m_todayDevice == 0)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (dateTime == m_dusk) {
|
if (dateTime == m_dusk) {
|
||||||
emit emitEvent(Event(duskEventTypeId, m_todayDevice->id()));
|
emit emitEvent(Event(duskEventTypeId, m_todayDevice->id()));
|
||||||
@ -482,4 +471,9 @@ void DevicePluginDateTime::validateTimeTypes(const QDateTime &dateTime)
|
|||||||
} else if (dateTime == m_sunset) {
|
} else if (dateTime == m_sunset) {
|
||||||
emit emitEvent(Event(sunsetEventTypeId, m_todayDevice->id()));
|
emit emitEvent(Event(sunsetEventTypeId, m_todayDevice->id()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Device *device, deviceManager()->findConfiguredDevices(alarmDeviceClassId)) {
|
||||||
|
Alarm *alarm = m_alarms.value(device);
|
||||||
|
alarm->validateTimes(dateTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,7 +79,6 @@ signals:
|
|||||||
void noon();
|
void noon();
|
||||||
void sunrise();
|
void sunrise();
|
||||||
void dawn();
|
void dawn();
|
||||||
void timeDataChanged();
|
|
||||||
void minuteChanged();
|
void minuteChanged();
|
||||||
void hourChanged();
|
void hourChanged();
|
||||||
void dayChanged();
|
void dayChanged();
|
||||||
@ -87,7 +86,6 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void onTimeout();
|
void onTimeout();
|
||||||
void onAlarm();
|
void onAlarm();
|
||||||
void onTimeDataUpdate();
|
|
||||||
void onMinuteChanged();
|
void onMinuteChanged();
|
||||||
void onHourChanged();
|
void onHourChanged();
|
||||||
void onDayChanged();
|
void onDayChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user