devices to things

master
bernhard.trinnes 2020-03-23 11:39:56 +01:00
parent 6af09273e1
commit 227b3abddc
9 changed files with 359 additions and 344 deletions

View File

@ -1,3 +1,9 @@
# Lifx
This plug-in implements the LAN API for Lifx devices
## Supported Things
## Requirements
## More

View File

@ -1,220 +0,0 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
* 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 "devicepluginlifx.h"
#include "devices/device.h"
#include "types/param.h"
#include "plugininfo.h"
#include <QDebug>
#include <QColor>
#include <QRgb>
DevicePluginLifx::DevicePluginLifx()
{
}
void DevicePluginLifx::init()
{
m_connectedStateTypeIds.insert(colorBulbDeviceClassId, colorBulbConnectedStateTypeId);
m_connectedStateTypeIds.insert(dimmableBulbDeviceClassId, dimmableBulbConnectedStateTypeId);
m_powerStateTypeIds.insert(colorBulbDeviceClassId, colorBulbPowerStateTypeId);
m_powerStateTypeIds.insert(dimmableBulbDeviceClassId, dimmableBulbPowerStateTypeId);
m_brightnessStateTypeIds.insert(colorBulbDeviceClassId, colorBulbBrightnessStateTypeId);
m_brightnessStateTypeIds.insert(dimmableBulbDeviceClassId, dimmableBulbBrightnessStateTypeId);
}
void DevicePluginLifx::discoverDevices(DeviceDiscoveryInfo *info)
{
if (!m_lifxConnection) {
m_lifxConnection = new Lifx(this);
m_lifxConnection->enable();
}
if (info->deviceClassId() == colorBulbDeviceClassId) {
}
}
void DevicePluginLifx::setupDevice(DeviceSetupInfo *info)
{
Device *device = info->device();
if (!m_lifxConnection) {
m_lifxConnection = new Lifx(this);
m_lifxConnection->enable();
}
if (device->deviceClassId() == colorBulbDeviceClassId) {
info->finish(Device::DeviceErrorNoError);
}
}
void DevicePluginLifx::postSetupDevice(Device *device)
{
connect(device, &Device::nameChanged, this, &DevicePluginLifx::onDeviceNameChanged);
if (!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
connect(m_pluginTimer, &PluginTimer::timeout, this, [this]() {
});
}
m_pluginTimer->timeout();
}
void DevicePluginLifx::executeAction(DeviceActionInfo *info)
{
Device *device = info->device();
Action action = info->action();
if (!m_lifxConnection)
return info->finish(Device::DeviceErrorHardwareFailure);
if (device->deviceClassId() == colorBulbDeviceClassId) {
if (action.actionTypeId() == colorBulbPowerActionTypeId) {
bool power = action.param(colorBulbPowerActionPowerParamTypeId).value().toBool();
int requestId = m_lifxConnection->setPower(power);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == colorBulbBrightnessActionTypeId) {
if (!device->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
if (m_pendingBrightnessAction.contains(device->id())) {
//Scrap old info and insert new one
m_pendingBrightnessAction.insert(device->id(), info);
} else {
m_pendingBrightnessAction.insert(device->id(), info);
QTimer::singleShot(500, this, [info, this]{
int brightness = info->action().param(colorBulbBrightnessActionBrightnessParamTypeId).value().toInt();
m_pendingBrightnessAction.remove(info->device()->id());
int requestId = m_lifxConnection->setBrightness(brightness);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
});
}
} else if (action.actionTypeId() == colorBulbColorActionColorParamTypeId) {
QRgb color = QColor(action.param(colorBulbColorActionColorParamTypeId).value().toString()).rgba();
if (!device->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setColor(color);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId) {
int colorTemperature = 6500 - (action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toUInt() * -11.12);
if (!device->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setColorTemperature(colorTemperature);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else {
qCWarning(dcLifx()) << "Unhandled action";
}
} else if (device->deviceClassId() == dimmableBulbDeviceClassId) {
if (action.actionTypeId() == dimmableBulbPowerActionTypeId) {
bool power = action.param(dimmableBulbPowerActionPowerParamTypeId).value().toBool();
int requestId = m_lifxConnection->setPower(power);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
} else if (action.actionTypeId() == dimmableBulbBrightnessActionTypeId) {
int brightness = action.param(dimmableBulbBrightnessActionBrightnessParamTypeId).value().toInt();
if (!device->stateValue(dimmableBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setBrightness(brightness);
connect(info, &DeviceActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else {
qCWarning(dcLifx()) << "Unhandled action";
}
} else {
qCWarning(dcLifx()) << "Unhandled device class";
}
}
void DevicePluginLifx::deviceRemoved(Device *device)
{
Q_UNUSED(device)
if (myDevices().isEmpty()) {
m_lifxConnection->deleteLater();
m_lifxConnection = nullptr;
}
}
void DevicePluginLifx::onDeviceNameChanged()
{
Device *device = static_cast<Device*>(sender());
Q_UNUSED(device)
}
void DevicePluginLifx::onConnectionChanged(bool connected)
{
Q_UNUSED(connected)
// device->setStateValue(m_connectedStateTypeIds.value(device->deviceClassId()), connected);
}
void DevicePluginLifx::onRequestExecuted(int requestId, bool success)
{
if (m_asyncActions.contains(requestId)) {
DeviceActionInfo *info = m_asyncActions.take(requestId);
if (success) {
info->finish(Device::DeviceErrorNoError);
} else {
info->finish(Device::DeviceErrorHardwareFailure);
}
}
}
/*void DevicePluginLifx::onPowerNotificationReceived(bool status)
{
Q_UNUSED(status)
Lifx *Lifx = static_cast<Lifx *>(sender());
Device * device = myDevices().findById(m_LifxConnections.key(Lifx));
if(!device)
return;
device->setStateValue(m_powerStateTypeIds.value(device->deviceClassId()), status);
}
void DevicePluginLifx::onBrightnessNotificationReceived(int percentage)
{
Q_UNUSED(percentage)
Lifx *lifx = static_cast<Lifx *>(sender());
Device * device = myDevices().findById(m_lifxConnections.key(lifx));
if(!device)
return;
device->setStateValue(m_brightnessStateTypeIds.value(device->deviceClassId()), percentage);
}*/

View File

@ -1,78 +0,0 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
* 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 DEVICEPLUGINLIFX_H
#define DEVICEPLUGINLIFX_H
#include "devices/deviceplugin.h"
#include "plugintimer.h"
#include "lifx.h"
#include <QTimer>
class DevicePluginLifx : public DevicePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "io.nymea.DevicePlugin" FILE "devicepluginlifx.json")
Q_INTERFACES(DevicePlugin)
public:
explicit DevicePluginLifx();
void init() override;
void discoverDevices(DeviceDiscoveryInfo *info) override;
void setupDevice(DeviceSetupInfo *info) override;
void postSetupDevice(Device *device) override;
void executeAction(DeviceActionInfo *info) override;
void deviceRemoved(Device *device) override;
private:
PluginTimer *m_pluginTimer = nullptr;
QHash<int, DeviceActionInfo *> m_asyncActions;
Lifx *m_lifxConnection;
QHash<DeviceClassId, StateTypeId> m_connectedStateTypeIds;
QHash<DeviceClassId, StateTypeId> m_powerStateTypeIds;
QHash<DeviceClassId, StateTypeId> m_brightnessStateTypeIds;
QHash<DeviceId, DeviceActionInfo *> m_pendingBrightnessAction;
private slots:
void onDeviceNameChanged();
void onConnectionChanged(bool connected);
void onRequestExecuted(int requestId, bool success);
/*void onPowerNotificationReceived(bool status);
void onBrightnessNotificationReceived(int percentage);
void onColorTemperatureNotificationReceived(int kelvin);
void onRgbNotificationReceived(QRgb rgbColor);
void onNameNotificationReceived(const QString &name);*/
};
#endif // DEVICEPLUGINLIFX_H

View File

@ -0,0 +1,222 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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 "integrationpluginlifx.h"
#include "integrations/integrationplugin.h"
#include "types/param.h"
#include "plugininfo.h"
#include <QDebug>
#include <QColor>
#include <QRgb>
IntegrationPluginLifx::IntegrationPluginLifx()
{
}
void IntegrationPluginLifx::init()
{
m_connectedStateTypeIds.insert(colorBulbThingClassId, colorBulbConnectedStateTypeId);
m_connectedStateTypeIds.insert(dimmableBulbThingClassId, dimmableBulbConnectedStateTypeId);
m_powerStateTypeIds.insert(colorBulbThingClassId, colorBulbPowerStateTypeId);
m_powerStateTypeIds.insert(dimmableBulbThingClassId, dimmableBulbPowerStateTypeId);
m_brightnessStateTypeIds.insert(colorBulbThingClassId, colorBulbBrightnessStateTypeId);
m_brightnessStateTypeIds.insert(dimmableBulbThingClassId, dimmableBulbBrightnessStateTypeId);
}
void IntegrationPluginLifx::discoverThings(ThingDiscoveryInfo *info)
{
if (!m_lifxConnection) {
m_lifxConnection = new Lifx(this);
m_lifxConnection->enable();
}
if (info->thingClassId() == colorBulbThingClassId) {
}
}
void IntegrationPluginLifx::setupThing(ThingSetupInfo *info)
{
Thing *thing = info->thing();
if (!m_lifxConnection) {
m_lifxConnection = new Lifx(this);
m_lifxConnection->enable();
}
if (thing->thingClassId() == colorBulbThingClassId) {
info->finish(Thing::ThingErrorNoError);
}
}
void IntegrationPluginLifx::postSetupThing(Thing *thing)
{
connect(thing, &Thing::nameChanged, this, &IntegrationPluginLifx::onDeviceNameChanged);
if (!m_pluginTimer) {
m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(60);
connect(m_pluginTimer, &PluginTimer::timeout, this, [this]() {
});
}
m_pluginTimer->timeout();
}
void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
{
Thing *thing = info->thing();
Action action = info->action();
if (!m_lifxConnection)
return info->finish(Thing::ThingErrorHardwareFailure);
if (thing->thingClassId() == colorBulbThingClassId) {
if (action.actionTypeId() == colorBulbPowerActionTypeId) {
bool power = action.param(colorBulbPowerActionPowerParamTypeId).value().toBool();
int requestId = m_lifxConnection->setPower(power);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == colorBulbBrightnessActionTypeId) {
if (!thing->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
if (m_pendingBrightnessAction.contains(thing->id())) {
//Scrap old info and insert new one
m_pendingBrightnessAction.insert(thing->id(), info);
} else {
m_pendingBrightnessAction.insert(thing->id(), info);
QTimer::singleShot(500, this, [info, this]{
int brightness = info->action().param(colorBulbBrightnessActionBrightnessParamTypeId).value().toInt();
m_pendingBrightnessAction.remove(info->thing()->id());
int requestId = m_lifxConnection->setBrightness(brightness);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
});
}
} else if (action.actionTypeId() == colorBulbColorActionColorParamTypeId) {
QRgb color = QColor(action.param(colorBulbColorActionColorParamTypeId).value().toString()).rgba();
if (!thing->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setColor(color);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId) {
int colorTemperature = 6500 - (action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toUInt() * -11.12);
if (!thing->stateValue(colorBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setColorTemperature(colorTemperature);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else {
qCWarning(dcLifx()) << "Unhandled action";
}
} else if (thing->thingClassId() == dimmableBulbThingClassId) {
if (action.actionTypeId() == dimmableBulbPowerActionTypeId) {
bool power = action.param(dimmableBulbPowerActionPowerParamTypeId).value().toBool();
int requestId = m_lifxConnection->setPower(power);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
} else if (action.actionTypeId() == dimmableBulbBrightnessActionTypeId) {
int brightness = action.param(dimmableBulbBrightnessActionBrightnessParamTypeId).value().toInt();
if (!thing->stateValue(dimmableBulbPowerStateTypeId).toBool())
m_lifxConnection->setPower(true);
int requestId = m_lifxConnection->setBrightness(brightness);
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else {
qCWarning(dcLifx()) << "Unhandled action";
}
} else {
qCWarning(dcLifx()) << "Unhandled device class";
}
}
void IntegrationPluginLifx::thingRemoved(Thing *thing)
{
Q_UNUSED(thing)
if (myThings().isEmpty()) {
m_lifxConnection->deleteLater();
m_lifxConnection = nullptr;
}
}
void IntegrationPluginLifx::onDeviceNameChanged()
{
Thing *thing = static_cast<Thing *>(sender());
Q_UNUSED(thing)
}
void IntegrationPluginLifx::onConnectionChanged(bool connected)
{
Q_UNUSED(connected)
// thing->setStateValue(m_connectedStateTypeIds.value(thing->ThingClassId()), connected);
}
void IntegrationPluginLifx::onRequestExecuted(int requestId, bool success)
{
if (m_asyncActions.contains(requestId)) {
ThingActionInfo *info = m_asyncActions.take(requestId);
if (success) {
info->finish(Thing::ThingErrorNoError);
} else {
info->finish(Thing::ThingErrorHardwareFailure);
}
}
}
/*void IntegrationPluginLifx::onPowerNotificationReceived(bool status)
{
Q_UNUSED(status)
Lifx *Lifx = static_cast<Lifx *>(sender());
Device * device = myThings().findById(m_LifxConnections.key(Lifx));
if(!device)
return;
thing->setStateValue(m_powerStateTypeIds.value(thing->ThingClassId()), status);
}
void IntegrationPluginLifx::onBrightnessNotificationReceived(int percentage)
{
Q_UNUSED(percentage)
Lifx *lifx = static_cast<Lifx *>(sender());
Device * device = myThings().findById(m_lifxConnections.key(lifx));
if(!device)
return;
thing->setStateValue(m_brightnessStateTypeIds.value(thing->ThingClassId()), percentage);
}*/

View File

@ -0,0 +1,80 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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 INTEGRATIONPLUGINLIFX_H
#define INTEGRATIONPLUGINLIFX_H
#include "integrations/integrationplugin.h"
#include "plugintimer.h"
#include "lifx.h"
#include <QTimer>
class IntegrationPluginLifx : public IntegrationPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "io.nymea.IntegrationPlugin" FILE "integrationpluginlifx.json")
Q_INTERFACES(IntegrationPlugin)
public:
explicit IntegrationPluginLifx();
void init() override;
void discoverThings(ThingDiscoveryInfo *info) override;
void setupThing(ThingSetupInfo *info) override;
void postSetupThing(Thing *thing) override;
void executeAction(ThingActionInfo *info) override;
void thingRemoved(Thing *thing) override;
private:
PluginTimer *m_pluginTimer = nullptr;
QHash<int, ThingActionInfo *> m_asyncActions;
Lifx *m_lifxConnection;
QHash<ThingClassId, StateTypeId> m_connectedStateTypeIds;
QHash<ThingClassId, StateTypeId> m_powerStateTypeIds;
QHash<ThingClassId, StateTypeId> m_brightnessStateTypeIds;
QHash<ThingId, ThingActionInfo *> m_pendingBrightnessAction;
private slots:
void onDeviceNameChanged();
void onConnectionChanged(bool connected);
void onRequestExecuted(int requestId, bool success);
/*void onPowerNotificationReceived(bool status);
void onBrightnessNotificationReceived(int percentage);
void onColorTemperatureNotificationReceived(int kelvin);
void onRgbNotificationReceived(QRgb rgbColor);
void onNameNotificationReceived(const QString &name);*/
};
#endif // INTEGRATIONPLUGIN_LIFX_H

View File

@ -7,7 +7,7 @@
"name": "lifx",
"displayName": "LIFX",
"id": "e5e48c0d-cff7-4c0f-983e-d23bd3e4ba87",
"deviceClasses": [
"thingClasses": [
{
"id": "12907c9c-e7f0-47f2-bd58-39d52ffdf24e",
"name": "colorBulb",

View File

@ -1,36 +1,38 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
* 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
* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
* 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.
* 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/>.
* 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
* 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 "lifx.h"
#include "extern-plugininfo.h"
#include <QColor>
#include <QRandomGenerator>
Lifx::Lifx(QObject *parent) :
QObject(parent)
@ -92,7 +94,7 @@ int Lifx::setColorTemperature(int mirad, int msFadeTime)
{
Q_UNUSED(mirad)
Q_UNUSED(msFadeTime)
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
return requestId;
}
@ -101,7 +103,7 @@ int Lifx::setColor(QColor color, int msFadeTime)
{
Q_UNUSED(color)
Q_UNUSED(msFadeTime)
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
return requestId;
}
@ -110,7 +112,7 @@ int Lifx::setBrightness(int percentage, int msFadeTime)
{
Q_UNUSED(percentage)
Q_UNUSED(msFadeTime)
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
Message message;
sendMessage(message);
return requestId;
@ -120,21 +122,21 @@ int Lifx::setPower(bool power, int msFadeTime)
{
Q_UNUSED(power)
Q_UNUSED(msFadeTime)
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
return requestId;
}
int Lifx::flash()
{
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
return requestId;
}
int Lifx::flash15s()
{
int requestId = static_cast<int>(QRandomGenerator::global()->generate());
int requestId = qrand();
return requestId;
}

View File

@ -1,30 +1,34 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, 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
* 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
* This project may also contain libraries licensed under the open source software license GNU GPL v.3.
* 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.
* 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/>.
* 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
* 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 LIFX_H
#define LIFX_H
@ -34,7 +38,6 @@
#include <QUdpSocket>
#include "network/networkaccessmanager.h"
#include "devices/device.h"
#include <QColor>

View File

@ -1,14 +1,14 @@
include(../plugins.pri)
TARGET = $$qtLibraryTarget(nymea_devicepluginlifx)
TARGET = $$qtLibraryTarget(nymea_integrationpluginlifx)
QT += network
SOURCES += \
devicepluginlifx.cpp \
integrationpluginlifx.cpp \
lifx.cpp \
HEADERS += \
devicepluginlifx.h \
integrationpluginlifx.h \
lifx.h \