added session time state
parent
5c6c5fd669
commit
0d74094546
|
|
@ -35,6 +35,7 @@
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
#include <QTimeZone>
|
||||||
|
|
||||||
IntegrationPluginKeba::IntegrationPluginKeba()
|
IntegrationPluginKeba::IntegrationPluginKeba()
|
||||||
{
|
{
|
||||||
|
|
@ -148,6 +149,20 @@ void IntegrationPluginKeba::updateData()
|
||||||
keba->getReport2();
|
keba->getReport2();
|
||||||
keba->getReport3();
|
keba->getReport3();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Device *device, myDevices().filterByDeviceClassId(wallboxDeviceClassId)) {
|
||||||
|
if (m_chargingSessionStartTime.contains(device->id())) {
|
||||||
|
QDateTime startTime = m_chargingSessionStartTime.value(device->id());
|
||||||
|
|
||||||
|
QTimeZone tz = QTimeZone(QTimeZone::systemTimeZoneId());
|
||||||
|
QDateTime currentTime = QDateTime::currentDateTime().toTimeZone(tz);
|
||||||
|
|
||||||
|
int minutes = (currentTime.toSecsSinceEpoch() - startTime.toSecsSinceEpoch())/60;
|
||||||
|
device->setStateValue(wallboxSessionTimeStateTypeId, minutes);
|
||||||
|
} else {
|
||||||
|
device->setStateValue(wallboxSessionTimeStateTypeId, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginKeba::setDeviceState(Device *device, KeContact::State state)
|
void DevicePluginKeba::setDeviceState(Device *device, KeContact::State state)
|
||||||
|
|
@ -172,6 +187,16 @@ void DevicePluginKeba::setDeviceState(Device *device, KeContact::State state)
|
||||||
device->setStateValue(wallboxActivityStateTypeId, "Authorization rejected");
|
device->setStateValue(wallboxActivityStateTypeId, "Authorization rejected");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state == KeContact::StateCharging) {
|
||||||
|
//Set charging session
|
||||||
|
QTimeZone tz = QTimeZone(QTimeZone::systemTimeZoneId());
|
||||||
|
QDateTime startedChargingSession = QDateTime::currentDateTime().toTimeZone(tz);
|
||||||
|
m_chargingSessionStartTime.insert(device->id(), startedChargingSession);
|
||||||
|
} else {
|
||||||
|
m_chargingSessionStartTime.remove(device->id());
|
||||||
|
device->setStateValue(wallboxSessionTimeStateTypeId, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginKeba::setDevicePlugState(Device *device, KeContact::PlugState plugState)
|
void DevicePluginKeba::setDevicePlugState(Device *device, KeContact::PlugState plugState)
|
||||||
|
|
@ -211,6 +236,7 @@ void DevicePluginKeba::onConnectionChanged(bool status)
|
||||||
|
|
||||||
void DevicePluginKeba::onCommandExecuted(QUuid requestId, bool success)
|
void DevicePluginKeba::onCommandExecuted(QUuid requestId, bool success)
|
||||||
{
|
{
|
||||||
|
updateData();
|
||||||
if (m_asyncActions.contains(requestId)) {
|
if (m_asyncActions.contains(requestId)) {
|
||||||
KeContact *keba = static_cast<KeContact *>(sender());
|
KeContact *keba = static_cast<KeContact *>(sender());
|
||||||
Device *device = myDevices().findById(m_kebaDevices.key(keba));
|
Device *device = myDevices().findById(m_kebaDevices.key(keba));
|
||||||
|
|
@ -234,7 +260,6 @@ void DevicePluginKeba::onReportOneReceived(const KeContact::ReportOne &reportOne
|
||||||
if (m_asyncSetup.contains(keba)) {
|
if (m_asyncSetup.contains(keba)) {
|
||||||
DeviceSetupInfo *info = m_asyncSetup.value(keba);
|
DeviceSetupInfo *info = m_asyncSetup.value(keba);
|
||||||
info->finish(Device::DeviceErrorNoError);
|
info->finish(Device::DeviceErrorNoError);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCDebug(dcKebaKeContact()) << "Report one received without an associated async setup";
|
qCDebug(dcKebaKeContact()) << "Report one received without an associated async setup";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
class IntegrationPluginKeba : public IntegrationPlugin
|
class IntegrationPluginKeba : public IntegrationPlugin
|
||||||
{
|
{
|
||||||
|
|
@ -65,6 +66,7 @@ private:
|
||||||
QHash<DeviceId, KeContact *> m_kebaDevices;
|
QHash<DeviceId, KeContact *> m_kebaDevices;
|
||||||
QHash<KeContact *, DeviceSetupInfo *> m_asyncSetup;
|
QHash<KeContact *, DeviceSetupInfo *> m_asyncSetup;
|
||||||
QHash<QUuid, DeviceActionInfo *> m_asyncActions;
|
QHash<QUuid, DeviceActionInfo *> m_asyncActions;
|
||||||
|
QHash<DeviceId, QDateTime> m_chargingSessionStartTime;
|
||||||
|
|
||||||
void setDeviceState(Device *device, KeContact::State state);
|
void setDeviceState(Device *device, KeContact::State state);
|
||||||
void setDevicePlugState(Device *device, KeContact::PlugState plugState);
|
void setDevicePlugState(Device *device, KeContact::PlugState plugState);
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,15 @@
|
||||||
"unit": "MilliWatt",
|
"unit": "MilliWatt",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "a6f35ea0-aaea-438b-b818-6d161762611e",
|
||||||
|
"name": "sessionTime",
|
||||||
|
"displayName": "Session time",
|
||||||
|
"displayNameEvent": "Session time changed",
|
||||||
|
"type": "int",
|
||||||
|
"unit": "Minutes",
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "8e277efe-21ef-4536-bfc0-901b32d44d7c",
|
"id": "8e277efe-21ef-4536-bfc0-901b32d44d7c",
|
||||||
"name": "EP",
|
"name": "EP",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue