From 1a1276366a18cd89895e9fbbfb6199329caedc92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 10 Jun 2021 11:25:17 +0200 Subject: [PATCH] Implement wanted states and update using signals --- mtec/integrationpluginmtec.cpp | 98 ++++++++++++++++++-------- mtec/integrationpluginmtec.h | 2 - mtec/integrationpluginmtec.json | 117 ++++++++++++++++++++------------ mtec/mtec.cpp | 72 +++++++++++++------- mtec/mtec.h | 102 ++++++++++++++++------------ mtec/mtec.pro | 3 - mtec/mtechelpers.cpp | 87 ------------------------ mtec/mtechelpers.h | 56 --------------- mtec/mtecinfo.h | 59 ---------------- 9 files changed, 249 insertions(+), 347 deletions(-) delete mode 100644 mtec/mtechelpers.cpp delete mode 100644 mtec/mtechelpers.h delete mode 100644 mtec/mtecinfo.h diff --git a/mtec/integrationpluginmtec.cpp b/mtec/integrationpluginmtec.cpp index a15ba43..eabef90 100644 --- a/mtec/integrationpluginmtec.cpp +++ b/mtec/integrationpluginmtec.cpp @@ -100,16 +100,81 @@ void IntegrationPluginMTec::setupThing(ThingSetupInfo *info) 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); - connect(mtec, &MTec::statusUpdated, this, &IntegrationPluginMTec::onStatusUpdated); connect(mtec, &MTec::connectedChanged, thing, [=](bool connected){ - qCDebug(dcMTec()) << "Connected changed to" << connected; + qCDebug(dcMTec()) << thing << "Connected changed to" << 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); + + // TODO: start timer and give 15 seconds until connected, since the controler is down for ~10 seconds after a disconnect + if (!mtec->connectDevice()) { 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(); // Action action = info->action(); 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) @@ -174,25 +232,9 @@ void IntegrationPluginMTec::update(Thing *thing) qCDebug(dcMTec()) << "Updating thing" << thing; MTec *mtec = m_mtecConnections.value(thing); if (!mtec) return; - mtec->requestStatus(); + mtec->updateValues(); } } -void IntegrationPluginMTec::onStatusUpdated(const MTecInfo &info) -{ - MTec *mtec = qobject_cast(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); -} diff --git a/mtec/integrationpluginmtec.h b/mtec/integrationpluginmtec.h index 0e7d484..c1302a4 100644 --- a/mtec/integrationpluginmtec.h +++ b/mtec/integrationpluginmtec.h @@ -34,7 +34,6 @@ #include "plugintimer.h" #include "mtec.h" -#include "mtechelpers.h" #include @@ -61,7 +60,6 @@ private: private slots: void update(Thing *thing); - void onStatusUpdated(const MTecInfo &info); }; diff --git a/mtec/integrationpluginmtec.json b/mtec/integrationpluginmtec.json index 3ba445c..1ab7f82 100644 --- a/mtec/integrationpluginmtec.json +++ b/mtec/integrationpluginmtec.json @@ -41,60 +41,91 @@ "type": "bool", "defaultValue": 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", - "name": "actualPowerConsumption", - "displayName": "Actual power consumption", - "displayNameEvent": "Actual power consumption changed", + "name": "totalAccumulatedElectricalEnergy", + "displayName": "Total accumulated electrical energy", + "displayNameEvent": "Total accumulated electrical energy changed", "type": "double", - "unit": "Watt", + "unit": "KiloWattHour", "defaultValue": 0, "suggestLogging": true }, { - "id": "663718fa-807e-4d85-bd78-61a65f8c0b5e", - "name": "actualExcessEnergySmartHome", - "displayName": "Actual excess energy from Smart home System", - "displayNameEvent": "Actual excess energy from Smart home System 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", + "id": "1e2037c8-09dc-4396-974c-efa9c486aa65", + "name": "heatPumpState", + "displayName": "Heat pump state", + "displayNameEvent": "Heat pump state changed", "type": "QString", - "defaultValue": "No request, external heat source must be turned off", "possibleValues": [ - "No request, external heat source must be turned off", - "External heat source is released and can be switched on", - "External heat source is required and must be turned on" + "Standby", + "Pre run", + "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 } ], diff --git a/mtec/mtec.cpp b/mtec/mtec.cpp index afa5864..c8fd5bb 100644 --- a/mtec/mtec.cpp +++ b/mtec/mtec.cpp @@ -30,9 +30,6 @@ #include "mtec.h" #include "extern-plugininfo.h" -#include "mtechelpers.h" - -#include MTec::MTec(const QHostAddress &address, QObject *parent) : QObject(parent), @@ -51,6 +48,7 @@ MTec::MTec(const QHostAddress &address, QObject *parent) : MTec::~MTec() { + m_modbusMaster->disconnectDevice(); } bool MTec::connectDevice() @@ -63,58 +61,82 @@ void MTec::disconnectDevice() m_modbusMaster->disconnectDevice(); } -void MTec::requestStatus() +void MTec::updateValues() { if (!m_modbusMaster->connected()) { return; } - m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::ActualPowerConsumption, 1); + m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterHotWaterTankTemperature, 1); } 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 &value) { Q_UNUSED(slaveAddress); switch (modbusRegister) { - case ActualPowerConsumption: + case RegisterHotWaterTankTemperature: 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; - case ActualExcessEnergySmartHome: + case RegisterBufferTankTemperature: 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; - case ActualExcessEnergyElectricityMeter: + case RegisterTotalAccumulatedElectricalEnergy: 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; - case ExternalSetValueScaling: + case RegisterHeatpumpState: if (value.length() == 1) { - m_info.externalSetValueScaling = MTecHelpers::convertRegisterToFloat(value[0]); + m_heatPumpState = static_cast(value[0]); + emit heatPumpStateChanged(m_heatPumpState); } - m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, MTec::RequestExternalHeatSource, 1); + m_modbusMaster->readHoldingRegister(MTec::ModbusUnitID, RegisterHeatMeterPowerConsumption, 1); break; - case RequestExternalHeatSource: + case RegisterHeatMeterPowerConsumption: 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; } } diff --git a/mtec/mtec.h b/mtec/mtec.h index 181da2c..7b20057 100644 --- a/mtec/mtec.h +++ b/mtec/mtec.h @@ -36,17 +36,23 @@ #include "../modbus/modbustcpmaster.h" -#include "mtecinfo.h" -#include "mtechelpers.h" - class MTec : public QObject { Q_OBJECT public: - /** Constructor */ - explicit MTec(const QHostAddress &address, QObject *parent = nullptr); + enum HeatpumpState { + 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(); inline QHostAddress hostAddress() const { return m_hostAddress; }; @@ -54,62 +60,70 @@ public: bool connectDevice(); void disconnectDevice(); - void requestStatus(); + void updateValues(); private: /** Modbus Unit ID (undocumented, guessing 1 for now) */ static const quint16 ModbusUnitID = 1; /** The following modbus addresses can be read: */ - enum RegisterList { - /** - * APPL.CtrlAppl.sParam.heatpump[0].ElectricEnergyMeter.values.power - * Actual power consumtion [W] - */ - ActualPowerConsumption = 707, + enum Register { + /* APPL.CtrlAppl.sParam.hotWaterTank[0].topTemp.values.actValue + * Hot water tank top temperature [1/10°C]. */ + RegisterHotWaterTankTemperature = 401, - /** - * APPL.CtrlAppl.sIOModule.Virt[0].param.sensor[0] - * Acutal excess energy given from Smart home System [W] - */ - ActualExcessEnergySmartHome = 1000, + /* APPL.CtrlAppl.sParam.bufferTank[0].topTemp.values.actValue + * Buffer Actual top temperature [1/10°C]. */ + RegisterBufferTankTemperature = 601, - /** - * APPL.CtrlAppl.sParam.photovoltaics.ElectricEnergyMeter.values.power - * Acutal excess energy given from Electricity Meter [W] - */ - ActualExcessEnergyElectricityMeter = 1002, + /* APPL.CtrlAppl.sStatisticalData.heatpump[0].consumption.electricalenergy + * Total accumulated electrical energy [kWh] */ + RegisterTotalAccumulatedElectricalEnergy = 702, - /** - * APPL.CtrlAppl.sParam.extHeatSource[0].param.externalSetvalueScaled - * Control of the heat source by an external control [100%] - */ - ExternalSetValueScaling = 1600, + /* APPL.CtrlAppl.sParam.heatpump[0].values.heatpumpState */ + RegisterHeatpumpState = 703, + + /* APPL.CtrlAppl.sParam.heatpump[0].HeatMeter.values.power + * 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; - - /** Pointer to ModbusTCPMaster object, responseible for low-level communicaiton */ ModbusTCPMaster *m_modbusMaster = nullptr; - /** This structure is filled by the receivedStatus... functions */ - MTecInfo m_info ; - + double m_waterTankTemperature = 0; + 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: 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: void onModbusError(); diff --git a/mtec/mtec.pro b/mtec/mtec.pro index eaaf6a0..c68ed3b 100644 --- a/mtec/mtec.pro +++ b/mtec/mtec.pro @@ -6,14 +6,11 @@ QT += \ SOURCES += \ mtec.cpp \ - mtechelpers.cpp \ integrationpluginmtec.cpp \ ../modbus/modbustcpmaster.cpp HEADERS += \ mtec.h \ - mtechelpers.h \ - mtecinfo.h \ integrationpluginmtec.h \ ../modbus/modbustcpmaster.h \ diff --git a/mtec/mtechelpers.cpp b/mtec/mtechelpers.cpp deleted file mode 100644 index b57547b..0000000 --- a/mtec/mtechelpers.cpp +++ /dev/null @@ -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 . -* -* 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; -} - diff --git a/mtec/mtechelpers.h b/mtec/mtechelpers.h deleted file mode 100644 index c95ae28..0000000 --- a/mtec/mtechelpers.h +++ /dev/null @@ -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 . -* -* 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 -#include -#include - -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 - diff --git a/mtec/mtecinfo.h b/mtec/mtecinfo.h deleted file mode 100644 index fe87854..0000000 --- a/mtec/mtecinfo.h +++ /dev/null @@ -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 . -* -* 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 -#include - -/** 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 -