add awattar manual/auto mode and corresponding actions
This commit is contained in:
parent
88706ccbc6
commit
286c948915
@ -237,6 +237,45 @@ void DevicePluginAwattar::guhTimer()
|
|||||||
searchHeatPumps();
|
searchHeatPumps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceManager::DeviceError DevicePluginAwattar::executeAction(Device *device, const Action &action)
|
||||||
|
{
|
||||||
|
if (!m_device || m_device != device)
|
||||||
|
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||||
|
|
||||||
|
if (action.actionTypeId() == sgSyncModeActionTypeId) {
|
||||||
|
qCDebug(dcAwattar) << "Set sg sync mode to" << action.param("sync mode").value();
|
||||||
|
device->setStateValue(sgSyncModeStateTypeId, action.param("sync mode").value());
|
||||||
|
if (action.param("sync mode").value() == "auto")
|
||||||
|
setSgMode(m_autoSgMode);
|
||||||
|
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
} else if (action.actionTypeId() == setSgModeActionTypeId) {
|
||||||
|
if (!device->stateValue(reachableStateTypeId).toBool()) {
|
||||||
|
qCWarning(dcAwattar) << "Could not set SG mode. The pump is not reachable";
|
||||||
|
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
device->setStateValue(sgSyncModeStateTypeId, "manual");
|
||||||
|
QString sgModeString = action.param("sg-mode").value().toString();
|
||||||
|
qCDebug(dcAwattar) << "Set manual SG mode to:" << sgModeString;
|
||||||
|
|
||||||
|
if(sgModeString == "1 - Off") {
|
||||||
|
m_manualSgMode = 1;
|
||||||
|
} else if (sgModeString == "2 - Normal") {
|
||||||
|
m_manualSgMode = 2;
|
||||||
|
} else if (sgModeString == "3 - High Temperature") {
|
||||||
|
m_manualSgMode = 3;
|
||||||
|
} else if (sgModeString == "4 - On") {
|
||||||
|
m_manualSgMode = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
setSgMode(m_manualSgMode);
|
||||||
|
return DeviceManager::DeviceErrorNoError;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DeviceManager::DeviceErrorActionTypeNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
void DevicePluginAwattar::processPriceData(const QVariantMap &data)
|
void DevicePluginAwattar::processPriceData(const QVariantMap &data)
|
||||||
{
|
{
|
||||||
if (!m_device)
|
if (!m_device)
|
||||||
@ -324,27 +363,13 @@ void DevicePluginAwattar::processUserData(const QVariantMap &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sgMode) {
|
m_autoSgMode = sgMode;
|
||||||
case 1:
|
|
||||||
m_device->setStateValue(sgModeStateTypeId, "1 - Off");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
m_device->setStateValue(sgModeStateTypeId, "2 - Normal");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
m_device->setStateValue(sgModeStateTypeId, "3 - High Temperature");
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
m_device->setStateValue(sgModeStateTypeId, "4 - On");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
m_device->setStateValue(sgModeStateTypeId, "0 - Invalid");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (HeatPump *pump, m_heatPumps) {
|
// sync the sg mode to each pump available
|
||||||
if (pump->reachable())
|
if (m_device->stateValue(sgSyncModeStateTypeId).toString() == "auto") {
|
||||||
pump->setSgMode(sgMode);
|
setSgMode(m_autoSgMode);
|
||||||
|
} else {
|
||||||
|
setSgMode(m_manualSgMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,14 +438,39 @@ void DevicePluginAwattar::searchHeatPumps()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//qCDebug(dcAwattar) << "Search heat pump" << rplAddress.toString();
|
|
||||||
|
|
||||||
QNetworkRequest request(QUrl(QString("http://[%1]").arg(rplAddress.toString())));
|
QNetworkRequest request(QUrl(QString("http://[%1]").arg(rplAddress.toString())));
|
||||||
QNetworkReply *reply = networkManagerGet(request);
|
QNetworkReply *reply = networkManagerGet(request);
|
||||||
|
|
||||||
m_searchPumpReplies.append(reply);
|
m_searchPumpReplies.append(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DevicePluginAwattar::setSgMode(const int &sgMode)
|
||||||
|
{
|
||||||
|
switch (sgMode) {
|
||||||
|
case 1:
|
||||||
|
m_device->setStateValue(sgModeStateTypeId, "1 - Off");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
m_device->setStateValue(sgModeStateTypeId, "2 - Normal");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
m_device->setStateValue(sgModeStateTypeId, "3 - High Temperature");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
m_device->setStateValue(sgModeStateTypeId, "4 - On");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_device->setStateValue(sgModeStateTypeId, "0 - Invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (HeatPump *pump, m_heatPumps) {
|
||||||
|
if (pump->reachable()) {
|
||||||
|
pump->setSgMode(sgMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool DevicePluginAwattar::heatPumpExists(const QHostAddress &pumpAddress)
|
bool DevicePluginAwattar::heatPumpExists(const QHostAddress &pumpAddress)
|
||||||
{
|
{
|
||||||
foreach (HeatPump *pump, m_heatPumps) {
|
foreach (HeatPump *pump, m_heatPumps) {
|
||||||
@ -439,8 +489,19 @@ void DevicePluginAwattar::connectionTest()
|
|||||||
void DevicePluginAwattar::onHeatPumpReachableChanged()
|
void DevicePluginAwattar::onHeatPumpReachableChanged()
|
||||||
{
|
{
|
||||||
HeatPump *pump = static_cast<HeatPump *>(sender());
|
HeatPump *pump = static_cast<HeatPump *>(sender());
|
||||||
|
qCDebug(dcAwattar) << "Heatpump" << pump->address().toString() << " -> reachable" << pump->reachable();
|
||||||
|
|
||||||
|
// if there is still one pump reachable, lets keep the state true
|
||||||
|
// if no pump can be reached, the state will be set to false
|
||||||
|
bool reachable = false;
|
||||||
|
foreach (HeatPump *heatPump, m_heatPumps) {
|
||||||
|
if (heatPump->reachable()){
|
||||||
|
reachable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Device *device, myDevices()) {
|
foreach (Device *device, myDevices()) {
|
||||||
device->setStateValue(reachableStateTypeId, pump->reachable());
|
device->setStateValue(reachableStateTypeId, reachable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,8 @@ public:
|
|||||||
|
|
||||||
void guhTimer() override;
|
void guhTimer() override;
|
||||||
|
|
||||||
|
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device *m_device;
|
Device *m_device;
|
||||||
QList<HeatPump *> m_heatPumps;
|
QList<HeatPump *> m_heatPumps;
|
||||||
@ -58,6 +60,9 @@ private:
|
|||||||
QString m_userUuid;
|
QString m_userUuid;
|
||||||
int m_setupRetry;
|
int m_setupRetry;
|
||||||
|
|
||||||
|
int m_autoSgMode;
|
||||||
|
int m_manualSgMode;
|
||||||
|
|
||||||
void processPriceData(const QVariantMap &data);
|
void processPriceData(const QVariantMap &data);
|
||||||
void processUserData(const QVariantMap &data);
|
void processUserData(const QVariantMap &data);
|
||||||
void processPumpSearchData(const QByteArray &data);
|
void processPumpSearchData(const QByteArray &data);
|
||||||
@ -67,6 +72,9 @@ private:
|
|||||||
|
|
||||||
void updateData();
|
void updateData();
|
||||||
void searchHeatPumps();
|
void searchHeatPumps();
|
||||||
|
|
||||||
|
void setSgMode(const int &sgMode);
|
||||||
|
|
||||||
bool heatPumpExists(const QHostAddress &pumpAddress);
|
bool heatPumpExists(const QHostAddress &pumpAddress);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
"id": "38b86cee-9588-4269-a585-128907929dc2",
|
"id": "38b86cee-9588-4269-a585-128907929dc2",
|
||||||
"idName": "averageDeviation",
|
"idName": "averageDeviation",
|
||||||
"name": "average deviation",
|
"name": "average deviation",
|
||||||
"type": "double",
|
"type": "int",
|
||||||
"unit": "Percentage",
|
"unit": "Percentage",
|
||||||
"defaultValue": 0
|
"defaultValue": 0
|
||||||
},
|
},
|
||||||
@ -108,6 +108,38 @@
|
|||||||
"4 - On"
|
"4 - On"
|
||||||
],
|
],
|
||||||
"defaultValue": "0 - Invalid"
|
"defaultValue": "0 - Invalid"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4c303bcd-152d-45ad-874d-d57fc87a26bb",
|
||||||
|
"idName": "sgSyncMode",
|
||||||
|
"name": "sync mode",
|
||||||
|
"type": "QString",
|
||||||
|
"possibleValues": [
|
||||||
|
"auto",
|
||||||
|
"manual"
|
||||||
|
],
|
||||||
|
"defaultValue": "auto",
|
||||||
|
"writable": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"actionTypes": [
|
||||||
|
{
|
||||||
|
"id": "dd82f6c7-5e92-48ca-b0bc-bdc55d3e1482",
|
||||||
|
"idName": "setSgMode",
|
||||||
|
"name": "set sg-mode",
|
||||||
|
"paramTypes": [
|
||||||
|
{
|
||||||
|
"name": "sg-mode",
|
||||||
|
"type": "QString",
|
||||||
|
"allowedValues": [
|
||||||
|
"1 - Off",
|
||||||
|
"2 - Normal",
|
||||||
|
"3 - High Temperature",
|
||||||
|
"4 - On"
|
||||||
|
],
|
||||||
|
"defaultValue": "2 - Normal"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ bool HeatPump::reachable() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HeatPump::setSgMode(const int &sgMode)
|
void HeatPump::setSgMode(const int &sgMode)
|
||||||
{
|
{
|
||||||
if (m_sgMode != sgMode) {
|
if (m_sgMode != sgMode) {
|
||||||
m_sgMode = sgMode;
|
m_sgMode = sgMode;
|
||||||
qCDebug(dcAwattar) << "Setting sg-mode to" << sgMode;
|
qCDebug(dcAwattar) << "Setting sg-mode to" << sgMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user