fixed zone date
This commit is contained in:
parent
7f6e0cf46d
commit
41126d016e
@ -84,27 +84,40 @@
|
|||||||
#include "plugininfo.h"
|
#include "plugininfo.h"
|
||||||
#include "loggingcategories.h"
|
#include "loggingcategories.h"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
DevicePluginDateTime::DevicePluginDateTime()
|
DevicePluginDateTime::DevicePluginDateTime()
|
||||||
{
|
{
|
||||||
m_timer = new QTimer(this);
|
m_timer = new QTimer(this);
|
||||||
m_timer->setInterval(1000);
|
m_timer->setInterval(1000);
|
||||||
|
|
||||||
|
qCDebug(dcDateTime) << configuration();
|
||||||
|
|
||||||
|
m_timeZone = QTimeZone(configValue("timezone").toByteArray());
|
||||||
|
|
||||||
connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::timeout);
|
connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::timeout);
|
||||||
|
connect(this, &DevicePluginDateTime::configValueChanged, this, &DevicePluginDateTime::onConfigValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceManager::HardwareResources DevicePluginDateTime::requiredHardware() const
|
||||||
|
{
|
||||||
|
return DeviceManager::HardwareResourceNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<ParamType> DevicePluginDateTime::configurationDescription() const
|
||||||
|
{
|
||||||
|
QList<ParamType> params;
|
||||||
|
ParamType timezoneParamType("timezone", QVariant::String, "Europe/Vienna");
|
||||||
|
QList<QVariant> allowedValues;
|
||||||
|
foreach (QByteArray timeZone, QTimeZone::availableTimeZoneIds()) {
|
||||||
|
allowedValues.append(timeZone);
|
||||||
|
}
|
||||||
|
timezoneParamType.setAllowedValues(allowedValues);
|
||||||
|
params.append(timezoneParamType);
|
||||||
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
|
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
|
||||||
{
|
{
|
||||||
// check the DeviceClassId
|
// check the DeviceClassId
|
||||||
if(device->deviceClassId() != dateTimeDeviceClassId){
|
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make shore there is just one date/time
|
|
||||||
if (myDevices().count() != 0 && myDevices().takeFirst()->id() != device->id()) {
|
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
device->setName("Time (" + device->paramValue("timezone").toString() + ")");
|
device->setName("Time (" + device->paramValue("timezone").toString() + ")");
|
||||||
m_timeZone = QTimeZone(device->paramValue("timezone").toByteArray());
|
m_timeZone = QTimeZone(device->paramValue("timezone").toByteArray());
|
||||||
@ -119,29 +132,10 @@ DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *devic
|
|||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginDateTime::discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms)
|
void DevicePluginDateTime::deviceRemoved(Device *device)
|
||||||
{
|
{
|
||||||
Q_UNUSED(deviceClassId);
|
Q_UNUSED(device);
|
||||||
|
m_timer->stop();
|
||||||
QList<DeviceDescriptor> deviceDescriptors;
|
|
||||||
foreach (QByteArray timeZone, QTimeZone::availableTimeZoneIds()) {
|
|
||||||
QByteArray continent = params.paramValue("continent").toByteArray();
|
|
||||||
if(timeZone.contains(continent)){
|
|
||||||
DeviceDescriptor descriptor(dateTimeDeviceClassId, timeZone.right(timeZone.length() - (continent.length() + 1)), continent);
|
|
||||||
ParamList params;
|
|
||||||
params.append(Param("timezone", timeZone));
|
|
||||||
descriptor.setParams(params);
|
|
||||||
deviceDescriptors.append(descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit devicesDiscovered(dateTimeDeviceClassId, deviceDescriptors);
|
|
||||||
|
|
||||||
return DeviceManager::DeviceErrorAsync;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginDateTime::requiredHardware() const
|
|
||||||
{
|
|
||||||
return DeviceManager::HardwareResourceNone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginDateTime::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginDateTime::executeAction(Device *device, const Action &action)
|
||||||
@ -152,20 +146,30 @@ DeviceManager::DeviceError DevicePluginDateTime::executeAction(Device *device, c
|
|||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDateTime::deviceRemoved(Device *device)
|
void DevicePluginDateTime::startMonitoringAutoDevices()
|
||||||
{
|
{
|
||||||
Q_UNUSED(device);
|
foreach (Device *device, myDevices()) {
|
||||||
m_timer->stop();
|
if (device->deviceClassId() == dateDeviceClassId) {
|
||||||
|
return; // We already have a Auto Mock device... do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceDescriptor dateDescriptor(dateDeviceClassId, QString("Date"), QString(m_timeZone.id()));
|
||||||
|
ParamList params;
|
||||||
|
params.append(Param("name", m_timeZone.id()));
|
||||||
|
dateDescriptor.setParams(params);
|
||||||
|
|
||||||
|
emit autoDevicesAppeared(dateDeviceClassId, QList<DeviceDescriptor>() << dateDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginDateTime::timeout()
|
void DevicePluginDateTime::timeout()
|
||||||
{
|
{
|
||||||
QDateTime zoneTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone).toLocalTime();
|
QDateTime zoneTime = QDateTime::currentDateTime().toTimeZone(m_timeZone);
|
||||||
|
|
||||||
if(deviceManager()->findConfiguredDevices(dateTimeDeviceClassId).count() == 1){
|
qCDebug(dcDateTime) << m_timeZone.id() << zoneTime.toString();
|
||||||
Device *device = deviceManager()->findConfiguredDevices(dateTimeDeviceClassId).first();
|
|
||||||
device->setStateValue(minuteStateTypeId, zoneTime.time().minute());
|
if(deviceManager()->findConfiguredDevices(dateDeviceClassId).count() == 1){
|
||||||
device->setStateValue(hourStateTypeId, zoneTime.time().hour());
|
Device *device = deviceManager()->findConfiguredDevices(dateDeviceClassId).first();
|
||||||
device->setStateValue(dayStateTypeId, zoneTime.date().day());
|
device->setStateValue(dayStateTypeId, zoneTime.date().day());
|
||||||
device->setStateValue(monthStateTypeId, zoneTime.date().month());
|
device->setStateValue(monthStateTypeId, zoneTime.date().month());
|
||||||
device->setStateValue(monthNameStateTypeId, zoneTime.date().longMonthName(zoneTime.date().month()));
|
device->setStateValue(monthNameStateTypeId, zoneTime.date().longMonthName(zoneTime.date().month()));
|
||||||
@ -183,3 +187,20 @@ void DevicePluginDateTime::timeout()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginDateTime::onConfigValueChanged(const QString ¶mName, const QVariant &value)
|
||||||
|
{
|
||||||
|
Q_UNUSED(paramName)
|
||||||
|
|
||||||
|
QTimeZone newZone = QTimeZone(value.toByteArray());
|
||||||
|
if (newZone.isValid()) {
|
||||||
|
m_timeZone = newZone;
|
||||||
|
QDateTime zoneTime = QDateTime(QDate::currentDate(), QTime::currentTime(), m_timeZone);
|
||||||
|
qCDebug(dcDateTime) << "set new time zone:" << value.toString();
|
||||||
|
qCDebug(dcDateTime) << "current time" << zoneTime.currentDateTime().toString();
|
||||||
|
qCDebug(dcDateTime) << "-----------------------------";
|
||||||
|
timeout();
|
||||||
|
} else {
|
||||||
|
qCWarning(dcDateTime) << "could not set new timezone" << value.toString() << ". keeping old time zone:" << m_timeZone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,12 +36,15 @@ class DevicePluginDateTime : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginDateTime();
|
explicit DevicePluginDateTime();
|
||||||
|
|
||||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
|
||||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
QList<ParamType> configurationDescription() const override;
|
||||||
|
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||||
|
void deviceRemoved(Device *device) override;
|
||||||
|
|
||||||
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
void deviceRemoved(Device *device) override;
|
void startMonitoringAutoDevices() override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
@ -49,6 +52,7 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void timeout();
|
void timeout();
|
||||||
|
void onConfigValueChanged(const QString ¶mName, const QVariant &value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,53 +8,29 @@
|
|||||||
"deviceClasses": [
|
"deviceClasses": [
|
||||||
{
|
{
|
||||||
"deviceClassId": "fbf665fb-9aca-423f-a5f2-924e50ebe6ca",
|
"deviceClassId": "fbf665fb-9aca-423f-a5f2-924e50ebe6ca",
|
||||||
"idName": "dateTime",
|
"idName": "date",
|
||||||
"name": "Time",
|
"name": "Date",
|
||||||
"createMethods": ["discovery"],
|
"createMethods": ["auto"],
|
||||||
"discoveryParamTypes": [
|
|
||||||
{
|
|
||||||
"name": "continent",
|
|
||||||
"type": "QString",
|
|
||||||
"inputType": "TextLine",
|
|
||||||
"allowedValues": ["Africa", "America", "Antarctica", "Asia", "Atlantic", "Australia", "Europe", "Indian", "Pacific"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
"name": "timezone",
|
"name": "name",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"inputType": "TextLine"
|
"inputType": "TextLine"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"stateTypes": [
|
"stateTypes": [
|
||||||
{
|
|
||||||
"id": "4f867051-bc3c-4b55-8493-10ab74c98a49",
|
|
||||||
"idName": "minute",
|
|
||||||
"name": "minute",
|
|
||||||
"type": "uint",
|
|
||||||
"unit": "Minutes",
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "5b19d9de-a533-4b6f-b42c-bf8069e31adc",
|
|
||||||
"idName": "hour",
|
|
||||||
"name": "hour",
|
|
||||||
"type": "uint",
|
|
||||||
"unit": "Hours",
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "eb5231ea-6a1b-4d7e-a95f-d49e7b25122e",
|
"id": "eb5231ea-6a1b-4d7e-a95f-d49e7b25122e",
|
||||||
"name": "day",
|
"name": "day",
|
||||||
"idName": "day",
|
"idName": "day",
|
||||||
"type": "uint",
|
"type": "int",
|
||||||
"defaultValue": "1"
|
"defaultValue": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "fcd8ec96-4488-438a-8b30-58bfe2a7fae2",
|
"id": "fcd8ec96-4488-438a-8b30-58bfe2a7fae2",
|
||||||
"name": "month",
|
"name": "month",
|
||||||
"idName": "month",
|
"idName": "month",
|
||||||
"type": "uint",
|
"type": "int",
|
||||||
"defaultValue": "1"
|
"defaultValue": "1"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -75,7 +51,7 @@
|
|||||||
"id": "79d4ae9b-ea27-4346-8229-1d90f1ddfc9d",
|
"id": "79d4ae9b-ea27-4346-8229-1d90f1ddfc9d",
|
||||||
"idName": "year",
|
"idName": "year",
|
||||||
"name": "year",
|
"name": "year",
|
||||||
"type": "uint",
|
"type": "int",
|
||||||
"defaultValue": "1970"
|
"defaultValue": "1970"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user