mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-10-23 14:43:44 +02:00
improved thing setup
This commit is contained in:
parent
9db85504c8
commit
25c80753a7
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* 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."));
|
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("This serial port is already in use."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NymeaLightSerialInterface *lightInterface = new NymeaLightSerialInterface(interface, thing);
|
NymeaLightSerialInterface *lightInterface = new NymeaLightSerialInterface(interface, thing);
|
||||||
light = new NymeaLight(lightInterface, this);
|
light = new NymeaLight(lightInterface, this);
|
||||||
lightInterface->setParent(light);
|
lightInterface->setParent(light);
|
||||||
m_usedInterfaces.append(interface);
|
|
||||||
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
} else if (thing->paramValue(nymeaLightThingConnectionTypeParamTypeId).toString() == "Network") {
|
} else if (thing->paramValue(nymeaLightThingConnectionTypeParamTypeId).toString() == "Network") {
|
||||||
if (m_usedInterfaces.contains(interface)) {
|
if (m_lights.contains(thing)) {
|
||||||
m_usedInterfaces.removeAll(interface);
|
|
||||||
qCDebug(dcWs2812fx()) << "Setup after reconfiguration, cleaning up ...";
|
qCDebug(dcWs2812fx()) << "Setup after reconfiguration, cleaning up ...";
|
||||||
|
m_lights.take(thing)->deleteLater();
|
||||||
|
m_usedInterfaces.removeAll(interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QHostAddress(interface).isNull()) {
|
if (QHostAddress(interface).isNull()) {
|
||||||
|
qCWarning(dcWs2812fx()) << "Setup failed, address not valid";
|
||||||
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Address not valid"));
|
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Address not valid"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,40 +92,32 @@ void IntegrationPluginWs2812fx::setupThing(ThingSetupInfo *info)
|
|||||||
NymeaLightTcpInterface *lightInterface = new NymeaLightTcpInterface(QHostAddress(interface), thing);
|
NymeaLightTcpInterface *lightInterface = new NymeaLightTcpInterface(QHostAddress(interface), thing);
|
||||||
light = new NymeaLight(lightInterface, this);
|
light = new NymeaLight(lightInterface, this);
|
||||||
lightInterface->setParent(light);
|
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;
|
qCDebug(dcWs2812fx()) << thing << "available changed" << available;
|
||||||
thing->setStateValue(nymeaLightConnectedStateTypeId, available);
|
thing->setStateValue(nymeaLightConnectedStateTypeId, available);
|
||||||
|
|
||||||
if (available) {
|
if (available) {
|
||||||
|
m_lights.insert(thing, light);
|
||||||
|
m_usedInterfaces.append(interface);
|
||||||
// Set the light to the current states
|
// Set the light to the current states
|
||||||
light->setPower(thing->stateValue(nymeaLightPowerStateTypeId).toBool());
|
light->setPower(thing->stateValue(nymeaLightPowerStateTypeId).toBool());
|
||||||
light->setBrightness(thing->stateValue(nymeaLightBrightnessStateTypeId).toUInt());
|
light->setBrightness(thing->stateValue(nymeaLightBrightnessStateTypeId).toUInt());
|
||||||
light->setColor(thing->stateValue(nymeaLightColorStateTypeId).value<QColor>());
|
light->setColor(thing->stateValue(nymeaLightColorStateTypeId).value<QColor>());
|
||||||
light->setEffect(thing->stateValue(nymeaLightEffectModeStateTypeId).toUInt());
|
light->setEffect(thing->stateValue(nymeaLightEffectModeStateTypeId).toUInt());
|
||||||
light->setSpeed(thing->stateValue(nymeaLightSpeedStateTypeId).toUInt());
|
light->setSpeed(thing->stateValue(nymeaLightSpeedStateTypeId).toUInt());
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
light->enable();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcWs2812fx()) << "ThingClass not supported" << thing->thingClassId();
|
qCWarning(dcWs2812fx()) << "ThingClass not supported" << thing->thingClassId();
|
||||||
return info->finish(Thing::ThingErrorThingClassNotFound);
|
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)
|
void IntegrationPluginWs2812fx::discoverThings(ThingDiscoveryInfo *info)
|
||||||
{
|
{
|
||||||
// Create the list of available serial interfaces
|
// Create the list of available serial interfaces
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2021, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -113,11 +113,10 @@ public:
|
|||||||
explicit IntegrationPluginWs2812fx();
|
explicit IntegrationPluginWs2812fx();
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
void setupThing(ThingSetupInfo *info) override;
|
|
||||||
void postSetupThing(Thing *thing) override;
|
|
||||||
void thingRemoved(Thing *thing) override;
|
|
||||||
void discoverThings(ThingDiscoveryInfo *info) override;
|
void discoverThings(ThingDiscoveryInfo *info) override;
|
||||||
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
void executeAction(ThingActionInfo *info) override;
|
void executeAction(ThingActionInfo *info) override;
|
||||||
|
void thingRemoved(Thing *thing) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<Thing *, NymeaLight *> m_lights;
|
QHash<Thing *, NymeaLight *> m_lights;
|
||||||
|
|||||||
@ -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 <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 "nymealight.h"
|
#include "nymealight.h"
|
||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.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 <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 NYMEALIGHT_H
|
#ifndef NYMEALIGHT_H
|
||||||
#define NYMEALIGHT_H
|
#define NYMEALIGHT_H
|
||||||
|
|
||||||
@ -41,11 +71,9 @@ private:
|
|||||||
NymeaLightInterfaceReply *createReply(const QByteArray &requestData);
|
NymeaLightInterfaceReply *createReply(const QByteArray &requestData);
|
||||||
void sendNextRequest();
|
void sendNextRequest();
|
||||||
|
|
||||||
|
|
||||||
void pollStatus();
|
void pollStatus();
|
||||||
NymeaLightInterfaceReply *getStatus();
|
NymeaLightInterfaceReply *getStatus();
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDataReceived(const QByteArray &data);
|
void onDataReceived(const QByteArray &data);
|
||||||
|
|
||||||
@ -53,6 +81,4 @@ signals:
|
|||||||
void availableChanged(bool available);
|
void availableChanged(bool available);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // NYMEALIGHT_H
|
#endif // 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 <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 NYMEALIGHTINTERFACE_H
|
#ifndef NYMEALIGHTINTERFACE_H
|
||||||
#define NYMEALIGHTINTERFACE_H
|
#define 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 <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 "nymealightserialinterface.h"
|
#include "nymealightserialinterface.h"
|
||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.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 <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 NYMEALIGHTSERIALINTERFACE_H
|
#ifndef NYMEALIGHTSERIALINTERFACE_H
|
||||||
#define NYMEALIGHTSERIALINTERFACE_H
|
#define NYMEALIGHTSERIALINTERFACE_H
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user