Skip to content

Commit

Permalink
Merge PR #489: New Plugin: Simple heat pump
Browse files Browse the repository at this point in the history
  • Loading branch information
nymea-jenkins committed Oct 22, 2021
2 parents e40c0eb + 3f0cb12 commit a998dfc
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 0 deletions.
17 changes: 17 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,22 @@ Description: nymea.io plugin for simulated devices
This package will install the nymea.io plugin for simulated devices


Package: nymea-plugin-simpleheatpump
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
libnymea-gpio,
nymea-plugins-translations,
Description: nymea.io plugin for simple heat pumps
The nymea daemon is a plugin based IoT (Internet of Things) server. The
server works like a translator for devices, things and services and
allows them to interact.
With the powerful rule engine you are able to connect any device available
in the system and create individual scenes and behaviors for your environment.
.
This package will install the nymea.io plugin for simple heat pumps


Package: nymea-plugin-somfytahoma
Architecture: any
Depends: ${shlibs:Depends},
Expand Down Expand Up @@ -1372,6 +1388,7 @@ Depends: nymea-plugin-boblight,
nymea-plugin-remotessh,
nymea-plugin-serialportcommander,
nymea-plugin-systemmonitor,
nymea-plugin-simpleheatpump,
nymea-plugin-onewire,
nymea-plugin-dynatrace,
Description: Meta package for nymea makers, tinkerers and hackers plugins.
Expand Down
1 change: 1 addition & 0 deletions debian/nymea-plugin-simpleheatpump.install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/libnymea_integrationpluginsimpleheatpump.so
1 change: 1 addition & 0 deletions nymea-plugins.pro
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ PLUGIN_DIRS = \
serialportcommander \
sgready \
simulation \
simpleheatpump \
sma \
somfytahoma \
sonos \
Expand Down
4 changes: 4 additions & 0 deletions simpleheatpump/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Simple heat pump

Control heat pumps offering a simple relay interface for boosting the energy consumption when cheap or self produced energy is available.

141 changes: 141 additions & 0 deletions simpleheatpump/integrationpluginsimpleheatpump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Contact: [email protected]
*
* 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
* [email protected] or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "integrationpluginsimpleheatpump.h"
#include "plugininfo.h"

IntegrationPluginSimpleHeatpump::IntegrationPluginSimpleHeatpump()
{

}

void IntegrationPluginSimpleHeatpump::init()
{

}

void IntegrationPluginSimpleHeatpump::discoverThings(ThingDiscoveryInfo *info)
{
// Check if GPIOs are available on this platform
if (!Gpio::isAvailable()) {
qCWarning(dcSimpleHeatPump()) << "There are no GPIOs available on this plattform";
//: Error discovering GPIOs
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs available on this system."));
}

// FIXME: provide once system configurations are loaded

info->finish(Thing::ThingErrorNoError);
}

void IntegrationPluginSimpleHeatpump::setupThing(ThingSetupInfo *info)
{
Thing *thing = info->thing();
qCDebug(dcSimpleHeatPump()) << "Setup" << thing->name() << thing->params();

if (thing->thingClassId() == simpleHeatPumpInterfaceThingClassId) {
// Check if GPIOs are available on this platform
if (!Gpio::isAvailable()) {
qCWarning(dcSimpleHeatPump()) << "There are no GPIOs available on this plattform";
//: Error set up GPIOs
return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("No GPIOs found on this system."));
}

int gpioNumber = thing->paramValue(simpleHeatPumpInterfaceThingGpioNumberParamTypeId).toInt();
bool initialValue = thing->stateValue(simpleHeatPumpInterfaceBoostStateTypeId).toBool();

if (gpioNumber < 0) {
qCWarning(dcSimpleHeatPump()) << "Invalid GPIO number" << gpioNumber;
info->finish(Thing::ThingErrorInvalidParameter);
return;
}

Gpio *gpio = new Gpio(gpioNumber, this);
if (!gpio->exportGpio()) {
qCWarning(dcSimpleHeatPump()) << "Could not export gpio" << gpioNumber;
gpio->deleteLater();
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface."));
}

if (!gpio->setDirection(Gpio::DirectionOutput)) {
qCWarning(dcSimpleHeatPump()) << "Failed to configure gpio" << gpioNumber << "as output";
gpio->deleteLater();
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface."));
}

// Set the pin to the initial value
if (!gpio->setValue(initialValue ? Gpio::ValueHigh : Gpio::ValueLow)) {
qCWarning(dcSimpleHeatPump()) << "Failed to set initially value" << initialValue << "for gpio" << gpioNumber;
gpio->deleteLater();
return info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("Failed to set up the GPIO interface."));
}

m_gpios.insert(thing, gpio);
info->finish(Thing::ThingErrorNoError);
}
}

void IntegrationPluginSimpleHeatpump::postSetupThing(Thing *thing)
{
Q_UNUSED(thing)
}

void IntegrationPluginSimpleHeatpump::thingRemoved(Thing *thing)
{
if (m_gpios.contains(thing)) {
delete m_gpios.take(thing);
}
}

void IntegrationPluginSimpleHeatpump::executeAction(ThingActionInfo *info)
{
Thing *thing = info->thing();

if (thing->thingClassId() == simpleHeatPumpInterfaceThingClassId) {
Gpio *gpio = m_gpios.value(info->thing());
if (!gpio) {
qCWarning(dcSimpleHeatPump()) << "Failed to execute action. There is no GPIO available for" << thing;
info->finish(Thing::ThingErrorHardwareNotAvailable);
return;
}

if (info->action().actionTypeId() == simpleHeatPumpInterfaceBoostActionTypeId) {
bool boostEnabled = info->action().paramValue(simpleHeatPumpInterfaceBoostActionBoostParamTypeId).toBool();
if (!gpio->setValue(boostEnabled ? Gpio::ValueHigh : Gpio::ValueLow)) {
qCWarning(dcSimpleHeatPump()) << "Failed to set the boost mode for" << thing << "to" << boostEnabled;
info->finish(Thing::ThingErrorHardwareFailure);
return;
}

thing->setStateValue(simpleHeatPumpInterfaceBoostStateTypeId, boostEnabled);
info->finish(Thing::ThingErrorNoError);
}
}
}
60 changes: 60 additions & 0 deletions simpleheatpump/integrationpluginsimpleheatpump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2021, nymea GmbH
* Contact: [email protected]
*
* 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
* [email protected] or see our FAQ/Licensing Information on
* https://nymea.io/license/faq
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef INTEGRATIONPLUGINSIMPLEHEATPUMP_H
#define INTEGRATIONPLUGINSIMPLEHEATPUMP_H

#include "integrations/integrationplugin.h"

#include <gpio.h>

class IntegrationPluginSimpleHeatpump : public IntegrationPlugin
{
Q_OBJECT

Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationpluginsimpleheatpump.json")
Q_INTERFACES(IntegrationPlugin)

public:
explicit IntegrationPluginSimpleHeatpump();

void init() override;
void discoverThings(ThingDiscoveryInfo *info) override;
void setupThing(ThingSetupInfo *info) override;
void postSetupThing(Thing *thing) override;
void thingRemoved(Thing *thing) override;
void executeAction(ThingActionInfo *info) override;

private:
QHash<Thing *, Gpio *> m_gpios;

};

#endif // INTEGRATIONPLUGINSIMPLEHEATPUMP_H
47 changes: 47 additions & 0 deletions simpleheatpump/integrationpluginsimpleheatpump.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "SimpleHeatPump",
"displayName": "Simple heat pump",
"id": "6e99e657-7fd6-4c5f-b321-62656c00e1d6",
"vendors": [
{
"name": "nymea",
"displayName": "nymea",
"id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6",
"thingClasses": [
{
"id": "bc553762-c842-422e-888f-6824aad099fb",
"name": "simpleHeatPumpInterface",
"displayName": "Simple heat pump interface",
"createMethods": ["user"],
"interfaces": [ "simpleheatpump" ],
"settingsTypes": [
],
"paramTypes": [
{
"id": "b97d03d9-35ce-445d-903e-b1e3857006ce",
"name": "gpioNumber",
"displayName": "GPIO number",
"type": "int",
"defaultValue": -1
}
],
"stateTypes": [
{
"id": "f8bccedf-5eb2-49a0-b892-c398dbd6a18d",
"name": "boost",
"displayName": "Boost production enabled",
"displayNameEvent": "Boost production changed",
"displayNameAction": "Boost production",
"type": "bool",
"writable": true,
"defaultValue": false,
"cached": true,
"ioType": "digitalOutput",
"suggestLogging": true
}
]
}
]
}
]
}
12 changes: 12 additions & 0 deletions simpleheatpump/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"title": "Simple heat pump",
"tagline": "Control heat pumps offering a simple relay interface for boosting the energy consumption when cheap or self produced energy is available.",
"icon": "",
"stability": "community",
"offline": true,
"technologies": [
],
"categories": [
"heating"
]
}
9 changes: 9 additions & 0 deletions simpleheatpump/simpleheatpump.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(../plugins.pri)

PKGCONFIG += nymea-gpio

SOURCES += \
integrationpluginsimpleheatpump.cpp

HEADERS += \
integrationpluginsimpleheatpump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
<name>IntegrationPluginSimpleHeatpump</name>
<message>
<location filename="../integrationpluginsimpleheatpump.cpp" line="50"/>
<source>No GPIOs available on this system.</source>
<extracomment>Error discovering GPIOs</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginsimpleheatpump.cpp" line="68"/>
<source>No GPIOs found on this system.</source>
<extracomment>Error set up GPIOs</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginsimpleheatpump.cpp" line="84"/>
<location filename="../integrationpluginsimpleheatpump.cpp" line="90"/>
<location filename="../integrationpluginsimpleheatpump.cpp" line="97"/>
<source>Failed to set up the GPIO interface.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SimpleHeatPump</name>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="34"/>
<source>Boost production</source>
<extracomment>The name of the ActionType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="37"/>
<source>Boost production changed</source>
<extracomment>The name of the EventType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="40"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="43"/>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="46"/>
<source>Boost production enabled</source>
<extracomment>The name of the ParamType (ThingClass: simpleHeatPumpInterface, ActionType: boost, ID: {f8bccedf-5eb2-49a0-b892-c398dbd6a18d})
----------
The name of the ParamType (ThingClass: simpleHeatPumpInterface, EventType: boost, ID: {f8bccedf-5eb2-49a0-b892-c398dbd6a18d})
----------
The name of the StateType ({f8bccedf-5eb2-49a0-b892-c398dbd6a18d}) of ThingClass simpleHeatPumpInterface</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="49"/>
<source>GPIO number</source>
<extracomment>The name of the ParamType (ThingClass: simpleHeatPumpInterface, Type: thing, ID: {b97d03d9-35ce-445d-903e-b1e3857006ce})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="52"/>
<source>Simple heat pump</source>
<extracomment>The name of the plugin SimpleHeatPump ({6e99e657-7fd6-4c5f-b321-62656c00e1d6})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="55"/>
<source>Simple heat pump interface</source>
<extracomment>The name of the ThingClass ({bc553762-c842-422e-888f-6824aad099fb})</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../../build-nymea-plugins-Desktop-Debug/simpleheatpump/plugininfo.h" line="58"/>
<source>nymea</source>
<extracomment>The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6})</extracomment>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

0 comments on commit a998dfc

Please sign in to comment.