diff --git a/ws2812fx/integrationpluginws2812fx.cpp b/ws2812fx/integrationpluginws2812fx.cpp index cc405fcf..5fb6415a 100644 --- a/ws2812fx/integrationpluginws2812fx.cpp +++ b/ws2812fx/integrationpluginws2812fx.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2021, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -72,20 +72,19 @@ void IntegrationPluginWs2812fx::setupThing(ThingSetupInfo *info) info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("This serial port is already in use.")); return; } - NymeaLightSerialInterface *lightInterface = new NymeaLightSerialInterface(interface, thing); light = new NymeaLight(lightInterface, this); lightInterface->setParent(light); - m_usedInterfaces.append(interface); - info->finish(Thing::ThingErrorNoError); } else if (thing->paramValue(nymeaLightThingConnectionTypeParamTypeId).toString() == "Network") { - if (m_usedInterfaces.contains(interface)) { - m_usedInterfaces.removeAll(interface); + if (m_lights.contains(thing)) { qCDebug(dcWs2812fx()) << "Setup after reconfiguration, cleaning up ..."; + m_lights.take(thing)->deleteLater(); + m_usedInterfaces.removeAll(interface); } if (QHostAddress(interface).isNull()) { + qCWarning(dcWs2812fx()) << "Setup failed, address not valid"; info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Address not valid")); return; } @@ -93,40 +92,32 @@ void IntegrationPluginWs2812fx::setupThing(ThingSetupInfo *info) NymeaLightTcpInterface *lightInterface = new NymeaLightTcpInterface(QHostAddress(interface), thing); light = new NymeaLight(lightInterface, this); lightInterface->setParent(light); - m_usedInterfaces.append(interface); - } - m_lights.insert(thing, light); - connect(light, &NymeaLight::availableChanged, thing, [=](bool available){ + connect(light, &NymeaLight::availableChanged, thing, [=] (bool available) { qCDebug(dcWs2812fx()) << thing << "available changed" << available; thing->setStateValue(nymeaLightConnectedStateTypeId, available); if (available) { + m_lights.insert(thing, light); + m_usedInterfaces.append(interface); // Set the light to the current states light->setPower(thing->stateValue(nymeaLightPowerStateTypeId).toBool()); light->setBrightness(thing->stateValue(nymeaLightBrightnessStateTypeId).toUInt()); light->setColor(thing->stateValue(nymeaLightColorStateTypeId).value()); light->setEffect(thing->stateValue(nymeaLightEffectModeStateTypeId).toUInt()); light->setSpeed(thing->stateValue(nymeaLightSpeedStateTypeId).toUInt()); + info->finish(Thing::ThingErrorNoError); } }); + light->enable(); + } else { qCWarning(dcWs2812fx()) << "ThingClass not supported" << thing->thingClassId(); return info->finish(Thing::ThingErrorThingClassNotFound); } } -void IntegrationPluginWs2812fx::postSetupThing(Thing *thing) -{ - qCDebug(dcWs2812fx()) << "Post setup thing" << thing; - if (thing->thingClassId() == nymeaLightThingClassId) { - NymeaLight *light = m_lights.value(thing); - light->enable(); - } -} - - void IntegrationPluginWs2812fx::discoverThings(ThingDiscoveryInfo *info) { // Create the list of available serial interfaces diff --git a/ws2812fx/integrationpluginws2812fx.h b/ws2812fx/integrationpluginws2812fx.h index 65ab9d38..60c69ac4 100644 --- a/ws2812fx/integrationpluginws2812fx.h +++ b/ws2812fx/integrationpluginws2812fx.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2021, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -113,11 +113,10 @@ public: explicit IntegrationPluginWs2812fx(); void init() override; - void setupThing(ThingSetupInfo *info) override; - void postSetupThing(Thing *thing) override; - void thingRemoved(Thing *thing) override; void discoverThings(ThingDiscoveryInfo *info) override; + void setupThing(ThingSetupInfo *info) override; void executeAction(ThingActionInfo *info) override; + void thingRemoved(Thing *thing) override; private: QHash m_lights; diff --git a/ws2812fx/nymealight.cpp b/ws2812fx/nymealight.cpp index 47436b9e..57286471 100644 --- a/ws2812fx/nymealight.cpp +++ b/ws2812fx/nymealight.cpp @@ -1,3 +1,33 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 "nymealight.h" #include "extern-plugininfo.h" diff --git a/ws2812fx/nymealight.h b/ws2812fx/nymealight.h index f1cc848d..16d326df 100644 --- a/ws2812fx/nymealight.h +++ b/ws2812fx/nymealight.h @@ -1,3 +1,33 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 NYMEALIGHT_H #define NYMEALIGHT_H @@ -41,11 +71,9 @@ private: NymeaLightInterfaceReply *createReply(const QByteArray &requestData); void sendNextRequest(); - void pollStatus(); NymeaLightInterfaceReply *getStatus(); - private slots: void onDataReceived(const QByteArray &data); @@ -53,6 +81,4 @@ signals: void availableChanged(bool available); }; - - #endif // NYMEALIGHT_H diff --git a/ws2812fx/nymealightinterface.h b/ws2812fx/nymealightinterface.h index d088d1a2..6810223b 100644 --- a/ws2812fx/nymealightinterface.h +++ b/ws2812fx/nymealightinterface.h @@ -1,3 +1,33 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 NYMEALIGHTINTERFACE_H #define NYMEALIGHTINTERFACE_H diff --git a/ws2812fx/nymealightserialinterface.cpp b/ws2812fx/nymealightserialinterface.cpp index ea831516..f8b384b1 100644 --- a/ws2812fx/nymealightserialinterface.cpp +++ b/ws2812fx/nymealightserialinterface.cpp @@ -1,3 +1,33 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 "nymealightserialinterface.h" #include "extern-plugininfo.h" diff --git a/ws2812fx/nymealightserialinterface.h b/ws2812fx/nymealightserialinterface.h index beb4863a..a7752203 100644 --- a/ws2812fx/nymealightserialinterface.h +++ b/ws2812fx/nymealightserialinterface.h @@ -1,3 +1,33 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* 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 NYMEALIGHTSERIALINTERFACE_H #define NYMEALIGHTSERIALINTERFACE_H