Implement wanted states and update using signals
This commit is contained in:
parent
f6b81746a6
commit
1a1276366a
@ -100,16 +100,81 @@ void IntegrationPluginMTec::setupThing(ThingSetupInfo *info)
|
|||||||
|
|
||||||
qCDebug(dcMTec()) << "Using ip address" << hostAddress.toString();
|
qCDebug(dcMTec()) << "Using ip address" << hostAddress.toString();
|
||||||
|
|
||||||
// TODO: start timer and give 15 seconds until connected, since the controler is down for ~10 seconds after a disconnect
|
|
||||||
|
|
||||||
MTec *mtec = new MTec(hostAddress, this);
|
MTec *mtec = new MTec(hostAddress, this);
|
||||||
connect(mtec, &MTec::statusUpdated, this, &IntegrationPluginMTec::onStatusUpdated);
|
|
||||||
connect(mtec, &MTec::connectedChanged, thing, [=](bool connected){
|
connect(mtec, &MTec::connectedChanged, thing, [=](bool connected){
|
||||||
qCDebug(dcMTec()) << "Connected changed to" << connected;
|
qCDebug(dcMTec()) << thing << "Connected changed to" << connected;
|
||||||
thing->setStateValue(mtecConnectedStateTypeId, connected);
|
thing->setStateValue(mtecConnectedStateTypeId, connected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::waterTankTemperatureChanged, thing, [=](double waterTankTemperature){
|
||||||
|
qCDebug(dcMTec()) << thing << "Water tank temperature" << waterTankTemperature << "°C";
|
||||||
|
thing->setStateValue(mtecWaterTankTemperatureStateTypeId, waterTankTemperature);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::bufferTankTemperatureChanged, thing, [=](double bufferTankTemperature){
|
||||||
|
qCDebug(dcMTec()) << thing << "Buffer tank temperature" << bufferTankTemperature << "°C";
|
||||||
|
thing->setStateValue(mtecBufferTankTemperatureStateTypeId, bufferTankTemperature);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::totalAccumulatedElectricalEnergyChanged, thing, [=](double totalAccumulatedElectricalEnergy){
|
||||||
|
qCDebug(dcMTec()) << thing << "Total accumulated energy" << totalAccumulatedElectricalEnergy << "kWh";
|
||||||
|
thing->setStateValue(mtecTotalAccumulatedElectricalEnergyStateTypeId, totalAccumulatedElectricalEnergy);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::heatPumpStateChanged, thing, [=](MTec::HeatpumpState heatPumpState){
|
||||||
|
qCDebug(dcMTec()) << thing << "Heat pump state" << heatPumpState;
|
||||||
|
switch (heatPumpState) {
|
||||||
|
case MTec::HeatpumpStateStandby:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Standby");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStatePreRun:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Pre run");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStateAutomaticHeat:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Automatic heat");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStateDefrost:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Defrost");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStateAutomaticCool:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Automatic cool");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStatePostRun:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Post run");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStateSaftyShutdown:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Safty shutdown");
|
||||||
|
break;
|
||||||
|
case MTec::HeatpumpStateError:
|
||||||
|
thing->setStateValue(mtecHeatPumpStateStateTypeId, "Error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::heatMeterPowerConsumptionChanged, thing, [=](double heatMeterPowerConsumption){
|
||||||
|
qCDebug(dcMTec()) << thing << "Heat meter power consumption" << heatMeterPowerConsumption << "W";
|
||||||
|
thing->setStateValue(mtecHeatMeterPowerConsumptionStateTypeId, heatMeterPowerConsumption);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::energyMeterPowerConsumptionChanged, thing, [=](double energyMeterPowerConsumption){
|
||||||
|
qCDebug(dcMTec()) << thing << "Energy meter power consumption" << energyMeterPowerConsumption << "W";
|
||||||
|
thing->setStateValue(mtecEnergyMeterPowerConsumptionStateTypeId, energyMeterPowerConsumption);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::actualExcessEnergySmartHomeChanged, thing, [=](double actualExcessEnergySmartHome){
|
||||||
|
qCDebug(dcMTec()) << thing << "Smart home energy" << actualExcessEnergySmartHome << "W";
|
||||||
|
thing->setStateValue(mtecSmartHomeEnergyStateTypeId, actualExcessEnergySmartHome);
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(mtec, &MTec::actualOutdoorTemperatureChanged, thing, [=](double actualOutdoorTemperature){
|
||||||
|
qCDebug(dcMTec()) << thing << "Outdoor temperature" << actualOutdoorTemperature << "°C";
|
||||||
|
thing->setStateValue(mtecOutdoorTemperatureStateTypeId, actualOutdoorTemperature);
|
||||||
|
});
|
||||||
|
|
||||||
m_mtecConnections.insert(thing, mtec);
|
m_mtecConnections.insert(thing, mtec);
|
||||||
|
|
||||||
|
// TODO: start timer and give 15 seconds until connected, since the controler is down for ~10 seconds after a disconnect
|
||||||
|
|
||||||
if (!mtec->connectDevice()) {
|
if (!mtec->connectDevice()) {
|
||||||
qCWarning(dcMTec()) << "Initial connect returned false. Lets wait 15 seconds until the connection can be established.";
|
qCWarning(dcMTec()) << "Initial connect returned false. Lets wait 15 seconds until the connection can be established.";
|
||||||
}
|
}
|
||||||
@ -159,13 +224,6 @@ void IntegrationPluginMTec::executeAction(ThingActionInfo *info)
|
|||||||
// Thing *thing = info->thing();
|
// Thing *thing = info->thing();
|
||||||
// Action action = info->action();
|
// Action action = info->action();
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
||||||
// if (thing->thingClassId() == mtecThingClassId) {
|
|
||||||
// /* if (action.actionTypeId() == mtecPowerActionTypeId) { */
|
|
||||||
|
|
||||||
// } else {
|
|
||||||
// Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginMTec::update(Thing *thing)
|
void IntegrationPluginMTec::update(Thing *thing)
|
||||||
@ -174,25 +232,9 @@ void IntegrationPluginMTec::update(Thing *thing)
|
|||||||
qCDebug(dcMTec()) << "Updating thing" << thing;
|
qCDebug(dcMTec()) << "Updating thing" << thing;
|
||||||
MTec *mtec = m_mtecConnections.value(thing);
|
MTec *mtec = m_mtecConnections.value(thing);
|
||||||
if (!mtec) return;
|
if (!mtec) return;
|
||||||
mtec->requestStatus();
|
mtec->updateValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginMTec::onStatusUpdated(const MTecInfo &info)
|
|
||||||
{
|
|
||||||
MTec *mtec = qobject_cast<MTec *>(sender());
|
|
||||||
Thing *thing = m_mtecConnections.key(mtec);
|
|
||||||
if (!thing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qCDebug(dcMTec()) << "Received status from heat pump" << thing;
|
|
||||||
/* Received a structure holding the status info of the
|
|
||||||
* heat pump. Update the thing states with the individual fields. */
|
|
||||||
thing->setStateValue(mtecActualPowerConsumptionStateTypeId, info.actualPowerConsumption);
|
|
||||||
thing->setStateValue(mtecActualExcessEnergySmartHomeStateTypeId, info.actualExcessEnergySmartHome);
|
|
||||||
thing->setStateValue(mtecActualExcessEnergyElectricityMeterStateTypeId, info.actualExcessEnergyElectricityMeter);
|
|
||||||
thing->setStateValue(mtecExternalSetValueScalingStateTypeId, info.externalSetValueScaling);
|
|
||||||
thing->setStateValue(mtecRequestExternalHeatSourceStateTypeId, info.requestExternalHeatSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
#include "plugintimer.h"
|
#include "plugintimer.h"
|
||||||
|
|
||||||
#include "mtec.h"
|
#include "mtec.h"
|
||||||
#include "mtechelpers.h"
|
|
||||||
|
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
@ -61,7 +60,6 @@ private:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void update(Thing *thing);
|
void update(Thing *thing);
|
||||||
void onStatusUpdated(const MTecInfo &info);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -41,60 +41,91 @@
|
|||||||
"type": "bool",
|
"type": "bool",
|
||||||
"defaultValue": false,
|
"defaultValue": false,
|
||||||
"cached": false
|
"cached": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "545f94d6-f4fd-48fe-bf3b-f193e5cb76e7",
|
||||||
|
"name": "waterTankTemperature",
|
||||||
|
"displayName": "Water tank temperature",
|
||||||
|
"displayNameEvent": "Water tank temperature changed",
|
||||||
|
"unit": "DegreeCelsius",
|
||||||
|
"type": "double",
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "a98e37f8-dcdc-4c4c-aecf-07f376321849",
|
||||||
|
"name": "bufferTankTemperature",
|
||||||
|
"displayName": "Buffer tank temperature",
|
||||||
|
"displayNameEvent": "Buffer tank temperature changed",
|
||||||
|
"unit": "DegreeCelsius",
|
||||||
|
"type": "double",
|
||||||
|
"defaultValue": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "d0c8f168-49b5-47ca-9988-c9922be38dd5",
|
||||||
|
"name": "outdoorTemperature",
|
||||||
|
"displayName": "Outdoor temperature",
|
||||||
|
"displayNameEvent": "Outdoor temperature changed",
|
||||||
|
"unit": "DegreeCelsius",
|
||||||
|
"type": "double",
|
||||||
|
"defaultValue": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "c67c79cf-7369-409f-b170-16c4ece9d25a",
|
"id": "c67c79cf-7369-409f-b170-16c4ece9d25a",
|
||||||
"name": "actualPowerConsumption",
|
"name": "totalAccumulatedElectricalEnergy",
|
||||||
"displayName": "Actual power consumption",
|
"displayName": "Total accumulated electrical energy",
|
||||||
"displayNameEvent": "Actual power consumption changed",
|
"displayNameEvent": "Total accumulated electrical energy changed",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
"unit": "Watt",
|
"unit": "KiloWattHour",
|
||||||
"defaultValue": 0,
|
"defaultValue": 0,
|
||||||
"suggestLogging": true
|
"suggestLogging": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "663718fa-807e-4d85-bd78-61a65f8c0b5e",
|
"id": "1e2037c8-09dc-4396-974c-efa9c486aa65",
|
||||||
"name": "actualExcessEnergySmartHome",
|
"name": "heatPumpState",
|
||||||
"displayName": "Actual excess energy from Smart home System",
|
"displayName": "Heat pump state",
|
||||||
"displayNameEvent": "Actual excess energy from Smart home System changed",
|
"displayNameEvent": "Heat pump state changed",
|
||||||
"displayNameAction": "Change actual excess energy from Smart home System",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "Watt",
|
|
||||||
"defaultValue": 0,
|
|
||||||
"suggestLogging": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "fd94d39c-0db6-497f-a0a5-6c5452cbcaaf",
|
|
||||||
"name": "actualExcessEnergyElectricityMeter",
|
|
||||||
"displayName": "Actual excess energy from Electricity Meter",
|
|
||||||
"displayNameEvent": "Actual excess energy from Electricity Meter changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "Watt",
|
|
||||||
"defaultValue": 0,
|
|
||||||
"suggestLogging": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "087c0296-705b-483a-b1e9-7ce08202c035",
|
|
||||||
"name": "externalSetValueScaling",
|
|
||||||
"displayName": "Control of the heat source by an external control [100%]",
|
|
||||||
"displayNameEvent": "Control of the heat source by an external control [100%] changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "Percentage",
|
|
||||||
"defaultValue": 100,
|
|
||||||
"suggestLogging": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "90b17788-ce63-47e3-b97d-1b025a41ce35",
|
|
||||||
"name": "requestExternalHeatSource",
|
|
||||||
"displayName": "Request external heat source",
|
|
||||||
"displayNameEvent": "Request external heat source changed",
|
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"defaultValue": "No request, external heat source must be turned off",
|
|
||||||
"possibleValues": [
|
"possibleValues": [
|
||||||
"No request, external heat source must be turned off",
|
"Standby",
|
||||||
"External heat source is released and can be switched on",
|
"Pre run",
|
||||||
"External heat source is required and must be turned on"
|
"Automatic heat",
|
||||||
|
"Defrost",
|
||||||
|
"Automatic cool",
|
||||||
|
"Post run",
|
||||||
|
"Safty shutdown",
|
||||||
|
"Error"
|
||||||
],
|
],
|
||||||
|
"defaultValue": "Standby",
|
||||||
|
"suggestLogging": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "581abddc-90d6-4dea-a43c-63b117b335fe",
|
||||||
|
"name": "heatMeterPowerConsumption",
|
||||||
|
"displayName": "Heat meter power consumption",
|
||||||
|
"displayNameEvent": "Heat meter power consumption changed",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Watt",
|
||||||
|
"defaultValue": 0,
|
||||||
|
"suggestLogging": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "fd52a97e-f94d-4529-b479-b74e61f75a89",
|
||||||
|
"name": "energyMeterPowerConsumption",
|
||||||
|
"displayName": "Energy meter power consumption",
|
||||||
|
"displayNameEvent": "Energy meter power consumption changed",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Watt",
|
||||||
|
"defaultValue": 0,
|
||||||
|
"suggestLogging": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b646ea10-ea7e-4eba-bfda-8e3cd38370a7",
|
||||||
|
"name": "smartHomeEnergy",
|
||||||
|
"displayName": "Smart home energy",
|
||||||
|
"displayNameEvent": "Smart home energy changed",
|
||||||
|
"type": "double",
|
||||||
|
"unit": "Watt",
|
||||||
|
"defaultValue": 0,
|
||||||
"suggestLogging": true
|
"suggestLogging": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@ -30,9 +30,6 @@
|
|||||||
|
|
||||||
#include "mtec.h"
|
#include "mtec.h"
|
||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.h"
|
||||||
#include "mtechelpers.h"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
MTec::MTec(const QHostAddress &address, QObject *parent) :
|
MTec::MTec(const QHostAddress &address, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
@ -51,6 +48,7 @@ MTec::MTec(const QHostAddress &address, QObject *parent) :
|
|||||||
|
|
||||||
MTec::~MTec()
|
MTec::~MTec()
|
||||||
{
|
{
|
||||||
|
m_modbusMaster->disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MTec::connectDevice()
|
bool MTec::connectDevice()
|
||||||
@ -63,58 +61,82 @@ void MTec::disconnectDevice()
|
|||||||
m_modbusMaster->disconnectDevice();
|
m_modbusMaster->disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTec::requestStatus()
|
void MTec::updateValues()
|
||||||
{
|
{
|
||||||
if (!m_modbusMaster->connected()) {
|
if (!m_modbusMaster->connected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::ActualPowerConsumption, 1);
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterHotWaterTankTemperature, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MTec::onModbusError()
|
void MTec::onModbusError()
|
||||||
{
|
{
|
||||||
qCWarning(dcMTec()) << "MTec: Received modbus error";
|
qCWarning(dcMTec()) << "Modbus error occured" << m_modbusMaster->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MTec::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
void MTec::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||||
{
|
{
|
||||||
Q_UNUSED(slaveAddress);
|
Q_UNUSED(slaveAddress);
|
||||||
|
|
||||||
switch (modbusRegister) {
|
switch (modbusRegister) {
|
||||||
case ActualPowerConsumption:
|
case RegisterHotWaterTankTemperature:
|
||||||
if (value.length() == 1) {
|
if (value.length() == 1) {
|
||||||
m_info.actualPowerConsumption = MTecHelpers::convertRegisterToFloat(value[0]);
|
m_waterTankTemperature = value[0] / 10.0;
|
||||||
|
emit waterTankTemperatureChanged(m_waterTankTemperature);
|
||||||
}
|
}
|
||||||
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::ActualExcessEnergySmartHome, 1);
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterBufferTankTemperature, 1);
|
||||||
break;
|
break;
|
||||||
case ActualExcessEnergySmartHome:
|
case RegisterBufferTankTemperature:
|
||||||
if (value.length() == 1) {
|
if (value.length() == 1) {
|
||||||
m_info.actualExcessEnergySmartHome = MTecHelpers::convertRegisterToFloat(value[0]);
|
m_bufferTankTemperature = value[0] / 10.0;
|
||||||
|
emit bufferTankTemperatureChanged(m_bufferTankTemperature);
|
||||||
}
|
}
|
||||||
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::ActualExcessEnergyElectricityMeter, 1);
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterTotalAccumulatedElectricalEnergy, 1);
|
||||||
break;
|
break;
|
||||||
case ActualExcessEnergyElectricityMeter:
|
case RegisterTotalAccumulatedElectricalEnergy:
|
||||||
if (value.length() == 1) {
|
if (value.length() == 1) {
|
||||||
m_info.actualExcessEnergyElectricityMeter = MTecHelpers::convertRegisterToFloat(value[0]);
|
m_totalAccumulatedElectricalEnergy = value[0] / 100.0;
|
||||||
|
emit totalAccumulatedElectricalEnergyChanged(m_totalAccumulatedElectricalEnergy);
|
||||||
}
|
}
|
||||||
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::ExternalSetValueScaling, 1);
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterHeatpumpState, 1);
|
||||||
break;
|
break;
|
||||||
case ExternalSetValueScaling:
|
case RegisterHeatpumpState:
|
||||||
if (value.length() == 1) {
|
if (value.length() == 1) {
|
||||||
m_info.externalSetValueScaling = MTecHelpers::convertRegisterToFloat(value[0]);
|
m_heatPumpState = static_cast<HeatpumpState>(value[0]);
|
||||||
|
emit heatPumpStateChanged(m_heatPumpState);
|
||||||
}
|
}
|
||||||
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::RequestExternalHeatSource, 1);
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterHeatMeterPowerConsumption, 1);
|
||||||
break;
|
break;
|
||||||
case RequestExternalHeatSource:
|
case RegisterHeatMeterPowerConsumption:
|
||||||
if (value.length() == 1) {
|
if (value.length() == 1) {
|
||||||
m_info.requestExternalHeatSource = MTecHelpers::externalHeatSourceRequestToString(value[0]);
|
m_heatMeterPowerConsumption = value[0] / 100.0;
|
||||||
|
emit heatMeterPowerConsumptionChanged(m_heatMeterPowerConsumption);
|
||||||
|
}
|
||||||
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterEnergyMeterPowerConsumption, 1);
|
||||||
|
break;
|
||||||
|
case RegisterEnergyMeterPowerConsumption:
|
||||||
|
if (value.length() == 1) {
|
||||||
|
m_energyMeterPowerConsumption = value[0] / 100.0;
|
||||||
|
emit energyMeterPowerConsumptionChanged(m_energyMeterPowerConsumption);
|
||||||
|
}
|
||||||
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterActualExcessEnergySmartHome, 1);
|
||||||
|
break;
|
||||||
|
case RegisterActualExcessEnergySmartHome:
|
||||||
|
if (value.length() == 1) {
|
||||||
|
m_actualExcessEnergySmartHome = value[0] / 100.0;
|
||||||
|
emit actualExcessEnergySmartHomeChanged(m_actualExcessEnergySmartHome);
|
||||||
|
}
|
||||||
|
m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterActualOutdoorTemperature, 1);
|
||||||
|
break;
|
||||||
|
case RegisterActualOutdoorTemperature:
|
||||||
|
if (value.length() == 1) {
|
||||||
|
m_actualOutdoorTemperature = value[0] / 10.0;
|
||||||
|
emit actualOutdoorTemperatureChanged(m_actualOutdoorTemperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: set initialized
|
||||||
|
|
||||||
/* Everything read without errors
|
|
||||||
* -> update status in plugin */
|
|
||||||
emit statusUpdated(m_info);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
102
mtec/mtec.h
102
mtec/mtec.h
@ -36,17 +36,23 @@
|
|||||||
|
|
||||||
#include "../modbus/modbustcpmaster.h"
|
#include "../modbus/modbustcpmaster.h"
|
||||||
|
|
||||||
#include "mtecinfo.h"
|
|
||||||
#include "mtechelpers.h"
|
|
||||||
|
|
||||||
class MTec : public QObject
|
class MTec : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/** Constructor */
|
enum HeatpumpState {
|
||||||
explicit MTec(const QHostAddress &address, QObject *parent = nullptr);
|
HeatpumpStateStandby = 0,
|
||||||
|
HeatpumpStatePreRun = 1,
|
||||||
|
HeatpumpStateAutomaticHeat = 2,
|
||||||
|
HeatpumpStateDefrost = 3,
|
||||||
|
HeatpumpStateAutomaticCool = 4,
|
||||||
|
HeatpumpStatePostRun = 5,
|
||||||
|
HeatpumpStateSaftyShutdown = 7,
|
||||||
|
HeatpumpStateError = 8
|
||||||
|
};
|
||||||
|
Q_ENUM(HeatpumpState)
|
||||||
|
|
||||||
/** Destructor */
|
explicit MTec(const QHostAddress &address, QObject *parent = nullptr);
|
||||||
~MTec();
|
~MTec();
|
||||||
|
|
||||||
inline QHostAddress hostAddress() const { return m_hostAddress; };
|
inline QHostAddress hostAddress() const { return m_hostAddress; };
|
||||||
@ -54,62 +60,70 @@ public:
|
|||||||
bool connectDevice();
|
bool connectDevice();
|
||||||
void disconnectDevice();
|
void disconnectDevice();
|
||||||
|
|
||||||
void requestStatus();
|
void updateValues();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Modbus Unit ID (undocumented, guessing 1 for now) */
|
/** Modbus Unit ID (undocumented, guessing 1 for now) */
|
||||||
static const quint16 ModbusUnitID = 1;
|
static const quint16 ModbusUnitID = 1;
|
||||||
|
|
||||||
/** The following modbus addresses can be read: */
|
/** The following modbus addresses can be read: */
|
||||||
enum RegisterList {
|
enum Register {
|
||||||
/**
|
/* APPL.CtrlAppl.sParam.hotWaterTank[0].topTemp.values.actValue
|
||||||
* APPL.CtrlAppl.sParam.heatpump[0].ElectricEnergyMeter.values.power
|
* Hot water tank top temperature [1/10°C]. */
|
||||||
* Actual power consumtion [W]
|
RegisterHotWaterTankTemperature = 401,
|
||||||
*/
|
|
||||||
ActualPowerConsumption = 707,
|
|
||||||
|
|
||||||
/**
|
/* APPL.CtrlAppl.sParam.bufferTank[0].topTemp.values.actValue
|
||||||
* APPL.CtrlAppl.sIOModule.Virt[0].param.sensor[0]
|
* Buffer Actual top temperature [1/10°C]. */
|
||||||
* Acutal excess energy given from Smart home System [W]
|
RegisterBufferTankTemperature = 601,
|
||||||
*/
|
|
||||||
ActualExcessEnergySmartHome = 1000,
|
|
||||||
|
|
||||||
/**
|
/* APPL.CtrlAppl.sStatisticalData.heatpump[0].consumption.electricalenergy
|
||||||
* APPL.CtrlAppl.sParam.photovoltaics.ElectricEnergyMeter.values.power
|
* Total accumulated electrical energy [kWh] */
|
||||||
* Acutal excess energy given from Electricity Meter [W]
|
RegisterTotalAccumulatedElectricalEnergy = 702,
|
||||||
*/
|
|
||||||
ActualExcessEnergyElectricityMeter = 1002,
|
|
||||||
|
|
||||||
/**
|
/* APPL.CtrlAppl.sParam.heatpump[0].values.heatpumpState */
|
||||||
* APPL.CtrlAppl.sParam.extHeatSource[0].param.externalSetvalueScaled
|
RegisterHeatpumpState = 703,
|
||||||
* Control of the heat source by an external control [100%]
|
|
||||||
*/
|
/* APPL.CtrlAppl.sParam.heatpump[0].HeatMeter.values.power
|
||||||
ExternalSetValueScaling = 1600,
|
* Actual power consumtion [W] */
|
||||||
|
RegisterHeatMeterPowerConsumption = 706,
|
||||||
|
|
||||||
|
/* APPL.CtrlAppl.sParam.heatpump[0].ElectricEnergyMeter.values.power
|
||||||
|
* Actual power consumtion [W] */
|
||||||
|
RegisterEnergyMeterPowerConsumption = 707,
|
||||||
|
|
||||||
|
/* APPL.CtrlAppl.sIOModule.Virt[0].param.sensor[0]
|
||||||
|
* Acutal excess energy given from Smart home System [W] */
|
||||||
|
RegisterActualExcessEnergySmartHome = 1000,
|
||||||
|
|
||||||
|
/* APPL.CtrlAppl.sParam.outdoorTemp.values.actValue
|
||||||
|
* Actual exterior temperature [°C] */
|
||||||
|
RegisterActualOutdoorTemperature = 1502,
|
||||||
|
|
||||||
/**
|
|
||||||
* APPL.CtrlAppl.sParam.extHeatSource[0].values.requestExtHeatsource
|
|
||||||
* 0…no request, external heat source must be turned off.
|
|
||||||
* 1…external heat source is released and can be switched on.
|
|
||||||
* 2…external heat source is required and must be turned on.
|
|
||||||
*/
|
|
||||||
RequestExternalHeatSource = 1601
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Note: This class only requires one IP address and one
|
|
||||||
* TCP Modbus connection. Multiple devices are managed
|
|
||||||
* within the IntegrationPluginMTec class. */
|
|
||||||
QHostAddress m_hostAddress;
|
QHostAddress m_hostAddress;
|
||||||
|
|
||||||
/** Pointer to ModbusTCPMaster object, responseible for low-level communicaiton */
|
|
||||||
ModbusTCPMaster *m_modbusMaster = nullptr;
|
ModbusTCPMaster *m_modbusMaster = nullptr;
|
||||||
|
|
||||||
/** This structure is filled by the receivedStatus... functions */
|
double m_waterTankTemperature = 0;
|
||||||
MTecInfo m_info ;
|
double m_bufferTankTemperature = 0;
|
||||||
|
double m_totalAccumulatedElectricalEnergy = 0;
|
||||||
|
HeatpumpState m_heatPumpState = HeatpumpStateStandby;
|
||||||
|
double m_heatMeterPowerConsumption = 0;
|
||||||
|
double m_energyMeterPowerConsumption = 0;
|
||||||
|
double m_actualExcessEnergySmartHome = 0;
|
||||||
|
double m_actualOutdoorTemperature = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectedChanged(bool connected);
|
void connectedChanged(bool connected);
|
||||||
void statusUpdated(const MTecInfo &info);
|
|
||||||
|
void waterTankTemperatureChanged(double waterTankTemperature);
|
||||||
|
void bufferTankTemperatureChanged(double bufferTankTemperature);
|
||||||
|
void totalAccumulatedElectricalEnergyChanged(double totalAccumulatedElectricalEnergy);
|
||||||
|
void heatPumpStateChanged(HeatpumpState heatPumpState);
|
||||||
|
void heatMeterPowerConsumptionChanged(double heatMeterPowerConsumption);
|
||||||
|
void energyMeterPowerConsumptionChanged(double energyMeterPowerConsumption);
|
||||||
|
void actualExcessEnergySmartHomeChanged(double actualExcessEnergySmartHome);
|
||||||
|
void actualOutdoorTemperatureChanged(double actualOutdoorTemperature);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onModbusError();
|
void onModbusError();
|
||||||
|
|||||||
@ -6,14 +6,11 @@ QT += \
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
mtec.cpp \
|
mtec.cpp \
|
||||||
mtechelpers.cpp \
|
|
||||||
integrationpluginmtec.cpp \
|
integrationpluginmtec.cpp \
|
||||||
../modbus/modbustcpmaster.cpp
|
../modbus/modbustcpmaster.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
mtec.h \
|
mtec.h \
|
||||||
mtechelpers.h \
|
|
||||||
mtecinfo.h \
|
|
||||||
integrationpluginmtec.h \
|
integrationpluginmtec.h \
|
||||||
../modbus/modbustcpmaster.h \
|
../modbus/modbustcpmaster.h \
|
||||||
|
|
||||||
|
|||||||
@ -1,87 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2021, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU Lesser General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU Lesser General Public License as published by the Free
|
|
||||||
* Software Foundation; version 3. This project is distributed in the hope that
|
|
||||||
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#include "mtechelpers.h"
|
|
||||||
|
|
||||||
float MTecHelpers::convertRegisterToFloat(const quint16 reg)
|
|
||||||
{
|
|
||||||
float value = 0.0;
|
|
||||||
|
|
||||||
value = reg/100.0;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MTecHelpers::convertFloatToRegister(quint16 ®, float value)
|
|
||||||
{
|
|
||||||
reg = qRound(value * 100.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MTecHelpers::connectionStateToString(ConnectionState state)
|
|
||||||
{
|
|
||||||
QString str{};
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case Offline:
|
|
||||||
str = QT_TR_NOOP("Off");
|
|
||||||
break;
|
|
||||||
case Connecting:
|
|
||||||
str = QT_TR_NOOP("Connecting");
|
|
||||||
break;
|
|
||||||
case Online:
|
|
||||||
str = QT_TR_NOOP("Connected");
|
|
||||||
break;
|
|
||||||
case Error:
|
|
||||||
str = QT_TR_NOOP("Error");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString MTecHelpers::externalHeatSourceRequestToString(quint16 value)
|
|
||||||
{
|
|
||||||
QString str{};
|
|
||||||
|
|
||||||
switch (value) {
|
|
||||||
case 0:
|
|
||||||
str = QT_TR_NOOP("No request, external heat source must be turned off");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
str = QT_TR_NOOP("External heat source is released and can be switched on");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
str = QT_TR_NOOP("External heat source is required and must be turned on");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2021, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU Lesser General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU Lesser General Public License as published by the Free
|
|
||||||
* Software Foundation; version 3. This project is distributed in the hope that
|
|
||||||
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#ifndef MTECHELPERS_H
|
|
||||||
#define MTECHELPERS_H
|
|
||||||
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
class MTecHelpers : public QObject {
|
|
||||||
public:
|
|
||||||
enum ConnectionState {
|
|
||||||
Offline,
|
|
||||||
Connecting,
|
|
||||||
Online,
|
|
||||||
Error
|
|
||||||
};
|
|
||||||
Q_ENUM(ConnectionState);
|
|
||||||
|
|
||||||
static float convertRegisterToFloat(quint16 reg);
|
|
||||||
static void convertFloatToRegister(quint16 ®, float value);
|
|
||||||
|
|
||||||
static QString connectionStateToString(ConnectionState state);
|
|
||||||
static QString externalHeatSourceRequestToString(quint16 value);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@ -1,59 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* Copyright 2013 - 2021, nymea GmbH
|
|
||||||
* Contact: contact@nymea.io
|
|
||||||
*
|
|
||||||
* This file is part of nymea.
|
|
||||||
* This project including source code and documentation is protected by
|
|
||||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
|
||||||
* reproduction, publication, editing and translation, are reserved. The use of
|
|
||||||
* this project is subject to the terms of a license agreement to be concluded
|
|
||||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
|
||||||
* under https://nymea.io/license
|
|
||||||
*
|
|
||||||
* GNU Lesser General Public License Usage
|
|
||||||
* Alternatively, this project may be redistributed and/or modified under the
|
|
||||||
* terms of the GNU Lesser General Public License as published by the Free
|
|
||||||
* Software Foundation; version 3. This project is distributed in the hope that
|
|
||||||
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
||||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this project. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For any further details and any questions please contact us under
|
|
||||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
|
||||||
* https://nymea.io/license/faq
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
||||||
|
|
||||||
#ifndef MTECINFO_H
|
|
||||||
#define MTECINFO_H
|
|
||||||
|
|
||||||
#include <QMetaType>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
/** This struct holds the status information that is read from the MTec device
|
|
||||||
* and passed to the nymea framework within this plugin.
|
|
||||||
*/
|
|
||||||
struct MTecInfo {
|
|
||||||
/** Contains more detailed info on the status
|
|
||||||
* (Off, Connecting, Connected, Error) */
|
|
||||||
QString status;
|
|
||||||
|
|
||||||
double actualPowerConsumption;
|
|
||||||
|
|
||||||
double actualExcessEnergySmartHome;
|
|
||||||
|
|
||||||
double actualExcessEnergyElectricityMeter;
|
|
||||||
|
|
||||||
double externalSetValueScaling;
|
|
||||||
|
|
||||||
QString requestExternalHeatSource;
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(MTecInfo);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user