Merge PR #118: Philips Hue: Add support for the hue indoor motion sensor

This commit is contained in:
Jenkins 2019-07-22 12:17:13 +02:00
commit bab355721e
99 changed files with 1239 additions and 991 deletions

View File

@ -169,7 +169,7 @@ void DevicePluginAnel::init()
{ {
} }
DeviceManager::DeviceError DevicePluginAnel::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginAnel::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
Q_UNUSED(params) Q_UNUSED(params)
@ -184,7 +184,7 @@ DeviceManager::DeviceError DevicePluginAnel::discoverDevices(const DeviceClassId
if (len != discoveryString.length()) { if (len != discoveryString.length()) {
searchSocket->deleteLater(); searchSocket->deleteLater();
qCWarning(dcAnelElektronik()) << "Error sending discovery"; qCWarning(dcAnelElektronik()) << "Error sending discovery";
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
QTimer::singleShot(2000, this, [this, searchSocket, deviceClassId](){ QTimer::singleShot(2000, this, [this, searchSocket, deviceClassId](){
@ -233,10 +233,10 @@ DeviceManager::DeviceError DevicePluginAnel::discoverDevices(const DeviceClassId
emit devicesDiscovered(deviceClassId, descriptorList); emit devicesDiscovered(deviceClassId, descriptorList);
searchSocket->deleteLater(); searchSocket->deleteLater();
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginAnel::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginAnel::setupDevice(Device *device)
{ {
if (device->deviceClassId() == netPwrCtlHomeDeviceClassId if (device->deviceClassId() == netPwrCtlHomeDeviceClassId
|| device->deviceClassId() == netPwrCtlProDeviceClassId) { || device->deviceClassId() == netPwrCtlProDeviceClassId) {
@ -253,11 +253,11 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupDevice(Device *device)
m_pollTimer = hardwareManager()->pluginTimerManager()->registerTimer(2); m_pollTimer = hardwareManager()->pluginTimerManager()->registerTimer(2);
connect(m_pollTimer, &PluginTimer::timeout, this, &DevicePluginAnel::refreshStates); connect(m_pollTimer, &PluginTimer::timeout, this, &DevicePluginAnel::refreshStates);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
qCWarning(dcAnelElektronik) << "Unhandled DeviceClass in setupDevice" << device->deviceClassId(); qCWarning(dcAnelElektronik) << "Unhandled DeviceClass in setupDevice" << device->deviceClassId();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginAnel::deviceRemoved(Device *device) void DevicePluginAnel::deviceRemoved(Device *device)
@ -269,7 +269,7 @@ void DevicePluginAnel::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginAnel::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginAnel::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == socketDeviceClassId) { if (device->deviceClassId() == socketDeviceClassId) {
if (action.actionTypeId() == socketPowerActionTypeId) { if (action.actionTypeId() == socketPowerActionTypeId) {
@ -291,15 +291,15 @@ DeviceManager::DeviceError DevicePluginAnel::executeAction(Device *device, const
connect(reply, &QNetworkReply::finished, device, [this, reply, action](){ connect(reply, &QNetworkReply::finished, device, [this, reply, action](){
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcAnelElektronik()) << "Execute action failed:" << reply->error() << reply->errorString(); qCWarning(dcAnelElektronik()) << "Execute action failed:" << reply->error() << reply->errorString();
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareNotAvailable); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareNotAvailable);
} }
qCDebug(dcAnelElektronik()) << "Execute action done."; qCDebug(dcAnelElektronik()) << "Execute action done.";
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(action.id(), Device::DeviceErrorNoError);
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginAnel::refreshStates() void DevicePluginAnel::refreshStates()
@ -326,7 +326,7 @@ void DevicePluginAnel::setConnectedState(Device *device, bool connected)
} }
} }
DeviceManager::DeviceSetupStatus DevicePluginAnel::setupHomeProDevice(Device *device) Device::DeviceSetupStatus DevicePluginAnel::setupHomeProDevice(Device *device)
{ {
QString ipAddress = device->paramValue(m_ipAddressParamTypeIdMap.value(device->deviceClassId())).toString(); QString ipAddress = device->paramValue(m_ipAddressParamTypeIdMap.value(device->deviceClassId())).toString();
int port = device->paramValue(m_portParamTypeIdMap.value(device->deviceClassId())).toInt(); int port = device->paramValue(m_portParamTypeIdMap.value(device->deviceClassId())).toInt();
@ -344,7 +344,7 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupHomeProDevice(Device *de
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcAnelElektronik()) << "Error fetching state for" << device->name() << reply->error() << reply->errorString(); qCWarning(dcAnelElektronik()) << "Error fetching state for" << device->name() << reply->error() << reply->errorString();
device->setStateValue(connectedStateTypeId, false); device->setStateValue(connectedStateTypeId, false);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
device->setStateValue(connectedStateTypeId, true); device->setStateValue(connectedStateTypeId, true);
@ -356,12 +356,12 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupHomeProDevice(Device *de
int startIndex = parts.indexOf("end") - 58; int startIndex = parts.indexOf("end") - 58;
if (startIndex < 0 || !parts.at(startIndex).startsWith("NET-PWRCTRL") || parts.length() < 60) { if (startIndex < 0 || !parts.at(startIndex).startsWith("NET-PWRCTRL") || parts.length() < 60) {
qCWarning(dcAnelElektronik()) << "Bad data from panel:" << data << "Length:" << parts.length(); qCWarning(dcAnelElektronik()) << "Bad data from panel:" << data << "Length:" << parts.length();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
// At this point we're done with gathering information about the panel. Setup defintely succeeded for the gateway device // At this point we're done with gathering information about the panel. Setup defintely succeeded for the gateway device
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
// If we haven't set up childs for this gateway yet, let's do it now // If we haven't set up childs for this gateway yet, let's do it now
foreach (Device *child, myDevices()) { foreach (Device *child, myDevices()) {
@ -390,10 +390,10 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupHomeProDevice(Device *de
emit autoDevicesAppeared(socketDeviceClassId, descriptorList); emit autoDevicesAppeared(socketDeviceClassId, descriptorList);
}); });
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginAnel::setupAdvDevice(Device *device) Device::DeviceSetupStatus DevicePluginAnel::setupAdvDevice(Device *device)
{ {
QString ipAddress = device->paramValue(m_ipAddressParamTypeIdMap.value(device->deviceClassId())).toString(); QString ipAddress = device->paramValue(m_ipAddressParamTypeIdMap.value(device->deviceClassId())).toString();
int port = device->paramValue(m_portParamTypeIdMap.value(device->deviceClassId())).toInt(); int port = device->paramValue(m_portParamTypeIdMap.value(device->deviceClassId())).toInt();
@ -411,7 +411,7 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupAdvDevice(Device *device
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcAnelElektronik()) << "Error fetching state for" << device->name() << reply->error() << reply->errorString(); qCWarning(dcAnelElektronik()) << "Error fetching state for" << device->name() << reply->error() << reply->errorString();
device->setStateValue(connectedStateTypeId, false); device->setStateValue(connectedStateTypeId, false);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
device->setStateValue(connectedStateTypeId, true); device->setStateValue(connectedStateTypeId, true);
@ -423,12 +423,12 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupAdvDevice(Device *device
int startIndex = parts.indexOf("end") - 40; int startIndex = parts.indexOf("end") - 40;
if (startIndex < 0 || parts.length() < 58) { if (startIndex < 0 || parts.length() < 58) {
qCWarning(dcAnelElektronik()) << "Bad data from panel:" << data << "Length:" << parts.length(); qCWarning(dcAnelElektronik()) << "Bad data from panel:" << data << "Length:" << parts.length();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
// At this point we're done with gathering information about the panel. Setup defintely succeeded for the gateway device // At this point we're done with gathering information about the panel. Setup defintely succeeded for the gateway device
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
// If we haven't set up childs for this gateway yet, let's do it now // If we haven't set up childs for this gateway yet, let's do it now
foreach (Device *child, myDevices()) { foreach (Device *child, myDevices()) {
@ -448,7 +448,7 @@ DeviceManager::DeviceSetupStatus DevicePluginAnel::setupAdvDevice(Device *device
emit autoDevicesAppeared(socketDeviceClassId, descriptorList); emit autoDevicesAppeared(socketDeviceClassId, descriptorList);
}); });
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginAnel::refreshHomePro(Device *device) void DevicePluginAnel::refreshHomePro(Device *device)

View File

@ -21,8 +21,7 @@
#ifndef DEVICEPLUGINANEL_H #ifndef DEVICEPLUGINANEL_H
#define DEVICEPLUGINANEL_H #define DEVICEPLUGINANEL_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include <QUdpSocket> #include <QUdpSocket>
@ -42,10 +41,10 @@ public:
~DevicePluginAnel(); ~DevicePluginAnel();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots: private slots:
void refreshStates(); void refreshStates();
@ -53,8 +52,8 @@ private slots:
private: private:
void setConnectedState(Device *device, bool connected); void setConnectedState(Device *device, bool connected);
DeviceManager::DeviceSetupStatus setupHomeProDevice(Device *device); Device::DeviceSetupStatus setupHomeProDevice(Device *device);
DeviceManager::DeviceSetupStatus setupAdvDevice(Device *device); Device::DeviceSetupStatus setupAdvDevice(Device *device);
void refreshHomePro(Device *device); void refreshHomePro(Device *device);
void refreshAdv(Device *device); void refreshAdv(Device *device);

View File

@ -23,8 +23,7 @@
#include "devicepluginavahimonitor.h" #include "devicepluginavahimonitor.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "platform/platformzeroconfcontroller.h" #include "platform/platformzeroconfcontroller.h"
#include "network/zeroconf/zeroconfservicebrowser.h" #include "network/zeroconf/zeroconfservicebrowser.h"
@ -39,19 +38,19 @@ DevicePluginAvahiMonitor::DevicePluginAvahiMonitor()
} }
DeviceManager::DeviceSetupStatus DevicePluginAvahiMonitor::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginAvahiMonitor::setupDevice(Device *device)
{ {
qCDebug(dcAvahiMonitor()) << "Setup" << device->name() << device->params(); qCDebug(dcAvahiMonitor()) << "Setup" << device->name() << device->params();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginAvahiMonitor::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
if (deviceClassId != avahiDeviceClassId) if (deviceClassId != avahiDeviceClassId)
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
if (!m_serviceBrowser) { if (!m_serviceBrowser) {
m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser(); m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser();
@ -77,7 +76,7 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic
emit devicesDiscovered(avahiDeviceClassId, deviceDescriptors); emit devicesDiscovered(avahiDeviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
void DevicePluginAvahiMonitor::onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry) void DevicePluginAvahiMonitor::onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry)

View File

@ -24,7 +24,7 @@
#ifndef DEVICEPLUGINAVAHIMONITOR_H #ifndef DEVICEPLUGINAVAHIMONITOR_H
#define DEVICEPLUGINAVAHIMONITOR_H #define DEVICEPLUGINAVAHIMONITOR_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "network/zeroconf/zeroconfservicebrowser.h" #include "network/zeroconf/zeroconfservicebrowser.h"
#include "network/zeroconf/zeroconfserviceentry.h" #include "network/zeroconf/zeroconfserviceentry.h"
@ -40,8 +40,8 @@ class DevicePluginAvahiMonitor : public DevicePlugin
public: public:
explicit DevicePluginAvahiMonitor(); explicit DevicePluginAvahiMonitor();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
private slots: private slots:
void onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry); void onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry);

View File

@ -22,7 +22,7 @@
#include "devicepluginawattar.h" #include "devicepluginawattar.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardwaremanager.h" #include "hardwaremanager.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -39,7 +39,7 @@ DevicePluginAwattar::~DevicePluginAwattar()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginAwattar::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginAwattar::setupDevice(Device *device)
{ {
qCDebug(dcAwattar) << "Setup device" << device->name() << device->params(); qCDebug(dcAwattar) << "Setup device" << device->name() << device->params();
@ -48,7 +48,7 @@ DeviceManager::DeviceSetupStatus DevicePluginAwattar::setupDevice(Device *device
if (token.isEmpty() || userUuid.isEmpty()) { if (token.isEmpty() || userUuid.isEmpty()) {
qCWarning(dcAwattar) << "Missing token oder user uuid."; qCWarning(dcAwattar) << "Missing token oder user uuid.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if (!m_pluginTimer) { if (!m_pluginTimer) {
@ -58,7 +58,7 @@ DeviceManager::DeviceSetupStatus DevicePluginAwattar::setupDevice(Device *device
requestPriceData(device, true); requestPriceData(device, true);
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginAwattar::deviceRemoved(Device *device) void DevicePluginAwattar::deviceRemoved(Device *device)
@ -93,7 +93,7 @@ void DevicePluginAwattar::requestPriceData(Device* device, bool setupInProgress)
if (status != 200) { if (status != 200) {
qCWarning(dcAwattar) << "Update reply HTTP error:" << status << reply->errorString(); qCWarning(dcAwattar) << "Update reply HTTP error:" << status << reply->errorString();
if (setupInProgress) { if (setupInProgress) {
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
} else { } else {
device->setStateValue(awattarConnectedStateTypeId, false); device->setStateValue(awattarConnectedStateTypeId, false);
} }
@ -105,14 +105,14 @@ void DevicePluginAwattar::requestPriceData(Device* device, bool setupInProgress)
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcAwattar) << "Update reply JSON error:" << error.errorString(); qCWarning(dcAwattar) << "Update reply JSON error:" << error.errorString();
if (setupInProgress) { if (setupInProgress) {
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
} else { } else {
device->setStateValue(awattarConnectedStateTypeId, false); device->setStateValue(awattarConnectedStateTypeId, false);
} }
return; return;
} }
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
device->setStateValue(awattarConnectedStateTypeId, true); device->setStateValue(awattarConnectedStateTypeId, true);
processPriceData(device, jsonDoc.toVariant().toMap()); processPriceData(device, jsonDoc.toVariant().toMap());

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINAWATTAR_H #ifndef DEVICEPLUGINAWATTAR_H
#define DEVICEPLUGINAWATTAR_H #define DEVICEPLUGINAWATTAR_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "heatpump.h" #include "heatpump.h"
@ -44,7 +44,7 @@ public:
explicit DevicePluginAwattar(); explicit DevicePluginAwattar();
~DevicePluginAwattar(); ~DevicePluginAwattar();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private: private:

View File

@ -21,8 +21,7 @@
#include "devicepluginboblight.h" #include "devicepluginboblight.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "bobclient.h" #include "bobclient.h"
#include "plugininfo.h" #include "plugininfo.h"
@ -164,7 +163,7 @@ QColor DevicePluginBoblight::tempToRgb(int temp)
return QColor(red, green, blue); return QColor(red, green, blue);
} }
DeviceManager::DeviceSetupStatus DevicePluginBoblight::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginBoblight::setupDevice(Device *device)
{ {
if (device->deviceClassId() == boblightServerDeviceClassId) { if (device->deviceClassId() == boblightServerDeviceClassId) {
@ -189,7 +188,7 @@ DeviceManager::DeviceSetupStatus DevicePluginBoblight::setupDevice(Device *devic
m_bobClients.insert(device->id(), bobClient); m_bobClients.insert(device->id(), bobClient);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginBoblight::postSetupDevice(Device *device) void DevicePluginBoblight::postSetupDevice(Device *device)
@ -214,53 +213,53 @@ void DevicePluginBoblight::postSetupDevice(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginBoblight::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginBoblight::executeAction(Device *device, const Action &action)
{ {
if (!device->setupComplete()) { if (!device->setupComplete()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
qCDebug(dcBoblight()) << "Execute action for boblight" << action.params(); qCDebug(dcBoblight()) << "Execute action for boblight" << action.params();
if (device->deviceClassId() == boblightServerDeviceClassId) { if (device->deviceClassId() == boblightServerDeviceClassId) {
BobClient *bobClient = m_bobClients.value(device->id()); BobClient *bobClient = m_bobClients.value(device->id());
if (!bobClient || !bobClient->connected()) { if (!bobClient || !bobClient->connected()) {
qCWarning(dcBoblight()) << "Boblight on" << device->paramValue(boblightServerDeviceHostAddressParamTypeId).toString() << "not connected"; qCWarning(dcBoblight()) << "Boblight on" << device->paramValue(boblightServerDeviceHostAddressParamTypeId).toString() << "not connected";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == boblightServerPriorityActionTypeId) { if (action.actionTypeId() == boblightServerPriorityActionTypeId) {
bobClient->setPriority(action.param(boblightServerPriorityActionPriorityParamTypeId).value().toInt()); bobClient->setPriority(action.param(boblightServerPriorityActionPriorityParamTypeId).value().toInt());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
qCWarning(dcBoblight()) << "Unhandled action" << action.actionTypeId() << "for BoblightServer device" << device; qCWarning(dcBoblight()) << "Unhandled action" << action.actionTypeId() << "for BoblightServer device" << device;
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == boblightDeviceClassId) { if (device->deviceClassId() == boblightDeviceClassId) {
BobClient *bobClient = m_bobClients.value(device->parentId()); BobClient *bobClient = m_bobClients.value(device->parentId());
if (!bobClient || !bobClient->connected()) { if (!bobClient || !bobClient->connected()) {
qCWarning(dcBoblight()) << "Boblight not connected"; qCWarning(dcBoblight()) << "Boblight not connected";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == boblightPowerActionTypeId) { if (action.actionTypeId() == boblightPowerActionTypeId) {
bobClient->setPower(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightPowerActionPowerParamTypeId).value().toBool()); bobClient->setPower(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightPowerActionPowerParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == boblightColorActionTypeId) { if (action.actionTypeId() == boblightColorActionTypeId) {
bobClient->setColor(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightColorActionColorParamTypeId).value().value<QColor>()); bobClient->setColor(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightColorActionColorParamTypeId).value().value<QColor>());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == boblightBrightnessActionTypeId) { if (action.actionTypeId() == boblightBrightnessActionTypeId) {
bobClient->setBrightness(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightBrightnessActionBrightnessParamTypeId).value().toInt()); bobClient->setBrightness(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), action.param(boblightBrightnessActionBrightnessParamTypeId).value().toInt());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == boblightColorTemperatureActionTypeId) { if (action.actionTypeId() == boblightColorTemperatureActionTypeId) {
bobClient->setColor(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), tempToRgb(action.param(boblightColorTemperatureActionColorTemperatureParamTypeId).value().toInt())); bobClient->setColor(device->paramValue(boblightDeviceChannelParamTypeId).toInt(), tempToRgb(action.param(boblightColorTemperatureActionColorTemperatureParamTypeId).value().toInt()));
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginBoblight::onConnectionChanged() void DevicePluginBoblight::onConnectionChanged()

View File

@ -21,7 +21,7 @@
#ifndef DEVICEPLUGINBOBLIGHT_H #ifndef DEVICEPLUGINBOBLIGHT_H
#define DEVICEPLUGINBOBLIGHT_H #define DEVICEPLUGINBOBLIGHT_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "bobclient.h" #include "bobclient.h"
class BobClient; class BobClient;
@ -39,13 +39,13 @@ public:
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
void startMonitoringAutoDevices() override; void startMonitoringAutoDevices() override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots: private slots:
void onConnectionChanged(); void onConnectionChanged();

View File

@ -23,8 +23,7 @@
#include "deviceplugincommandlauncher.h" #include "deviceplugincommandlauncher.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -34,11 +33,11 @@ DevicePluginCommandLauncher::DevicePluginCommandLauncher()
} }
DeviceManager::DeviceSetupStatus DevicePluginCommandLauncher::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginCommandLauncher::setupDevice(Device *device)
{ {
// Application // Application
if(device->deviceClassId() == applicationDeviceClassId) if(device->deviceClassId() == applicationDeviceClassId)
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
// Script // Script
if(device->deviceClassId() == scriptDeviceClassId){ if(device->deviceClassId() == scriptDeviceClassId){
@ -47,23 +46,23 @@ DeviceManager::DeviceSetupStatus DevicePluginCommandLauncher::setupDevice(Device
QFileInfo fileInfo(scriptArguments.first()); QFileInfo fileInfo(scriptArguments.first());
if (!fileInfo.exists()) { if (!fileInfo.exists()) {
qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "does not exist."; qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "does not exist.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if (!fileInfo.isExecutable()) { if (!fileInfo.isExecutable()) {
qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "is not executable. Please check the permissions."; qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "is not executable. Please check the permissions.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if (!fileInfo.isReadable()) { if (!fileInfo.isReadable()) {
qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "is not readable. Please check the permissions."; qCWarning(dcCommandLauncher) << "script " << scriptArguments.first() << "is not readable. Please check the permissions.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginCommandLauncher::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginCommandLauncher::executeAction(Device *device, const Action &action)
{ {
// Application // Application
if (device->deviceClassId() == applicationDeviceClassId ) { if (device->deviceClassId() == applicationDeviceClassId ) {
@ -72,7 +71,7 @@ DeviceManager::DeviceError DevicePluginCommandLauncher::executeAction(Device *de
// check if we already have started the application // check if we already have started the application
if (m_applications.values().contains(device)) { if (m_applications.values().contains(device)) {
if (m_applications.key(device)->state() == QProcess::Running) { if (m_applications.key(device)->state() == QProcess::Running) {
return DeviceManager::DeviceErrorDeviceInUse; return Device::DeviceErrorDeviceInUse;
} }
} }
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
@ -83,21 +82,21 @@ DeviceManager::DeviceError DevicePluginCommandLauncher::executeAction(Device *de
m_startingApplications.insert(process, action.id()); m_startingApplications.insert(process, action.id());
process->start("/bin/bash", QStringList() << "-c" << device->paramValue(applicationDeviceCommandParamTypeId).toString()); process->start("/bin/bash", QStringList() << "-c" << device->paramValue(applicationDeviceCommandParamTypeId).toString());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
// kill application... // kill application...
if (action.actionTypeId() == applicationKillActionTypeId) { if (action.actionTypeId() == applicationKillActionTypeId) {
// check if the application is running... // check if the application is running...
if (!m_applications.values().contains(device)) { if (!m_applications.values().contains(device)) {
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
QProcess *process = m_applications.key(device); QProcess *process = m_applications.key(device);
m_killingApplications.insert(process,action.id()); m_killingApplications.insert(process,action.id());
process->kill(); process->kill();
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Script // Script
@ -107,7 +106,7 @@ DeviceManager::DeviceError DevicePluginCommandLauncher::executeAction(Device *de
// check if we already have started the script // check if we already have started the script
if (m_scripts.values().contains(device)) { if (m_scripts.values().contains(device)) {
if (m_scripts.key(device)->state() == QProcess::Running) { if (m_scripts.key(device)->state() == QProcess::Running) {
return DeviceManager::DeviceErrorDeviceInUse; return Device::DeviceErrorDeviceInUse;
} }
} }
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
@ -118,23 +117,23 @@ DeviceManager::DeviceError DevicePluginCommandLauncher::executeAction(Device *de
m_startingScripts.insert(process, action.id()); m_startingScripts.insert(process, action.id());
process->start("/bin/bash", QStringList() << device->paramValue(scriptDeviceScriptParamTypeId).toString()); process->start("/bin/bash", QStringList() << device->paramValue(scriptDeviceScriptParamTypeId).toString());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
// kill script... // kill script...
if (action.actionTypeId() == scriptKillActionTypeId) { if (action.actionTypeId() == scriptKillActionTypeId) {
// check if the script is running... // check if the script is running...
if (!m_scripts.values().contains(device)) { if (!m_scripts.values().contains(device)) {
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
QProcess *process = m_scripts.key(device); QProcess *process = m_scripts.key(device);
m_killingScripts.insert(process,action.id()); m_killingScripts.insert(process,action.id());
process->kill(); process->kill();
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginCommandLauncher::deviceRemoved(Device *device) void DevicePluginCommandLauncher::deviceRemoved(Device *device)
@ -179,13 +178,13 @@ void DevicePluginCommandLauncher::scriptStateChanged(QProcess::ProcessState stat
switch (state) { switch (state) {
case QProcess::Running: case QProcess::Running:
device->setStateValue(scriptRunningStateTypeId, true); device->setStateValue(scriptRunningStateTypeId, true);
emit actionExecutionFinished(m_startingScripts.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_startingScripts.value(process), Device::DeviceErrorNoError);
m_startingScripts.remove(process); m_startingScripts.remove(process);
break; break;
case QProcess::NotRunning: case QProcess::NotRunning:
device->setStateValue(scriptRunningStateTypeId, false); device->setStateValue(scriptRunningStateTypeId, false);
if (m_killingScripts.contains(process)) { if (m_killingScripts.contains(process)) {
emit actionExecutionFinished(m_killingScripts.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_killingScripts.value(process), Device::DeviceErrorNoError);
m_killingScripts.remove(process); m_killingScripts.remove(process);
} }
break; break;
@ -216,13 +215,13 @@ void DevicePluginCommandLauncher::applicationStateChanged(QProcess::ProcessState
switch (state) { switch (state) {
case QProcess::Running: case QProcess::Running:
device->setStateValue(applicationRunningStateTypeId, true); device->setStateValue(applicationRunningStateTypeId, true);
emit actionExecutionFinished(m_startingApplications.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_startingApplications.value(process), Device::DeviceErrorNoError);
m_startingApplications.remove(process); m_startingApplications.remove(process);
break; break;
case QProcess::NotRunning: case QProcess::NotRunning:
device->setStateValue(applicationRunningStateTypeId, false); device->setStateValue(applicationRunningStateTypeId, false);
if (m_killingApplications.contains(process)) { if (m_killingApplications.contains(process)) {
emit actionExecutionFinished(m_killingApplications.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_killingApplications.value(process), Device::DeviceErrorNoError);
m_killingApplications.remove(process); m_killingApplications.remove(process);
} }
break; break;

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINCOMMANDLAUNCHER_H #ifndef DEVICEPLUGINCOMMANDLAUNCHER_H
#define DEVICEPLUGINCOMMANDLAUNCHER_H #define DEVICEPLUGINCOMMANDLAUNCHER_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QProcess> #include <QProcess>
#include <QFileInfo> #include <QFileInfo>
@ -38,8 +38,8 @@ class DevicePluginCommandLauncher : public DevicePlugin
public: public:
explicit DevicePluginCommandLauncher(); explicit DevicePluginCommandLauncher();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;

View File

@ -23,8 +23,7 @@
#include "devicepluginconrad.h" #include "devicepluginconrad.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
@ -37,19 +36,19 @@ DevicePluginConrad::DevicePluginConrad()
} }
DeviceManager::DeviceSetupStatus DevicePluginConrad::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginConrad::setupDevice(Device *device)
{ {
if (device->deviceClassId() == conradShutterDeviceClassId) if (device->deviceClassId() == conradShutterDeviceClassId)
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action)
{ {
if (!hardwareManager()->radio433()->available()) { if (!hardwareManager()->radio433()->available()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
QList<int> rawData; QList<int> rawData;
@ -65,7 +64,7 @@ DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, con
binCode = "10100000"; binCode = "10100000";
repetitions = 20; repetitions = 20;
} else { } else {
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// append ID // append ID
@ -104,9 +103,9 @@ DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, con
qCDebug(dcConrad) << "Transmitted successfully" << device->name() << action.actionTypeId(); qCDebug(dcConrad) << "Transmitted successfully" << device->name() << action.actionTypeId();
}else{ }else{
qCWarning(dcConrad) << "Could not transmitt" << pluginName() << device->name() << action.actionTypeId(); qCWarning(dcConrad) << "Could not transmitt" << pluginName() << device->name() << action.actionTypeId();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginConrad::radioData(const QList<int> &rawData) void DevicePluginConrad::radioData(const QList<int> &rawData)

View File

@ -24,7 +24,7 @@
#ifndef DEVICEPLUGINCONRAD_H #ifndef DEVICEPLUGINCONRAD_H
#define DEVICEPLUGINCONRAD_H #define DEVICEPLUGINCONRAD_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginConrad : public DevicePlugin class DevicePluginConrad : public DevicePlugin
{ {
@ -36,12 +36,12 @@ class DevicePluginConrad : public DevicePlugin
public: public:
explicit DevicePluginConrad(); explicit DevicePluginConrad();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void radioData(const QList<int> &rawData); void radioData(const QList<int> &rawData);
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -22,8 +22,7 @@
#include "deviceplugindatetime.h" #include "deviceplugindatetime.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardwaremanager.h" #include "hardwaremanager.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -49,19 +48,19 @@ DevicePluginDateTime::DevicePluginDateTime() :
connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::onSecondChanged); connect(m_timer, &QTimer::timeout, this, &DevicePluginDateTime::onSecondChanged);
} }
DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *device)
{ {
// check timezone // check timezone
if(!m_timeZone.isValid()){ if(!m_timeZone.isValid()){
qCWarning(dcDateTime) << "Invalid time zone."; qCWarning(dcDateTime) << "Invalid time zone.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
// date // date
if (device->deviceClassId() == todayDeviceClassId) { if (device->deviceClassId() == todayDeviceClassId) {
if (m_todayDevice != 0) { if (m_todayDevice != 0) {
qCWarning(dcDateTime) << "There is already a date device or not deleted correctly! this should never happen!!"; qCWarning(dcDateTime) << "There is already a date device or not deleted correctly! this should never happen!!";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
m_todayDevice = device; m_todayDevice = device;
qCDebug(dcDateTime) << "Create today device: current time" << m_currentDateTime.currentDateTime().toString(); qCDebug(dcDateTime) << "Create today device: current time" << m_currentDateTime.currentDateTime().toString();
@ -109,7 +108,7 @@ DeviceManager::DeviceSetupStatus DevicePluginDateTime::setupDevice(Device *devic
m_timer->start(); m_timer->start();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginDateTime::postSetupDevice(Device *device) void DevicePluginDateTime::postSetupDevice(Device *device)
@ -150,23 +149,23 @@ void DevicePluginDateTime::deviceRemoved(Device *device)
//startMonitoringAutoDevices(); //startMonitoringAutoDevices();
} }
DeviceManager::DeviceError DevicePluginDateTime::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginDateTime::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == countdownDeviceClassId) { if (device->deviceClassId() == countdownDeviceClassId) {
Countdown *countdown = m_countdowns.value(device); Countdown *countdown = m_countdowns.value(device);
if (action.actionTypeId() == countdownStartActionTypeId) { if (action.actionTypeId() == countdownStartActionTypeId) {
countdown->start(); countdown->start();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == countdownRestartActionTypeId) { } else if (action.actionTypeId() == countdownRestartActionTypeId) {
countdown->restart(); countdown->restart();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == countdownStopActionTypeId) { } else if (action.actionTypeId() == countdownStopActionTypeId) {
countdown->stop(); countdown->stop();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginDateTime::startMonitoringAutoDevices() void DevicePluginDateTime::startMonitoringAutoDevices()

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINDATETIME_H #ifndef DEVICEPLUGINDATETIME_H
#define DEVICEPLUGINDATETIME_H #define DEVICEPLUGINDATETIME_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "alarm.h" #include "alarm.h"
#include "countdown.h" #include "countdown.h"
@ -43,11 +43,11 @@ class DevicePluginDateTime : public DevicePlugin
public: public:
explicit DevicePluginDateTime(); explicit DevicePluginDateTime();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void startMonitoringAutoDevices() override; void startMonitoringAutoDevices() override;

View File

@ -22,7 +22,6 @@
#include "plugininfo.h" #include "plugininfo.h"
#include "devicemanager.h"
#include "deviceplugindaylightsensor.h" #include "deviceplugindaylightsensor.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -45,7 +44,7 @@ DevicePluginDaylightSensor::~DevicePluginDaylightSensor()
} }
DeviceManager::DeviceError DevicePluginDaylightSensor::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginDaylightSensor::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
Q_UNUSED(params) Q_UNUSED(params)
@ -84,14 +83,14 @@ DeviceManager::DeviceError DevicePluginDaylightSensor::discoverDevices(const Dev
emit devicesDiscovered(deviceClassId, results); emit devicesDiscovered(deviceClassId, results);
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginDaylightSensor::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginDaylightSensor::setupDevice(Device *device)
{ {
updateDevice(device); updateDevice(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginDaylightSensor::deviceRemoved(Device *device) void DevicePluginDaylightSensor::deviceRemoved(Device *device)

View File

@ -24,8 +24,7 @@
#define DEVICEPLUGINDAYLIGHTSENSOR_H #define DEVICEPLUGINDAYLIGHTSENSOR_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "plugintimer.h" #include "plugintimer.h"
class DevicePluginDaylightSensor: public DevicePlugin class DevicePluginDaylightSensor: public DevicePlugin
@ -38,8 +37,8 @@ public:
explicit DevicePluginDaylightSensor(); explicit DevicePluginDaylightSensor();
~DevicePluginDaylightSensor() override; ~DevicePluginDaylightSensor() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private slots: private slots:

View File

@ -40,20 +40,20 @@ void DevicePluginDenon::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginDenon::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginDenon::onPluginTimer);
} }
DeviceManager::DeviceSetupStatus DevicePluginDenon::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginDenon::setupDevice(Device *device)
{ {
qCDebug(dcDenon) << "Setup Denon device" << device->paramValue(AVRX1000DeviceIpParamTypeId).toString(); qCDebug(dcDenon) << "Setup Denon device" << device->paramValue(AVRX1000DeviceIpParamTypeId).toString();
// Check if we already have a denon device // Check if we already have a denon device
if (!myDevices().isEmpty()) { if (!myDevices().isEmpty()) {
qCWarning(dcDenon) << "Could not add denon device. Only one denon device allowed."; qCWarning(dcDenon) << "Could not add denon device. Only one denon device allowed.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
QHostAddress address(device->paramValue(AVRX1000DeviceIpParamTypeId).toString()); QHostAddress address(device->paramValue(AVRX1000DeviceIpParamTypeId).toString());
if (address.isNull()) { if (address.isNull()) {
qCWarning(dcDenon) << "Could not parse ip address" << device->paramValue(AVRX1000DeviceIpParamTypeId).toString(); qCWarning(dcDenon) << "Could not parse ip address" << device->paramValue(AVRX1000DeviceIpParamTypeId).toString();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
m_device = device; m_device = device;
@ -65,7 +65,7 @@ DeviceManager::DeviceSetupStatus DevicePluginDenon::setupDevice(Device *device)
m_asyncSetups.append(m_denonConnection); m_asyncSetups.append(m_denonConnection);
m_denonConnection->connectDenon(); m_denonConnection->connectDenon();
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginDenon::deviceRemoved(Device *device) void DevicePluginDenon::deviceRemoved(Device *device)
@ -80,14 +80,14 @@ void DevicePluginDenon::deviceRemoved(Device *device)
m_denonConnection->deleteLater(); m_denonConnection->deleteLater();
} }
DeviceManager::DeviceError DevicePluginDenon::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginDenon::executeAction(Device *device, const Action &action)
{ {
qCDebug(dcDenon) << "Execute action" << device->id() << action.id() << action.params(); qCDebug(dcDenon) << "Execute action" << device->id() << action.id() << action.params();
if (device->deviceClassId() == AVRX1000DeviceClassId) { if (device->deviceClassId() == AVRX1000DeviceClassId) {
// check connection state // check connection state
if (m_denonConnection.isNull() || !m_denonConnection->connected()) if (m_denonConnection.isNull() || !m_denonConnection->connected())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
// check if the requested action is our "update" action ... // check if the requested action is our "update" action ...
if (action.actionTypeId() == AVRX1000PowerActionTypeId) { if (action.actionTypeId() == AVRX1000PowerActionTypeId) {
@ -106,7 +106,7 @@ DeviceManager::DeviceError DevicePluginDenon::executeAction(Device *device, cons
m_denonConnection->sendData(cmd); m_denonConnection->sendData(cmd);
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == AVRX1000VolumeActionTypeId) { } else if (action.actionTypeId() == AVRX1000VolumeActionTypeId) {
@ -116,7 +116,7 @@ DeviceManager::DeviceError DevicePluginDenon::executeAction(Device *device, cons
qCDebug(dcDenon) << "Execute volume" << action.id() << cmd; qCDebug(dcDenon) << "Execute volume" << action.id() << cmd;
m_denonConnection->sendData(cmd); m_denonConnection->sendData(cmd);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == AVRX1000ChannelActionTypeId) { } else if (action.actionTypeId() == AVRX1000ChannelActionTypeId) {
@ -127,11 +127,11 @@ DeviceManager::DeviceError DevicePluginDenon::executeAction(Device *device, cons
qCDebug(dcDenon) << "Change to channel:" << cmd; qCDebug(dcDenon) << "Change to channel:" << cmd;
m_denonConnection->sendData(cmd); m_denonConnection->sendData(cmd);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginDenon::onPluginTimer() void DevicePluginDenon::onPluginTimer()
@ -157,7 +157,7 @@ void DevicePluginDenon::onConnectionChanged()
if (m_asyncSetups.contains(m_denonConnection)) { if (m_asyncSetups.contains(m_denonConnection)) {
m_asyncSetups.removeAll(m_denonConnection); m_asyncSetups.removeAll(m_denonConnection);
m_denonConnection->sendData("PW?\rSI?\rMV?\r"); m_denonConnection->sendData("PW?\rSI?\rMV?\r");
emit deviceSetupFinished(m_device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(m_device, Device::DeviceSetupStatusSuccess);
} }
} }
@ -247,7 +247,7 @@ void DevicePluginDenon::onSocketError()
// Check if setup running for this device // Check if setup running for this device
if (m_asyncSetups.contains(m_denonConnection)) { if (m_asyncSetups.contains(m_denonConnection)) {
qCWarning(dcDenon()) << "Could not add device. The setup failed."; qCWarning(dcDenon()) << "Could not add device. The setup failed.";
emit deviceSetupFinished(m_device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(m_device, Device::DeviceSetupStatusFailure);
// Delete the connection, the device will not be added and // Delete the connection, the device will not be added and
// the connection will be created in the next setup // the connection will be created in the next setup
m_denonConnection->deleteLater(); m_denonConnection->deleteLater();

View File

@ -24,8 +24,7 @@
#ifndef DEVICEPLUGINDENON_H #ifndef DEVICEPLUGINDENON_H
#define DEVICEPLUGINDENON_H #define DEVICEPLUGINDENON_H
#include "devicemanager.h" #include "devices/deviceplugin.h"
#include "plugin/deviceplugin.h"
#include <QHash> #include <QHash>
@ -49,9 +48,9 @@ public:
~DevicePluginDenon(); ~DevicePluginDenon();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;

View File

@ -49,7 +49,7 @@ void DevicePluginDweetio::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginDweetio::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginDweetio::onPluginTimer);
} }
DeviceManager::DeviceSetupStatus DevicePluginDweetio::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginDweetio::setupDevice(Device *device)
{ {
if (device->deviceClassId() == postDeviceClassId) { if (device->deviceClassId() == postDeviceClassId) {
@ -59,12 +59,12 @@ DeviceManager::DeviceSetupStatus DevicePluginDweetio::setupDevice(Device *device
qDebug(dcDweetio) << "No thing name given, creating one"; qDebug(dcDweetio) << "No thing name given, creating one";
thing = QUuid::createUuid().toString(); thing = QUuid::createUuid().toString();
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == getDeviceClassId) { } else if (device->deviceClassId() == getDeviceClassId) {
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginDweetio::postSetupDevice(Device *device) void DevicePluginDweetio::postSetupDevice(Device *device)
@ -93,7 +93,7 @@ void DevicePluginDweetio::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginDweetio::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginDweetio::executeAction(Device *device, const Action &action)
{ {
qCDebug(dcDweetio) << "Execute action" << device->id() << action.id() << action.params(); qCDebug(dcDweetio) << "Execute action" << device->id() << action.id() << action.params();
@ -104,11 +104,11 @@ DeviceManager::DeviceError DevicePluginDweetio::executeAction(Device *device, co
QString content = action.param(postContentDataActionContentDataAreaParamTypeId).value().toString(); QString content = action.param(postContentDataActionContentDataAreaParamTypeId).value().toString();
postContent(content, device, action); postContent(content, device, action);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginDweetio::postContent(const QString &content, Device *device, const Action &action) void DevicePluginDweetio::postContent(const QString &content, Device *device, const Action &action)
@ -174,13 +174,13 @@ void DevicePluginDweetio::onNetworkReplyFinished()
// check HTTP status code // check HTTP status code
if ((status != 200) && (status != 204)) { if ((status != 200) && (status != 204)) {
qCWarning(dcDweetio) << "Update reply HTTP error:" << status << reply->errorString() << reply->readAll(); qCWarning(dcDweetio) << "Update reply HTTP error:" << status << reply->errorString() << reply->readAll();
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorMissingParameter); emit actionExecutionFinished(actionId, Device::DeviceErrorMissingParameter);
setConnectionStatus(false, device); setConnectionStatus(false, device);
reply->deleteLater(); reply->deleteLater();
return; return;
} }
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
setConnectionStatus(true, device); setConnectionStatus(true, device);
if (status == 204){ if (status == 204){
reply->deleteLater(); reply->deleteLater();

View File

@ -23,8 +23,7 @@
#ifndef DEVICEPLUGINDWEETIO_H #ifndef DEVICEPLUGINDWEETIO_H
#define DEVICEPLUGINDWEETIO_H #define DEVICEPLUGINDWEETIO_H
#include "devicemanager.h" #include "devices/deviceplugin.h"
#include "plugin/deviceplugin.h"
#include <QHash> #include <QHash>
#include <QObject> #include <QObject>
@ -46,9 +45,9 @@ public:
~DevicePluginDweetio(); ~DevicePluginDweetio();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
private: private:

View File

@ -28,7 +28,7 @@
#include <QColor> #include <QColor>
#include "typeutils.h" #include "typeutils.h"
#include "plugin/device.h" #include "devices/device.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
static QBluetoothUuid colorServiceUuid = QBluetoothUuid(QUuid("f815e810-456c-6761-746f-4d756e696368")); static QBluetoothUuid colorServiceUuid = QBluetoothUuid(QUuid("f815e810-456c-6761-746f-4d756e696368"));

View File

@ -375,8 +375,7 @@
#include "devicepluginelgato.h" #include "devicepluginelgato.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h"
@ -396,25 +395,25 @@ void DevicePluginElgato::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginElgato::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginElgato::onPluginTimer);
} }
DeviceManager::DeviceError DevicePluginElgato::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginElgato::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
if (deviceClassId != aveaDeviceClassId) if (deviceClassId != aveaDeviceClassId)
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
if (!hardwareManager()->bluetoothLowEnergyManager()->available()) if (!hardwareManager()->bluetoothLowEnergyManager()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
if (!hardwareManager()->bluetoothLowEnergyManager()->enabled()) if (!hardwareManager()->bluetoothLowEnergyManager()->enabled())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices(); BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginElgato::onBluetoothDiscoveryFinished); connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginElgato::onBluetoothDiscoveryFinished);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginElgato::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginElgato::setupDevice(Device *device)
{ {
qCDebug(dcElgato()) << "Setup device" << device->name() << device->params(); qCDebug(dcElgato()) << "Setup device" << device->name() << device->params();
@ -428,9 +427,9 @@ DeviceManager::DeviceSetupStatus DevicePluginElgato::setupDevice(Device *device)
AveaBulb *bulb = new AveaBulb(device, bluetoothDevice, this); AveaBulb *bulb = new AveaBulb(device, bluetoothDevice, this);
m_bulbs.insert(device, bulb); m_bulbs.insert(device, bulb);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginElgato::postSetupDevice(Device *device) void DevicePluginElgato::postSetupDevice(Device *device)
@ -447,7 +446,7 @@ void DevicePluginElgato::postSetupDevice(Device *device)
bulb->bluetoothDevice()->connectDevice(); bulb->bluetoothDevice()->connectDevice();
} }
DeviceManager::DeviceError DevicePluginElgato::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginElgato::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == aveaDeviceClassId) { if (device->deviceClassId() == aveaDeviceClassId) {
AveaBulb *bulb = m_bulbs.value(device); AveaBulb *bulb = m_bulbs.value(device);
@ -456,22 +455,22 @@ DeviceManager::DeviceError DevicePluginElgato::executeAction(Device *device, con
bool power = action.param(aveaPowerActionPowerParamTypeId).value().toBool(); bool power = action.param(aveaPowerActionPowerParamTypeId).value().toBool();
device->setStateValue(aveaPowerStateTypeId, power); device->setStateValue(aveaPowerStateTypeId, power);
if (!bulb->setPower(power)) if (!bulb->setPower(power))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaBrightnessActionTypeId) { } else if (action.actionTypeId() == aveaBrightnessActionTypeId) {
int percentage = action.param(aveaBrightnessActionBrightnessParamTypeId).value().toInt(); int percentage = action.param(aveaBrightnessActionBrightnessParamTypeId).value().toInt();
if (!bulb->setBrightness(percentage)) if (!bulb->setBrightness(percentage))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaColorActionTypeId) { } else if (action.actionTypeId() == aveaColorActionTypeId) {
QColor color = action.param(aveaColorActionColorParamTypeId).value().value<QColor>(); QColor color = action.param(aveaColorActionColorParamTypeId).value().value<QColor>();
color.setAlpha(0); // Alpha is white color.setAlpha(0); // Alpha is white
if (!bulb->setColor(color)) if (!bulb->setColor(color))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) { } else if (action.actionTypeId() == aveaColorTemperatureActionTypeId) {
int ctValue = action.param(aveaColorTemperatureActionColorTemperatureParamTypeId).value().toInt(); int ctValue = action.param(aveaColorTemperatureActionColorTemperatureParamTypeId).value().toInt();
// normalize from 0 to 347 instead of 153 to 500 // normalize from 0 to 347 instead of 153 to 500
@ -489,45 +488,45 @@ DeviceManager::DeviceError DevicePluginElgato::executeAction(Device *device, con
color.setBlue(blue); color.setBlue(blue);
color.setAlpha(255); // Alpha is white color.setAlpha(255); // Alpha is white
if (!bulb->setColor(color)) { if (!bulb->setColor(color)) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
device->setStateValue(aveaColorTemperatureStateTypeId, ctValue); device->setStateValue(aveaColorTemperatureStateTypeId, ctValue);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaWhiteActionTypeId) { } else if (action.actionTypeId() == aveaWhiteActionTypeId) {
int whiteValue = action.param(aveaWhiteActionWhiteParamTypeId).value().toInt(); int whiteValue = action.param(aveaWhiteActionWhiteParamTypeId).value().toInt();
if (!bulb->setWhite(whiteValue)) if (!bulb->setWhite(whiteValue))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaGreenActionTypeId) { } else if (action.actionTypeId() == aveaGreenActionTypeId) {
int greenValue = action.param(aveaGreenActionGreenParamTypeId).value().toInt(); int greenValue = action.param(aveaGreenActionGreenParamTypeId).value().toInt();
if (!bulb->setGreen(greenValue)) if (!bulb->setGreen(greenValue))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaRedActionTypeId) { } else if (action.actionTypeId() == aveaRedActionTypeId) {
int redValue = action.param(aveaRedActionRedParamTypeId).value().toInt(); int redValue = action.param(aveaRedActionRedParamTypeId).value().toInt();
if (!bulb->setRed(redValue)) if (!bulb->setRed(redValue))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaBlueActionTypeId) { } else if (action.actionTypeId() == aveaBlueActionTypeId) {
int blueValue = action.param(aveaBlueActionBlueParamTypeId).value().toInt(); int blueValue = action.param(aveaBlueActionBlueParamTypeId).value().toInt();
if (!bulb->setBlue(blueValue)) if (!bulb->setBlue(blueValue))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == aveaFadeActionTypeId) { } else if (action.actionTypeId() == aveaFadeActionTypeId) {
int fadeValue = action.param(aveaFadeActionFadeParamTypeId).value().toInt(); int fadeValue = action.param(aveaFadeActionFadeParamTypeId).value().toInt();
if (!bulb->setFade(fadeValue)) if (!bulb->setFade(fadeValue))
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginElgato::deviceRemoved(Device *device) void DevicePluginElgato::deviceRemoved(Device *device)

View File

@ -25,7 +25,7 @@
#include "aveabulb.h" #include "aveabulb.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
class DevicePluginElgato : public DevicePlugin class DevicePluginElgato : public DevicePlugin
@ -40,10 +40,10 @@ public:
~DevicePluginElgato(); ~DevicePluginElgato();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private: private:

View File

@ -21,7 +21,6 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginelro.h" #include "devicepluginelro.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
@ -33,13 +32,13 @@ DevicePluginElro::DevicePluginElro()
{ {
} }
DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action)
{ {
if (!hardwareManager()->radio433()->available()) if (!hardwareManager()->radio433()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
if (action.actionTypeId() != elroSocketPowerActionTypeId) if (action.actionTypeId() != elroSocketPowerActionTypeId)
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
QList<int> rawData; QList<int> rawData;
QByteArray binCode; QByteArray binCode;
@ -129,10 +128,10 @@ DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const
qCDebug(dcElro) << "Transmitted" << pluginName() << device->name() << "power: " << action.param(elroSocketPowerActionPowerParamTypeId).value().toBool(); qCDebug(dcElro) << "Transmitted" << pluginName() << device->name() << "power: " << action.param(elroSocketPowerActionPowerParamTypeId).value().toBool();
} else { } else {
qCWarning(dcElro) << "Could not transmitt" << pluginName() << device->name() << "power: " << action.param(elroSocketPowerActionPowerParamTypeId).value().toBool(); qCWarning(dcElro) << "Could not transmitt" << pluginName() << device->name() << "power: " << action.param(elroSocketPowerActionPowerParamTypeId).value().toBool();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginElro::radioData(const QList<int> &rawData) void DevicePluginElro::radioData(const QList<int> &rawData)

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINELRO_H #ifndef DEVICEPLUGINELRO_H
#define DEVICEPLUGINELRO_H #define DEVICEPLUGINELRO_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginElro : public DevicePlugin class DevicePluginElro : public DevicePlugin
{ {
@ -38,7 +38,7 @@ public:
void radioData(const QList<int> &rawData); void radioData(const QList<int> &rawData);
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -22,8 +22,7 @@
#include "deviceplugineq-3.h" #include "deviceplugineq-3.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "types/param.h" #include "types/param.h"
#include "plugininfo.h" #include "plugininfo.h"
@ -54,22 +53,22 @@ void DevicePluginEQ3::init()
connect(m_eqivaBluetoothDiscovery, &EqivaBluetoothDiscovery::finished, this, &DevicePluginEQ3::bluetoothDiscoveryDone); connect(m_eqivaBluetoothDiscovery, &EqivaBluetoothDiscovery::finished, this, &DevicePluginEQ3::bluetoothDiscoveryDone);
} }
DeviceManager::DeviceError DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginEQ3::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
qCDebug(dcEQ3()) << "Discover devices called"; qCDebug(dcEQ3()) << "Discover devices called";
if(deviceClassId == cubeDeviceClassId){ if(deviceClassId == cubeDeviceClassId){
m_cubeDiscovery->detectCubes(); m_cubeDiscovery->detectCubes();
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == eqivaBluetoothDeviceClassId) { if (deviceClassId == eqivaBluetoothDeviceClassId) {
bool ret = m_eqivaBluetoothDiscovery->startDiscovery(); bool ret = m_eqivaBluetoothDiscovery->startDiscovery();
if (!ret) { if (!ret) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginEQ3::startMonitoringAutoDevices() void DevicePluginEQ3::startMonitoringAutoDevices()
@ -77,7 +76,7 @@ void DevicePluginEQ3::startMonitoringAutoDevices()
} }
DeviceManager::DeviceSetupStatus DevicePluginEQ3::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginEQ3::setupDevice(Device *device)
{ {
qCDebug(dcEQ3) << "Setup device" << device->params(); qCDebug(dcEQ3) << "Setup device" << device->params();
@ -85,7 +84,7 @@ DeviceManager::DeviceSetupStatus DevicePluginEQ3::setupDevice(Device *device)
foreach (MaxCube *cube, m_cubes.keys()) { foreach (MaxCube *cube, m_cubes.keys()) {
if(cube->serialNumber() == device->paramValue(cubeDeviceSerialParamTypeId).toString()){ if(cube->serialNumber() == device->paramValue(cubeDeviceSerialParamTypeId).toString()){
qCDebug(dcEQ3) << cube->serialNumber() << " already exists..."; qCDebug(dcEQ3) << cube->serialNumber() << " already exists...";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
} }
@ -102,7 +101,7 @@ DeviceManager::DeviceSetupStatus DevicePluginEQ3::setupDevice(Device *device)
cube->connectToCube(); cube->connectToCube();
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
if(device->deviceClassId() == wallThermostateDeviceClassId){ if(device->deviceClassId() == wallThermostateDeviceClassId){
device->setName("Max! Wall Thermostat (" + device->paramValue(wallThermostateDeviceSerialParamTypeId).toString() + ")"); device->setName("Max! Wall Thermostat (" + device->paramValue(wallThermostateDeviceSerialParamTypeId).toString() + ")");
@ -160,12 +159,12 @@ DeviceManager::DeviceSetupStatus DevicePluginEQ3::setupDevice(Device *device)
// Command handler // Command handler
connect(eqivaDevice, &EqivaBluetooth::commandResult, this, [this](int commandId, bool success){ connect(eqivaDevice, &EqivaBluetooth::commandResult, this, [this](int commandId, bool success){
if (m_commandMap.contains(commandId)) { if (m_commandMap.contains(commandId)) {
emit actionExecutionFinished(m_commandMap.take(commandId), success ? DeviceManager::DeviceErrorNoError : DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(m_commandMap.take(commandId), success ? Device::DeviceErrorNoError : Device::DeviceErrorHardwareFailure);
} }
}); });
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginEQ3::deviceRemoved(Device *device) void DevicePluginEQ3::deviceRemoved(Device *device)
@ -214,7 +213,7 @@ EqivaBluetooth::Mode DevicePluginEQ3::stringToMode(const QString &string)
return EqivaBluetooth::ModeAuto; return EqivaBluetooth::ModeAuto;
} }
DeviceManager::DeviceError DevicePluginEQ3::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginEQ3::executeAction(Device *device, const Action &action)
{ {
if(device->deviceClassId() == wallThermostateDeviceClassId){ if(device->deviceClassId() == wallThermostateDeviceClassId){
foreach (MaxCube *cube, m_cubes.keys()){ foreach (MaxCube *cube, m_cubes.keys()){
@ -234,7 +233,7 @@ DeviceManager::DeviceError DevicePluginEQ3::executeAction(Device *device, const
} else if (action.actionTypeId() == wallThermostateDisplayCurrentTempActionTypeId){ } else if (action.actionTypeId() == wallThermostateDisplayCurrentTempActionTypeId){
cube->displayCurrentTemperature(rfAddress, roomId, action.param(wallThermostateDisplayCurrentTempActionDisplayParamTypeId).value().toBool(), action.id()); cube->displayCurrentTemperature(rfAddress, roomId, action.param(wallThermostateDisplayCurrentTempActionDisplayParamTypeId).value().toBool(), action.id());
} }
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
} }
} else if (device->deviceClassId() == radiatorThermostateDeviceClassId){ } else if (device->deviceClassId() == radiatorThermostateDeviceClassId){
@ -253,7 +252,7 @@ DeviceManager::DeviceError DevicePluginEQ3::executeAction(Device *device, const
} else if (action.actionTypeId() == radiatorThermostateSetEcoModeActionTypeId){ } else if (action.actionTypeId() == radiatorThermostateSetEcoModeActionTypeId){
cube->setDeviceEcoMode(rfAddress, roomId, action.id()); cube->setDeviceEcoMode(rfAddress, roomId, action.id());
} }
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
} }
} else if (device->deviceClassId() == eqivaBluetoothDeviceClassId) { } else if (device->deviceClassId() == eqivaBluetoothDeviceClassId) {
@ -273,10 +272,10 @@ DeviceManager::DeviceError DevicePluginEQ3::executeAction(Device *device, const
qCWarning(dcEQ3()) << "An action type has not been handled!"; qCWarning(dcEQ3()) << "An action type has not been handled!";
} }
m_commandMap.insert(commandId, action.id()); m_commandMap.insert(commandId, action.id());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
void DevicePluginEQ3::onPluginTimer() void DevicePluginEQ3::onPluginTimer()
@ -297,7 +296,7 @@ void DevicePluginEQ3::cubeConnectionStatusChanged(const bool &connected)
device = m_cubes.value(cube); device = m_cubes.value(cube);
device->setName("Max! Cube " + cube->serialNumber()); device->setName("Max! Cube " + cube->serialNumber());
device->setStateValue(cubeConnectedStateTypeId,true); device->setStateValue(cubeConnectedStateTypeId,true);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
} }
}else{ }else{
MaxCube *cube = static_cast<MaxCube*>(sender()); MaxCube *cube = static_cast<MaxCube*>(sender());
@ -305,7 +304,7 @@ void DevicePluginEQ3::cubeConnectionStatusChanged(const bool &connected)
if (m_cubes.contains(cube)){ if (m_cubes.contains(cube)){
device = m_cubes.value(cube); device = m_cubes.value(cube);
device->setStateValue(cubeConnectedStateTypeId,false); device->setStateValue(cubeConnectedStateTypeId,false);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
} }
} }
} }
@ -363,9 +362,9 @@ void DevicePluginEQ3::bluetoothDiscoveryDone(const QStringList results)
void DevicePluginEQ3::commandActionFinished(const bool &succeeded, const ActionId &actionId) void DevicePluginEQ3::commandActionFinished(const bool &succeeded, const ActionId &actionId)
{ {
if(succeeded){ if(succeeded){
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
}else{ }else{
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorSetupFailed); emit actionExecutionFinished(actionId, Device::DeviceErrorSetupFailed);
} }
} }
@ -377,7 +376,7 @@ void DevicePluginEQ3::wallThermostatFound()
foreach (WallThermostat *wallThermostat, cube->wallThermostatList()) { foreach (WallThermostat *wallThermostat, cube->wallThermostatList()) {
bool allreadyAdded = false; bool allreadyAdded = false;
foreach (Device *device, deviceManager()->findConfiguredDevices(wallThermostateDeviceClassId)){ foreach (Device *device, myDevices().filterByDeviceClassId(wallThermostateDeviceClassId)){
if(wallThermostat->serialNumber() == device->paramValue(wallThermostateDeviceSerialParamTypeId).toString()){ if(wallThermostat->serialNumber() == device->paramValue(wallThermostateDeviceSerialParamTypeId).toString()){
allreadyAdded = true; allreadyAdded = true;
break; break;
@ -411,7 +410,7 @@ void DevicePluginEQ3::radiatorThermostatFound()
foreach (RadiatorThermostat *radiatorThermostat, cube->radiatorThermostatList()) { foreach (RadiatorThermostat *radiatorThermostat, cube->radiatorThermostatList()) {
bool allreadyAdded = false; bool allreadyAdded = false;
foreach (Device *device, deviceManager()->findConfiguredDevices(radiatorThermostateDeviceClassId)){ foreach (Device *device, myDevices().filterByDeviceClassId(radiatorThermostateDeviceClassId)){
if(radiatorThermostat->serialNumber() == device->paramValue(radiatorThermostateDeviceSerialParamTypeId).toString()){ if(radiatorThermostat->serialNumber() == device->paramValue(radiatorThermostateDeviceSerialParamTypeId).toString()){
allreadyAdded = true; allreadyAdded = true;
break; break;
@ -452,7 +451,7 @@ void DevicePluginEQ3::wallThermostatDataUpdated()
MaxCube *cube = static_cast<MaxCube*>(sender()); MaxCube *cube = static_cast<MaxCube*>(sender());
foreach (WallThermostat *wallThermostat, cube->wallThermostatList()) { foreach (WallThermostat *wallThermostat, cube->wallThermostatList()) {
foreach (Device *device, deviceManager()->findConfiguredDevices(wallThermostateDeviceClassId)){ foreach (Device *device, myDevices().filterByDeviceClassId(wallThermostateDeviceClassId)){
if(device->paramValue(wallThermostateDeviceSerialParamTypeId).toString() == wallThermostat->serialNumber()){ if(device->paramValue(wallThermostateDeviceSerialParamTypeId).toString() == wallThermostat->serialNumber()){
device->setStateValue(wallThermostateComfortTemperatureStateTypeId, wallThermostat->comfortTemp()); device->setStateValue(wallThermostateComfortTemperatureStateTypeId, wallThermostat->comfortTemp());
device->setStateValue(wallThermostateEcoTempStateTypeId, wallThermostat->ecoTemp()); device->setStateValue(wallThermostateEcoTempStateTypeId, wallThermostat->ecoTemp());
@ -479,7 +478,7 @@ void DevicePluginEQ3::radiatorThermostatDataUpdated()
MaxCube *cube = static_cast<MaxCube*>(sender()); MaxCube *cube = static_cast<MaxCube*>(sender());
foreach (RadiatorThermostat *radiatorThermostat, cube->radiatorThermostatList()) { foreach (RadiatorThermostat *radiatorThermostat, cube->radiatorThermostatList()) {
foreach (Device *device, deviceManager()->findConfiguredDevices(radiatorThermostateDeviceClassId)){ foreach (Device *device, myDevices().filterByDeviceClassId(radiatorThermostateDeviceClassId)){
if(device->paramValue(radiatorThermostateDeviceSerialParamTypeId).toString() == radiatorThermostat->serialNumber()){ if(device->paramValue(radiatorThermostateDeviceSerialParamTypeId).toString() == radiatorThermostat->serialNumber()){
device->setStateValue(radiatorThermostateComfortTempStateTypeId, radiatorThermostat->comfortTemp()); device->setStateValue(radiatorThermostateComfortTempStateTypeId, radiatorThermostat->comfortTemp());
device->setStateValue(radiatorThermostateMaxSetpointTempStateTypeId, radiatorThermostat->maxSetPointTemp()); device->setStateValue(radiatorThermostateMaxSetpointTempStateTypeId, radiatorThermostat->maxSetPointTemp());

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINEQ3_H #ifndef DEVICEPLUGINEQ3_H
#define DEVICEPLUGINEQ3_H #define DEVICEPLUGINEQ3_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "maxcubediscovery.h" #include "maxcubediscovery.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "eqivabluetooth.h" #include "eqivabluetooth.h"
@ -44,11 +44,11 @@ public:
~DevicePluginEQ3(); ~DevicePluginEQ3();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
void startMonitoringAutoDevices() override; void startMonitoringAutoDevices() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private: private:
@ -65,7 +65,7 @@ private:
QHash<int, ActionId> m_commandMap; QHash<int, ActionId> m_commandMap;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action); Device::DeviceError executeAction(Device *device, const Action &action);
private slots: private slots:
void onPluginTimer(); void onPluginTimer();

View File

@ -32,7 +32,7 @@
#include "room.h" #include "room.h"
#include "wallthermostat.h" #include "wallthermostat.h"
#include "radiatorthermostat.h" #include "radiatorthermostat.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class MaxCube : public QTcpSocket class MaxCube : public QTcpSocket
{ {

View File

@ -31,7 +31,6 @@
* {0000fef5-0000-1000-8000-00805f9b34fb} * {0000fef5-0000-1000-8000-00805f9b34fb}
*/ */
#include "plugininfo.h" #include "plugininfo.h"
#include "devicemanager.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h"
#include "devicepluginflowercare.h" #include "devicepluginflowercare.h"
#include "flowercare.h" #include "flowercare.h"
@ -52,23 +51,23 @@ void DevicePluginFlowercare::init()
{ {
} }
DeviceManager::DeviceError DevicePluginFlowercare::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginFlowercare::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
if (!hardwareManager()->bluetoothLowEnergyManager()->available()) if (!hardwareManager()->bluetoothLowEnergyManager()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
if (!hardwareManager()->bluetoothLowEnergyManager()->enabled()) if (!hardwareManager()->bluetoothLowEnergyManager()->enabled())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices(); BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginFlowercare::onBluetoothDiscoveryFinished); connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginFlowercare::onBluetoothDiscoveryFinished);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginFlowercare::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginFlowercare::setupDevice(Device *device)
{ {
qCDebug(dcFlowerCare) << "Setting up Flower care" << device->name() << device->params(); qCDebug(dcFlowerCare) << "Setting up Flower care" << device->name() << device->params();
@ -87,9 +86,9 @@ DeviceManager::DeviceSetupStatus DevicePluginFlowercare::setupDevice(Device *dev
m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer(); m_reconnectTimer = hardwareManager()->pluginTimerManager()->registerTimer();
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginFlowercare::onPluginTimer); connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginFlowercare::onPluginTimer);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginFlowercare::postSetupDevice(Device *device) void DevicePluginFlowercare::postSetupDevice(Device *device)
@ -114,11 +113,11 @@ void DevicePluginFlowercare::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginFlowercare::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginFlowercare::executeAction(Device *device, const Action &action)
{ {
Q_UNUSED(device) Q_UNUSED(device)
Q_UNUSED(action) Q_UNUSED(action)
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
bool DevicePluginFlowercare::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo) bool DevicePluginFlowercare::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo)

View File

@ -26,8 +26,7 @@
#include <QPointer> #include <QPointer>
#include <QHash> #include <QHash>
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
@ -44,12 +43,12 @@ public:
~DevicePluginFlowercare(); ~DevicePluginFlowercare();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_reconnectTimer = nullptr; PluginTimer *m_reconnectTimer = nullptr;

View File

@ -21,7 +21,6 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "deviceplugingenericelements.h" #include "deviceplugingenericelements.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -30,52 +29,52 @@ DevicePluginGenericElements::DevicePluginGenericElements()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginGenericElements::setupDevice(Device *device)
{ {
// Toggle Button // Toggle Button
if (device->deviceClassId() == toggleButtonDeviceClassId) { if (device->deviceClassId() == toggleButtonDeviceClassId) {
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Button // Button
if (device->deviceClassId() == buttonDeviceClassId) { if (device->deviceClassId() == buttonDeviceClassId) {
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// ON/OFF Button // ON/OFF Button
if (device->deviceClassId() == onOffButtonDeviceClassId) { if (device->deviceClassId() == onOffButtonDeviceClassId) {
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginGenericElements::executeAction(Device *device, const Action &action)
{ {
// Toggle Button // Toggle Button
if (device->deviceClassId() == toggleButtonDeviceClassId ) { if (device->deviceClassId() == toggleButtonDeviceClassId ) {
if (action.actionTypeId() == toggleButtonStateActionTypeId) { if (action.actionTypeId() == toggleButtonStateActionTypeId) {
device->setStateValue(toggleButtonStateStateTypeId, !device->stateValue(toggleButtonStateStateTypeId).toBool()); device->setStateValue(toggleButtonStateStateTypeId, !device->stateValue(toggleButtonStateStateTypeId).toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Button // Button
if (device->deviceClassId() == buttonDeviceClassId ) { if (device->deviceClassId() == buttonDeviceClassId ) {
if (action.actionTypeId() == buttonButtonPressActionTypeId) { if (action.actionTypeId() == buttonButtonPressActionTypeId) {
emit emitEvent(Event(buttonButtonPressedEventTypeId, device->id())); emit emitEvent(Event(buttonButtonPressedEventTypeId, device->id()));
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// ON/OFF Button // ON/OFF Button
if (device->deviceClassId() == onOffButtonDeviceClassId ) { if (device->deviceClassId() == onOffButtonDeviceClassId ) {
if (action.actionTypeId() == onOffButtonOnActionTypeId) { if (action.actionTypeId() == onOffButtonOnActionTypeId) {
emit emitEvent(Event(onOffButtonOnEventTypeId, device->id())); emit emitEvent(Event(onOffButtonOnEventTypeId, device->id()));
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == onOffButtonOffActionTypeId) { if (action.actionTypeId() == onOffButtonOffActionTypeId) {
emit emitEvent(Event(onOffButtonOffEventTypeId, device->id())); emit emitEvent(Event(onOffButtonOffEventTypeId, device->id()));
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINGENERICELEMENTS_H #ifndef DEVICEPLUGINGENERICELEMENTS_H
#define DEVICEPLUGINGENERICELEMENTS_H #define DEVICEPLUGINGENERICELEMENTS_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginGenericElements : public DevicePlugin class DevicePluginGenericElements : public DevicePlugin
{ {
@ -34,10 +34,10 @@ class DevicePluginGenericElements : public DevicePlugin
public: public:
explicit DevicePluginGenericElements(); explicit DevicePluginGenericElements();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -22,8 +22,7 @@
#include "deviceplugingpio.h" #include "deviceplugingpio.h"
#include "types/param.h" #include "types/param.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
DevicePluginGpio::DevicePluginGpio() DevicePluginGpio::DevicePluginGpio()
@ -31,14 +30,14 @@ DevicePluginGpio::DevicePluginGpio()
} }
DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
{ {
qCDebug(dcGpioController()) << "Setup" << device->name() << device->params(); qCDebug(dcGpioController()) << "Setup" << device->name() << device->params();
// Check if GPIOs are available on this platform // Check if GPIOs are available on this platform
if (!Gpio::isAvailable()) { if (!Gpio::isAvailable()) {
qCWarning(dcGpioController()) << "There are ou GPIOs on this plattform"; qCWarning(dcGpioController()) << "There are ou GPIOs on this plattform";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
// GPIO Switch // GPIO Switch
@ -55,17 +54,17 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
if (!gpio->exportGpio()) { if (!gpio->exportGpio()) {
qCWarning(dcGpioController()) << "Could not export gpio for device" << device->name(); qCWarning(dcGpioController()) << "Could not export gpio for device" << device->name();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if (!gpio->setDirection(Gpio::DirectionOutput)) { if (!gpio->setDirection(Gpio::DirectionOutput)) {
qCWarning(dcGpioController()) << "Could not configure output gpio for device" << device->name(); qCWarning(dcGpioController()) << "Could not configure output gpio for device" << device->name();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if (!gpio->setValue(Gpio::ValueLow)) { if (!gpio->setValue(Gpio::ValueLow)) {
qCWarning(dcGpioController()) << "Could not set gpio value for device" << device->name(); qCWarning(dcGpioController()) << "Could not set gpio value for device" << device->name();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
m_gpioDevices.insert(gpio, device); m_gpioDevices.insert(gpio, device);
@ -76,7 +75,7 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
if (device->deviceClassId() == gpioOutputBbbDeviceClassId) if (device->deviceClassId() == gpioOutputBbbDeviceClassId)
m_beagleboneBlackGpios.insert(gpio->gpioNumber(), gpio); m_beagleboneBlackGpios.insert(gpio->gpioNumber(), gpio);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) { if (device->deviceClassId() == gpioInputRpiDeviceClassId || device->deviceClassId() == gpioInputBbbDeviceClassId) {
@ -92,7 +91,7 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
if (!monior->enable()) { if (!monior->enable()) {
qCWarning(dcGpioController()) << "Could not enable gpio monitor for device" << device->name(); qCWarning(dcGpioController()) << "Could not enable gpio monitor for device" << device->name();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
connect(monior, &GpioMonitor::valueChanged, this, &DevicePluginGpio::onGpioValueChanged); connect(monior, &GpioMonitor::valueChanged, this, &DevicePluginGpio::onGpioValueChanged);
@ -105,24 +104,24 @@ DeviceManager::DeviceSetupStatus DevicePluginGpio::setupDevice(Device *device)
if (device->deviceClassId() == gpioOutputBbbDeviceClassId) if (device->deviceClassId() == gpioOutputBbbDeviceClassId)
m_beagleboneBlackGpioMoniors.insert(monior->gpio()->gpioNumber(), monior); m_beagleboneBlackGpioMoniors.insert(monior->gpio()->gpioNumber(), monior);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
// Check if GPIOs are available on this platform // Check if GPIOs are available on this platform
if (!Gpio::isAvailable()) { if (!Gpio::isAvailable()) {
qCWarning(dcGpioController()) << "There are no GPIOs on this plattform"; qCWarning(dcGpioController()) << "There are no GPIOs on this plattform";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
// Check which board / gpio configuration // Check which board / gpio configuration
const DeviceClass deviceClass = deviceManager()->findDeviceClass(deviceClassId); const DeviceClass deviceClass = supportedDevices().findById(deviceClassId);
if (deviceClass.vendorId() == raspberryPiVendorId) { if (deviceClass.vendorId() == raspberryPiVendorId) {
// Create the list of available gpios // Create the list of available gpios
@ -170,7 +169,7 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClass.vendorId() == beagleboneBlackVendorId) { if (deviceClass.vendorId() == beagleboneBlackVendorId) {
@ -213,10 +212,10 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorVendorNotFound; return Device::DeviceErrorVendorNotFound;
} }
void DevicePluginGpio::deviceRemoved(Device *device) void DevicePluginGpio::deviceRemoved(Device *device)
@ -255,10 +254,10 @@ void DevicePluginGpio::deviceRemoved(Device *device)
} }
DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginGpio::executeAction(Device *device, const Action &action)
{ {
// Get the gpio // Get the gpio
const DeviceClass deviceClass = deviceManager()->findDeviceClass(device->deviceClassId()); const DeviceClass deviceClass = supportedDevices().findById(device->deviceClassId());
Gpio *gpio = Q_NULLPTR; Gpio *gpio = Q_NULLPTR;
// Find the gpio in the corresponding hash // Find the gpio in the corresponding hash
@ -271,7 +270,7 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
// Check if gpio was found // Check if gpio was found
if (!gpio) { if (!gpio) {
qCWarning(dcGpioController()) << "Could not find gpio for executing action on" << device->name(); qCWarning(dcGpioController()) << "Could not find gpio for executing action on" << device->name();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
// GPIO Switch power action // GPIO Switch power action
@ -286,13 +285,13 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
if (!success) { if (!success) {
qCWarning(dcGpioController()) << "Could not set gpio value while execute action on" << device->name(); qCWarning(dcGpioController()) << "Could not set gpio value while execute action on" << device->name();
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
// Set the current state // Set the current state
device->setStateValue(gpioOutputRpiPowerValueStateTypeId, action.param(gpioOutputRpiPowerValueActionPowerValueParamTypeId).value()); device->setStateValue(gpioOutputRpiPowerValueStateTypeId, action.param(gpioOutputRpiPowerValueActionPowerValueParamTypeId).value());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} else if (deviceClass.vendorId() == beagleboneBlackVendorId) { } else if (deviceClass.vendorId() == beagleboneBlackVendorId) {
if (action.actionTypeId() == gpioOutputBbbPowerValueActionTypeId) { if (action.actionTypeId() == gpioOutputBbbPowerValueActionTypeId) {
@ -305,17 +304,17 @@ DeviceManager::DeviceError DevicePluginGpio::executeAction(Device *device, const
if (!success) { if (!success) {
qCWarning(dcGpioController()) << "Could not set gpio value while execute action on" << device->name(); qCWarning(dcGpioController()) << "Could not set gpio value while execute action on" << device->name();
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
// Set the current state // Set the current state
device->setStateValue(gpioOutputBbbPowerValueStateTypeId, action.param(gpioOutputBbbPowerValueActionPowerValueParamTypeId).value()); device->setStateValue(gpioOutputBbbPowerValueStateTypeId, action.param(gpioOutputBbbPowerValueActionPowerValueParamTypeId).value());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginGpio::postSetupDevice(Device *device) void DevicePluginGpio::postSetupDevice(Device *device)

View File

@ -27,7 +27,7 @@
#include "hardware/gpiomonitor.h" #include "hardware/gpiomonitor.h"
#include "gpiodescriptor.h" #include "gpiodescriptor.h"
#include "hardware/gpiomonitor.h" #include "hardware/gpiomonitor.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginGpio : public DevicePlugin class DevicePluginGpio : public DevicePlugin
{ {
@ -39,10 +39,10 @@ class DevicePluginGpio : public DevicePlugin
public: public:
explicit DevicePluginGpio(); explicit DevicePluginGpio();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void postSetupDevice(Device *device); void postSetupDevice(Device *device);

View File

@ -29,7 +29,7 @@ DevicePluginHttpCommander::DevicePluginHttpCommander()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *device)
{ {
qDebug(dcHttpCommander()) << "Setup device" << device->name() << device->params(); qDebug(dcHttpCommander()) << "Setup device" << device->name() << device->params();
@ -42,30 +42,30 @@ DeviceManager::DeviceSetupStatus DevicePluginHttpCommander::setupDevice(Device *
QUrl url = device->paramValue(httpGetCommanderDeviceUrlParamTypeId).toUrl(); QUrl url = device->paramValue(httpGetCommanderDeviceUrlParamTypeId).toUrl();
if (!url.isValid()) { if (!url.isValid()) {
qDebug(dcHttpCommander()) << "Given URL is not valid"; qDebug(dcHttpCommander()) << "Given URL is not valid";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == httpPutCommanderDeviceClassId) { if (device->deviceClassId() == httpPutCommanderDeviceClassId) {
QUrl url = device->paramValue(httpPutCommanderDeviceUrlParamTypeId).toUrl(); QUrl url = device->paramValue(httpPutCommanderDeviceUrlParamTypeId).toUrl();
if (!url.isValid()) { if (!url.isValid()) {
qDebug(dcHttpCommander()) << "Given URL is not valid"; qDebug(dcHttpCommander()) << "Given URL is not valid";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == httpPostCommanderDeviceClassId) { if (device->deviceClassId() == httpPostCommanderDeviceClassId) {
QUrl url = device->paramValue(httpPostCommanderDeviceUrlParamTypeId).toUrl(); QUrl url = device->paramValue(httpPostCommanderDeviceUrlParamTypeId).toUrl();
if (!url.isValid()) { if (!url.isValid()) {
qDebug(dcHttpCommander()) << "Given URL is not valid"; qDebug(dcHttpCommander()) << "Given URL is not valid";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
@ -77,7 +77,7 @@ void DevicePluginHttpCommander::postSetupDevice(Device *device)
} }
DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginHttpCommander::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == httpPostCommanderDeviceClassId) { if (device->deviceClassId() == httpPostCommanderDeviceClassId) {
@ -91,9 +91,9 @@ DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *devi
m_httpRequests.insert(reply, device); m_httpRequests.insert(reply, device);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
@ -110,10 +110,10 @@ DeviceManager::DeviceError DevicePluginHttpCommander::executeAction(Device *devi
m_httpRequests.insert(reply, device); m_httpRequests.insert(reply, device);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginHttpCommander::makeGetCall(Device *device) void DevicePluginHttpCommander::makeGetCall(Device *device)

View File

@ -24,8 +24,7 @@
#ifndef DEVICEPLUGINHTTPCOMMANDER_H #ifndef DEVICEPLUGINHTTPCOMMANDER_H
#define DEVICEPLUGINHTTPCOMMANDER_H #define DEVICEPLUGINHTTPCOMMANDER_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "plugintimer.h" #include "plugintimer.h"
#include <QNetworkReply> #include <QNetworkReply>
@ -41,10 +40,10 @@ class DevicePluginHttpCommander : public DevicePlugin
public: public:
explicit DevicePluginHttpCommander(); explicit DevicePluginHttpCommander();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;

View File

@ -22,8 +22,7 @@
#include "devicepluginintertechno.h" #include "devicepluginintertechno.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
#include "plugininfo.h" #include "plugininfo.h"
@ -36,10 +35,10 @@ DevicePluginIntertechno::DevicePluginIntertechno()
} }
DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action)
{ {
if (!hardwareManager()->radio433()->available()) if (!hardwareManager()->radio433()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
QList<int> rawData; QList<int> rawData;
QByteArray binCode; QByteArray binCode;
@ -121,7 +120,7 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
} }
if (binCode.length() != 16){ if (binCode.length() != 16){
return DeviceManager::DeviceErrorInvalidParameter; return Device::DeviceErrorInvalidParameter;
} }
// ======================================= // =======================================
@ -160,9 +159,9 @@ DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device
qCDebug(dcIntertechno) << "transmitted" << pluginName() << device->name() << "power: " << action.param(switchSetPowerActionPowerParamTypeId).value().toBool(); qCDebug(dcIntertechno) << "transmitted" << pluginName() << device->name() << "power: " << action.param(switchSetPowerActionPowerParamTypeId).value().toBool();
} else { } else {
qCWarning(dcIntertechno) << "could not transmitt" << pluginName() << device->name() << "power: " << action.param(switchSetPowerActionPowerParamTypeId).value().toBool(); qCWarning(dcIntertechno) << "could not transmitt" << pluginName() << device->name() << "power: " << action.param(switchSetPowerActionPowerParamTypeId).value().toBool();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginIntertechno::radioData(const QList<int> &rawData) void DevicePluginIntertechno::radioData(const QList<int> &rawData)

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGININTERTECHNO_H #ifndef DEVICEPLUGININTERTECHNO_H
#define DEVICEPLUGININTERTECHNO_H #define DEVICEPLUGININTERTECHNO_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginIntertechno : public DevicePlugin class DevicePluginIntertechno : public DevicePlugin
{ {
@ -38,7 +38,7 @@ public:
void radioData(const QList<int> &rawData); void radioData(const QList<int> &rawData);
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -44,7 +44,7 @@ void DevicePluginKeba::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginKeba::updateData); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginKeba::updateData);
} }
DeviceManager::DeviceSetupStatus DevicePluginKeba::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginKeba::setupDevice(Device *device)
{ {
qCDebug(dcKebaKeContact()) << "Setting up a new device:" << device->name() << device->params(); qCDebug(dcKebaKeContact()) << "Setting up a new device:" << device->name() << device->params();
@ -53,7 +53,7 @@ DeviceManager::DeviceSetupStatus DevicePluginKeba::setupDevice(Device *device)
if (!m_kebaSocket->bind(QHostAddress::AnyIPv4, 7090)) { if (!m_kebaSocket->bind(QHostAddress::AnyIPv4, 7090)) {
qCWarning(dcKebaKeContact()) << "Cannot bind to port" << 7090; qCWarning(dcKebaKeContact()) << "Cannot bind to port" << 7090;
delete m_kebaSocket; delete m_kebaSocket;
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
connect(m_kebaSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); connect(m_kebaSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
qCDebug(dcKebaKeContact()) << "Create keba socket"; qCDebug(dcKebaKeContact()) << "Create keba socket";
@ -64,16 +64,16 @@ DeviceManager::DeviceSetupStatus DevicePluginKeba::setupDevice(Device *device)
//Check if the IP is empty //Check if the IP is empty
if (address.isNull()) { if (address.isNull()) {
delete m_kebaSocket; delete m_kebaSocket;
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
// check if IP is already added to another keba device // check if IP is already added to another keba device
if(m_kebaDevices.keys().contains(address)){ if(m_kebaDevices.keys().contains(address)){
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
m_kebaDevices.insert(address, device); m_kebaDevices.insert(address, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginKeba::postSetupDevice(Device *device) void DevicePluginKeba::postSetupDevice(Device *device)
@ -109,7 +109,7 @@ void DevicePluginKeba::updateData()
} }
} }
DeviceManager::DeviceError DevicePluginKeba::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginKeba::executeAction(Device *device, const Action &action)
{ {
qCDebug(dcKebaKeContact()) << "Execute action" << device->name() << action.actionTypeId().toString(); qCDebug(dcKebaKeContact()) << "Execute action" << device->name() << action.actionTypeId().toString();
@ -140,10 +140,10 @@ DeviceManager::DeviceError DevicePluginKeba::executeAction(Device *device, const
m_kebaSocket->writeDatagram(datagram.data(),datagram.size(), QHostAddress(device->paramValue(wallboxDeviceIpParamTypeId).toString()) , 7090); m_kebaSocket->writeDatagram(datagram.data(),datagram.size(), QHostAddress(device->paramValue(wallboxDeviceIpParamTypeId).toString()) , 7090);
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginKeba::readPendingDatagrams() void DevicePluginKeba::readPendingDatagrams()

View File

@ -22,8 +22,7 @@
#ifndef DEVICEPLUGINKEBA_H #ifndef DEVICEPLUGINKEBA_H
#define DEVICEPLUGINKEBA_H #define DEVICEPLUGINKEBA_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "plugintimer.h" #include "plugintimer.h"
#include <QHash> #include <QHash>
@ -42,12 +41,12 @@ public:
~DevicePluginKeba(); ~DevicePluginKeba();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device* device) override; void postSetupDevice(Device* device) override;
void deviceRemoved(Device* device) override; void deviceRemoved(Device* device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void updateData(); void updateData();
private: private:

View File

@ -21,7 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginkodi.h" #include "devicepluginkodi.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdiscovery.h"
#include "platform/platformzeroconfcontroller.h" #include "platform/platformzeroconfcontroller.h"
@ -60,7 +60,7 @@ void DevicePluginKodi::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginKodi::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginKodi::onPluginTimer);
} }
DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
{ {
qCDebug(dcKodi) << "Setup Kodi device" << device->paramValue(kodiDeviceIpParamTypeId).toString(); qCDebug(dcKodi) << "Setup Kodi device" << device->paramValue(kodiDeviceIpParamTypeId).toString();
Kodi *kodi= new Kodi(QHostAddress(device->paramValue(kodiDeviceIpParamTypeId).toString()), 9090, this); Kodi *kodi= new Kodi(QHostAddress(device->paramValue(kodiDeviceIpParamTypeId).toString()), 9090, this);
@ -127,7 +127,7 @@ DeviceManager::DeviceSetupStatus DevicePluginKodi::setupDevice(Device *device)
kodi->connectKodi(); kodi->connectKodi();
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginKodi::deviceRemoved(Device *device) void DevicePluginKodi::deviceRemoved(Device *device)
@ -138,7 +138,7 @@ void DevicePluginKodi::deviceRemoved(Device *device)
kodi->deleteLater(); kodi->deleteLater();
} }
DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
@ -159,17 +159,17 @@ DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId
serviceBrowser->deleteLater(); serviceBrowser->deleteLater();
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceError DevicePluginKodi::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginKodi::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == kodiDeviceClassId) { if (device->deviceClassId() == kodiDeviceClassId) {
Kodi *kodi = m_kodis.key(device); Kodi *kodi = m_kodis.key(device);
// check connection state // check connection state
if (!kodi->connected()) { if (!kodi->connected()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
int commandId = -1; int commandId = -1;
@ -214,12 +214,12 @@ DeviceManager::DeviceError DevicePluginKodi::executeAction(Device *device, const
} }
} else { } else {
qWarning(dcKodi()) << "Unhandled action type" << action.actionTypeId(); qWarning(dcKodi()) << "Unhandled action type" << action.actionTypeId();
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
m_pendingActions.insert(commandId, action.id()); m_pendingActions.insert(commandId, action.id());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginKodi::onPluginTimer() void DevicePluginKodi::onPluginTimer()
@ -263,7 +263,7 @@ void DevicePluginKodi::onActionExecuted(int actionId, bool success)
if (!m_pendingActions.contains(actionId)) { if (!m_pendingActions.contains(actionId)) {
return; return;
} }
emit actionExecutionFinished(m_pendingActions.value(actionId), success ? DeviceManager::DeviceErrorNoError : DeviceManager::DeviceErrorInvalidParameter); emit actionExecutionFinished(m_pendingActions.value(actionId), success ? Device::DeviceErrorNoError : Device::DeviceErrorInvalidParameter);
} }
void DevicePluginKodi::versionDataReceived(const QVariantMap &data) void DevicePluginKodi::versionDataReceived(const QVariantMap &data)
@ -277,7 +277,7 @@ void DevicePluginKodi::versionDataReceived(const QVariantMap &data)
if (version.value("major").toInt() < 6) { if (version.value("major").toInt() < 6) {
qCWarning(dcKodi) << "incompatible api version:" << apiVersion; qCWarning(dcKodi) << "incompatible api version:" << apiVersion;
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
kodi->update(); kodi->update();
@ -292,7 +292,7 @@ void DevicePluginKodi::onSetupFinished(const QVariantMap &data)
QString kodiVersion = QString("%1.%2 (%3)").arg(version.value("major").toString()).arg(version.value("minor").toString()).arg(version.value("tag").toString()); QString kodiVersion = QString("%1.%2 (%3)").arg(version.value("major").toString()).arg(version.value("minor").toString()).arg(version.value("tag").toString());
qCDebug(dcKodi) << "Version:" << kodiVersion; qCDebug(dcKodi) << "Version:" << kodiVersion;
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
kodi->showNotification("Connected", 2000, "info"); kodi->showNotification("Connected", 2000, "info");
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINKODI_H #ifndef DEVICEPLUGINKODI_H
#define DEVICEPLUGINKODI_H #define DEVICEPLUGINKODI_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "kodi.h" #include "kodi.h"
@ -42,10 +42,10 @@ public:
~DevicePluginKodi(); ~DevicePluginKodi();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer; PluginTimer *m_pluginTimer;

View File

@ -21,7 +21,6 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginleynew.h" #include "devicepluginleynew.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
@ -32,21 +31,21 @@ DevicePluginLeynew::DevicePluginLeynew()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginLeynew::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginLeynew::setupDevice(Device *device)
{ {
Q_UNUSED(device); Q_UNUSED(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginLeynew::executeAction(Device *device, const Action &action)
{ {
if (!hardwareManager()->radio433()->available()) { if (!hardwareManager()->radio433()->available()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (device->deviceClassId() != rfControllerDeviceClassId) { if (device->deviceClassId() != rfControllerDeviceClassId) {
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
QList<int> rawData; QList<int> rawData;
@ -64,7 +63,7 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
binCode.append("111101010101"); binCode.append("111101010101");
} else { } else {
qCWarning(dcLeynew) << "Could not get id of device: invalid parameter" << device->paramValue(rfControllerDeviceIdParamTypeId); qCWarning(dcLeynew) << "Could not get id of device: invalid parameter" << device->paramValue(rfControllerDeviceIdParamTypeId);
return DeviceManager::DeviceErrorInvalidParameter; return Device::DeviceErrorInvalidParameter;
} }
int repetitions = 12; int repetitions = 12;
@ -115,7 +114,7 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
} else if (action.actionTypeId() == rfControllerFade7ActionTypeId) { } else if (action.actionTypeId() == rfControllerFade7ActionTypeId) {
binCode.append("001100000000"); binCode.append("001100000000");
} else { } else {
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// ======================================= // =======================================
@ -147,7 +146,7 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
qCDebug(dcLeynew) << "Transmitted" << pluginName() << device->name() << action.id(); qCDebug(dcLeynew) << "Transmitted" << pluginName() << device->name() << action.id();
}else{ }else{
qCWarning(dcLeynew) << "Could not transmitt" << pluginName() << device->name() << action.id(); qCWarning(dcLeynew) << "Could not transmitt" << pluginName() << device->name() << action.id();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINLEYNEW_H #ifndef DEVICEPLUGINLEYNEW_H
#define DEVICEPLUGINLEYNEW_H #define DEVICEPLUGINLEYNEW_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginLeynew : public DevicePlugin class DevicePluginLeynew : public DevicePlugin
{ {
@ -35,10 +35,10 @@ class DevicePluginLeynew : public DevicePlugin
public: public:
explicit DevicePluginLeynew(); explicit DevicePluginLeynew();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -22,8 +22,7 @@
#include "devicepluginlgsmarttv.h" #include "devicepluginlgsmarttv.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
#include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdiscovery.h"
@ -45,7 +44,7 @@ void DevicePluginLgSmartTv::init()
} }
DeviceManager::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
@ -53,10 +52,10 @@ DeviceManager::DeviceError DevicePluginLgSmartTv::discoverDevices(const DeviceCl
qCDebug(dcLgSmartTv()) << "Start discovering"; qCDebug(dcLgSmartTv()) << "Start discovering";
UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices("udap:rootservice","UDAP/2.0"); UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices("udap:rootservice","UDAP/2.0");
connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginLgSmartTv::onUpnpDiscoveryFinished); connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginLgSmartTv::onUpnpDiscoveryFinished);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *device)
{ {
qCDebug(dcLgSmartTv()) << "Setup LG smart TV" << device->name() << device->params(); qCDebug(dcLgSmartTv()) << "Setup LG smart TV" << device->name() << device->params();
QHostAddress address = QHostAddress(device->paramValue(lgSmartTvDeviceHostAddressParamTypeId).toString()); QHostAddress address = QHostAddress(device->paramValue(lgSmartTvDeviceHostAddressParamTypeId).toString());
@ -68,7 +67,7 @@ DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *devi
// Check if we know the key from the pairing procedure // Check if we know the key from the pairing procedure
if (!m_tvKeys.contains(device->paramValue(lgSmartTvDeviceUuidParamTypeId).toString())) { if (!m_tvKeys.contains(device->paramValue(lgSmartTvDeviceUuidParamTypeId).toString())) {
qCWarning(dcLgSmartTv) << "could not find any pairing key"; qCWarning(dcLgSmartTv) << "could not find any pairing key";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
// Use the key from the pairing procedure // Use the key from the pairing procedure
QString key = m_tvKeys.value(device->paramValue(lgSmartTvDeviceUuidParamTypeId).toString()); QString key = m_tvKeys.value(device->paramValue(lgSmartTvDeviceUuidParamTypeId).toString());
@ -90,7 +89,7 @@ DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::setupDevice(Device *devi
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginLgSmartTv::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginLgSmartTv::onPluginTimer);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginLgSmartTv::deviceRemoved(Device *device) void DevicePluginLgSmartTv::deviceRemoved(Device *device)
@ -115,13 +114,13 @@ void DevicePluginLgSmartTv::postSetupDevice(Device *device)
pairTvDevice(device); pairTvDevice(device);
} }
DeviceManager::DeviceError DevicePluginLgSmartTv::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginLgSmartTv::executeAction(Device *device, const Action &action)
{ {
TvDevice * tvDevice = m_tvList.key(device); TvDevice * tvDevice = m_tvList.key(device);
if (!tvDevice->reachable()) { if (!tvDevice->reachable()) {
qCWarning(dcLgSmartTv) << "Device not reachable"; qCWarning(dcLgSmartTv) << "Device not reachable";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == lgSmartTvCommandVolumeUpActionTypeId) { if (action.actionTypeId() == lgSmartTvCommandVolumeUpActionTypeId) {
@ -215,12 +214,12 @@ DeviceManager::DeviceError DevicePluginLgSmartTv::executeAction(Device *device,
connect(reply, &QNetworkReply::finished, this, &DevicePluginLgSmartTv::onNetworkManagerReplyFinished); connect(reply, &QNetworkReply::finished, this, &DevicePluginLgSmartTv::onNetworkManagerReplyFinished);
m_asyncActions.insert(reply, action.id()); m_asyncActions.insert(reply, action.id());
} else { } else {
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceError DevicePluginLgSmartTv::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) Device::DeviceError DevicePluginLgSmartTv::displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor)
{ {
Q_UNUSED(pairingTransactionId) Q_UNUSED(pairingTransactionId)
@ -231,10 +230,10 @@ DeviceManager::DeviceError DevicePluginLgSmartTv::displayPin(const PairingTransa
connect(reply, &QNetworkReply::finished, this, &DevicePluginLgSmartTv::onNetworkManagerReplyFinished); connect(reply, &QNetworkReply::finished, this, &DevicePluginLgSmartTv::onNetworkManagerReplyFinished);
m_showPinReply.append(reply); m_showPinReply.append(reply);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) Device::DeviceSetupStatus DevicePluginLgSmartTv::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret)
{ {
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
@ -247,7 +246,7 @@ DeviceManager::DeviceSetupStatus DevicePluginLgSmartTv::confirmPairing(const Pai
m_setupPairingTv.insert(reply, pairingTransactionId); m_setupPairingTv.insert(reply, pairingTransactionId);
m_tvKeys.insert(params.paramValue(lgSmartTvDeviceUuidParamTypeId).toString(), secret); m_tvKeys.insert(params.paramValue(lgSmartTvDeviceUuidParamTypeId).toString(), secret);
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginLgSmartTv::pairTvDevice(Device *device) void DevicePluginLgSmartTv::pairTvDevice(Device *device)
@ -350,7 +349,7 @@ void DevicePluginLgSmartTv::onNetworkManagerReplyFinished()
PairingTransactionId pairingTransactionId = m_setupPairingTv.take(reply); PairingTransactionId pairingTransactionId = m_setupPairingTv.take(reply);
if(status != 200) { if(status != 200) {
qCWarning(dcLgSmartTv) << "pair TV request error:" << status << reply->errorString(); qCWarning(dcLgSmartTv) << "pair TV request error:" << status << reply->errorString();
emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingTransactionId, Device::DeviceSetupStatusFailure);
} else { } else {
// End pairing before calling setupDevice, which will always try to pair // End pairing before calling setupDevice, which will always try to pair
QPair<QNetworkRequest, QByteArray> request = TvDevice::createEndPairingRequest(reply->request().url()); QPair<QNetworkRequest, QByteArray> request = TvDevice::createEndPairingRequest(reply->request().url());
@ -362,9 +361,9 @@ void DevicePluginLgSmartTv::onNetworkManagerReplyFinished()
PairingTransactionId pairingTransactionId = m_setupEndPairingTv.take(reply); PairingTransactionId pairingTransactionId = m_setupEndPairingTv.take(reply);
if(status != 200) { if(status != 200) {
qCWarning(dcLgSmartTv) << "end pairing TV request error:" << status << reply->errorString(); qCWarning(dcLgSmartTv) << "end pairing TV request error:" << status << reply->errorString();
emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingTransactionId, Device::DeviceSetupStatusFailure);
} else { } else {
emit pairingFinished(pairingTransactionId, DeviceManager::DeviceSetupStatusSuccess); emit pairingFinished(pairingTransactionId, Device::DeviceSetupStatusSuccess);
} }
} else if (m_asyncSetup.keys().contains(reply)) { } else if (m_asyncSetup.keys().contains(reply)) {
Device *device = m_asyncSetup.take(reply); Device *device = m_asyncSetup.take(reply);
@ -420,10 +419,10 @@ void DevicePluginLgSmartTv::onNetworkManagerReplyFinished()
} else if (m_asyncActions.keys().contains(reply)) { } else if (m_asyncActions.keys().contains(reply)) {
ActionId actionId = m_asyncActions.value(reply); ActionId actionId = m_asyncActions.value(reply);
if(status != 200) { if(status != 200) {
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorHardwareNotAvailable); emit actionExecutionFinished(actionId, Device::DeviceErrorHardwareNotAvailable);
qCWarning(dcLgSmartTv) << "Action request error:" << status << reply->errorString(); qCWarning(dcLgSmartTv) << "Action request error:" << status << reply->errorString();
} else { } else {
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
} }
} }
} }

View File

@ -25,7 +25,7 @@
#include "tvdevice.h" #include "tvdevice.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "network/upnp/upnpdevicedescriptor.h" #include "network/upnp/upnpdevicedescriptor.h"
class DevicePluginLgSmartTv : public DevicePlugin class DevicePluginLgSmartTv : public DevicePlugin
@ -40,14 +40,14 @@ public:
~DevicePluginLgSmartTv(); ~DevicePluginLgSmartTv();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override; Device::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor) override;
DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override; Device::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;

View File

@ -35,7 +35,7 @@
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include <QXmlStreamAttributes> #include <QXmlStreamAttributes>
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "tveventhandler.h" #include "tveventhandler.h"
class TvDevice : public QObject class TvDevice : public QObject

View File

@ -22,8 +22,7 @@
#include "devicepluginmailnotification.h" #include "devicepluginmailnotification.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -39,7 +38,7 @@ DevicePluginMailNotification::~DevicePluginMailNotification()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Device *device)
{ {
// Custom mail // Custom mail
if(device->deviceClassId() == customMailDeviceClassId) { if(device->deviceClassId() == customMailDeviceClassId) {
@ -56,7 +55,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
} else if(device->paramValue(customMailDeviceAuthenticationParamTypeId).toString() == "LOGIN") { } else if(device->paramValue(customMailDeviceAuthenticationParamTypeId).toString() == "LOGIN") {
smtpClient->setAuthenticationMethod(SmtpClient::AuthenticationMethodLogin); smtpClient->setAuthenticationMethod(SmtpClient::AuthenticationMethodLogin);
} else { } else {
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
if(device->paramValue(customMailDeviceEncryptionParamTypeId).toString() == "NONE") { if(device->paramValue(customMailDeviceEncryptionParamTypeId).toString() == "NONE") {
@ -66,7 +65,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
} else if(device->paramValue(customMailDeviceEncryptionParamTypeId).toString() == "TLS") { } else if(device->paramValue(customMailDeviceEncryptionParamTypeId).toString() == "TLS") {
smtpClient->setEncryptionType(SmtpClient::EncryptionTypeTLS); smtpClient->setEncryptionType(SmtpClient::EncryptionTypeTLS);
} else { } else {
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
QString recipientsString = device->paramValue(customMailDeviceCustomRecipientParamTypeId).toString(); QString recipientsString = device->paramValue(customMailDeviceCustomRecipientParamTypeId).toString();
@ -81,29 +80,29 @@ DeviceManager::DeviceSetupStatus DevicePluginMailNotification::setupDevice(Devic
smtpClient->testLogin(); smtpClient->testLogin();
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginMailNotification::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginMailNotification::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == customMailDeviceClassId) { if (device->deviceClassId() == customMailDeviceClassId) {
if(action.actionTypeId() == customMailNotifyActionTypeId) { if(action.actionTypeId() == customMailNotifyActionTypeId) {
SmtpClient *smtpClient = m_clients.key(device); SmtpClient *smtpClient = m_clients.key(device);
if (!smtpClient) { if (!smtpClient) {
qCWarning(dcMailNotification()) << "Could not find SMTP client for " << device; qCWarning(dcMailNotification()) << "Could not find SMTP client for " << device;
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
smtpClient->sendMail(action.param(customMailNotifyActionTitleParamTypeId).value().toString(), smtpClient->sendMail(action.param(customMailNotifyActionTitleParamTypeId).value().toString(),
action.param(customMailNotifyActionBodyParamTypeId).value().toString(), action.param(customMailNotifyActionBodyParamTypeId).value().toString(),
action.id()); action.id());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginMailNotification::deviceRemoved(Device *device) void DevicePluginMailNotification::deviceRemoved(Device *device)
@ -119,10 +118,10 @@ void DevicePluginMailNotification::testLoginFinished(const bool &success)
Device *device = m_clients.value(smtpClient); Device *device = m_clients.value(smtpClient);
if (success) { if (success) {
qCDebug(dcMailNotification()) << "Email login test successfull"; qCDebug(dcMailNotification()) << "Email login test successfull";
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
} else { } else {
qCWarning(dcMailNotification()) << "Email login test failed"; qCWarning(dcMailNotification()) << "Email login test failed";
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
if(m_clients.contains(smtpClient)) { if(m_clients.contains(smtpClient)) {
m_clients.remove(smtpClient); m_clients.remove(smtpClient);
} }
@ -134,9 +133,9 @@ void DevicePluginMailNotification::sendMailFinished(const bool &success, const A
{ {
if (success) { if (success) {
qCDebug(dcMailNotification()) << "Email sent successfully"; qCDebug(dcMailNotification()) << "Email sent successfully";
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
} else { } else {
qCWarning(dcMailNotification()) << "Email sending failed"; qCWarning(dcMailNotification()) << "Email sending failed";
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorDeviceNotFound); emit actionExecutionFinished(actionId, Device::DeviceErrorDeviceNotFound);
} }
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINMAILNOTIFICATION_H #ifndef DEVICEPLUGINMAILNOTIFICATION_H
#define DEVICEPLUGINMAILNOTIFICATION_H #define DEVICEPLUGINMAILNOTIFICATION_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "smtpclient.h" #include "smtpclient.h"
class DevicePluginMailNotification : public DevicePlugin class DevicePluginMailNotification : public DevicePlugin
@ -37,8 +37,8 @@ public:
explicit DevicePluginMailNotification(); explicit DevicePluginMailNotification();
~DevicePluginMailNotification(); ~DevicePluginMailNotification();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private: private:

View File

@ -31,7 +31,7 @@
#include <QStringList> #include <QStringList>
#include <QLoggingCategory> #include <QLoggingCategory>
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
Q_DECLARE_LOGGING_CATEGORY(dcSmtpClient) Q_DECLARE_LOGGING_CATEGORY(dcSmtpClient)

View File

@ -21,7 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginmqttclient.h" #include "devicepluginmqttclient.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/mqtt/mqttprovider.h" #include "network/mqtt/mqttprovider.h"
@ -32,7 +32,7 @@ DevicePluginMqttClient::DevicePluginMqttClient()
} }
DeviceManager::DeviceSetupStatus DevicePluginMqttClient::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginMqttClient::setupDevice(Device *device)
{ {
MqttClient *client = nullptr; MqttClient *client = nullptr;
if (device->deviceClassId() == internalMqttClientDeviceClassId) { if (device->deviceClassId() == internalMqttClientDeviceClassId) {
@ -50,7 +50,7 @@ DeviceManager::DeviceSetupStatus DevicePluginMqttClient::setupDevice(Device *dev
}); });
connect(client, &MqttClient::subscribeResult, this, [this, device](quint16 packetId, const Mqtt::SubscribeReturnCodes returnCodes){ connect(client, &MqttClient::subscribeResult, this, [this, device](quint16 packetId, const Mqtt::SubscribeReturnCodes returnCodes){
Q_UNUSED(packetId) Q_UNUSED(packetId)
emit deviceSetupFinished(device, returnCodes.first() == Mqtt::SubscribeReturnCodeFailure ? DeviceManager::DeviceSetupStatusFailure : DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, returnCodes.first() == Mqtt::SubscribeReturnCodeFailure ? Device::DeviceSetupStatusFailure : Device::DeviceSetupStatusSuccess);
}); });
connect(client, &MqttClient::publishReceived, this, &DevicePluginMqttClient::publishReceived); connect(client, &MqttClient::publishReceived, this, &DevicePluginMqttClient::publishReceived);
connect(client, &MqttClient::published, this, &DevicePluginMqttClient::published); connect(client, &MqttClient::published, this, &DevicePluginMqttClient::published);
@ -59,11 +59,11 @@ DeviceManager::DeviceSetupStatus DevicePluginMqttClient::setupDevice(Device *dev
subscribe(device); subscribe(device);
} }
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
DeviceManager::DeviceError DevicePluginMqttClient::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginMqttClient::executeAction(Device *device, const Action &action)
{ {
ParamTypeId topicParamTypeId = internalMqttClientTriggerActionTopicParamTypeId; ParamTypeId topicParamTypeId = internalMqttClientTriggerActionTopicParamTypeId;
ParamTypeId payloadParamTypeId = internalMqttClientTriggerActionDataParamTypeId; ParamTypeId payloadParamTypeId = internalMqttClientTriggerActionDataParamTypeId;
@ -80,7 +80,7 @@ DeviceManager::DeviceError DevicePluginMqttClient::executeAction(Device *device,
MqttClient *client = m_clients.value(device); MqttClient *client = m_clients.value(device);
if (!client) { if (!client) {
qCWarning(dcMqttclient) << "No valid MQTT client for device" << device->name(); qCWarning(dcMqttclient) << "No valid MQTT client for device" << device->name();
return DeviceManager::DeviceErrorDeviceNotFound; return Device::DeviceErrorDeviceNotFound;
} }
Mqtt::QoS qos = Mqtt::QoS0; Mqtt::QoS qos = Mqtt::QoS0;
switch (action.param(qosParamTypeId).value().toInt()) { switch (action.param(qosParamTypeId).value().toInt()) {
@ -100,7 +100,7 @@ DeviceManager::DeviceError DevicePluginMqttClient::executeAction(Device *device,
action.param(retainParamTypeId).value().toBool()); action.param(retainParamTypeId).value().toBool());
m_pendingPublishes.insert(packetId, action); m_pendingPublishes.insert(packetId, action);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
void DevicePluginMqttClient::subscribe(Device *device) void DevicePluginMqttClient::subscribe(Device *device)
@ -146,7 +146,7 @@ void DevicePluginMqttClient::published(quint16 packetId)
return; return;
} }
emit actionExecutionFinished(m_pendingPublishes.take(packetId).id(), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_pendingPublishes.take(packetId).id(), Device::DeviceErrorNoError);
} }
void DevicePluginMqttClient::deviceRemoved(Device *device) void DevicePluginMqttClient::deviceRemoved(Device *device)

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINMQTTCLIENT_H #ifndef DEVICEPLUGINMQTTCLIENT_H
#define DEVICEPLUGINMQTTCLIENT_H #define DEVICEPLUGINMQTTCLIENT_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QHash> #include <QHash>
#include <QDebug> #include <QDebug>
@ -40,10 +40,10 @@ class DevicePluginMqttClient: public DevicePlugin
public: public:
explicit DevicePluginMqttClient(); explicit DevicePluginMqttClient();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots: private slots:
void subscribe(Device *device); void subscribe(Device *device);

View File

@ -21,7 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginnetatmo.h" #include "devicepluginnetatmo.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -44,7 +44,7 @@ void DevicePluginNetatmo::init()
} }
DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device)
{ {
if (device->deviceClassId() == netatmoConnectionDeviceClassId) { if (device->deviceClassId() == netatmoConnectionDeviceClassId) {
qCDebug(dcNetatmo) << "Setup netatmo connection" << device->name() << device->params(); qCDebug(dcNetatmo) << "Setup netatmo connection" << device->name() << device->params();
@ -65,7 +65,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
connect(authentication, &OAuth2::authenticationChanged, this, &DevicePluginNetatmo::onAuthenticationChanged); connect(authentication, &OAuth2::authenticationChanged, this, &DevicePluginNetatmo::onAuthenticationChanged);
authentication->startAuthentication(); authentication->startAuthentication();
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} else if (device->deviceClassId() == indoorDeviceClassId) { } else if (device->deviceClassId() == indoorDeviceClassId) {
qCDebug(dcNetatmo) << "Setup netatmo indoor base station" << device->params(); qCDebug(dcNetatmo) << "Setup netatmo indoor base station" << device->params();
@ -76,7 +76,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
m_indoorDevices.insert(indoor, device); m_indoorDevices.insert(indoor, device);
connect(indoor, SIGNAL(statesChanged()), this, SLOT(onIndoorStatesChanged())); connect(indoor, SIGNAL(statesChanged()), this, SLOT(onIndoorStatesChanged()));
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == outdoorDeviceClassId) { } else if (device->deviceClassId() == outdoorDeviceClassId) {
qCDebug(dcNetatmo) << "Setup netatmo outdoor module" << device->params(); qCDebug(dcNetatmo) << "Setup netatmo outdoor module" << device->params();
NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(device->paramValue(outdoorDeviceNameParamTypeId).toString(), NetatmoOutdoorModule *outdoor = new NetatmoOutdoorModule(device->paramValue(outdoorDeviceNameParamTypeId).toString(),
@ -87,9 +87,9 @@ DeviceManager::DeviceSetupStatus DevicePluginNetatmo::setupDevice(Device *device
m_outdoorDevices.insert(outdoor, device); m_outdoorDevices.insert(outdoor, device);
connect(outdoor, SIGNAL(statesChanged()), this, SLOT(onOutdoorStatesChanged())); connect(outdoor, SIGNAL(statesChanged()), this, SLOT(onOutdoorStatesChanged()));
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginNetatmo::deviceRemoved(Device *device) void DevicePluginNetatmo::deviceRemoved(Device *device)
@ -129,12 +129,12 @@ void DevicePluginNetatmo::postSetupDevice(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginNetatmo::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginNetatmo::executeAction(Device *device, const Action &action)
{ {
Q_UNUSED(device) Q_UNUSED(device)
Q_UNUSED(action) Q_UNUSED(action)
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginNetatmo::refreshData(Device *device, const QString &token) void DevicePluginNetatmo::refreshData(Device *device, const QString &token)
@ -291,11 +291,11 @@ void DevicePluginNetatmo::onAuthenticationChanged()
if (m_asyncSetups.contains(device)) { if (m_asyncSetups.contains(device)) {
m_asyncSetups.removeAll(device); m_asyncSetups.removeAll(device);
if (authentication->authenticated()) { if (authentication->authenticated()) {
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
refreshData(device, authentication->token()); refreshData(device, authentication->token());
} else { } else {
authentication->deleteLater(); authentication->deleteLater();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
} }
} }
} }

View File

@ -24,7 +24,7 @@
#define DEVICEPLUGINNETATMO_H #define DEVICEPLUGINNETATMO_H
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "network/oauth2.h" #include "network/oauth2.h"
#include "netatmobasestation.h" #include "netatmobasestation.h"
#include "netatmooutdoormodule.h" #include "netatmooutdoormodule.h"
@ -43,12 +43,12 @@ public:
~DevicePluginNetatmo(); ~DevicePluginNetatmo();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;

View File

@ -23,8 +23,7 @@
#include "devicepluginnetworkdetector.h" #include "devicepluginnetworkdetector.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -50,7 +49,7 @@ void DevicePluginNetworkDetector::init()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device *device)
{ {
qCDebug(dcNetworkDetector()) << "Setup" << device->name() << device->params(); qCDebug(dcNetworkDetector()) << "Setup" << device->name() << device->params();
DeviceMonitor *monitor = new DeviceMonitor(device->name(), DeviceMonitor *monitor = new DeviceMonitor(device->name(),
@ -81,25 +80,25 @@ DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device
m_broadcastPing->run(); m_broadcastPing->run();
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginNetworkDetector::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginNetworkDetector::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
if (deviceClassId != networkDeviceDeviceClassId) if (deviceClassId != networkDeviceDeviceClassId)
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
if (m_discovery->isRunning()) { if (m_discovery->isRunning()) {
qCWarning(dcNetworkDetector()) << "Network discovery already running"; qCWarning(dcNetworkDetector()) << "Network discovery already running";
return DeviceManager::DeviceErrorDeviceInUse; return Device::DeviceErrorDeviceInUse;
} }
m_discovery->discoverHosts(25); m_discovery->discoverHosts(25);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
void DevicePluginNetworkDetector::deviceRemoved(Device *device) void DevicePluginNetworkDetector::deviceRemoved(Device *device)

View File

@ -24,7 +24,7 @@
#ifndef DEVICEPLUGINNETWORKDETECTOR_H #ifndef DEVICEPLUGINNETWORKDETECTOR_H
#define DEVICEPLUGINNETWORKDETECTOR_H #define DEVICEPLUGINNETWORKDETECTOR_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "host.h" #include "host.h"
#include "discovery.h" #include "discovery.h"
#include "plugintimer.h" #include "plugintimer.h"
@ -48,8 +48,8 @@ public:
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;

View File

@ -21,8 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginopenweathermap.h" #include "devicepluginopenweathermap.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -62,10 +61,10 @@ void DevicePluginOpenweathermap::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOpenweathermap::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOpenweathermap::onPluginTimer);
} }
DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginOpenweathermap::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
if (deviceClassId != openweathermapDeviceClassId) { if (deviceClassId != openweathermapDeviceClassId) {
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
QString location = params.paramValue(openweathermapDiscoveryLocationParamTypeId).toString(); QString location = params.paramValue(openweathermapDiscoveryLocationParamTypeId).toString();
@ -76,26 +75,26 @@ DeviceManager::DeviceError DevicePluginOpenweathermap::discoverDevices(const Dev
} else { } else {
search(location); search(location);
} }
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginOpenweathermap::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginOpenweathermap::setupDevice(Device *device)
{ {
if (device->deviceClassId() != openweathermapDeviceClassId) if (device->deviceClassId() != openweathermapDeviceClassId)
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
update(device); update(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginOpenweathermap::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginOpenweathermap::executeAction(Device *device, const Action &action)
{ {
if(action.actionTypeId() == openweathermapRefreshWeatherActionTypeId){ if(action.actionTypeId() == openweathermapRefreshWeatherActionTypeId){
update(device); update(device);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
void DevicePluginOpenweathermap::deviceRemoved(Device *device) void DevicePluginOpenweathermap::deviceRemoved(Device *device)

View File

@ -24,7 +24,7 @@
#define DEVICEPLUGINOPENWEATHERMAP_H #define DEVICEPLUGINOPENWEATHERMAP_H
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
#include <QTimer> #include <QTimer>
@ -42,9 +42,9 @@ public:
~DevicePluginOpenweathermap(); ~DevicePluginOpenweathermap();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;

View File

@ -44,7 +44,7 @@
*/ */
#include "devicepluginosdomotics.h" #include "devicepluginosdomotics.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -67,7 +67,7 @@ void DevicePluginOsdomotics::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOsdomotics::onPluginTimer); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginOsdomotics::onPluginTimer);
} }
DeviceManager::DeviceSetupStatus DevicePluginOsdomotics::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginOsdomotics::setupDevice(Device *device)
{ {
if (device->deviceClassId() == rplRouterDeviceClassId) { if (device->deviceClassId() == rplRouterDeviceClassId) {
qCDebug(dcOsdomotics) << "Setup RPL router" << device->paramValue(rplRouterDeviceRplHostParamTypeId).toString(); qCDebug(dcOsdomotics) << "Setup RPL router" << device->paramValue(rplRouterDeviceRplHostParamTypeId).toString();
@ -75,7 +75,7 @@ DeviceManager::DeviceSetupStatus DevicePluginOsdomotics::setupDevice(Device *dev
if (address.isNull()) { if (address.isNull()) {
qCWarning(dcOsdomotics) << "Got invalid address" << device->paramValue(rplRouterDeviceRplHostParamTypeId).toString(); qCWarning(dcOsdomotics) << "Got invalid address" << device->paramValue(rplRouterDeviceRplHostParamTypeId).toString();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
QUrl url; QUrl url;
@ -86,13 +86,13 @@ DeviceManager::DeviceSetupStatus DevicePluginOsdomotics::setupDevice(Device *dev
connect(reply, &QNetworkReply::finished, this, &DevicePluginOsdomotics::onNetworkReplyFinished); connect(reply, &QNetworkReply::finished, this, &DevicePluginOsdomotics::onNetworkReplyFinished);
m_asyncSetup.insert(reply, device); m_asyncSetup.insert(reply, device);
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} else if (device->deviceClassId() == merkurNodeDeviceClassId) { } else if (device->deviceClassId() == merkurNodeDeviceClassId) {
qCDebug(dcOsdomotics) << "Setup Merkur node" << device->paramValue(merkurNodeDeviceHostParamTypeId).toString(); qCDebug(dcOsdomotics) << "Setup Merkur node" << device->paramValue(merkurNodeDeviceHostParamTypeId).toString();
device->setParentId(DeviceId(device->paramValue(merkurNodeDeviceRouterParamTypeId).toString())); device->setParentId(DeviceId(device->paramValue(merkurNodeDeviceRouterParamTypeId).toString()));
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginOsdomotics::deviceRemoved(Device *device) void DevicePluginOsdomotics::deviceRemoved(Device *device)
@ -105,7 +105,7 @@ void DevicePluginOsdomotics::postSetupDevice(Device *device)
updateNode(device); updateNode(device);
} }
DeviceManager::DeviceError DevicePluginOsdomotics::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginOsdomotics::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == merkurNodeDeviceClassId) { if (device->deviceClassId() == merkurNodeDeviceClassId) {
if (action.actionTypeId() == merkurNodeToggleLedActionTypeId) { if (action.actionTypeId() == merkurNodeToggleLedActionTypeId) {
@ -122,17 +122,17 @@ DeviceManager::DeviceError DevicePluginOsdomotics::executeAction(Device *device,
if (reply->error() != CoapReply::NoError) { if (reply->error() != CoapReply::NoError) {
qCWarning(dcOsdomotics) << "CoAP reply finished with error" << reply->errorString(); qCWarning(dcOsdomotics) << "CoAP reply finished with error" << reply->errorString();
reply->deleteLater(); reply->deleteLater();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
} }
m_toggleLightRequests.insert(reply, action); m_toggleLightRequests.insert(reply, action);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginOsdomotics::scanNodes(Device *device) void DevicePluginOsdomotics::scanNodes(Device *device)
@ -243,7 +243,7 @@ void DevicePluginOsdomotics::onNetworkReplyFinished()
// check HTTP status code // check HTTP status code
if (status != 200) { if (status != 200) {
qCWarning(dcOsdomotics) << "Setup reply HTTP error:" << reply->errorString(); qCWarning(dcOsdomotics) << "Setup reply HTTP error:" << reply->errorString();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
reply->deleteLater(); reply->deleteLater();
return; return;
} }
@ -251,14 +251,14 @@ void DevicePluginOsdomotics::onNetworkReplyFinished()
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
parseNodes(device, data); parseNodes(device, data);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
} else if (m_asyncNodeRescans.contains(reply)) { } else if (m_asyncNodeRescans.contains(reply)) {
Device *device = m_asyncSetup.take(reply); Device *device = m_asyncSetup.take(reply);
// check HTTP status code // check HTTP status code
if (status != 200) { if (status != 200) {
qCWarning(dcOsdomotics) << "Setup reply HTTP error:" << reply->errorString(); qCWarning(dcOsdomotics) << "Setup reply HTTP error:" << reply->errorString();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
reply->deleteLater(); reply->deleteLater();
return; return;
} }
@ -296,11 +296,11 @@ void DevicePluginOsdomotics::coapReplyFinished(CoapReply *reply)
if (reply->error() != CoapReply::NoError) { if (reply->error() != CoapReply::NoError) {
qCWarning(dcOsdomotics) << "CoAP toggle reply finished with error" << reply->errorString(); qCWarning(dcOsdomotics) << "CoAP toggle reply finished with error" << reply->errorString();
reply->deleteLater(); reply->deleteLater();
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareFailure);
return; return;
} }
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(action.id(), Device::DeviceErrorNoError);
} else if (m_updateRequests.contains(reply)) { } else if (m_updateRequests.contains(reply)) {
Device *device = m_updateRequests.take(reply); Device *device = m_updateRequests.take(reply);
if (reply->error() != CoapReply::NoError) { if (reply->error() != CoapReply::NoError) {

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINOSDOMOTICS_H #ifndef DEVICEPLUGINOSDOMOTICS_H
#define DEVICEPLUGINOSDOMOTICS_H #define DEVICEPLUGINOSDOMOTICS_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QHash> #include <QHash>
#include <QDebug> #include <QDebug>
@ -43,10 +43,10 @@ public:
~DevicePluginOsdomotics(); ~DevicePluginOsdomotics();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer = nullptr; PluginTimer *m_pluginTimer = nullptr;

View File

@ -24,8 +24,7 @@
#include "devicepluginphilipshue.h" #include "devicepluginphilipshue.h"
#include "devicemanager.h" #include "devices/device.h"
#include "plugin/device.h"
#include "types/param.h" #include "types/param.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdiscovery.h"
@ -78,7 +77,7 @@ void DevicePluginPhilipsHue::init()
} }
DeviceManager::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
@ -165,10 +164,10 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::discoverDevices(const DeviceC
finishDiscovery(discovery); finishDiscovery(discovery);
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *device)
{ {
// Update the name on the bridge if the user changes the device name // Update the name on the bridge if the user changes the device name
connect(device, &Device::nameChanged, this, &DevicePluginPhilipsHue::onDeviceNameChanged); connect(device, &Device::nameChanged, this, &DevicePluginPhilipsHue::onDeviceNameChanged);
@ -187,7 +186,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
m_bridges.insert(b, device); m_bridges.insert(b, device);
device->setStateValue(bridgeConnectedStateTypeId, true); device->setStateValue(bridgeConnectedStateTypeId, true);
discoverBridgeDevices(b); discoverBridgeDevices(b);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
} }
@ -203,7 +202,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
m_bridges.insert(bridge, device); m_bridges.insert(bridge, device);
discoverBridgeDevices(bridge); discoverBridgeDevices(bridge);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Hue color light // Hue color light
@ -224,7 +223,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
refreshLight(device); refreshLight(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Hue color temperature light // Hue color temperature light
@ -245,7 +244,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
refreshLight(device); refreshLight(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Hue white light // Hue white light
@ -266,7 +265,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
m_lights.insert(hueLight, device); m_lights.insert(hueLight, device);
refreshLight(device); refreshLight(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Hue remote // Hue remote
@ -286,7 +285,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
connect(hueRemote, &HueRemote::buttonPressed, this, &DevicePluginPhilipsHue::onRemoteButtonEvent); connect(hueRemote, &HueRemote::buttonPressed, this, &DevicePluginPhilipsHue::onRemoteButtonEvent);
m_remotes.insert(hueRemote, device); m_remotes.insert(hueRemote, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
// Hue tap // Hue tap
@ -300,14 +299,47 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
connect(hueTap, &HueRemote::buttonPressed, this, &DevicePluginPhilipsHue::onRemoteButtonEvent); connect(hueTap, &HueRemote::buttonPressed, this, &DevicePluginPhilipsHue::onRemoteButtonEvent);
m_remotes.insert(hueTap, device); m_remotes.insert(hueTap, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
}
// Hue Motion sensor
if (device->deviceClassId() == motionSensorDeviceClassId) {
qCDebug(dcPhilipsHue) << "Setup Hue motion sensor" << device->params();
HueIndoorSensor *motionSensor = new HueIndoorSensor(this);
motionSensor->setTimeout(device->setting(motionSensorSettingsTimeoutParamTypeId).toUInt());
motionSensor->setUuid(device->paramValue(motionSensorDeviceUuidParamTypeId).toString());
motionSensor->setModelId(device->paramValue(motionSensorDeviceModelIdParamTypeId).toString());
motionSensor->setTemperatureSensorId(device->paramValue(motionSensorDeviceSensorIdTemperatureParamTypeId).toInt());
motionSensor->setTemperatureSensorUuid(device->paramValue(motionSensorDeviceSensorUuidTemperatureParamTypeId).toString());
motionSensor->setPresenceSensorId(device->paramValue(motionSensorDeviceSensorIdPresenceParamTypeId).toInt());
motionSensor->setPresenceSensorUuid(device->paramValue(motionSensorDeviceSensorUuidPresenceParamTypeId).toString());
motionSensor->setLightSensorId(device->paramValue(motionSensorDeviceSensorIdLightParamTypeId).toInt());
motionSensor->setLightSensorUuid(device->paramValue(motionSensorDeviceSensorUuidLightParamTypeId).toString());
connect(motionSensor, &HueMotionSensor::reachableChanged, this, &DevicePluginPhilipsHue::onMotionSensorReachableChanged);
connect(motionSensor, &HueMotionSensor::batteryLevelChanged, this, &DevicePluginPhilipsHue::onMotionSensorBatteryLevelChanged);
connect(motionSensor, &HueMotionSensor::temperatureChanged, this, &DevicePluginPhilipsHue::onMotionSensorTemperatureChanged);
connect(motionSensor, &HueMotionSensor::presenceChanged, this, &DevicePluginPhilipsHue::onMotionSensorPresenceChanged);
connect(motionSensor, &HueMotionSensor::lightIntensityChanged, this, &DevicePluginPhilipsHue::onMotionSensorLightIntensityChanged);
connect(device, &Device::settingChanged, motionSensor, [motionSensor](const ParamTypeId &paramTypeId, const QVariant &value){
if (paramTypeId == motionSensorSettingsTimeoutParamTypeId) {
motionSensor->setTimeout(value.toUInt());
}
});
m_motionSensors.insert(motionSensor, device);
return Device::DeviceSetupStatusSuccess;
} }
// Hue Outdoor sensor // Hue Outdoor sensor
if (device->deviceClassId() == outdoorSensorDeviceClassId) { if (device->deviceClassId() == outdoorSensorDeviceClassId) {
qCDebug(dcPhilipsHue) << "Setup Hue Outdoor sensor" << device->params(); qCDebug(dcPhilipsHue) << "Setup Hue Outdoor sensor" << device->params();
HueOutdoorSensor *outdoorSensor = new HueOutdoorSensor(this); HueMotionSensor *outdoorSensor = new HueOutdoorSensor(this);
outdoorSensor->setTimeout(device->setting(outdoorSensorSettingsTimeoutParamTypeId).toUInt());
outdoorSensor->setUuid(device->paramValue(outdoorSensorDeviceUuidParamTypeId).toString()); outdoorSensor->setUuid(device->paramValue(outdoorSensorDeviceUuidParamTypeId).toString());
outdoorSensor->setModelId(device->paramValue(outdoorSensorDeviceModelIdParamTypeId).toString()); outdoorSensor->setModelId(device->paramValue(outdoorSensorDeviceModelIdParamTypeId).toString());
outdoorSensor->setTemperatureSensorId(device->paramValue(outdoorSensorDeviceSensorIdTemperatureParamTypeId).toInt()); outdoorSensor->setTemperatureSensorId(device->paramValue(outdoorSensorDeviceSensorIdTemperatureParamTypeId).toInt());
@ -317,20 +349,26 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
outdoorSensor->setLightSensorId(device->paramValue(outdoorSensorDeviceSensorIdLightParamTypeId).toInt()); outdoorSensor->setLightSensorId(device->paramValue(outdoorSensorDeviceSensorIdLightParamTypeId).toInt());
outdoorSensor->setLightSensorUuid(device->paramValue(outdoorSensorDeviceSensorUuidLightParamTypeId).toString()); outdoorSensor->setLightSensorUuid(device->paramValue(outdoorSensorDeviceSensorUuidLightParamTypeId).toString());
connect(outdoorSensor, &HueOutdoorSensor::reachableChanged, this, &DevicePluginPhilipsHue::onOutdoorSensorReachableChanged); connect(outdoorSensor, &HueMotionSensor::reachableChanged, this, &DevicePluginPhilipsHue::onMotionSensorReachableChanged);
connect(outdoorSensor, &HueOutdoorSensor::batteryLevelChanged, this, &DevicePluginPhilipsHue::onOutdoorSensorBatteryLevelChanged); connect(outdoorSensor, &HueMotionSensor::batteryLevelChanged, this, &DevicePluginPhilipsHue::onMotionSensorBatteryLevelChanged);
connect(outdoorSensor, &HueOutdoorSensor::temperatureChanged, this, &DevicePluginPhilipsHue::onOutdoorSensorTemperatureChanged); connect(outdoorSensor, &HueMotionSensor::temperatureChanged, this, &DevicePluginPhilipsHue::onMotionSensorTemperatureChanged);
connect(outdoorSensor, &HueOutdoorSensor::presenceChanged, this, &DevicePluginPhilipsHue::onOutdoorSensorPresenceChanged); connect(outdoorSensor, &HueMotionSensor::presenceChanged, this, &DevicePluginPhilipsHue::onMotionSensorPresenceChanged);
connect(outdoorSensor, &HueOutdoorSensor::lightIntensityChanged, this, &DevicePluginPhilipsHue::onOutdoorSensorLightIntensityChanged); connect(outdoorSensor, &HueMotionSensor::lightIntensityChanged, this, &DevicePluginPhilipsHue::onMotionSensorLightIntensityChanged);
m_outdoorSensors.insert(outdoorSensor, device); connect(device, &Device::settingChanged, outdoorSensor, [outdoorSensor](const ParamTypeId &paramTypeId, const QVariant &value){
if (paramTypeId == outdoorSensorSettingsTimeoutParamTypeId) {
outdoorSensor->setTimeout(value.toUInt());
}
});
return DeviceManager::DeviceSetupStatusSuccess; m_motionSensors.insert(outdoorSensor, device);
return Device::DeviceSetupStatusSuccess;
} }
qCWarning(dcPhilipsHue()) << "Unhandled setupDevice call" << device->deviceClassId(); qCWarning(dcPhilipsHue()) << "Unhandled setupDevice call" << device->deviceClassId();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginPhilipsHue::deviceRemoved(Device *device) void DevicePluginPhilipsHue::deviceRemoved(Device *device)
@ -365,19 +403,19 @@ void DevicePluginPhilipsHue::deviceRemoved(Device *device)
} }
if (device->deviceClassId() == outdoorSensorDeviceClassId) { if (device->deviceClassId() == outdoorSensorDeviceClassId) {
HueOutdoorSensor *outdoorSensor = m_outdoorSensors.key(device); HueMotionSensor *outdoorSensor = m_motionSensors.key(device);
m_outdoorSensors.remove(outdoorSensor); m_motionSensors.remove(outdoorSensor);
outdoorSensor->deleteLater(); outdoorSensor->deleteLater();
} }
} }
DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) Device::DeviceSetupStatus DevicePluginPhilipsHue::confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret)
{ {
Q_UNUSED(secret) Q_UNUSED(secret)
qCDebug(dcPhilipsHue()) << "Confirming pairing for transactionId" << pairingTransactionId; qCDebug(dcPhilipsHue()) << "Confirming pairing for transactionId" << pairingTransactionId;
if (deviceClassId != bridgeDeviceClassId) if (deviceClassId != bridgeDeviceClassId)
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
PairingInfo *pairingInfo = new PairingInfo(this); PairingInfo *pairingInfo = new PairingInfo(this);
pairingInfo->setPairingTransactionId(pairingTransactionId); pairingInfo->setPairingTransactionId(pairingTransactionId);
@ -395,7 +433,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::confirmPairing(const Pa
m_pairingRequests.insert(reply, pairingInfo); m_pairingRequests.insert(reply, pairingInfo);
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
void DevicePluginPhilipsHue::networkManagerReplyReady() void DevicePluginPhilipsHue::networkManagerReplyReady()
@ -520,7 +558,7 @@ void DevicePluginPhilipsHue::networkManagerReplyReady()
if (status != 200 || reply->error() != QNetworkReply::NoError) { if (status != 200 || reply->error() != QNetworkReply::NoError) {
qCWarning(dcPhilipsHue) << "Execute Hue Light action request error:" << status << reply->errorString(); qCWarning(dcPhilipsHue) << "Execute Hue Light action request error:" << status << reply->errorString();
bridgeReachableChanged(actionInfo.first, false); bridgeReachableChanged(actionInfo.first, false);
emit actionExecutionFinished(actionInfo.second, DeviceManager::DeviceErrorHardwareNotAvailable); emit actionExecutionFinished(actionInfo.second, Device::DeviceErrorHardwareNotAvailable);
return; return;
} }
processActionResponse(actionInfo.first, actionInfo.second, reply->readAll()); processActionResponse(actionInfo.first, actionInfo.second, reply->readAll());
@ -578,7 +616,7 @@ void DevicePluginPhilipsHue::finishDiscovery(DevicePluginPhilipsHue::DiscoveryJo
delete job; delete job;
} }
DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginPhilipsHue::executeAction(Device *device, const Action &action)
{ {
qCDebug(dcPhilipsHue) << "Execute action" << action.actionTypeId() << action.params(); qCDebug(dcPhilipsHue) << "Execute action" << action.actionTypeId() << action.params();
@ -588,7 +626,7 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
if (!light->reachable()) { if (!light->reachable()) {
qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable"; qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == colorLightPowerActionTypeId) { if (action.actionTypeId() == colorLightPowerActionTypeId) {
@ -596,39 +634,39 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorLightColorActionTypeId) { } else if (action.actionTypeId() == colorLightColorActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetColorRequest(action.param(colorLightColorActionColorParamTypeId).value().value<QColor>()); QPair<QNetworkRequest, QByteArray> request = light->createSetColorRequest(action.param(colorLightColorActionColorParamTypeId).value().value<QColor>());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply,QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply,QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorLightBrightnessActionTypeId) { } else if (action.actionTypeId() == colorLightBrightnessActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(colorLightBrightnessActionBrightnessParamTypeId).value().toInt())); QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(colorLightBrightnessActionBrightnessParamTypeId).value().toInt()));
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorLightEffectActionTypeId) { } else if (action.actionTypeId() == colorLightEffectActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetEffectRequest(action.param(colorLightEffectActionEffectParamTypeId).value().toString()); QPair<QNetworkRequest, QByteArray> request = light->createSetEffectRequest(action.param(colorLightEffectActionEffectParamTypeId).value().toString());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorLightAlertActionTypeId) { } else if (action.actionTypeId() == colorLightAlertActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(colorLightAlertActionAlertParamTypeId).value().toString()); QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(colorLightAlertActionAlertParamTypeId).value().toString());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorLightColorTemperatureActionTypeId) { } else if (action.actionTypeId() == colorLightColorTemperatureActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(colorLightColorTemperatureActionColorTemperatureParamTypeId).value().toInt()); QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(colorLightColorTemperatureActionColorTemperatureParamTypeId).value().toInt());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Color temperature light // Color temperature light
@ -637,7 +675,7 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
if (!light->reachable()) { if (!light->reachable()) {
qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable"; qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == colorTemperatureLightPowerActionTypeId) { if (action.actionTypeId() == colorTemperatureLightPowerActionTypeId) {
@ -645,27 +683,27 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorTemperatureLightBrightnessActionTypeId) { } else if (action.actionTypeId() == colorTemperatureLightBrightnessActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(colorTemperatureLightBrightnessActionBrightnessParamTypeId).value().toInt())); QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(colorTemperatureLightBrightnessActionBrightnessParamTypeId).value().toInt()));
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorTemperatureLightAlertActionTypeId) { } else if (action.actionTypeId() == colorTemperatureLightAlertActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(colorTemperatureLightAlertActionAlertParamTypeId).value().toString()); QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(colorTemperatureLightAlertActionAlertParamTypeId).value().toString());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == colorTemperatureLightColorTemperatureActionTypeId) { } else if (action.actionTypeId() == colorTemperatureLightColorTemperatureActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(colorTemperatureLightColorTemperatureActionColorTemperatureParamTypeId).value().toInt()); QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(colorTemperatureLightColorTemperatureActionColorTemperatureParamTypeId).value().toInt());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Dimmable light // Dimmable light
@ -674,7 +712,7 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
if (!light->reachable()) { if (!light->reachable()) {
qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable"; qCWarning(dcPhilipsHue) << "Light" << light->name() << "not reachable";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == dimmableLightPowerActionTypeId) { if (action.actionTypeId() == dimmableLightPowerActionTypeId) {
@ -682,21 +720,21 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == dimmableLightBrightnessActionTypeId) { } else if (action.actionTypeId() == dimmableLightBrightnessActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(dimmableLightBrightnessActionBrightnessParamTypeId).value().toInt())); QPair<QNetworkRequest, QByteArray> request = light->createSetBrightnessRequest(percentageToBrightness(action.param(dimmableLightBrightnessActionBrightnessParamTypeId).value().toInt()));
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == dimmableLightAlertActionTypeId) { } else if (action.actionTypeId() == dimmableLightAlertActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(dimmableLightAlertActionAlertParamTypeId).value().toString()); QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(dimmableLightAlertActionAlertParamTypeId).value().toString());
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Hue bridge // Hue bridge
@ -704,28 +742,28 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
HueBridge *bridge = m_bridges.key(device); HueBridge *bridge = m_bridges.key(device);
if (!device->stateValue(bridgeConnectedStateTypeId).toBool()) { if (!device->stateValue(bridgeConnectedStateTypeId).toBool()) {
qCWarning(dcPhilipsHue) << "Bridge" << bridge->hostAddress().toString() << "not reachable"; qCWarning(dcPhilipsHue) << "Bridge" << bridge->hostAddress().toString() << "not reachable";
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == bridgeSearchNewDevicesActionTypeId) { if (action.actionTypeId() == bridgeSearchNewDevicesActionTypeId) {
searchNewDevices(bridge, action.param(bridgeSearchNewDevicesActionSerialParamTypeId).value().toString()); searchNewDevices(bridge, action.param(bridgeSearchNewDevicesActionSerialParamTypeId).value().toString());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == bridgeCheckForUpdatesActionTypeId) { } else if (action.actionTypeId() == bridgeCheckForUpdatesActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = bridge->createCheckUpdatesRequest(); QPair<QNetworkRequest, QByteArray> request = bridge->createCheckUpdatesRequest();
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else if (action.actionTypeId() == bridgeUpgradeActionTypeId) { } else if (action.actionTypeId() == bridgeUpgradeActionTypeId) {
QPair<QNetworkRequest, QByteArray> request = bridge->createUpgradeRequest(); QPair<QNetworkRequest, QByteArray> request = bridge->createUpgradeRequest();
QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second); QNetworkReply *reply = hardwareManager()->networkManager()->put(request.first, request.second);
connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady); connect(reply, &QNetworkReply::finished, this, &DevicePluginPhilipsHue::networkManagerReplyReady);
m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id())); m_asyncActions.insert(reply, QPair<Device *, ActionId>(device, action.id()));
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginPhilipsHue::lightStateChanged() void DevicePluginPhilipsHue::lightStateChanged()
@ -837,41 +875,41 @@ void DevicePluginPhilipsHue::onRemoteButtonEvent(int buttonCode)
emitEvent(Event(id, m_remotes.value(remote)->id(), ParamList() << param)); emitEvent(Event(id, m_remotes.value(remote)->id(), ParamList() << param));
} }
void DevicePluginPhilipsHue::onOutdoorSensorReachableChanged(bool reachable) void DevicePluginPhilipsHue::onMotionSensorReachableChanged(bool reachable)
{ {
HueOutdoorSensor *sensor = static_cast<HueOutdoorSensor *>(sender()); HueMotionSensor *sensor = static_cast<HueMotionSensor *>(sender());
Device *sensorDevice = m_outdoorSensors.value(sensor); Device *sensorDevice = m_motionSensors.value(sensor);
sensorDevice->setStateValue(outdoorSensorConnectedStateTypeId, reachable); sensorDevice->setStateValue(sensor->connectedStateTypeId(), reachable);
} }
void DevicePluginPhilipsHue::onOutdoorSensorBatteryLevelChanged(int batteryLevel) void DevicePluginPhilipsHue::onMotionSensorBatteryLevelChanged(int batteryLevel)
{ {
HueOutdoorSensor *sensor = static_cast<HueOutdoorSensor *>(sender()); HueMotionSensor *sensor = static_cast<HueMotionSensor *>(sender());
Device *sensorDevice = m_outdoorSensors.value(sensor); Device *sensorDevice = m_motionSensors.value(sensor);
sensorDevice->setStateValue(outdoorSensorBatteryLevelStateTypeId, batteryLevel); sensorDevice->setStateValue(sensor->batteryLevelStateTypeId(), batteryLevel);
sensorDevice->setStateValue(outdoorSensorBatteryCriticalStateTypeId, (batteryLevel < 5)); sensorDevice->setStateValue(sensor->batteryCriticalStateTypeId(), (batteryLevel < 5));
} }
void DevicePluginPhilipsHue::onOutdoorSensorTemperatureChanged(double temperature) void DevicePluginPhilipsHue::onMotionSensorTemperatureChanged(double temperature)
{ {
HueOutdoorSensor *sensor = static_cast<HueOutdoorSensor *>(sender()); HueMotionSensor *sensor = static_cast<HueMotionSensor *>(sender());
Device *sensorDevice = m_outdoorSensors.value(sensor); Device *sensorDevice = m_motionSensors.value(sensor);
sensorDevice->setStateValue(outdoorSensorTemperatureStateTypeId, temperature); sensorDevice->setStateValue(sensor->temperatureStateTypeId(), temperature);
} }
void DevicePluginPhilipsHue::onOutdoorSensorPresenceChanged(bool presence) void DevicePluginPhilipsHue::onMotionSensorPresenceChanged(bool presence)
{ {
HueOutdoorSensor *sensor = static_cast<HueOutdoorSensor *>(sender()); HueMotionSensor *sensor = static_cast<HueMotionSensor *>(sender());
Device *sensorDevice = m_outdoorSensors.value(sensor); Device *sensorDevice = m_motionSensors.value(sensor);
sensorDevice->setStateValue(outdoorSensorIsPresentStateTypeId, presence); sensorDevice->setStateValue(sensor->isPresentStateTypeId(), presence);
if (presence) sensorDevice->setStateValue(outdoorSensorLastSeenTimeStateTypeId, QDateTime::currentDateTime().toTime_t()); if (presence) sensorDevice->setStateValue(sensor->lastSeenTimeStateTypeId(), QDateTime::currentDateTime().toTime_t());
} }
void DevicePluginPhilipsHue::onOutdoorSensorLightIntensityChanged(double lightIntensity) void DevicePluginPhilipsHue::onMotionSensorLightIntensityChanged(double lightIntensity)
{ {
HueOutdoorSensor *sensor = static_cast<HueOutdoorSensor *>(sender()); HueMotionSensor *sensor = static_cast<HueMotionSensor *>(sender());
Device *sensorDevice = m_outdoorSensors.value(sensor); Device *sensorDevice = m_motionSensors.value(sensor);
sensorDevice->setStateValue(outdoorSensorLightIntensityStateTypeId, lightIntensity); sensorDevice->setStateValue(sensor->lightIntensityStateTypeId(), lightIntensity);
} }
void DevicePluginPhilipsHue::refreshLight(Device *device) void DevicePluginPhilipsHue::refreshLight(Device *device)
@ -1084,7 +1122,7 @@ void DevicePluginPhilipsHue::processBridgeSensorDiscoveryResponse(Device *device
// Create sensors if not already added // Create sensors if not already added
QVariantMap sensorsMap = jsonDoc.toVariant().toMap(); QVariantMap sensorsMap = jsonDoc.toVariant().toMap();
QHash<QString, HueOutdoorSensor *> outdoorSensors; QHash<QString, HueMotionSensor *> motionSensors;
foreach (const QString &sensorId, sensorsMap.keys()) { foreach (const QString &sensorId, sensorsMap.keys()) {
QVariantMap sensorMap = sensorsMap.value(sensorId).toMap(); QVariantMap sensorMap = sensorsMap.value(sensorId).toMap();
@ -1113,7 +1151,8 @@ void DevicePluginPhilipsHue::processBridgeSensorDiscoveryResponse(Device *device
descriptor.setParams(params); descriptor.setParams(params);
emit autoDevicesAppeared(tapDeviceClassId, {descriptor}); emit autoDevicesAppeared(tapDeviceClassId, {descriptor});
qCDebug(dcPhilipsHue()) << "Found hue tap:" << sensorMap << tapDeviceClassId; qCDebug(dcPhilipsHue()) << "Found hue tap:" << sensorMap << tapDeviceClassId;
} else if (model == "SML002") {
} else if (model == "SML001" || model == "SML002") {
// Get the base uuid from this sensor // Get the base uuid from this sensor
QString baseUuid = HueDevice::getBaseUuid(uuid); QString baseUuid = HueDevice::getBaseUuid(uuid);
@ -1121,52 +1160,69 @@ void DevicePluginPhilipsHue::processBridgeSensorDiscoveryResponse(Device *device
if (sensorMap.value("type").toString() == "ZLLTemperature") { if (sensorMap.value("type").toString() == "ZLLTemperature") {
qCDebug(dcPhilipsHue()) << "Found temperature sensor from OurdoorSensor:" << baseUuid << sensorMap; qCDebug(dcPhilipsHue()) << "Found temperature sensor from OurdoorSensor:" << baseUuid << sensorMap;
// Check if we haven outdoor sensor for this temperature sensor // Check if we haven outdoor sensor for this temperature sensor
if (outdoorSensors.keys().contains(baseUuid)) { if (motionSensors.contains(baseUuid)) {
HueOutdoorSensor *outdoorSensor = outdoorSensors.value(baseUuid); HueMotionSensor *motionSensor = motionSensors.value(baseUuid);
outdoorSensor->setTemperatureSensorUuid(uuid); motionSensor->setTemperatureSensorUuid(uuid);
outdoorSensor->setTemperatureSensorId(sensorId.toInt()); motionSensor->setTemperatureSensorId(sensorId.toInt());
} else { } else {
// Create an outdoor sensor // Create an outdoor sensor
HueOutdoorSensor *outdoorSensor = new HueOutdoorSensor(this); HueMotionSensor *motionSensor = nullptr;
outdoorSensor->setModelId(model); if (model == "SML001") {
outdoorSensor->setUuid(baseUuid); motionSensor = new HueIndoorSensor(this);
outdoorSensor->setTemperatureSensorUuid(uuid); } else {
outdoorSensor->setTemperatureSensorId(sensorId.toInt()); motionSensor = new HueOutdoorSensor(this);
outdoorSensors.insert(baseUuid, outdoorSensor); }
motionSensor->setModelId(model);
motionSensor->setUuid(baseUuid);
motionSensor->setTemperatureSensorUuid(uuid);
motionSensor->setTemperatureSensorId(sensorId.toInt());
motionSensors.insert(baseUuid, motionSensor);
} }
} }
if (sensorMap.value("type").toString() == "ZLLPresence") { if (sensorMap.value("type").toString() == "ZLLPresence") {
qCDebug(dcPhilipsHue()) << "Found presence sensor from OurdoorSensor:" << baseUuid << sensorMap; qCDebug(dcPhilipsHue()) << "Found presence sensor from OurdoorSensor:" << baseUuid << sensorMap;
// Check if we haven outdoor sensor for this presence sensor // Check if we haven outdoor sensor for this presence sensor
if (outdoorSensors.keys().contains(baseUuid)) { if (motionSensors.contains(baseUuid)) {
HueOutdoorSensor *outdoorSensor = outdoorSensors.value(baseUuid); HueMotionSensor *motionSensor = motionSensors.value(baseUuid);
outdoorSensor->setPresenceSensorUuid(uuid); motionSensor->setPresenceSensorUuid(uuid);
outdoorSensor->setPresenceSensorId(sensorId.toInt()); motionSensor->setPresenceSensorId(sensorId.toInt());
} else { } else {
// Create an outdoor sensor // Create an outdoor sensor
HueOutdoorSensor *outdoorSensor = new HueOutdoorSensor(this); HueMotionSensor *motionSensor = nullptr;
outdoorSensor->setUuid(baseUuid); if (model == "SML001") {
outdoorSensor->setPresenceSensorUuid(uuid); motionSensor = new HueIndoorSensor(this);
outdoorSensor->setPresenceSensorId(sensorId.toInt()); } else {
outdoorSensors.insert(baseUuid, outdoorSensor); motionSensor = new HueOutdoorSensor(this);
}
motionSensor->setModelId(model);
motionSensor->setUuid(baseUuid);
motionSensor->setPresenceSensorUuid(uuid);
motionSensor->setPresenceSensorId(sensorId.toInt());
motionSensors.insert(baseUuid, motionSensor);
} }
} }
if (sensorMap.value("type").toString() == "ZLLLightLevel") { if (sensorMap.value("type").toString() == "ZLLLightLevel") {
qCDebug(dcPhilipsHue()) << "Found light sensor from OurdoorSensor:" << sensorMap; qCDebug(dcPhilipsHue()) << "Found light sensor from OurdoorSensor:" << sensorMap;
// Check if we haven outdoor sensor for this light sensor // Check if we haven outdoor sensor for this light sensor
if (outdoorSensors.keys().contains(baseUuid)) { if (motionSensors.contains(baseUuid)) {
HueOutdoorSensor *outdoorSensor = outdoorSensors.value(baseUuid); HueMotionSensor *motionSensor = motionSensors.value(baseUuid);
outdoorSensor->setLightSensorUuid(uuid); motionSensor->setLightSensorUuid(uuid);
outdoorSensor->setLightSensorId(sensorId.toInt()); motionSensor->setLightSensorId(sensorId.toInt());
} else { } else {
// Create an outdoor sensor // Create an outdoor sensor
HueOutdoorSensor *outdoorSensor = new HueOutdoorSensor(this); HueMotionSensor *motionSensor = nullptr;
outdoorSensor->setUuid(baseUuid); if (model == "SML001") {
outdoorSensor->setLightSensorUuid(uuid); motionSensor = new HueIndoorSensor(this);
outdoorSensor->setLightSensorId(sensorId.toInt()); } else {
outdoorSensors.insert(baseUuid, outdoorSensor); motionSensor = new HueOutdoorSensor(this);
}
motionSensor->setModelId(model);
motionSensor->setUuid(baseUuid);
motionSensor->setLightSensorUuid(uuid);
motionSensor->setLightSensorId(sensorId.toInt());
motionSensors.insert(baseUuid, motionSensor);
} }
} }
} else { } else {
@ -1175,28 +1231,43 @@ void DevicePluginPhilipsHue::processBridgeSensorDiscoveryResponse(Device *device
} }
// Create outdoor sensors if there are any new sensors found // Create outdoor sensors if there are any new sensors found
foreach (HueOutdoorSensor *outdoorSensor, outdoorSensors.values()) { foreach (HueMotionSensor *motionSensor, motionSensors.values()) {
QString baseUuid = outdoorSensors.key(outdoorSensor); QString baseUuid = motionSensors.key(motionSensor);
if (outdoorSensor->isValid()) { if (motionSensor->isValid()) {
DeviceDescriptor descriptor(outdoorSensorDeviceClassId, "Philips Hue Outdoor sensor", baseUuid, device->id()); if (motionSensor->modelId() == "SML001") {
ParamList params; DeviceDescriptor descriptor(motionSensorDeviceClassId, tr("Philips Hue Motion sensor"), baseUuid, device->id());
params.append(Param(outdoorSensorDeviceUuidParamTypeId, outdoorSensor->uuid())); ParamList params;
params.append(Param(outdoorSensorDeviceModelIdParamTypeId, outdoorSensor->modelId())); params.append(Param(motionSensorDeviceUuidParamTypeId, motionSensor->uuid()));
params.append(Param(outdoorSensorDeviceSensorUuidTemperatureParamTypeId, outdoorSensor->temperatureSensorUuid())); params.append(Param(motionSensorDeviceModelIdParamTypeId, motionSensor->modelId()));
params.append(Param(outdoorSensorDeviceSensorIdTemperatureParamTypeId, outdoorSensor->temperatureSensorId())); params.append(Param(motionSensorDeviceSensorUuidTemperatureParamTypeId, motionSensor->temperatureSensorUuid()));
params.append(Param(outdoorSensorDeviceSensorUuidPresenceParamTypeId, outdoorSensor->presenceSensorUuid())); params.append(Param(motionSensorDeviceSensorIdTemperatureParamTypeId, motionSensor->temperatureSensorId()));
params.append(Param(outdoorSensorDeviceSensorIdPresenceParamTypeId, outdoorSensor->presenceSensorId())); params.append(Param(motionSensorDeviceSensorUuidPresenceParamTypeId, motionSensor->presenceSensorUuid()));
params.append(Param(outdoorSensorDeviceSensorUuidLightParamTypeId, outdoorSensor->lightSensorUuid())); params.append(Param(motionSensorDeviceSensorIdPresenceParamTypeId, motionSensor->presenceSensorId()));
params.append(Param(outdoorSensorDeviceSensorIdLightParamTypeId, outdoorSensor->lightSensorId())); params.append(Param(motionSensorDeviceSensorUuidLightParamTypeId, motionSensor->lightSensorUuid()));
descriptor.setParams(params); params.append(Param(motionSensorDeviceSensorIdLightParamTypeId, motionSensor->lightSensorId()));
descriptor.setParams(params);
qCDebug(dcPhilipsHue()) << "Found new Outdoor sensor" << baseUuid << outdoorSensorDeviceClassId; qCDebug(dcPhilipsHue()) << "Found new motion sensor" << baseUuid << outdoorSensorDeviceClassId;
emit autoDevicesAppeared(outdoorSensorDeviceClassId, {descriptor}); emit autoDevicesAppeared(motionSensorDeviceClassId, {descriptor});
} else if (motionSensor->modelId() == "SML002") {
DeviceDescriptor descriptor(outdoorSensorDeviceClassId, tr("Philips Hue Outdoor sensor"), baseUuid, device->id());
ParamList params;
params.append(Param(outdoorSensorDeviceUuidParamTypeId, motionSensor->uuid()));
params.append(Param(outdoorSensorDeviceModelIdParamTypeId, motionSensor->modelId()));
params.append(Param(outdoorSensorDeviceSensorUuidTemperatureParamTypeId, motionSensor->temperatureSensorUuid()));
params.append(Param(outdoorSensorDeviceSensorIdTemperatureParamTypeId, motionSensor->temperatureSensorId()));
params.append(Param(outdoorSensorDeviceSensorUuidPresenceParamTypeId, motionSensor->presenceSensorUuid()));
params.append(Param(outdoorSensorDeviceSensorIdPresenceParamTypeId, motionSensor->presenceSensorId()));
params.append(Param(outdoorSensorDeviceSensorUuidLightParamTypeId, motionSensor->lightSensorUuid()));
params.append(Param(outdoorSensorDeviceSensorIdLightParamTypeId, motionSensor->lightSensorId()));
descriptor.setParams(params);
qCDebug(dcPhilipsHue()) << "Found new outdoor sensor" << baseUuid << outdoorSensorDeviceClassId;
emit autoDevicesAppeared(outdoorSensorDeviceClassId, {descriptor});
}
} }
// Clean up // Clean up
outdoorSensors.remove(baseUuid); motionSensors.remove(baseUuid);
outdoorSensor->deleteLater(); motionSensor->deleteLater();
} }
} }
@ -1334,9 +1405,9 @@ void DevicePluginPhilipsHue::processSensorsRefreshResponse(Device *device, const
} }
// Outdoor sensors // Outdoor sensors
foreach (HueOutdoorSensor *outdoorSensor, m_outdoorSensors.keys()) { foreach (HueMotionSensor *motionSensor, m_motionSensors.keys()) {
if (outdoorSensor->hasSensor(sensorId.toInt()) && m_outdoorSensors.value(outdoorSensor)->parentId() == device->id()) { if (motionSensor->hasSensor(sensorId.toInt()) && m_motionSensors.value(motionSensor)->parentId() == device->id()) {
outdoorSensor->updateStates(sensorMap); motionSensor->updateStates(sensorMap);
} }
} }
} }
@ -1350,7 +1421,7 @@ void DevicePluginPhilipsHue::processSetNameResponse(Device *device, const QByteA
// check JSON error // check JSON error
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString(); qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
@ -1361,7 +1432,7 @@ void DevicePluginPhilipsHue::processSetNameResponse(Device *device, const QByteA
} else { } else {
qCWarning(dcPhilipsHue) << "Failed to set name of Hue: Invalid error message format"; qCWarning(dcPhilipsHue) << "Failed to set name of Hue: Invalid error message format";
} }
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
@ -1378,7 +1449,7 @@ void DevicePluginPhilipsHue::processPairingResponse(PairingInfo *pairingInfo, co
// check JSON error // check JSON error
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString(); qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString();
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusFailure);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
return; return;
} }
@ -1390,7 +1461,7 @@ void DevicePluginPhilipsHue::processPairingResponse(PairingInfo *pairingInfo, co
} else { } else {
qCWarning(dcPhilipsHue) << "Failed to pair Hue Bridge: Invalid error message format"; qCWarning(dcPhilipsHue) << "Failed to pair Hue Bridge: Invalid error message format";
} }
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusFailure);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
return; return;
} }
@ -1401,7 +1472,7 @@ void DevicePluginPhilipsHue::processPairingResponse(PairingInfo *pairingInfo, co
if (pairingInfo->apiKey().isEmpty()) { if (pairingInfo->apiKey().isEmpty()) {
qCWarning(dcPhilipsHue) << "Failed to pair Hue Bridge: did not get any key from the bridge"; qCWarning(dcPhilipsHue) << "Failed to pair Hue Bridge: did not get any key from the bridge";
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusFailure);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
return; return;
} }
@ -1422,7 +1493,7 @@ void DevicePluginPhilipsHue::processInformationResponse(PairingInfo *pairingInfo
// check JSON error // check JSON error
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString(); qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString();
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusFailure);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
return; return;
} }
@ -1432,7 +1503,7 @@ void DevicePluginPhilipsHue::processInformationResponse(PairingInfo *pairingInfo
// check response error // check response error
if (response.contains("error")) { if (response.contains("error")) {
qCWarning(dcPhilipsHue) << "Failed to get information from Hue Bridge:" << response.value("error").toMap().value("description").toString(); qCWarning(dcPhilipsHue) << "Failed to get information from Hue Bridge:" << response.value("error").toMap().value("description").toString();
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusFailure);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
return; return;
} }
@ -1450,7 +1521,7 @@ void DevicePluginPhilipsHue::processInformationResponse(PairingInfo *pairingInfo
m_unconfiguredBridges.append(bridge); m_unconfiguredBridges.append(bridge);
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusSuccess); emit pairingFinished(pairingInfo->pairingTransactionId(), Device::DeviceSetupStatusSuccess);
pairingInfo->deleteLater(); pairingInfo->deleteLater();
} }
@ -1462,7 +1533,7 @@ void DevicePluginPhilipsHue::processActionResponse(Device *device, const ActionI
// check JSON error // check JSON error
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString(); qCWarning(dcPhilipsHue) << "Hue Bridge json error in response" << error.errorString();
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(actionId, Device::DeviceErrorHardwareFailure);
return; return;
} }
@ -1473,14 +1544,14 @@ void DevicePluginPhilipsHue::processActionResponse(Device *device, const ActionI
} else { } else {
qCWarning(dcPhilipsHue) << "Failed to execute Hue action: Invalid error message format"; qCWarning(dcPhilipsHue) << "Failed to execute Hue action: Invalid error message format";
} }
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(actionId, Device::DeviceErrorHardwareFailure);
return; return;
} }
if (device->deviceClassId() != bridgeDeviceClassId) if (device->deviceClassId() != bridgeDeviceClassId)
m_lights.key(device)->processActionResponse(jsonDoc.toVariant().toList()); m_lights.key(device)->processActionResponse(jsonDoc.toVariant().toList());
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
} }
void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &reachable) void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &reachable)
@ -1516,12 +1587,10 @@ void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &
} }
} }
foreach (HueOutdoorSensor *outdoorSensor, m_outdoorSensors.keys()) { foreach (HueMotionSensor *motionSensor, m_motionSensors.keys()) {
if (m_outdoorSensors.value(outdoorSensor)->parentId() == device->id()) { if (m_motionSensors.value(motionSensor)->parentId() == device->id()) {
outdoorSensor->setReachable(false); motionSensor->setReachable(false);
if (m_outdoorSensors.value(outdoorSensor)->deviceClassId() == outdoorSensorDeviceClassId) { m_motionSensors.value(motionSensor)->setStateValue(motionSensor->connectedStateTypeId(), false);
m_outdoorSensors.value(outdoorSensor)->setStateValue(outdoorSensorConnectedStateTypeId, false);
}
} }
} }
} }
@ -1588,6 +1657,16 @@ bool DevicePluginPhilipsHue::sensorAlreadyAdded(const QString &uuid)
return true; return true;
} }
} }
// Motion sensor consits out of 3 sensors
if (device->deviceClassId() == motionSensorDeviceClassId) {
if (device->paramValue(motionSensorDeviceSensorUuidLightParamTypeId).toString() == uuid) {
return true;
} else if (device->paramValue(motionSensorDeviceSensorUuidPresenceParamTypeId).toString() == uuid) {
return true;
} else if (device->paramValue(motionSensorDeviceSensorUuidTemperatureParamTypeId).toString() == uuid) {
return true;
}
}
} }
return false; return false;

View File

@ -24,13 +24,15 @@
#ifndef DEVICEPLUGINPHILIPSHUE_H #ifndef DEVICEPLUGINPHILIPSHUE_H
#define DEVICEPLUGINPHILIPSHUE_H #define DEVICEPLUGINPHILIPSHUE_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "huebridge.h" #include "huebridge.h"
#include "huelight.h" #include "huelight.h"
#include "hueremote.h" #include "hueremote.h"
#include "pairinginfo.h" #include "pairinginfo.h"
#include "huemotionsensor.h"
#include "huemotionsensor.h"
#include "plugintimer.h" #include "plugintimer.h"
#include "hueoutdoorsensor.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
#include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdiscovery.h"
@ -48,25 +50,25 @@ public:
~DevicePluginPhilipsHue(); ~DevicePluginPhilipsHue();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override; Device::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList &params, const QString &secret) override;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action); Device::DeviceError executeAction(Device *device, const Action &action);
private slots: private slots:
void lightStateChanged(); void lightStateChanged();
void remoteStateChanged(); void remoteStateChanged();
void onRemoteButtonEvent(int buttonCode); void onRemoteButtonEvent(int buttonCode);
// Outdoor sensor // Motion sensor
void onOutdoorSensorReachableChanged(bool reachable); void onMotionSensorReachableChanged(bool reachable);
void onOutdoorSensorBatteryLevelChanged(int batteryLevel); void onMotionSensorBatteryLevelChanged(int batteryLevel);
void onOutdoorSensorTemperatureChanged(double temperature); void onMotionSensorTemperatureChanged(double temperature);
void onOutdoorSensorPresenceChanged(bool presence); void onMotionSensorPresenceChanged(bool presence);
void onOutdoorSensorLightIntensityChanged(double lightIntensity); void onMotionSensorLightIntensityChanged(double lightIntensity);
private slots: private slots:
void networkManagerReplyReady(); void networkManagerReplyReady();
@ -105,7 +107,7 @@ private:
QHash<HueBridge *, Device *> m_bridges; QHash<HueBridge *, Device *> m_bridges;
QHash<HueLight *, Device *> m_lights; QHash<HueLight *, Device *> m_lights;
QHash<HueRemote *, Device *> m_remotes; QHash<HueRemote *, Device *> m_remotes;
QHash<HueOutdoorSensor *, Device *> m_outdoorSensors; QHash<HueMotionSensor *, Device *> m_motionSensors;
void refreshLight(Device *device); void refreshLight(Device *device);
void refreshBridge(Device *device); void refreshBridge(Device *device);

View File

@ -671,6 +671,18 @@
"readOnly": true "readOnly": true
} }
], ],
"settingsTypes": [
{
"id": "21d461b2-b4dd-4a70-b3d5-aaedc88605a4",
"name": "timeout",
"displayName": "Time period",
"type": "uint",
"unit": "Seconds",
"defaultValue": 10,
"minValue": 10
}
],
"stateTypes": [ "stateTypes": [
{ {
"id": "9fe43e6b-3c29-43a9-bb96-3b80eacc10db", "id": "9fe43e6b-3c29-43a9-bb96-3b80eacc10db",
@ -735,6 +747,147 @@
"defaultValue": 0 "defaultValue": 0
} }
] ]
},
{
"id": "25b79fff-4b88-4af8-b06c-2fe246238790",
"name": "motionSensor",
"displayName": "Hue Motion Sensor",
"interfaces": ["presencesensor", "temperaturesensor", "lightsensor", "batterylevel", "connectable"],
"createMethods": ["auto"],
"paramTypes": [
{
"id": "9cb488b7-a76f-4389-a6b5-b36250246f2b",
"name": "modelId",
"displayName": "Model id",
"type" : "QString",
"readOnly": true
},
{
"id": "3e9aad4c-1dff-42c0-bbd4-cdd8635c01a7",
"name": "uuid",
"displayName": "Uuid",
"type" : "QString",
"readOnly": true
},
{
"id": "c9e81e29-f8d4-4370-ada2-f48b32def1fe",
"name": "sensorIdTemperature",
"displayName": "Temperature sensor id",
"type" : "int",
"readOnly": true
},
{
"id": "aa29b5f1-5589-4fa9-bbd4-8869723c037c",
"name": "sensorUuidTemperature",
"displayName": "Temperature sensor uuid",
"type" : "QString",
"readOnly": true
},
{
"id": "337b2c6c-e3bf-495c-943c-b45fa08add37",
"name": "sensorIdPresence",
"displayName": "Presence sensor id",
"type" : "int",
"readOnly": true
},
{
"id": "3829bddb-e722-4724-be36-3a8402738581",
"name": "sensorUuidPresence",
"displayName": "Presence sensor uuid",
"type" : "QString",
"readOnly": true
},
{
"id": "04fba73e-730e-437a-b6f2-10df21296af5",
"name": "sensorIdLight",
"displayName": "Light sensor id",
"type" : "int",
"readOnly": true
},
{
"id": "171cc2e7-7a95-4116-986c-66d75e3e23eb",
"name": "sensorUuidLight",
"displayName": "Light sensor uuid",
"type" : "QString",
"readOnly": true
}
],
"settingsTypes": [
{
"id": "beedc4af-c107-4c53-be25-fd01a349fd35",
"name": "timeout",
"displayName": "Time period",
"type": "uint",
"unit": "Seconds",
"defaultValue": 10,
"minValue": 10
}
],
"stateTypes": [
{
"id": "19c28b69-a9c2-4908-8255-7681f72c2d92",
"name": "connected",
"displayName": "Reachable",
"displayNameEvent": "Reachable changed",
"defaultValue": false,
"type": "bool"
},
{
"id": "ac463b30-24af-4352-84da-19a3ffc906bd",
"name": "batteryLevel",
"displayName": "Battery",
"displayNameEvent": "Battery changed",
"type": "int",
"unit": "Percentage",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100
},
{
"id": "d7c4e143-6f03-411e-a12e-dd22806270fd",
"name": "batteryCritical",
"displayName": "Battery critical",
"displayNameEvent": "Battery critical changed",
"type": "bool",
"defaultValue": false
},
{
"id": "63ee79f7-702b-48c1-86cf-8ddebb78bae6",
"name": "temperature",
"displayName": "Temperature",
"displayNameEvent": "Temperature changed",
"unit": "DegreeCelsius",
"type": "double",
"defaultValue": 0
},
{
"id": "064f48c1-f86d-4a0a-bdae-3420123dff3f",
"name": "lightIntensity",
"displayName": "Ambient light",
"displayNameEvent": "Ambient light changed",
"unit": "Lux",
"type": "double",
"defaultValue": 0
},
{
"id": "e38ee39c-c77f-40b5-b122-4efc411da0ed",
"name": "isPresent",
"displayName": "Person is present",
"displayNameEvent": "Person is present changed",
"type": "bool",
"defaultValue": false
},
{
"id": "ef2e564e-2443-448f-bcd9-f85a1126ee6a",
"name": "lastSeenTime",
"displayName": "Last seen time",
"displayNameEvent": "Last seen time changed",
"type": "int",
"unit": "UnixTime",
"defaultValue": 0
}
]
} }
] ]
} }

View File

@ -33,7 +33,7 @@ class HueDevice : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit HueDevice(QObject *parent = 0); explicit HueDevice(QObject *parent = nullptr);
int id() const; int id() const;
void setId(const int &id); void setId(const int &id);

View File

@ -20,106 +20,109 @@
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "hueoutdoorsensor.h" #include "huemotionsensor.h"
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
HueOutdoorSensor::HueOutdoorSensor(QObject *parent) : HueMotionSensor::HueMotionSensor(QObject *parent) :
HueDevice(parent) HueDevice(parent)
{ {
m_timeout.setInterval(10000);
connect(&m_timeout, &QTimer::timeout, this, [this](){
if (m_presence) {
qCDebug(dcPhilipsHue) << "Motion sensor timeout reached" << m_timeout.interval();
m_presence = false;
emit presenceChanged(m_presence);
}
});
} }
QString HueOutdoorSensor::uuid() const void HueMotionSensor::setTimeout(int timeout)
{ {
return m_uuid; // The sensor keeps emitting presence = true for 10 secs, let's subtract that time from the timeout to compensate
m_timeout.setInterval((timeout - 9)* 1000);
} }
void HueOutdoorSensor::setUuid(const QString &uuid) int HueMotionSensor::temperatureSensorId() const
{
m_uuid = uuid;
}
int HueOutdoorSensor::temperatureSensorId() const
{ {
return m_temperatureSensorId; return m_temperatureSensorId;
} }
void HueOutdoorSensor::setTemperatureSensorId(int sensorId) void HueMotionSensor::setTemperatureSensorId(int sensorId)
{ {
m_temperatureSensorId = sensorId; m_temperatureSensorId = sensorId;
} }
QString HueOutdoorSensor::temperatureSensorUuid() const QString HueMotionSensor::temperatureSensorUuid() const
{ {
return m_temperatureSensorUuid; return m_temperatureSensorUuid;
} }
void HueOutdoorSensor::setTemperatureSensorUuid(const QString &temperatureSensorUuid) void HueMotionSensor::setTemperatureSensorUuid(const QString &temperatureSensorUuid)
{ {
m_temperatureSensorUuid = temperatureSensorUuid; m_temperatureSensorUuid = temperatureSensorUuid;
} }
int HueOutdoorSensor::presenceSensorId() const int HueMotionSensor::presenceSensorId() const
{ {
return m_presenceSensorId; return m_presenceSensorId;
} }
void HueOutdoorSensor::setPresenceSensorId(int sensorId) void HueMotionSensor::setPresenceSensorId(int sensorId)
{ {
m_presenceSensorId = sensorId; m_presenceSensorId = sensorId;
} }
QString HueOutdoorSensor::presenceSensorUuid() const QString HueMotionSensor::presenceSensorUuid() const
{ {
return m_presenceSensorUuid; return m_presenceSensorUuid;
} }
void HueOutdoorSensor::setPresenceSensorUuid(const QString &presenceSensorUuid) void HueMotionSensor::setPresenceSensorUuid(const QString &presenceSensorUuid)
{ {
m_presenceSensorUuid = presenceSensorUuid; m_presenceSensorUuid = presenceSensorUuid;
} }
int HueOutdoorSensor::lightSensorId() const int HueMotionSensor::lightSensorId() const
{ {
return m_lightSensorId; return m_lightSensorId;
} }
void HueOutdoorSensor::setLightSensorId(int sensorId) void HueMotionSensor::setLightSensorId(int sensorId)
{ {
m_lightSensorId = sensorId; m_lightSensorId = sensorId;
} }
QString HueOutdoorSensor::lightSensorUuid() const QString HueMotionSensor::lightSensorUuid() const
{ {
return m_lightSensorUuid; return m_lightSensorUuid;
} }
void HueOutdoorSensor::setLightSensorUuid(const QString &lightSensorUuid) void HueMotionSensor::setLightSensorUuid(const QString &lightSensorUuid)
{ {
m_lightSensorUuid = lightSensorUuid; m_lightSensorUuid = lightSensorUuid;
} }
double HueOutdoorSensor::temperature() const double HueMotionSensor::temperature() const
{ {
return m_temperature; return m_temperature;
} }
double HueOutdoorSensor::lightIntensity() const double HueMotionSensor::lightIntensity() const
{ {
return m_lightIntensity; return m_lightIntensity;
} }
bool HueOutdoorSensor::present() const bool HueMotionSensor::present() const
{ {
return m_presence; return m_presence;
} }
int HueOutdoorSensor::batteryLevel() const int HueMotionSensor::batteryLevel() const
{ {
return m_batteryLevel; return m_batteryLevel;
} }
void HueOutdoorSensor::updateStates(const QVariantMap &sensorMap) void HueMotionSensor::updateStates(const QVariantMap &sensorMap)
{ {
//qCDebug(dcPhilipsHue()) << "Outdoor sensor: Process sensor map" << qUtf8Printable(QJsonDocument::fromVariant(sensorMap).toJson(QJsonDocument::Indented)); //qCDebug(dcPhilipsHue()) << "Outdoor sensor: Process sensor map" << qUtf8Printable(QJsonDocument::fromVariant(sensorMap).toJson(QJsonDocument::Indented));
@ -144,17 +147,21 @@ void HueOutdoorSensor::updateStates(const QVariantMap &sensorMap)
if (m_temperature != temperature) { if (m_temperature != temperature) {
m_temperature = temperature; m_temperature = temperature;
emit temperatureChanged(m_temperature); emit temperatureChanged(m_temperature);
qCDebug(dcPhilipsHue) << "Outdoor sensor temperature changed" << m_temperature; qCDebug(dcPhilipsHue) << "Motion sensor temperature changed" << m_temperature;
} }
} }
// If presence sensor // If presence sensor
if (sensorMap.value("uniqueid").toString() == m_presenceSensorUuid) { if (sensorMap.value("uniqueid").toString() == m_presenceSensorUuid) {
bool presence = stateMap.value("presence", false).toBool(); bool presence = stateMap.value("presence", false).toBool();
if (m_presence != presence) { if (presence) {
m_presence = presence; if (!m_presence) {
emit presenceChanged(m_presence); m_presence = true;
qCDebug(dcPhilipsHue) << "Outdoor sensor presence changed" << presence; emit presenceChanged(m_presence);
qCDebug(dcPhilipsHue) << "Motion sensor presence changed" << presence;
}
qCDebug(dcPhilipsHue) << "Motion sensor restarting timeout" << m_timeout.interval();
m_timeout.start();
} }
} }
@ -169,17 +176,17 @@ void HueOutdoorSensor::updateStates(const QVariantMap &sensorMap)
} }
} }
bool HueOutdoorSensor::isValid() bool HueMotionSensor::isValid()
{ {
return !m_temperatureSensorUuid.isEmpty() && !m_presenceSensorUuid.isEmpty() && !m_lightSensorUuid.isEmpty(); return !m_temperatureSensorUuid.isEmpty() && !m_presenceSensorUuid.isEmpty() && !m_lightSensorUuid.isEmpty();
} }
bool HueOutdoorSensor::hasSensor(int sensorId) bool HueMotionSensor::hasSensor(int sensorId)
{ {
return m_temperatureSensorId == sensorId || m_presenceSensorId == sensorId || m_lightSensorId == sensorId; return m_temperatureSensorId == sensorId || m_presenceSensorId == sensorId || m_lightSensorId == sensorId;
} }
bool HueOutdoorSensor::hasSensor(const QString &sensorUuid) bool HueMotionSensor::hasSensor(const QString &sensorUuid)
{ {
return m_temperatureSensorUuid == sensorUuid || m_presenceSensorUuid == sensorUuid || m_lightSensorUuid == sensorUuid; return m_temperatureSensorUuid == sensorUuid || m_presenceSensorUuid == sensorUuid || m_lightSensorUuid == sensorUuid;
} }

View File

@ -20,21 +20,23 @@
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef HUEOUTDOORSENSOR_H #ifndef HUEMOTIONSENSOR_H
#define HUEOUTDOORSENSOR_H #define HUEMOTIONSENSOR_H
#include <QObject> #include <QObject>
#include <QTimer>
#include "extern-plugininfo.h"
#include "huedevice.h" #include "huedevice.h"
class HueOutdoorSensor : public HueDevice class HueMotionSensor : public HueDevice
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit HueOutdoorSensor(QObject *parent = nullptr); explicit HueMotionSensor(QObject *parent = nullptr);
virtual ~HueMotionSensor() = default;
QString uuid() const; void setTimeout(int timeout);
void setUuid(const QString &uuid);
int temperatureSensorId() const; int temperatureSensorId() const;
void setTemperatureSensorId(int sensorId); void setTemperatureSensorId(int sensorId);
@ -65,10 +67,16 @@ public:
bool hasSensor(int sensorId); bool hasSensor(int sensorId);
bool hasSensor(const QString &sensorUuid); bool hasSensor(const QString &sensorUuid);
virtual StateTypeId connectedStateTypeId() const = 0;
virtual StateTypeId temperatureStateTypeId() const = 0;
virtual StateTypeId lightIntensityStateTypeId() const = 0;
virtual StateTypeId isPresentStateTypeId() const = 0;
virtual StateTypeId lastSeenTimeStateTypeId() const = 0;
virtual StateTypeId batteryLevelStateTypeId() const = 0;
virtual StateTypeId batteryCriticalStateTypeId() const = 0;
private: private:
// Params // Params
QString m_uuid;
int m_temperatureSensorId; int m_temperatureSensorId;
QString m_temperatureSensorUuid; QString m_temperatureSensorUuid;
@ -78,6 +86,8 @@ private:
int m_lightSensorId; int m_lightSensorId;
QString m_lightSensorUuid; QString m_lightSensorUuid;
QTimer m_timeout;
// States // States
QString m_lastUpdate; QString m_lastUpdate;
double m_temperature = 0; double m_temperature = 0;
@ -93,4 +103,36 @@ signals:
}; };
#endif // HUEOUTDOORSENSOR_H class HueIndoorSensor: public HueMotionSensor
{
Q_OBJECT
public:
HueIndoorSensor(QObject *parent = nullptr): HueMotionSensor(parent) {}
StateTypeId connectedStateTypeId() const override { return motionSensorConnectedStateTypeId; }
StateTypeId temperatureStateTypeId() const override { return motionSensorTemperatureStateTypeId; }
StateTypeId lightIntensityStateTypeId() const override { return motionSensorLightIntensityStateTypeId; }
StateTypeId isPresentStateTypeId() const override { return motionSensorIsPresentStateTypeId; }
StateTypeId lastSeenTimeStateTypeId() const override { return motionSensorLastSeenTimeStateTypeId; }
StateTypeId batteryLevelStateTypeId() const override { return motionSensorBatteryLevelStateTypeId; }
StateTypeId batteryCriticalStateTypeId() const override { return motionSensorBatteryCriticalStateTypeId; }
};
class HueOutdoorSensor: public HueMotionSensor
{
Q_OBJECT
public:
HueOutdoorSensor(QObject *parent = nullptr): HueMotionSensor(parent) {}
StateTypeId connectedStateTypeId() const override { return outdoorSensorTemperatureStateTypeId; }
StateTypeId temperatureStateTypeId() const override { return outdoorSensorTemperatureStateTypeId; }
StateTypeId lightIntensityStateTypeId() const override { return outdoorSensorLightIntensityStateTypeId; }
StateTypeId isPresentStateTypeId() const override { return outdoorSensorIsPresentStateTypeId; }
StateTypeId lastSeenTimeStateTypeId() const override { return outdoorSensorLastSeenTimeStateTypeId; }
StateTypeId batteryLevelStateTypeId() const override { return outdoorSensorBatteryLevelStateTypeId; }
StateTypeId batteryCriticalStateTypeId() const override { return outdoorSensorBatteryCriticalStateTypeId; }
};
#endif // HUEMOTIONSENSOR_H

View File

@ -10,10 +10,10 @@ SOURCES += \
#light.cpp \ #light.cpp \
huebridge.cpp \ huebridge.cpp \
huelight.cpp \ huelight.cpp \
huemotionsensor.cpp \
pairinginfo.cpp \ pairinginfo.cpp \
hueremote.cpp \ hueremote.cpp \
huedevice.cpp \ huedevice.cpp
hueoutdoorsensor.cpp
HEADERS += \ HEADERS += \
devicepluginphilipshue.h \ devicepluginphilipshue.h \
@ -22,10 +22,10 @@ HEADERS += \
#lightinterface.h \ #lightinterface.h \
huebridge.h \ huebridge.h \
huelight.h \ huelight.h \
huemotionsensor.h \
pairinginfo.h \ pairinginfo.h \
hueremote.h \ hueremote.h \
huedevice.h \ huedevice.h
hueoutdoorsensor.h

View File

@ -37,7 +37,7 @@ DevicePluginPushbullet::~DevicePluginPushbullet()
} }
DeviceManager::DeviceSetupStatus DevicePluginPushbullet::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginPushbullet::setupDevice(Device *device)
{ {
qCDebug(dcPushbullet()) << "Setting up Pushbullet device" << device->name() << device->id().toString(); qCDebug(dcPushbullet()) << "Setting up Pushbullet device" << device->name() << device->id().toString();
@ -48,7 +48,7 @@ DeviceManager::DeviceSetupStatus DevicePluginPushbullet::setupDevice(Device *dev
connect(reply, &QNetworkReply::finished, device, [this, reply, device]() { connect(reply, &QNetworkReply::finished, device, [this, reply, device]() {
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcPushbullet()) << "Error fetching user profile:" << reply->errorString() << reply->error(); qCWarning(dcPushbullet()) << "Error fetching user profile:" << reply->errorString() << reply->error();
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
@ -59,25 +59,25 @@ DeviceManager::DeviceSetupStatus DevicePluginPushbullet::setupDevice(Device *dev
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPushbullet()) << "Error parsing reply from Pushbullet:" << error.errorString(); qCWarning(dcPushbullet()) << "Error parsing reply from Pushbullet:" << error.errorString();
qCWarning(dcPushbullet()) << qUtf8Printable(data); qCWarning(dcPushbullet()) << qUtf8Printable(data);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
QVariantMap replyMap = jsonDoc.toVariant().toMap(); QVariantMap replyMap = jsonDoc.toVariant().toMap();
if (!replyMap.value("active").toBool()) { if (!replyMap.value("active").toBool()) {
qCWarning(dcPushbullet()) << "Pushbullet account seems to be deactivated."; qCWarning(dcPushbullet()) << "Pushbullet account seems to be deactivated.";
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
qCDebug(dcPushbullet()) << "Pushbullet device" << device->name() << device->id().toString() << "setup complete"; qCDebug(dcPushbullet()) << "Pushbullet device" << device->name() << device->id().toString() << "setup complete";
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
}); });
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
DeviceManager::DeviceError DevicePluginPushbullet::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginPushbullet::executeAction(Device *device, const Action &action)
{ {
qCDebug(dcPushbullet()) << "Executing action" << action.actionTypeId() << "for device" << device->name() << device->id().toString(); qCDebug(dcPushbullet()) << "Executing action" << action.actionTypeId() << "for device" << device->name() << device->id().toString();
@ -94,7 +94,7 @@ DeviceManager::DeviceError DevicePluginPushbullet::executeAction(Device *device,
connect(reply, &QNetworkReply::finished, device, [this, reply, device, action]{ connect(reply, &QNetworkReply::finished, device, [this, reply, device, action]{
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcPushbullet()) << "Push message sending failed for" << device->name() << device->id() << reply->errorString() << reply->error(); qCWarning(dcPushbullet()) << "Push message sending failed for" << device->name() << device->id() << reply->errorString() << reply->error();
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareNotAvailable); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareNotAvailable);
return; return;
} }
@ -105,27 +105,27 @@ DeviceManager::DeviceError DevicePluginPushbullet::executeAction(Device *device,
if (error.error != QJsonParseError::NoError) { if (error.error != QJsonParseError::NoError) {
qCWarning(dcPushbullet()) << "Error reading reply from Pushbullet for" << device->name() << device->id().toString() << error.errorString(); qCWarning(dcPushbullet()) << "Error reading reply from Pushbullet for" << device->name() << device->id().toString() << error.errorString();
qCWarning(dcPushbullet()) << qUtf8Printable(data); qCWarning(dcPushbullet()) << qUtf8Printable(data);
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareFailure);
return; return;
} }
QVariantMap replyMap = jsonDoc.toVariant().toMap(); QVariantMap replyMap = jsonDoc.toVariant().toMap();
if (!replyMap.value("active").toBool()) { if (!replyMap.value("active").toBool()) {
qCWarning(dcPushbullet()) << "Error sending message. The account seems to be deactivated" << device->name() << device->id().toString(); qCWarning(dcPushbullet()) << "Error sending message. The account seems to be deactivated" << device->name() << device->id().toString();
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareFailure);
return; return;
} }
if (replyMap.value("dismissed", true).toBool()) { if (replyMap.value("dismissed", true).toBool()) {
qCWarning(dcPushbullet()) << "Error sending message. The message has been dismissed by the server" << device->name() << device->id().toString(); qCWarning(dcPushbullet()) << "Error sending message. The message has been dismissed by the server" << device->name() << device->id().toString();
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareFailure);
return; return;
} }
qCDebug(dcPushbullet()) << "Message sent successfully"; qCDebug(dcPushbullet()) << "Message sent successfully";
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(action.id(), Device::DeviceErrorNoError);
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINPUSHBULLET_H #ifndef DEVICEPLUGINPUSHBULLET_H
#define DEVICEPLUGINPUSHBULLET_H #define DEVICEPLUGINPUSHBULLET_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginPushbullet: public DevicePlugin class DevicePluginPushbullet: public DevicePlugin
{ {
@ -36,8 +36,8 @@ public:
explicit DevicePluginPushbullet(QObject *parent = nullptr); explicit DevicePluginPushbullet(QObject *parent = nullptr);
~DevicePluginPushbullet() override; ~DevicePluginPushbullet() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -38,18 +38,18 @@ void DevicePluginRemoteSsh::init()
connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginRemoteSsh::onPluginTimeout); connect(m_pluginTimer, &PluginTimer::timeout, this, &DevicePluginRemoteSsh::onPluginTimeout);
} }
DeviceManager::DeviceSetupStatus DevicePluginRemoteSsh::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginRemoteSsh::setupDevice(Device *device)
{ {
qCDebug(dcRemoteSsh()) << "Setup" << device->name() << device->params(); qCDebug(dcRemoteSsh()) << "Setup" << device->name() << device->params();
if (device->deviceClassId() == reverseSshDeviceClassId) { if (device->deviceClassId() == reverseSshDeviceClassId) {
m_identityFilePath = QString("%1/.ssh/id_rsa_guh").arg(QDir::homePath()); m_identityFilePath = QString("%1/.ssh/id_rsa_guh").arg(QDir::homePath());
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginRemoteSsh::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginRemoteSsh::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == reverseSshDeviceClassId ) { if (device->deviceClassId() == reverseSshDeviceClassId ) {
@ -59,26 +59,26 @@ DeviceManager::DeviceError DevicePluginRemoteSsh::executeAction(Device *device,
QProcess *process = startReverseSSHProcess(device); QProcess *process = startReverseSSHProcess(device);
m_reverseSSHProcess.insert(process, device); m_reverseSSHProcess.insert(process, device);
m_startingProcess.insert(process, action.id()); m_startingProcess.insert(process, action.id());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else { } else {
QProcess *process = m_reverseSSHProcess.key(device); QProcess *process = m_reverseSSHProcess.key(device);
// Check if the application is running... // Check if the application is running...
if (!process) if (!process)
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
if (process->state() == QProcess::NotRunning) if (process->state() == QProcess::NotRunning)
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
process->kill(); process->kill();
m_killingProcess.insert(process, action.id()); m_killingProcess.insert(process, action.id());
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
@ -179,7 +179,7 @@ void DevicePluginRemoteSsh::processStateChanged(QProcess::ProcessState state)
case QProcess::Running: case QProcess::Running:
device->setStateValue(reverseSshConnectedStateTypeId, true); device->setStateValue(reverseSshConnectedStateTypeId, true);
if (m_startingProcess.contains(process)) { if (m_startingProcess.contains(process)) {
emit actionExecutionFinished(m_startingProcess.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_startingProcess.value(process), Device::DeviceErrorNoError);
m_startingProcess.remove(process); m_startingProcess.remove(process);
} }
break; break;
@ -189,12 +189,12 @@ void DevicePluginRemoteSsh::processStateChanged(QProcess::ProcessState state)
device->setStateValue(reverseSshConnectedStateTypeId, false); device->setStateValue(reverseSshConnectedStateTypeId, false);
if (m_startingProcess.contains(process)) { if (m_startingProcess.contains(process)) {
emit actionExecutionFinished(m_startingProcess.value(process), DeviceManager::DeviceErrorInvalidParameter); emit actionExecutionFinished(m_startingProcess.value(process), Device::DeviceErrorInvalidParameter);
m_startingProcess.remove(process); m_startingProcess.remove(process);
} }
if (m_killingProcess.contains(process)) { if (m_killingProcess.contains(process)) {
emit actionExecutionFinished(m_killingProcess.value(process), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(m_killingProcess.value(process), Device::DeviceErrorNoError);
m_reverseSSHProcess.remove(process); m_reverseSSHProcess.remove(process);
m_killingProcess.remove(process); m_killingProcess.remove(process);
} }

View File

@ -25,7 +25,7 @@
#define DEVICEPLUGINREMOTESSH_H #define DEVICEPLUGINREMOTESSH_H
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QProcess> #include <QProcess>
@ -40,9 +40,9 @@ public:
explicit DevicePluginRemoteSsh(); explicit DevicePluginRemoteSsh();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
QHash<QProcess *, Device *> m_reverseSSHProcess; QHash<QProcess *, Device *> m_reverseSSHProcess;

View File

@ -21,8 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginsenic.h" #include "devicepluginsenic.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergymanager.h"
@ -37,26 +36,26 @@ void DevicePluginSenic::init()
connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout); connect(m_reconnectTimer, &PluginTimer::timeout, this, &DevicePluginSenic::onReconnectTimeout);
} }
DeviceManager::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginSenic::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
if (deviceClassId != nuimoDeviceClassId) if (deviceClassId != nuimoDeviceClassId)
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
if (!hardwareManager()->bluetoothLowEnergyManager()->available()) if (!hardwareManager()->bluetoothLowEnergyManager()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
if (!hardwareManager()->bluetoothLowEnergyManager()->enabled()) if (!hardwareManager()->bluetoothLowEnergyManager()->enabled())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices(); BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginSenic::onBluetoothDiscoveryFinished); connect(reply, &BluetoothDiscoveryReply::finished, this, &DevicePluginSenic::onBluetoothDiscoveryFinished);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
{ {
qCDebug(dcSenic()) << "Setup device" << device->name() << device->params(); qCDebug(dcSenic()) << "Setup device" << device->name() << device->params();
@ -75,17 +74,17 @@ DeviceManager::DeviceSetupStatus DevicePluginSenic::setupDevice(Device *device)
m_nuimos.insert(nuimo, device); m_nuimos.insert(nuimo, device);
nuimo->bluetoothDevice()->connectDevice(); nuimo->bluetoothDevice()->connectDevice();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginSenic::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginSenic::executeAction(Device *device, const Action &action)
{ {
QPointer<Nuimo> nuimo = m_nuimos.key(device); QPointer<Nuimo> nuimo = m_nuimos.key(device);
if (nuimo.isNull()) if (nuimo.isNull())
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
if (!nuimo->bluetoothDevice()->connected()) { if (!nuimo->bluetoothDevice()->connected()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
if (action.actionTypeId() == nuimoShowLogoActionTypeId) { if (action.actionTypeId() == nuimoShowLogoActionTypeId) {
@ -109,10 +108,10 @@ DeviceManager::DeviceError DevicePluginSenic::executeAction(Device *device, cons
if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart") if (action.param(nuimoShowLogoActionLogoParamTypeId).value().toString() == "Heart")
nuimo->showImage(Nuimo::MatrixTypeHeart); nuimo->showImage(Nuimo::MatrixTypeHeart);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
void DevicePluginSenic::deviceRemoved(Device *device) void DevicePluginSenic::deviceRemoved(Device *device)

View File

@ -24,7 +24,7 @@
#define DEVICEPLUGINSENIC_H #define DEVICEPLUGINSENIC_H
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
#include "nuimo.h" #include "nuimo.h"
@ -40,9 +40,9 @@ public:
explicit DevicePluginSenic(); explicit DevicePluginSenic();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;

View File

@ -27,7 +27,7 @@
#include <QBluetoothUuid> #include <QBluetoothUuid>
#include "typeutils.h" #include "typeutils.h"
#include "plugin/device.h" #include "devices/device.h"
#include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h" #include "hardware/bluetoothlowenergy/bluetoothlowenergydevice.h"
class Nuimo : public QObject class Nuimo : public QObject

View File

@ -28,7 +28,7 @@ DevicePluginSerialPortCommander::DevicePluginSerialPortCommander()
} }
DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginSerialPortCommander::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
// Create the list of available serial interfaces // Create the list of available serial interfaces
@ -51,11 +51,11 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::discoverDevices(cons
deviceDescriptors.append(deviceDescriptor); deviceDescriptors.append(deviceDescriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(Device *device)
{ {
if(!m_reconnectTimer) { if(!m_reconnectTimer) {
m_reconnectTimer = new QTimer(this); m_reconnectTimer = new QTimer(this);
@ -69,7 +69,7 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De
QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString(); QString interface = device->paramValue(serialPortCommanderDeviceSerialPortParamTypeId).toString();
QSerialPort *serialPort = new QSerialPort(interface, this); QSerialPort *serialPort = new QSerialPort(interface, this);
if(!serialPort) if(!serialPort)
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
serialPort->setBaudRate(device->paramValue(serialPortCommanderDeviceBaudRateParamTypeId).toInt()); serialPort->setBaudRate(device->paramValue(serialPortCommanderDeviceBaudRateParamTypeId).toInt());
serialPort->setDataBits(QSerialPort::DataBits(device->paramValue(serialPortCommanderDeviceDataBitsParamTypeId).toInt())); serialPort->setDataBits(QSerialPort::DataBits(device->paramValue(serialPortCommanderDeviceDataBitsParamTypeId).toInt()));
@ -99,7 +99,7 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De
if (!serialPort->open(QIODevice::ReadWrite)) { if (!serialPort->open(QIODevice::ReadWrite)) {
qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString(); qCWarning(dcSerialPortCommander()) << "Could not open serial port" << interface << serialPort->errorString();
serialPort->deleteLater(); serialPort->deleteLater();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError))); connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onSerialError(QSerialPort::SerialPortError)));
@ -112,11 +112,11 @@ DeviceManager::DeviceSetupStatus DevicePluginSerialPortCommander::setupDevice(De
m_serialPorts.insert(device, serialPort); m_serialPorts.insert(device, serialPort);
device->setStateValue(serialPortCommanderConnectedStateTypeId, true); device->setStateValue(serialPortCommanderConnectedStateTypeId, true);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginSerialPortCommander::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginSerialPortCommander::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == serialPortCommanderDeviceClassId ) { if (device->deviceClassId() == serialPortCommanderDeviceClassId ) {
@ -125,13 +125,13 @@ DeviceManager::DeviceError DevicePluginSerialPortCommander::executeAction(Device
QSerialPort *serialPort = m_serialPorts.value(device); QSerialPort *serialPort = m_serialPorts.value(device);
qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray()); qint64 size = serialPort->write(action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray());
if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) { if(size != action.param(serialPortCommanderTriggerActionOutputDataParamTypeId).value().toByteArray().length()) {
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }

View File

@ -23,8 +23,7 @@
#ifndef DEVICEPLUGINSERIALPORTCOMMANDER_H #ifndef DEVICEPLUGINSERIALPORTCOMMANDER_H
#define DEVICEPLUGINSERIALPORTCOMMANDER_H #define DEVICEPLUGINSERIALPORTCOMMANDER_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include <QTimer> #include <QTimer>
#include <QSerialPort> #include <QSerialPort>
@ -40,10 +39,10 @@ class DevicePluginSerialPortCommander : public DevicePlugin
public: public:
explicit DevicePluginSerialPortCommander(); explicit DevicePluginSerialPortCommander();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
QTimer *m_reconnectTimer = nullptr; QTimer *m_reconnectTimer = nullptr;

View File

@ -52,7 +52,7 @@ void DevicePluginSimulation::init()
connect(m_pluginTimer5Min, &PluginTimer::timeout, this, &DevicePluginSimulation::onPluginTimer5Minutes); connect(m_pluginTimer5Min, &PluginTimer::timeout, this, &DevicePluginSimulation::onPluginTimer5Minutes);
} }
DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *device)
{ {
qCDebug(dcSimulation()) << "Set up device" << device->name(); qCDebug(dcSimulation()) << "Set up device" << device->name();
if (device->deviceClassId() == garageGateDeviceClassId || if (device->deviceClassId() == garageGateDeviceClassId ||
@ -67,7 +67,7 @@ DeviceManager::DeviceSetupStatus DevicePluginSimulation::setupDevice(Device *dev
if (device->deviceClassId() == fingerPrintSensorDeviceClassId && device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList().count() > 0) { if (device->deviceClassId() == fingerPrintSensorDeviceClassId && device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList().count() > 0) {
m_simulationTimers.value(device)->start(10000); m_simulationTimers.value(device)->start(10000);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginSimulation::deviceRemoved(Device *device) void DevicePluginSimulation::deviceRemoved(Device *device)
@ -80,7 +80,7 @@ void DevicePluginSimulation::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginSimulation::executeAction(Device *device, const Action &action)
{ {
// Check the DeviceClassId for "Simple Button" // Check the DeviceClassId for "Simple Button"
if (device->deviceClassId() == simpleButtonDeviceClassId ) { if (device->deviceClassId() == simpleButtonDeviceClassId ) {
@ -93,9 +93,9 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
Event event(simpleButtonPressedEventTypeId, device->id()); Event event(simpleButtonPressedEventTypeId, device->id());
emit emitEvent(event); emit emitEvent(event);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Check the DeviceClassId for "Alternative Button" // Check the DeviceClassId for "Alternative Button"
@ -113,9 +113,9 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
// Set the "power" state // Set the "power" state
device->setStateValue(alternativeButtonPowerStateTypeId, power); device->setStateValue(alternativeButtonPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == heatingDeviceClassId) { if (device->deviceClassId() == heatingDeviceClassId) {
@ -128,7 +128,7 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
bool power = powerParam.value().toBool(); bool power = powerParam.value().toBool();
qCDebug(dcSimulation()) << "Set power" << power << "for heating device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for heating device" << device->name();
device->setStateValue(heatingPowerStateTypeId, power); device->setStateValue(heatingPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == heatingPercentageActionTypeId) { } else if (action.actionTypeId() == heatingPercentageActionTypeId) {
@ -139,9 +139,9 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
qCDebug(dcSimulation()) << "Set target temperature percentage" << percentage << "for heating device" << device->name(); qCDebug(dcSimulation()) << "Set target temperature percentage" << percentage << "for heating device" << device->name();
device->setStateValue(heatingPercentageStateTypeId, percentage); device->setStateValue(heatingPercentageStateTypeId, percentage);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == thermostatDeviceClassId) { if (device->deviceClassId() == thermostatDeviceClassId) {
@ -152,7 +152,7 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
} }
qCDebug(dcSimulation()) << "Set power" << power << "for thermostat device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for thermostat device" << device->name();
device->setStateValue(thermostatPowerStateTypeId, power); device->setStateValue(thermostatPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == thermostatBoostActionTypeId) { if (action.actionTypeId() == thermostatBoostActionTypeId) {
bool boost = action.param(thermostatBoostActionBoostParamTypeId).value().toBool(); bool boost = action.param(thermostatBoostActionBoostParamTypeId).value().toBool();
@ -162,7 +162,7 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
qCDebug(dcSimulation()) << "Set boost" << boost << "for thermostat device" << device->name(); qCDebug(dcSimulation()) << "Set boost" << boost << "for thermostat device" << device->name();
device->setStateValue(thermostatBoostStateTypeId, boost); device->setStateValue(thermostatBoostStateTypeId, boost);
m_simulationTimers.value(device)->start(5 * 60 * 1000); m_simulationTimers.value(device)->start(5 * 60 * 1000);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) { if (action.actionTypeId() == thermostatTargetTemperatureActionTypeId) {
if (!device->stateValue(thermostatPowerStateTypeId).toBool()) { if (!device->stateValue(thermostatPowerStateTypeId).toBool()) {
@ -171,7 +171,7 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
double targetTemp = action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value().toDouble(); double targetTemp = action.param(thermostatTargetTemperatureActionTargetTemperatureParamTypeId).value().toDouble();
qCDebug(dcSimulation()) << "Set targetTemp" << targetTemp << "for thermostat device" << device->name(); qCDebug(dcSimulation()) << "Set targetTemp" << targetTemp << "for thermostat device" << device->name();
device->setStateValue(thermostatTargetTemperatureStateTypeId, targetTemp); device->setStateValue(thermostatTargetTemperatureStateTypeId, targetTemp);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
@ -185,7 +185,7 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
qCDebug(dcSimulation()) << "Set power" << power << "for heating device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for heating device" << device->name();
device->setStateValue(evChargerPowerStateTypeId, power); device->setStateValue(evChargerPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if(action.actionTypeId() == evChargerMaxChargingCurrentActionTypeId){ } else if(action.actionTypeId() == evChargerMaxChargingCurrentActionTypeId){
// get the param value // get the param value
@ -193,9 +193,9 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
uint maxCharge = maxChargeParam.value().toInt(); uint maxCharge = maxChargeParam.value().toInt();
qCDebug(dcSimulation()) << "Set maximum charging current to" << maxCharge << "for EV Charger device" << device->name(); qCDebug(dcSimulation()) << "Set maximum charging current to" << maxCharge << "for EV Charger device" << device->name();
device->setStateValue(evChargerMaxChargingCurrentStateTypeId, maxCharge); device->setStateValue(evChargerMaxChargingCurrentStateTypeId, maxCharge);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if(device->deviceClassId() == socketDeviceClassId){ if(device->deviceClassId() == socketDeviceClassId){
@ -207,9 +207,9 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
// Set the "power" state // Set the "power" state
qCDebug(dcSimulation()) << "Set power" << power << "for socket device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for socket device" << device->name();
device->setStateValue(socketPowerStateTypeId, power); device->setStateValue(socketPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if(device->deviceClassId() == colorBulbDeviceClassId){ if(device->deviceClassId() == colorBulbDeviceClassId){
@ -218,28 +218,28 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
int brightness = action.param(colorBulbBrightnessActionBrightnessParamTypeId).value().toInt(); int brightness = action.param(colorBulbBrightnessActionBrightnessParamTypeId).value().toInt();
qCDebug(dcSimulation()) << "Set brightness" << brightness << "for color bulb device" << device->name(); qCDebug(dcSimulation()) << "Set brightness" << brightness << "for color bulb device" << device->name();
device->setStateValue(colorBulbBrightnessStateTypeId, brightness); device->setStateValue(colorBulbBrightnessStateTypeId, brightness);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId){ } else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId){
int temperature = action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toInt(); int temperature = action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toInt();
qCDebug(dcSimulation()) << "Set color temperature" << temperature << "for color bulb device" << device->name(); qCDebug(dcSimulation()) << "Set color temperature" << temperature << "for color bulb device" << device->name();
device->setStateValue(colorBulbColorTemperatureStateTypeId, temperature); device->setStateValue(colorBulbColorTemperatureStateTypeId, temperature);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == colorBulbColorActionTypeId) { } else if (action.actionTypeId() == colorBulbColorActionTypeId) {
QColor color = action.param(colorBulbColorActionColorParamTypeId).value().value<QColor>(); QColor color = action.param(colorBulbColorActionColorParamTypeId).value().value<QColor>();
qCDebug(dcSimulation()) << "Set color" << color << "for color bulb device" << device->name(); qCDebug(dcSimulation()) << "Set color" << color << "for color bulb device" << device->name();
device->setStateValue(colorBulbColorStateTypeId, color); device->setStateValue(colorBulbColorStateTypeId, color);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == colorBulbPowerActionTypeId) { } else if (action.actionTypeId() == colorBulbPowerActionTypeId) {
bool power = action.param(colorBulbPowerActionPowerParamTypeId).value().toBool(); bool power = action.param(colorBulbPowerActionPowerParamTypeId).value().toBool();
qCDebug(dcSimulation()) << "Set power" << power << "for color bulb device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for color bulb device" << device->name();
device->setStateValue(colorBulbPowerStateTypeId, power); device->setStateValue(colorBulbPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == heatingRodDeviceClassId) { if (device->deviceClassId() == heatingRodDeviceClassId) {
@ -248,15 +248,15 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
bool power = action.param(heatingRodPowerActionPowerParamTypeId).value().toBool(); bool power = action.param(heatingRodPowerActionPowerParamTypeId).value().toBool();
qCDebug(dcSimulation()) << "Set power" << power << "for heating rod device" << device->name(); qCDebug(dcSimulation()) << "Set power" << power << "for heating rod device" << device->name();
device->setStateValue(heatingRodPowerStateTypeId, power); device->setStateValue(heatingRodPowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == heatingRodPercentageActionTypeId) { } else if (action.actionTypeId() == heatingRodPercentageActionTypeId) {
int percentage = action.param(heatingRodPercentageActionPercentageParamTypeId).value().toInt(); int percentage = action.param(heatingRodPercentageActionPercentageParamTypeId).value().toInt();
qCDebug(dcSimulation()) << "Set percentage" << percentage << "for heating rod device" << device->name(); qCDebug(dcSimulation()) << "Set percentage" << percentage << "for heating rod device" << device->name();
device->setStateValue(heatingRodPercentageStateTypeId, percentage); device->setStateValue(heatingRodPercentageStateTypeId, percentage);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == batteryDeviceClassId) { if (device->deviceClassId() == batteryDeviceClassId) {
@ -265,64 +265,64 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
device->setStateValue(batteryMaxChargingStateTypeId, maxCharging); device->setStateValue(batteryMaxChargingStateTypeId, maxCharging);
qCDebug(dcSimulation()) << "Set max charging power" << maxCharging << "for battery device" << device->name(); qCDebug(dcSimulation()) << "Set max charging power" << maxCharging << "for battery device" << device->name();
device->setStateValue(batteryChargingStateTypeId, maxCharging); device->setStateValue(batteryChargingStateTypeId, maxCharging);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == waterValveDeviceClassId) { if (device->deviceClassId() == waterValveDeviceClassId) {
if (action.actionTypeId() == waterValvePowerActionTypeId) { if (action.actionTypeId() == waterValvePowerActionTypeId) {
bool power = action.param(waterValvePowerActionPowerParamTypeId).value().toBool(); bool power = action.param(waterValvePowerActionPowerParamTypeId).value().toBool();
device->setStateValue(waterValvePowerStateTypeId, power); device->setStateValue(waterValvePowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == garageGateDeviceClassId) { if (device->deviceClassId() == garageGateDeviceClassId) {
if (action.actionTypeId() == garageGateOpenActionTypeId) { if (action.actionTypeId() == garageGateOpenActionTypeId) {
if (device->stateValue(garageGateStateStateTypeId).toString() == "opening") { if (device->stateValue(garageGateStateStateTypeId).toString() == "opening") {
qCDebug(dcSimulation()) << "Garage gate already opening."; qCDebug(dcSimulation()) << "Garage gate already opening.";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (device->stateValue(garageGateStateStateTypeId).toString() == "open" && if (device->stateValue(garageGateStateStateTypeId).toString() == "open" &&
!device->stateValue(garageGateIntermediatePositionStateTypeId).toBool()) { !device->stateValue(garageGateIntermediatePositionStateTypeId).toBool()) {
qCDebug(dcSimulation()) << "Garage gate already open."; qCDebug(dcSimulation()) << "Garage gate already open.";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
device->setStateValue(garageGateStateStateTypeId, "opening"); device->setStateValue(garageGateStateStateTypeId, "opening");
device->setStateValue(garageGateIntermediatePositionStateTypeId, true); device->setStateValue(garageGateIntermediatePositionStateTypeId, true);
m_simulationTimers.value(device)->start(5000); m_simulationTimers.value(device)->start(5000);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == garageGateCloseActionTypeId) { if (action.actionTypeId() == garageGateCloseActionTypeId) {
if (device->stateValue(garageGateStateStateTypeId).toString() == "closing") { if (device->stateValue(garageGateStateStateTypeId).toString() == "closing") {
qCDebug(dcSimulation()) << "Garage gate already closing."; qCDebug(dcSimulation()) << "Garage gate already closing.";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (device->stateValue(garageGateStateStateTypeId).toString() == "closed" && if (device->stateValue(garageGateStateStateTypeId).toString() == "closed" &&
!device->stateValue(garageGateIntermediatePositionStateTypeId).toBool()) { !device->stateValue(garageGateIntermediatePositionStateTypeId).toBool()) {
qCDebug(dcSimulation()) << "Garage gate already closed."; qCDebug(dcSimulation()) << "Garage gate already closed.";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
device->setStateValue(garageGateStateStateTypeId, "closing"); device->setStateValue(garageGateStateStateTypeId, "closing");
device->setStateValue(garageGateIntermediatePositionStateTypeId, true); device->setStateValue(garageGateIntermediatePositionStateTypeId, true);
m_simulationTimers.value(device)->start(5000); m_simulationTimers.value(device)->start(5000);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == garageGateStopActionTypeId) { if (action.actionTypeId() == garageGateStopActionTypeId) {
if (device->stateValue(garageGateStateStateTypeId).toString() == "opening" || if (device->stateValue(garageGateStateStateTypeId).toString() == "opening" ||
device->stateValue(garageGateStateStateTypeId).toString() == "closing") { device->stateValue(garageGateStateStateTypeId).toString() == "closing") {
device->setStateValue(garageGateStateStateTypeId, "open"); device->setStateValue(garageGateStateStateTypeId, "open");
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
qCDebug(dcSimulation()) << "Garage gate not moving"; qCDebug(dcSimulation()) << "Garage gate not moving";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == garageGatePowerActionTypeId) { if (action.actionTypeId() == garageGatePowerActionTypeId) {
bool power = action.param(garageGatePowerActionPowerParamTypeId).value().toBool(); bool power = action.param(garageGatePowerActionPowerParamTypeId).value().toBool();
device->setStateValue(garageGatePowerStateTypeId, power); device->setStateValue(garageGatePowerStateTypeId, power);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
@ -332,27 +332,27 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
m_simulationTimers.value(device)->setProperty("targetValue", 0); m_simulationTimers.value(device)->setProperty("targetValue", 0);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(rollerShutterMovingStateTypeId, true); device->setStateValue(rollerShutterMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == rollerShutterCloseActionTypeId) { if (action.actionTypeId() == rollerShutterCloseActionTypeId) {
qCDebug(dcSimulation()) << "Closing roller shutter"; qCDebug(dcSimulation()) << "Closing roller shutter";
m_simulationTimers.value(device)->setProperty("targetValue", 100); m_simulationTimers.value(device)->setProperty("targetValue", 100);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(rollerShutterMovingStateTypeId, true); device->setStateValue(rollerShutterMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == rollerShutterStopActionTypeId) { if (action.actionTypeId() == rollerShutterStopActionTypeId) {
qCDebug(dcSimulation()) << "Stopping roller shutter"; qCDebug(dcSimulation()) << "Stopping roller shutter";
m_simulationTimers.value(device)->stop(); m_simulationTimers.value(device)->stop();
device->setStateValue(rollerShutterMovingStateTypeId, false); device->setStateValue(rollerShutterMovingStateTypeId, false);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == rollerShutterPercentageActionTypeId) { if (action.actionTypeId() == rollerShutterPercentageActionTypeId) {
qCDebug(dcSimulation()) << "Setting awning to" << action.param(rollerShutterPercentageActionPercentageParamTypeId); qCDebug(dcSimulation()) << "Setting awning to" << action.param(rollerShutterPercentageActionPercentageParamTypeId);
m_simulationTimers.value(device)->setProperty("targetValue", action.param(rollerShutterPercentageActionPercentageParamTypeId).value()); m_simulationTimers.value(device)->setProperty("targetValue", action.param(rollerShutterPercentageActionPercentageParamTypeId).value());
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(rollerShutterMovingStateTypeId, true); device->setStateValue(rollerShutterMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
@ -362,27 +362,27 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
m_simulationTimers.value(device)->setProperty("targetValue", 100); m_simulationTimers.value(device)->setProperty("targetValue", 100);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedAwningMovingStateTypeId, true); device->setStateValue(extendedAwningMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedAwningCloseActionTypeId) { if (action.actionTypeId() == extendedAwningCloseActionTypeId) {
qCDebug(dcSimulation()) << "Closing awning"; qCDebug(dcSimulation()) << "Closing awning";
m_simulationTimers.value(device)->setProperty("targetValue", 0); m_simulationTimers.value(device)->setProperty("targetValue", 0);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedAwningMovingStateTypeId, true); device->setStateValue(extendedAwningMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedAwningStopActionTypeId) { if (action.actionTypeId() == extendedAwningStopActionTypeId) {
qCDebug(dcSimulation()) << "Stopping awning"; qCDebug(dcSimulation()) << "Stopping awning";
m_simulationTimers.value(device)->stop(); m_simulationTimers.value(device)->stop();
device->setStateValue(extendedAwningMovingStateTypeId, false); device->setStateValue(extendedAwningMovingStateTypeId, false);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedAwningPercentageActionTypeId) { if (action.actionTypeId() == extendedAwningPercentageActionTypeId) {
qCDebug(dcSimulation()) << "Setting awning to" << action.param(extendedAwningPercentageActionPercentageParamTypeId); qCDebug(dcSimulation()) << "Setting awning to" << action.param(extendedAwningPercentageActionPercentageParamTypeId);
m_simulationTimers.value(device)->setProperty("targetValue", action.param(extendedAwningPercentageActionPercentageParamTypeId).value()); m_simulationTimers.value(device)->setProperty("targetValue", action.param(extendedAwningPercentageActionPercentageParamTypeId).value());
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedAwningMovingStateTypeId, true); device->setStateValue(extendedAwningMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
@ -395,13 +395,13 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
settings.beginGroup(device->id().toString()); settings.beginGroup(device->id().toString());
QStringList usedFingers = settings.value(username).toStringList(); QStringList usedFingers = settings.value(username).toStringList();
if (users.contains(username) && usedFingers.contains(finger)) { if (users.contains(username) && usedFingers.contains(finger)) {
return DeviceManager::DeviceErrorDuplicateUuid; return Device::DeviceErrorDuplicateUuid;
} }
QTimer::singleShot(5000, this, [this, action, device, username, finger]() { QTimer::singleShot(5000, this, [this, action, device, username, finger]() {
if (username.toLower().trimmed() == "john") { if (username.toLower().trimmed() == "john") {
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorHardwareFailure); emit actionExecutionFinished(action.id(), Device::DeviceErrorHardwareFailure);
} else { } else {
emit actionExecutionFinished(action.id(), DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(action.id(), Device::DeviceErrorNoError);
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList(); QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
if (!users.contains(username)) { if (!users.contains(username)) {
users.append(username); users.append(username);
@ -417,35 +417,35 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
settings.endGroup(); settings.endGroup();
} }
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (action.actionTypeId() == fingerPrintSensorRemoveUserActionTypeId) { if (action.actionTypeId() == fingerPrintSensorRemoveUserActionTypeId) {
QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList(); QStringList users = device->stateValue(fingerPrintSensorUsersStateTypeId).toStringList();
QString username = action.params().first().value().toString(); QString username = action.params().first().value().toString();
if (!users.contains(username)) { if (!users.contains(username)) {
return DeviceManager::DeviceErrorInvalidParameter; return Device::DeviceErrorInvalidParameter;
} }
users.removeAll(username); users.removeAll(username);
device->setStateValue(fingerPrintSensorUsersStateTypeId, users); device->setStateValue(fingerPrintSensorUsersStateTypeId, users);
if (users.count() == 0) { if (users.count() == 0) {
m_simulationTimers.value(device)->stop(); m_simulationTimers.value(device)->stop();
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
if (device->deviceClassId() == simpleBlindDeviceClassId) { if (device->deviceClassId() == simpleBlindDeviceClassId) {
if (action.actionTypeId() == simpleBlindOpenActionTypeId) { if (action.actionTypeId() == simpleBlindOpenActionTypeId) {
qCDebug(dcSimulation()) << "Opening simple blind"; qCDebug(dcSimulation()) << "Opening simple blind";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == simpleBlindCloseActionTypeId) { if (action.actionTypeId() == simpleBlindCloseActionTypeId) {
qCDebug(dcSimulation()) << "Closing simple blind"; qCDebug(dcSimulation()) << "Closing simple blind";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == simpleBlindStopActionTypeId) { if (action.actionTypeId() == simpleBlindStopActionTypeId) {
qCDebug(dcSimulation()) << "Stopping simple blind"; qCDebug(dcSimulation()) << "Stopping simple blind";
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
@ -455,33 +455,33 @@ DeviceManager::DeviceError DevicePluginSimulation::executeAction(Device *device,
m_simulationTimers.value(device)->setProperty("targetValue", 0); m_simulationTimers.value(device)->setProperty("targetValue", 0);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedBlindMovingStateTypeId, true); device->setStateValue(extendedBlindMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedBlindCloseActionTypeId) { if (action.actionTypeId() == extendedBlindCloseActionTypeId) {
qCDebug(dcSimulation()) << "Closing extended blind"; qCDebug(dcSimulation()) << "Closing extended blind";
m_simulationTimers.value(device)->setProperty("targetValue", 100); m_simulationTimers.value(device)->setProperty("targetValue", 100);
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedBlindMovingStateTypeId, true); device->setStateValue(extendedBlindMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedBlindStopActionTypeId) { if (action.actionTypeId() == extendedBlindStopActionTypeId) {
qCDebug(dcSimulation()) << "Stopping extended blind"; qCDebug(dcSimulation()) << "Stopping extended blind";
m_simulationTimers.value(device)->stop(); m_simulationTimers.value(device)->stop();
device->setStateValue(extendedBlindMovingStateTypeId, false); device->setStateValue(extendedBlindMovingStateTypeId, false);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == extendedBlindPercentageActionTypeId) { if (action.actionTypeId() == extendedBlindPercentageActionTypeId) {
qCDebug(dcSimulation()) << "Setting extended blind to" << action.param(extendedBlindPercentageActionPercentageParamTypeId); qCDebug(dcSimulation()) << "Setting extended blind to" << action.param(extendedBlindPercentageActionPercentageParamTypeId);
m_simulationTimers.value(device)->setProperty("targetValue", action.param(extendedBlindPercentageActionPercentageParamTypeId).value()); m_simulationTimers.value(device)->setProperty("targetValue", action.param(extendedBlindPercentageActionPercentageParamTypeId).value());
m_simulationTimers.value(device)->start(500); m_simulationTimers.value(device)->start(500);
device->setStateValue(extendedBlindMovingStateTypeId, true); device->setStateValue(extendedBlindMovingStateTypeId, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} }
qCWarning(dcSimulation()) << "Unhandled device class" << device->deviceClassId() << "for device" << device->name(); qCWarning(dcSimulation()) << "Unhandled device class" << device->deviceClassId() << "for device" << device->name();
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
int DevicePluginSimulation::generateRandomIntValue(int min, int max) int DevicePluginSimulation::generateRandomIntValue(int min, int max)

View File

@ -22,8 +22,7 @@
#ifndef DEVICEPLUGINSIMMULATION_H #ifndef DEVICEPLUGINSIMMULATION_H
#define DEVICEPLUGINSIMMULATION_H #define DEVICEPLUGINSIMMULATION_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "plugintimer.h" #include "plugintimer.h"
#include <QDateTime> #include <QDateTime>
@ -41,9 +40,9 @@ public:
~DevicePluginSimulation(); ~DevicePluginSimulation();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
PluginTimer *m_pluginTimer20Seconds = nullptr; PluginTimer *m_pluginTimer20Seconds = nullptr;

View File

@ -21,7 +21,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginsnapd.h" #include "devicepluginsnapd.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
@ -103,7 +103,7 @@ void DevicePluginSnapd::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceSetupStatus DevicePluginSnapd::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginSnapd::setupDevice(Device *device)
{ {
qCDebug(dcSnapd()) << "Setup" << device->name() << device->params(); qCDebug(dcSnapd()) << "Setup" << device->name() << device->params();
@ -122,59 +122,59 @@ DeviceManager::DeviceSetupStatus DevicePluginSnapd::setupDevice(Device *device)
m_snapDevices.insert(device->paramValue(snapDeviceIdParamTypeId).toString(), device); m_snapDevices.insert(device->paramValue(snapDeviceIdParamTypeId).toString(), device);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginSnapd::executeAction(Device *device, const Action &action) { Device::DeviceError DevicePluginSnapd::executeAction(Device *device, const Action &action) {
if (device->deviceClassId() == snapdControlDeviceClassId) { if (device->deviceClassId() == snapdControlDeviceClassId) {
if (!m_snapdControl) { if (!m_snapdControl) {
qCDebug(dcSnapd()) << "There is currently no snapd controller."; qCDebug(dcSnapd()) << "There is currently no snapd controller.";
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
if (!m_snapdControl->connected()) { if (!m_snapdControl->connected()) {
qCDebug(dcSnapd()) << "Snapd controller not connected to to backend."; qCDebug(dcSnapd()) << "Snapd controller not connected to to backend.";
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
if (action.actionTypeId() == snapdControlStartUpdateActionTypeId) { if (action.actionTypeId() == snapdControlStartUpdateActionTypeId) {
m_snapdControl->snapRefresh(); m_snapdControl->snapRefresh();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == snapdControlCheckUpdatesActionTypeId) { } else if (action.actionTypeId() == snapdControlCheckUpdatesActionTypeId) {
m_snapdControl->checkForUpdates(); m_snapdControl->checkForUpdates();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} else if (device->deviceClassId() == snapDeviceClassId) { } else if (device->deviceClassId() == snapDeviceClassId) {
if (!m_snapdControl) { if (!m_snapdControl) {
qCDebug(dcSnapd()) << "There is currently no snapd controller."; qCDebug(dcSnapd()) << "There is currently no snapd controller.";
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
if (!m_snapdControl->connected()) { if (!m_snapdControl->connected()) {
qCDebug(dcSnapd()) << "Snapd controller not connected to the backend."; qCDebug(dcSnapd()) << "Snapd controller not connected to the backend.";
return DeviceManager::DeviceErrorHardwareFailure; return Device::DeviceErrorHardwareFailure;
} }
if (action.actionTypeId() == snapChannelActionTypeId) { if (action.actionTypeId() == snapChannelActionTypeId) {
QString snapName = device->paramValue(snapDeviceNameParamTypeId).toString(); QString snapName = device->paramValue(snapDeviceNameParamTypeId).toString();
m_snapdControl->changeSnapChannel(snapName, action.param(snapChannelActionChannelParamTypeId).value().toString()); m_snapdControl->changeSnapChannel(snapName, action.param(snapChannelActionChannelParamTypeId).value().toString());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == snapRevertActionTypeId) { } else if (action.actionTypeId() == snapRevertActionTypeId) {
QString snapName = device->paramValue(snapDeviceNameParamTypeId).toString(); QString snapName = device->paramValue(snapDeviceNameParamTypeId).toString();
m_snapdControl->snapRevert(snapName); m_snapdControl->snapRevert(snapName);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginSnapd::onPluginConfigurationChanged(const ParamTypeId &paramTypeId, const QVariant &value) void DevicePluginSnapd::onPluginConfigurationChanged(const ParamTypeId &paramTypeId, const QVariant &value)

View File

@ -23,8 +23,7 @@
#ifndef DEVICEPLUGINSNAPD_H #ifndef DEVICEPLUGINSNAPD_H
#define DEVICEPLUGINSNAPD_H #define DEVICEPLUGINSNAPD_H
#include "devicemanager.h" #include "devices/deviceplugin.h"
#include "plugin/deviceplugin.h"
#include "plugintimer.h" #include "plugintimer.h"
#include <QDebug> #include <QDebug>
@ -49,8 +48,8 @@ public:
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
SnapdControl *m_snapdControl = nullptr; SnapdControl *m_snapdControl = nullptr;

View File

@ -26,7 +26,7 @@
#include <QObject> #include <QObject>
#include <QLocalSocket> #include <QLocalSocket>
#include "plugin/device.h" #include "devices/device.h"
#include "snapdconnection.h" #include "snapdconnection.h"
class SnapdControl : public QObject class SnapdControl : public QObject

View File

@ -71,7 +71,7 @@ void DevicePluginTasmota::init()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device)
{ {
if (m_ipAddressParamTypeMap.contains(device->deviceClassId())) { if (m_ipAddressParamTypeMap.contains(device->deviceClassId())) {
ParamTypeId ipAddressParamTypeId = m_ipAddressParamTypeMap.value(device->deviceClassId()); ParamTypeId ipAddressParamTypeId = m_ipAddressParamTypeMap.value(device->deviceClassId());
@ -79,12 +79,12 @@ DeviceManager::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device
QHostAddress deviceAddress = QHostAddress(device->paramValue(ipAddressParamTypeId).toString()); QHostAddress deviceAddress = QHostAddress(device->paramValue(ipAddressParamTypeId).toString());
if (deviceAddress.isNull()) { if (deviceAddress.isNull()) {
qCWarning(dcTasmota) << "Not a valid IP address given for IP address parameter"; qCWarning(dcTasmota) << "Not a valid IP address given for IP address parameter";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
MqttChannel *channel = hardwareManager()->mqttProvider()->createChannel(device->id(), deviceAddress); MqttChannel *channel = hardwareManager()->mqttProvider()->createChannel(device->id(), deviceAddress);
if (!channel) { if (!channel) {
qCWarning(dcTasmota) << "Failed to create MQTT channel."; qCWarning(dcTasmota) << "Failed to create MQTT channel.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
QUrl url(QString("http://%1/cm").arg(deviceAddress.toString())); QUrl url(QString("http://%1/cm").arg(deviceAddress.toString()));
@ -115,7 +115,7 @@ DeviceManager::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device
if (reply->error() != QNetworkReply::NoError) { if (reply->error() != QNetworkReply::NoError) {
qCDebug(dcTasmota) << "Sonoff device setup call failed:" << reply->error() << reply->errorString() << reply->readAll(); qCDebug(dcTasmota) << "Sonoff device setup call failed:" << reply->error() << reply->errorString() << reply->readAll();
hardwareManager()->mqttProvider()->releaseChannel(channel); hardwareManager()->mqttProvider()->releaseChannel(channel);
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusFailure); emit deviceSetupFinished(device, Device::DeviceSetupStatusFailure);
return; return;
} }
m_mqttChannels.insert(device, channel); m_mqttChannels.insert(device, channel);
@ -124,7 +124,7 @@ DeviceManager::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device
connect(channel, &MqttChannel::publishReceived, this, &DevicePluginTasmota::onPublishReceived); connect(channel, &MqttChannel::publishReceived, this, &DevicePluginTasmota::onPublishReceived);
qCDebug(dcTasmota) << "Sonoff setup complete"; qCDebug(dcTasmota) << "Sonoff setup complete";
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
foreach (Device *child, myDevices()) { foreach (Device *child, myDevices()) {
if (child->parentId() == device->id()) { if (child->parentId() == device->id()) {
@ -184,18 +184,18 @@ DeviceManager::DeviceSetupStatus DevicePluginTasmota::setupDevice(Device *device
emit autoDevicesAppeared(tasmotaShutterDeviceClassId, deviceDescriptors); emit autoDevicesAppeared(tasmotaShutterDeviceClassId, deviceDescriptors);
} }
}); });
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
if (m_connectedStateTypeMap.contains(device->deviceClassId())) { if (m_connectedStateTypeMap.contains(device->deviceClassId())) {
Device* parentDevice = myDevices().findById(device->parentId()); Device* parentDevice = myDevices().findById(device->parentId());
StateTypeId connectedStateTypeId = m_connectedStateTypeMap.value(device->deviceClassId()); StateTypeId connectedStateTypeId = m_connectedStateTypeMap.value(device->deviceClassId());
device->setStateValue(m_connectedStateTypeMap.value(device->deviceClassId()), parentDevice->stateValue(connectedStateTypeId)); device->setStateValue(m_connectedStateTypeMap.value(device->deviceClassId()), parentDevice->stateValue(connectedStateTypeId));
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
qCWarning(dcTasmota) << "Unhandled DeviceClass in setupDevice" << device->deviceClassId(); qCWarning(dcTasmota) << "Unhandled DeviceClass in setupDevice" << device->deviceClassId();
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
void DevicePluginTasmota::deviceRemoved(Device *device) void DevicePluginTasmota::deviceRemoved(Device *device)
@ -208,7 +208,7 @@ void DevicePluginTasmota::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginTasmota::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginTasmota::executeAction(Device *device, const Action &action)
{ {
if (m_powerStateTypeMap.contains(device->deviceClassId())) { if (m_powerStateTypeMap.contains(device->deviceClassId())) {
Device *parentDev = myDevices().findById(device->parentId()); Device *parentDev = myDevices().findById(device->parentId());
@ -218,7 +218,7 @@ DeviceManager::DeviceError DevicePluginTasmota::executeAction(Device *device, co
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString() << (action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF"); qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString() << (action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF");
channel->publish(channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString().toLower(), action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF"); channel->publish(channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(channelParamTypeId).toString().toLower(), action.param(powerActionParamTypeId).value().toBool() ? "ON" : "OFF");
device->setStateValue(m_powerStateTypeMap.value(device->deviceClassId()), action.param(powerActionParamTypeId).value().toBool()); device->setStateValue(m_powerStateTypeMap.value(device->deviceClassId()), action.param(powerActionParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (device->deviceClassId() == tasmotaShutterDeviceClassId) { if (device->deviceClassId() == tasmotaShutterDeviceClassId) {
Device *parentDev = myDevices().findById(device->parentId()); Device *parentDev = myDevices().findById(device->parentId());
@ -241,10 +241,10 @@ DeviceManager::DeviceError DevicePluginTasmota::executeAction(Device *device, co
qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(closingChannelParamTypeId).toString() << "OFF"; qCDebug(dcTasmota) << "Publishing:" << channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(closingChannelParamTypeId).toString() << "OFF";
channel->publish(channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(closingChannelParamTypeId).toString().toLower(), "OFF"); channel->publish(channel->topicPrefix() + "/sonoff/cmnd/" + device->paramValue(closingChannelParamTypeId).toString().toLower(), "OFF");
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
qCWarning(dcTasmota) << "Unhandled execute action call for device" << device; qCWarning(dcTasmota) << "Unhandled execute action call for device" << device;
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginTasmota::onClientConnected(MqttChannel *channel) void DevicePluginTasmota::onClientConnected(MqttChannel *channel)

View File

@ -21,8 +21,7 @@
#ifndef DEVICEPLUGINTASMOTA_H #ifndef DEVICEPLUGINTASMOTA_H
#define DEVICEPLUGINTASMOTA_H #define DEVICEPLUGINTASMOTA_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
class MqttChannel; class MqttChannel;
@ -39,9 +38,9 @@ public:
~DevicePluginTasmota(); ~DevicePluginTasmota();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots: private slots:
void onClientConnected(MqttChannel *channel); void onClientConnected(MqttChannel *channel);

View File

@ -26,7 +26,7 @@ DevicePluginTcpCommander::DevicePluginTcpCommander()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *device)
{ {
if (device->deviceClassId() == tcpOutputDeviceClassId) { if (device->deviceClassId() == tcpOutputDeviceClassId) {
QTcpSocket *tcpSocket = new QTcpSocket(this); QTcpSocket *tcpSocket = new QTcpSocket(this);
@ -34,7 +34,7 @@ DeviceManager::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *d
connect(tcpSocket, &QTcpSocket::connected, this, &DevicePluginTcpCommander::onTcpSocketConnected); connect(tcpSocket, &QTcpSocket::connected, this, &DevicePluginTcpCommander::onTcpSocketConnected);
connect(tcpSocket, &QTcpSocket::disconnected, this, &DevicePluginTcpCommander::onTcpSocketDisconnected); connect(tcpSocket, &QTcpSocket::disconnected, this, &DevicePluginTcpCommander::onTcpSocketDisconnected);
connect(tcpSocket, &QTcpSocket::bytesWritten, this, &DevicePluginTcpCommander::onTcpSocketBytesWritten); connect(tcpSocket, &QTcpSocket::bytesWritten, this, &DevicePluginTcpCommander::onTcpSocketBytesWritten);
return DeviceManager::DeviceSetupStatusAsync; return Device::DeviceSetupStatusAsync;
} }
if (device->deviceClassId() == tcpInputDeviceClassId) { if (device->deviceClassId() == tcpInputDeviceClassId) {
@ -45,17 +45,17 @@ DeviceManager::DeviceSetupStatus DevicePluginTcpCommander::setupDevice(Device *d
m_tcpServer.insert(tcpServer, device); m_tcpServer.insert(tcpServer, device);
connect(tcpServer, &TcpServer::connected, this, &DevicePluginTcpCommander::onTcpServerConnected); connect(tcpServer, &TcpServer::connected, this, &DevicePluginTcpCommander::onTcpServerConnected);
connect(tcpServer, &TcpServer::disconnected, this, &DevicePluginTcpCommander::onTcpServerDisconnected); connect(tcpServer, &TcpServer::disconnected, this, &DevicePluginTcpCommander::onTcpServerDisconnected);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} else { } else {
tcpServer->deleteLater(); tcpServer->deleteLater();
qDebug(dcTCPCommander()) << "Could not open TCP Server"; qDebug(dcTCPCommander()) << "Could not open TCP Server";
} }
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginTcpCommander::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginTcpCommander::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() == tcpOutputDeviceClassId) { if (device->deviceClassId() == tcpOutputDeviceClassId) {
@ -64,11 +64,11 @@ DeviceManager::DeviceError DevicePluginTcpCommander::executeAction(Device *devic
QHostAddress address= QHostAddress(device->paramValue(tcpOutputDeviceIpv4addressParamTypeId).toString()); QHostAddress address= QHostAddress(device->paramValue(tcpOutputDeviceIpv4addressParamTypeId).toString());
QTcpSocket *tcpSocket = m_tcpSockets.key(device); QTcpSocket *tcpSocket = m_tcpSockets.key(device);
tcpSocket->connectToHost(address, port); tcpSocket->connectToHost(address, port);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
@ -96,7 +96,7 @@ void DevicePluginTcpCommander::onTcpSocketConnected()
if (device->deviceClassId() == tcpOutputDeviceClassId) { if (device->deviceClassId() == tcpOutputDeviceClassId) {
if (!device->setupComplete()) { if (!device->setupComplete()) {
qDebug(dcTCPCommander()) << device->name() << "Setup finished" ; qDebug(dcTCPCommander()) << device->name() << "Setup finished" ;
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
} else { } else {
QByteArray data = device->paramValue(tcpOutputTriggerActionOutputDataAreaParamTypeId).toByteArray(); QByteArray data = device->paramValue(tcpOutputTriggerActionOutputDataAreaParamTypeId).toByteArray();
tcpSocket->write(data); tcpSocket->write(data);
@ -106,7 +106,7 @@ void DevicePluginTcpCommander::onTcpSocketConnected()
if (device->deviceClassId() == tcpInputDeviceClassId) { if (device->deviceClassId() == tcpInputDeviceClassId) {
if (!device->setupComplete()) { if (!device->setupComplete()) {
qDebug(dcTCPCommander()) << device->name() << "Setup finished" ; qDebug(dcTCPCommander()) << device->name() << "Setup finished" ;
emit deviceSetupFinished(device, DeviceManager::DeviceSetupStatusSuccess); emit deviceSetupFinished(device, Device::DeviceSetupStatusSuccess);
} }
device->setStateValue(tcpInputConnectedStateTypeId, true); device->setStateValue(tcpInputConnectedStateTypeId, true);
} }

View File

@ -21,8 +21,7 @@
#ifndef DEVICEPLUGINDEVTCPCOMMANDER_H #ifndef DEVICEPLUGINDEVTCPCOMMANDER_H
#define DEVICEPLUGINDEVTCPCOMMANDER_H #define DEVICEPLUGINDEVTCPCOMMANDER_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include "tcpserver.h" #include "tcpserver.h"
class DevicePluginTcpCommander : public DevicePlugin class DevicePluginTcpCommander : public DevicePlugin
@ -35,11 +34,11 @@ class DevicePluginTcpCommander : public DevicePlugin
public: public:
explicit DevicePluginTcpCommander(); explicit DevicePluginTcpCommander();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
QHash<QTcpSocket *, Device *> m_tcpSockets; QHash<QTcpSocket *, Device *> m_tcpSockets;

View File

@ -39,13 +39,13 @@ DevicePluginTexasInstruments::~DevicePluginTexasInstruments()
} }
DeviceManager::DeviceError DevicePluginTexasInstruments::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginTexasInstruments::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
Q_ASSERT_X(deviceClassId == sensorTagDeviceClassId, "DevicePluginTexasInstruments", "Unhandled DeviceClassId!"); Q_ASSERT_X(deviceClassId == sensorTagDeviceClassId, "DevicePluginTexasInstruments", "Unhandled DeviceClassId!");
if (!hardwareManager()->bluetoothLowEnergyManager()->available() || !hardwareManager()->bluetoothLowEnergyManager()->enabled()) { if (!hardwareManager()->bluetoothLowEnergyManager()->available() || !hardwareManager()->bluetoothLowEnergyManager()->enabled()) {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices(); BluetoothDiscoveryReply *reply = hardwareManager()->bluetoothLowEnergyManager()->discoverDevices();
@ -85,10 +85,10 @@ DeviceManager::DeviceError DevicePluginTexasInstruments::discoverDevices(const D
emit devicesDiscovered(sensorTagDeviceClassId, deviceDescriptors); emit devicesDiscovered(sensorTagDeviceClassId, deviceDescriptors);
}); });
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginTexasInstruments::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginTexasInstruments::setupDevice(Device *device)
{ {
qCDebug(dcTexasInstruments()) << "Setting up Multi Sensor" << device->name() << device->params(); qCDebug(dcTexasInstruments()) << "Setting up Multi Sensor" << device->name() << device->params();
@ -111,7 +111,7 @@ DeviceManager::DeviceSetupStatus DevicePluginTexasInstruments::setupDevice(Devic
}); });
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
void DevicePluginTexasInstruments::postSetupDevice(Device *device) void DevicePluginTexasInstruments::postSetupDevice(Device *device)
@ -150,72 +150,72 @@ void DevicePluginTexasInstruments::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginTexasInstruments::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginTexasInstruments::executeAction(Device *device, const Action &action)
{ {
SensorTag *sensorTag = m_sensorTags.value(device); SensorTag *sensorTag = m_sensorTags.value(device);
if (action.actionTypeId() == sensorTagBuzzerActionTypeId) { if (action.actionTypeId() == sensorTagBuzzerActionTypeId) {
sensorTag->setBuzzerPower(action.param(sensorTagBuzzerActionBuzzerParamTypeId).value().toBool()); sensorTag->setBuzzerPower(action.param(sensorTagBuzzerActionBuzzerParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagGreenLedActionTypeId) { } else if (action.actionTypeId() == sensorTagGreenLedActionTypeId) {
sensorTag->setGreenLedPower(action.param(sensorTagGreenLedActionGreenLedParamTypeId).value().toBool()); sensorTag->setGreenLedPower(action.param(sensorTagGreenLedActionGreenLedParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagRedLedActionTypeId) { } else if (action.actionTypeId() == sensorTagRedLedActionTypeId) {
sensorTag->setRedLedPower(action.param(sensorTagRedLedActionRedLedParamTypeId).value().toBool()); sensorTag->setRedLedPower(action.param(sensorTagRedLedActionRedLedParamTypeId).value().toBool());
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagBuzzerImpulseActionTypeId) { } else if (action.actionTypeId() == sensorTagBuzzerImpulseActionTypeId) {
sensorTag->buzzerImpulse(); sensorTag->buzzerImpulse();
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagTemperatureSensorEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagTemperatureSensorEnabledActionTypeId) {
bool enabled = action.param(sensorTagTemperatureSensorEnabledActionTemperatureSensorEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagTemperatureSensorEnabledActionTemperatureSensorEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagTemperatureSensorEnabledStateTypeId, enabled); device->setStateValue(sensorTagTemperatureSensorEnabledStateTypeId, enabled);
sensorTag->setTemperatureSensorEnabled(enabled); sensorTag->setTemperatureSensorEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagHumiditySensorEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagHumiditySensorEnabledActionTypeId) {
bool enabled = action.param(sensorTagHumiditySensorEnabledActionHumiditySensorEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagHumiditySensorEnabledActionHumiditySensorEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagHumiditySensorEnabledStateTypeId, enabled); device->setStateValue(sensorTagHumiditySensorEnabledStateTypeId, enabled);
sensorTag->setHumiditySensorEnabled(enabled); sensorTag->setHumiditySensorEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagPressureSensorEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagPressureSensorEnabledActionTypeId) {
bool enabled = action.param(sensorTagPressureSensorEnabledActionPressureSensorEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagPressureSensorEnabledActionPressureSensorEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagPressureSensorEnabledStateTypeId, enabled); device->setStateValue(sensorTagPressureSensorEnabledStateTypeId, enabled);
sensorTag->setPressureSensorEnabled(enabled); sensorTag->setPressureSensorEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagOpticalSensorEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagOpticalSensorEnabledActionTypeId) {
bool enabled = action.param(sensorTagOpticalSensorEnabledActionOpticalSensorEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagOpticalSensorEnabledActionOpticalSensorEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagOpticalSensorEnabledStateTypeId, enabled); device->setStateValue(sensorTagOpticalSensorEnabledStateTypeId, enabled);
sensorTag->setOpticalSensorEnabled(enabled); sensorTag->setOpticalSensorEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagAccelerometerEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagAccelerometerEnabledActionTypeId) {
bool enabled = action.param(sensorTagAccelerometerEnabledActionAccelerometerEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagAccelerometerEnabledActionAccelerometerEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagAccelerometerEnabledStateTypeId, enabled); device->setStateValue(sensorTagAccelerometerEnabledStateTypeId, enabled);
sensorTag->setAccelerometerEnabled(enabled); sensorTag->setAccelerometerEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagGyroscopeEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagGyroscopeEnabledActionTypeId) {
bool enabled = action.param(sensorTagGyroscopeEnabledActionGyroscopeEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagGyroscopeEnabledActionGyroscopeEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagGyroscopeEnabledStateTypeId, enabled); device->setStateValue(sensorTagGyroscopeEnabledStateTypeId, enabled);
sensorTag->setGyroscopeEnabled(enabled); sensorTag->setGyroscopeEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagMagnetometerEnabledActionTypeId) { } else if (action.actionTypeId() == sensorTagMagnetometerEnabledActionTypeId) {
bool enabled = action.param(sensorTagMagnetometerEnabledActionMagnetometerEnabledParamTypeId).value().toBool(); bool enabled = action.param(sensorTagMagnetometerEnabledActionMagnetometerEnabledParamTypeId).value().toBool();
device->setStateValue(sensorTagMagnetometerEnabledStateTypeId, enabled); device->setStateValue(sensorTagMagnetometerEnabledStateTypeId, enabled);
sensorTag->setMagnetometerEnabled(enabled); sensorTag->setMagnetometerEnabled(enabled);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagMeasurementPeriodActionTypeId) { } else if (action.actionTypeId() == sensorTagMeasurementPeriodActionTypeId) {
int period = action.param(sensorTagMeasurementPeriodActionMeasurementPeriodParamTypeId).value().toInt(); int period = action.param(sensorTagMeasurementPeriodActionMeasurementPeriodParamTypeId).value().toInt();
device->setStateValue(sensorTagMeasurementPeriodStateTypeId, period); device->setStateValue(sensorTagMeasurementPeriodStateTypeId, period);
sensorTag->setMeasurementPeriod(period); sensorTag->setMeasurementPeriod(period);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagMeasurementPeriodMovementActionTypeId) { } else if (action.actionTypeId() == sensorTagMeasurementPeriodMovementActionTypeId) {
int period = action.param(sensorTagMeasurementPeriodMovementActionMeasurementPeriodMovementParamTypeId).value().toInt(); int period = action.param(sensorTagMeasurementPeriodMovementActionMeasurementPeriodMovementParamTypeId).value().toInt();
device->setStateValue(sensorTagMeasurementPeriodMovementStateTypeId, period); device->setStateValue(sensorTagMeasurementPeriodMovementStateTypeId, period);
sensorTag->setMeasurementPeriodMovement(period); sensorTag->setMeasurementPeriodMovement(period);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} else if (action.actionTypeId() == sensorTagMovementSensitivityActionTypeId) { } else if (action.actionTypeId() == sensorTagMovementSensitivityActionTypeId) {
int sensitivity = action.param(sensorTagMovementSensitivityActionMovementSensitivityParamTypeId).value().toInt(); int sensitivity = action.param(sensorTagMovementSensitivityActionMovementSensitivityParamTypeId).value().toInt();
device->setStateValue(sensorTagMovementSensitivityStateTypeId, sensitivity); device->setStateValue(sensorTagMovementSensitivityStateTypeId, sensitivity);
sensorTag->setMovementSensitivity(sensitivity); sensorTag->setMovementSensitivity(sensitivity);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }

View File

@ -25,7 +25,7 @@
#include <QObject> #include <QObject>
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class SensorTag; class SensorTag;
@ -41,11 +41,11 @@ public:
explicit DevicePluginTexasInstruments(QObject *parent = nullptr); explicit DevicePluginTexasInstruments(QObject *parent = nullptr);
~DevicePluginTexasInstruments() override; ~DevicePluginTexasInstruments() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void postSetupDevice(Device *device) override; void postSetupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
QHash<Device*, SensorTag*> m_sensorTags; QHash<Device*, SensorTag*> m_sensorTags;

View File

@ -26,7 +26,7 @@
#include <QFile> #include <QFile>
#include <QObject> #include <QObject>
#include "plugin/device.h" #include "devices/device.h"
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
#include "sensorfilter.h" #include "sensorfilter.h"

View File

@ -25,7 +25,7 @@
#include <QObject> #include <QObject>
#include "plugin/device.h" #include "devices/device.h"
#include "extern-plugininfo.h" #include "extern-plugininfo.h"
#include "sensordataprocessor.h" #include "sensordataprocessor.h"

View File

@ -22,7 +22,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginudpcommander.h" #include "devicepluginudpcommander.h"
#include "plugin/device.h" #include "devices/device.h"
#include "plugininfo.h" #include "plugininfo.h"
DevicePluginUdpCommander::DevicePluginUdpCommander() DevicePluginUdpCommander::DevicePluginUdpCommander()
@ -30,7 +30,7 @@ DevicePluginUdpCommander::DevicePluginUdpCommander()
} }
DeviceManager::DeviceSetupStatus DevicePluginUdpCommander::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginUdpCommander::setupDevice(Device *device)
{ {
qCDebug(dcUdpCommander()) << "Setup device" << device->name() << device->params(); qCDebug(dcUdpCommander()) << "Setup device" << device->name() << device->params();
@ -40,25 +40,25 @@ DeviceManager::DeviceSetupStatus DevicePluginUdpCommander::setupDevice(Device *d
if (!udpSocket->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress)) { if (!udpSocket->bind(QHostAddress::Any, port, QUdpSocket::ShareAddress)) {
qCWarning(dcUdpCommander()) << device->name() << "cannot bind to port" << port; qCWarning(dcUdpCommander()) << device->name() << "cannot bind to port" << port;
delete udpSocket; delete udpSocket;
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
qCDebug(dcUdpCommander()) << "Listening on port" << port; qCDebug(dcUdpCommander()) << "Listening on port" << port;
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
m_receiverList.insert(udpSocket, device); m_receiverList.insert(udpSocket, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} else if (device->deviceClassId() == udpCommanderDeviceClassId) { } else if (device->deviceClassId() == udpCommanderDeviceClassId) {
QUdpSocket *udpSocket = new QUdpSocket(this); QUdpSocket *udpSocket = new QUdpSocket(this);
m_commanderList.insert(udpSocket, device); m_commanderList.insert(udpSocket, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginUdpCommander::executeAction(Device *device, const Action &action) { Device::DeviceError DevicePluginUdpCommander::executeAction(Device *device, const Action &action) {
if (device->deviceClassId() == udpCommanderDeviceClassId) { if (device->deviceClassId() == udpCommanderDeviceClassId) {
if (action.actionTypeId() == udpCommanderTriggerActionTypeId) { if (action.actionTypeId() == udpCommanderTriggerActionTypeId) {
@ -69,11 +69,11 @@ DeviceManager::DeviceError DevicePluginUdpCommander::executeAction(Device *devic
qDebug(dcUdpCommander()) << "Send UDP datagram:" << data << "address:" << address.toIPv4Address() << "port:" << port; qDebug(dcUdpCommander()) << "Send UDP datagram:" << data << "address:" << address.toIPv4Address() << "port:" << port;
udpSocket->writeDatagram(data, address, port); udpSocket->writeDatagram(data, address, port);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginUdpCommander::deviceRemoved(Device *device) void DevicePluginUdpCommander::deviceRemoved(Device *device)

View File

@ -24,7 +24,7 @@
#ifndef DEVICEPLUGINUDPCOMMANDER_H #ifndef DEVICEPLUGINUDPCOMMANDER_H
#define DEVICEPLUGINUDPCOMMANDER_H #define DEVICEPLUGINUDPCOMMANDER_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QHash> #include <QHash>
#include <QDebug> #include <QDebug>
@ -39,10 +39,10 @@ class DevicePluginUdpCommander : public DevicePlugin
public: public:
explicit DevicePluginUdpCommander(); explicit DevicePluginUdpCommander();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private: private:
QHash<QUdpSocket *, Device *> m_receiverList; QHash<QUdpSocket *, Device *> m_receiverList;

View File

@ -39,7 +39,7 @@ void DevicePluginUniPi::init()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
{ {
connectToEvok(); connectToEvok();
@ -51,33 +51,33 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
if (device->deviceClassId() == relayOutputDeviceClassId) { if (device->deviceClassId() == relayOutputDeviceClassId) {
m_usedRelais.insert(device->paramValue(relayOutputDeviceNumberParamTypeId).toString(), device); m_usedRelais.insert(device->paramValue(relayOutputDeviceNumberParamTypeId).toString(), device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == digitalOutputDeviceClassId) { if (device->deviceClassId() == digitalOutputDeviceClassId) {
m_usedDigitalOutputs.insert(device->paramValue(digitalOutputDeviceNumberParamTypeId).toString(), device); m_usedDigitalOutputs.insert(device->paramValue(digitalOutputDeviceNumberParamTypeId).toString(), device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == digitalInputDeviceClassId) { if (device->deviceClassId() == digitalInputDeviceClassId) {
m_usedDigitalInputs.insert(device->paramValue(digitalInputDeviceNumberParamTypeId).toString(), device); m_usedDigitalInputs.insert(device->paramValue(digitalInputDeviceNumberParamTypeId).toString(), device);
requestAllData(); requestAllData();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == analogInputDeviceClassId) { if (device->deviceClassId() == analogInputDeviceClassId) {
m_usedAnalogInputs.insert(device->paramValue(analogInputDeviceInputNumberParamTypeId).toString(), device); m_usedAnalogInputs.insert(device->paramValue(analogInputDeviceInputNumberParamTypeId).toString(), device);
requestAllData(); requestAllData();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == analogOutputDeviceClassId) { if (device->deviceClassId() == analogOutputDeviceClassId) {
m_usedAnalogOutputs.insert(device->paramValue(analogOutputDeviceOutputNumberParamTypeId).toString(), device); m_usedAnalogOutputs.insert(device->paramValue(analogOutputDeviceOutputNumberParamTypeId).toString(), device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == blindDeviceClassId) { if (device->deviceClassId() == blindDeviceClassId) {
@ -94,7 +94,7 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
m_usedDigitalOutputs.insert(device->paramValue(blindDeviceOutputCloseParamTypeId).toString(), device); m_usedDigitalOutputs.insert(device->paramValue(blindDeviceOutputCloseParamTypeId).toString(), device);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == lightDeviceClassId) { if (device->deviceClassId() == lightDeviceClassId) {
@ -104,7 +104,7 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
} else if (device->paramValue(lightDeviceOutputParamTypeId) == GpioType::DigitalOutput) { } else if (device->paramValue(lightDeviceOutputParamTypeId) == GpioType::DigitalOutput) {
m_usedDigitalOutputs.insert(device->paramValue(lightDeviceOutputParamTypeId).toString(), device); m_usedDigitalOutputs.insert(device->paramValue(lightDeviceOutputParamTypeId).toString(), device);
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == dimmerSwitchDeviceClassId) { if (device->deviceClassId() == dimmerSwitchDeviceClassId) {
@ -116,20 +116,20 @@ DeviceManager::DeviceSetupStatus DevicePluginUniPi::setupDevice(Device *device)
connect(dimmerSwitch, &DimmerSwitch::doublePressed, this, &DevicePluginUniPi::onDimmerSwitchDoublePressed); connect(dimmerSwitch, &DimmerSwitch::doublePressed, this, &DevicePluginUniPi::onDimmerSwitchDoublePressed);
connect(dimmerSwitch, &DimmerSwitch::dimValueChanged, this, &DevicePluginUniPi::onDimmerSwitchDimValueChanged); connect(dimmerSwitch, &DimmerSwitch::dimValueChanged, this, &DevicePluginUniPi::onDimmerSwitchDimValueChanged);
m_dimmerSwitches.insert(dimmerSwitch, device); m_dimmerSwitches.insert(dimmerSwitch, device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
if (device->deviceClassId() == temperatureSensorDeviceClassId) { if (device->deviceClassId() == temperatureSensorDeviceClassId) {
m_usedTemperatureSensors.insert(device->paramValue(temperatureSensorDeviceAddressParamTypeId).toString(), device); m_usedTemperatureSensors.insert(device->paramValue(temperatureSensorDeviceAddressParamTypeId).toString(), device);
requestAllData(); requestAllData();
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params); Q_UNUSED(params);
qSort(m_relais); qSort(m_relais);
@ -138,7 +138,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
qSort(m_analogInputs); qSort(m_analogInputs);
qSort(m_analogOutputs); qSort(m_analogOutputs);
const DeviceClass deviceClass = deviceManager()->findDeviceClass(deviceClassId); const DeviceClass deviceClass = supportedDevices().findById(deviceClassId);
if (deviceClass.vendorId() == unipiVendorId) { if (deviceClass.vendorId() == unipiVendorId) {
if (deviceClassId == relayOutputDeviceClassId) { if (deviceClassId == relayOutputDeviceClassId) {
@ -167,7 +167,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == digitalOutputDeviceClassId) { if (deviceClassId == digitalOutputDeviceClassId) {
@ -187,7 +187,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == digitalInputDeviceClassId) { if (deviceClassId == digitalInputDeviceClassId) {
@ -207,7 +207,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == analogInputDeviceClassId) { if (deviceClassId == analogInputDeviceClassId) {
@ -227,7 +227,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == analogOutputDeviceClassId) { if (deviceClassId == analogOutputDeviceClassId) {
@ -247,7 +247,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == blindDeviceClassId) { if (deviceClassId == blindDeviceClassId) {
@ -308,7 +308,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == lightDeviceClassId) { if (deviceClassId == lightDeviceClassId) {
@ -344,7 +344,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == dimmerSwitchDeviceClassId) { if (deviceClassId == dimmerSwitchDeviceClassId) {
@ -364,7 +364,7 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
if (deviceClassId == temperatureSensorDeviceClassId) { if (deviceClassId == temperatureSensorDeviceClassId) {
@ -384,10 +384,10 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
deviceDescriptors.append(descriptor); deviceDescriptors.append(descriptor);
} }
emit devicesDiscovered(deviceClassId, deviceDescriptors); emit devicesDiscovered(deviceClassId, deviceDescriptors);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }
void DevicePluginUniPi::setOutput(const QString &circuit, bool value) void DevicePluginUniPi::setOutput(const QString &circuit, bool value)
@ -472,10 +472,10 @@ void DevicePluginUniPi::deviceRemoved(Device *device)
} }
} }
DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginUniPi::executeAction(Device *device, const Action &action)
{ {
if (m_webSocket->state() != QAbstractSocket::ConnectedState) if (m_webSocket->state() != QAbstractSocket::ConnectedState)
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
if (device->deviceClassId() == relayOutputDeviceClassId) { if (device->deviceClassId() == relayOutputDeviceClassId) {
@ -484,9 +484,9 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
int stateValue = action.param(relayOutputPowerActionPowerParamTypeId).value().toInt(); int stateValue = action.param(relayOutputPowerActionPowerParamTypeId).value().toInt();
setOutput(relayNumber, stateValue); setOutput(relayNumber, stateValue);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == digitalOutputDeviceClassId) { if (device->deviceClassId() == digitalOutputDeviceClassId) {
@ -495,9 +495,9 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
bool stateValue = action.param(digitalOutputPowerActionPowerParamTypeId).value().toBool(); bool stateValue = action.param(digitalOutputPowerActionPowerParamTypeId).value().toBool();
setOutput(digitalOutputNumber, stateValue); setOutput(digitalOutputNumber, stateValue);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == analogOutputDeviceClassId) { if (device->deviceClassId() == analogOutputDeviceClassId) {
@ -516,9 +516,9 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
QByteArray bytes = doc.toJson(QJsonDocument::Compact); QByteArray bytes = doc.toJson(QJsonDocument::Compact);
qCDebug(dcUniPi()) << "Send command" << bytes; qCDebug(dcUniPi()) << "Send command" << bytes;
m_webSocket->sendTextMessage(bytes); m_webSocket->sendTextMessage(bytes);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == blindDeviceClassId) { if (device->deviceClassId() == blindDeviceClassId) {
@ -529,21 +529,21 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
setOutput(circuitOpen, false); setOutput(circuitOpen, false);
setOutput(circuitClose, true); setOutput(circuitClose, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == blindOpenActionTypeId) { if (action.actionTypeId() == blindOpenActionTypeId) {
setOutput(circuitClose, false); setOutput(circuitClose, false);
setOutput(circuitOpen, true); setOutput(circuitOpen, true);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
if (action.actionTypeId() == blindStopActionTypeId) { if (action.actionTypeId() == blindStopActionTypeId) {
setOutput(circuitOpen, false); setOutput(circuitOpen, false);
setOutput(circuitClose, false); setOutput(circuitClose, false);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
if (device->deviceClassId() == lightDeviceClassId) { if (device->deviceClassId() == lightDeviceClassId) {
@ -552,10 +552,10 @@ DeviceManager::DeviceError DevicePluginUniPi::executeAction(Device *device, cons
bool stateValue = action.param(lightPowerActionPowerParamTypeId).value().toBool(); bool stateValue = action.param(lightPowerActionPowerParamTypeId).value().toBool();
setOutput(circuit, stateValue); setOutput(circuit, stateValue);
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
} }

View File

@ -24,8 +24,7 @@
#ifndef DEVICEPLUGINUNIPI_H #ifndef DEVICEPLUGINUNIPI_H
#define DEVICEPLUGINUNIPI_H #define DEVICEPLUGINUNIPI_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include "devicemanager.h"
#include <QtWebSockets/QtWebSockets> #include <QtWebSockets/QtWebSockets>
#include "plugintimer.h" #include "plugintimer.h"
#include "dimmerswitch.h" #include "dimmerswitch.h"
@ -43,10 +42,10 @@ public:
~DevicePluginUniPi(); ~DevicePluginUniPi();
void init() override; void init() override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
private: private:

View File

@ -21,7 +21,6 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "devicepluginunitec.h" #include "devicepluginunitec.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "hardwaremanager.h" #include "hardwaremanager.h"
#include "hardware/radio433/radio433.h" #include "hardware/radio433/radio433.h"
@ -33,32 +32,32 @@ DevicePluginUnitec::DevicePluginUnitec()
{ {
} }
DeviceManager::DeviceSetupStatus DevicePluginUnitec::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginUnitec::setupDevice(Device *device)
{ {
if (device->deviceClassId() != switchDeviceClassId) { if (device->deviceClassId() != switchDeviceClassId) {
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
foreach (Device* d, myDevices()) { foreach (Device* d, myDevices()) {
if (d->paramValue(switchDeviceChannelParamTypeId).toString() == device->paramValue(switchDeviceChannelParamTypeId).toString()) { if (d->paramValue(switchDeviceChannelParamTypeId).toString() == device->paramValue(switchDeviceChannelParamTypeId).toString()) {
qCWarning(dcUnitec) << "Unitec switch with channel " << device->paramValue(switchDeviceChannelParamTypeId).toString() << "already added."; qCWarning(dcUnitec) << "Unitec switch with channel " << device->paramValue(switchDeviceChannelParamTypeId).toString() << "already added.";
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
} }
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginUnitec::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginUnitec::executeAction(Device *device, const Action &action)
{ {
if (!hardwareManager()->radio433()->available()) if (!hardwareManager()->radio433()->available())
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
QList<int> rawData; QList<int> rawData;
QByteArray binCode; QByteArray binCode;
if (action.actionTypeId() != switchPowerActionTypeId) { if (action.actionTypeId() != switchPowerActionTypeId) {
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
// Bin codes for buttons // Bin codes for buttons
@ -105,8 +104,8 @@ DeviceManager::DeviceError DevicePluginUnitec::executeAction(Device *device, con
qCDebug(dcUnitec) << "transmitted" << pluginName() << device->name() << "power: " << action.param(switchPowerActionPowerParamTypeId).value().toBool(); qCDebug(dcUnitec) << "transmitted" << pluginName() << device->name() << "power: " << action.param(switchPowerActionPowerParamTypeId).value().toBool();
}else{ }else{
qCWarning(dcUnitec) << "could not transmitt" << pluginName() << device->name() << "power: " << action.param(switchPowerActionPowerParamTypeId).value().toBool(); qCWarning(dcUnitec) << "could not transmitt" << pluginName() << device->name() << "power: " << action.param(switchPowerActionPowerParamTypeId).value().toBool();
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINUNITEC_H #ifndef DEVICEPLUGINUNITEC_H
#define DEVICEPLUGINUNITEC_H #define DEVICEPLUGINUNITEC_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
class DevicePluginUnitec : public DevicePlugin class DevicePluginUnitec : public DevicePlugin
{ {
@ -35,10 +35,10 @@ class DevicePluginUnitec : public DevicePlugin
public: public:
explicit DevicePluginUnitec(); explicit DevicePluginUnitec();
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
public slots: public slots:
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
}; };

View File

@ -22,8 +22,7 @@
#include "devicepluginwakeonlan.h" #include "devicepluginwakeonlan.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include <QDebug> #include <QDebug>
@ -34,13 +33,13 @@ DevicePluginWakeOnLan::DevicePluginWakeOnLan()
{ {
} }
DeviceManager::DeviceError DevicePluginWakeOnLan::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginWakeOnLan::executeAction(Device *device, const Action &action)
{ {
if(action.actionTypeId() == wolTriggerActionTypeId){ if(action.actionTypeId() == wolTriggerActionTypeId){
qCDebug(dcWakeOnLan) << "Wake up" << device->name(); qCDebug(dcWakeOnLan) << "Wake up" << device->name();
wakeup(device->paramValue(wolDeviceMacParamTypeId).toString()); wakeup(device->paramValue(wolDeviceMacParamTypeId).toString());
} }
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
void DevicePluginWakeOnLan::wakeup(QString mac) void DevicePluginWakeOnLan::wakeup(QString mac)

View File

@ -23,7 +23,7 @@
#ifndef DEVICEPLUGINWAKEONLAN_H #ifndef DEVICEPLUGINWAKEONLAN_H
#define DEVICEPLUGINWAKEONLAN_H #define DEVICEPLUGINWAKEONLAN_H
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QProcess> #include <QProcess>
@ -37,7 +37,7 @@ class DevicePluginWakeOnLan : public DevicePlugin
public: public:
explicit DevicePluginWakeOnLan(); explicit DevicePluginWakeOnLan();
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
private slots: private slots:
void wakeup(QString mac); void wakeup(QString mac);

View File

@ -22,8 +22,7 @@
#include "devicepluginwemo.h" #include "devicepluginwemo.h"
#include "plugin/device.h" #include "devices/device.h"
#include "devicemanager.h"
#include "plugininfo.h" #include "plugininfo.h"
#include "network/networkaccessmanager.h" #include "network/networkaccessmanager.h"
#include "network/upnp/upnpdiscovery.h" #include "network/upnp/upnpdiscovery.h"
@ -52,30 +51,30 @@ void DevicePluginWemo::init()
connect(hardwareManager()->upnpDiscovery(), &UpnpDiscovery::upnpNotify, this, &DevicePluginWemo::onUpnpNotifyReceived); connect(hardwareManager()->upnpDiscovery(), &UpnpDiscovery::upnpNotify, this, &DevicePluginWemo::onUpnpNotifyReceived);
} }
DeviceManager::DeviceError DevicePluginWemo::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) Device::DeviceError DevicePluginWemo::discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params)
{ {
Q_UNUSED(params); Q_UNUSED(params);
Q_UNUSED(deviceClassId) Q_UNUSED(deviceClassId)
UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices("upnp:rootdevice"); UpnpDiscoveryReply *reply = hardwareManager()->upnpDiscovery()->discoverDevices("upnp:rootdevice");
connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginWemo::onUpnpDiscoveryFinished); connect(reply, &UpnpDiscoveryReply::finished, this, &DevicePluginWemo::onUpnpDiscoveryFinished);
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} }
DeviceManager::DeviceSetupStatus DevicePluginWemo::setupDevice(Device *device) Device::DeviceSetupStatus DevicePluginWemo::setupDevice(Device *device)
{ {
if (device->deviceClassId() != wemoSwitchDeviceClassId) { if (device->deviceClassId() != wemoSwitchDeviceClassId) {
return DeviceManager::DeviceSetupStatusFailure; return Device::DeviceSetupStatusFailure;
} }
refresh(device); refresh(device);
return DeviceManager::DeviceSetupStatusSuccess; return Device::DeviceSetupStatusSuccess;
} }
DeviceManager::DeviceError DevicePluginWemo::executeAction(Device *device, const Action &action) Device::DeviceError DevicePluginWemo::executeAction(Device *device, const Action &action)
{ {
if (device->deviceClassId() != wemoSwitchDeviceClassId) if (device->deviceClassId() != wemoSwitchDeviceClassId)
return DeviceManager::DeviceErrorDeviceClassNotFound; return Device::DeviceErrorDeviceClassNotFound;
// Set power // Set power
if (action.actionTypeId() == wemoSwitchPowerActionTypeId) { if (action.actionTypeId() == wemoSwitchPowerActionTypeId) {
@ -83,16 +82,16 @@ DeviceManager::DeviceError DevicePluginWemo::executeAction(Device *device, const
if (device->stateValue(wemoSwitchConnectedStateTypeId).toBool()) { if (device->stateValue(wemoSwitchConnectedStateTypeId).toBool()) {
// setPower returns false, if the curent powerState is already the new powerState // setPower returns false, if the curent powerState is already the new powerState
if (setPower(device, action.param(wemoSwitchPowerActionPowerParamTypeId).value().toBool(), action.id())) { if (setPower(device, action.param(wemoSwitchPowerActionPowerParamTypeId).value().toBool(), action.id())) {
return DeviceManager::DeviceErrorAsync; return Device::DeviceErrorAsync;
} else { } else {
return DeviceManager::DeviceErrorNoError; return Device::DeviceErrorNoError;
} }
} else { } else {
return DeviceManager::DeviceErrorHardwareNotAvailable; return Device::DeviceErrorHardwareNotAvailable;
} }
} }
return DeviceManager::DeviceErrorActionTypeNotFound; return Device::DeviceErrorActionTypeNotFound;
} }
void DevicePluginWemo::deviceRemoved(Device *device) void DevicePluginWemo::deviceRemoved(Device *device)
@ -168,12 +167,12 @@ void DevicePluginWemo::processRefreshData(const QByteArray &data, Device *device
void DevicePluginWemo::processSetPowerData(const QByteArray &data, Device *device, const ActionId &actionId) void DevicePluginWemo::processSetPowerData(const QByteArray &data, Device *device, const ActionId &actionId)
{ {
if (data.contains("<BinaryState>1</BinaryState>") || data.contains("<BinaryState>0</BinaryState>")) { if (data.contains("<BinaryState>1</BinaryState>") || data.contains("<BinaryState>0</BinaryState>")) {
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorNoError); emit actionExecutionFinished(actionId, Device::DeviceErrorNoError);
device->setStateValue(wemoSwitchConnectedStateTypeId, true); device->setStateValue(wemoSwitchConnectedStateTypeId, true);
refresh(device); refresh(device);
} else { } else {
device->setStateValue(wemoSwitchConnectedStateTypeId, false); device->setStateValue(wemoSwitchConnectedStateTypeId, false);
emit actionExecutionFinished(actionId, DeviceManager::DeviceErrorHardwareNotAvailable); emit actionExecutionFinished(actionId, Device::DeviceErrorHardwareNotAvailable);
} }
} }

View File

@ -24,7 +24,7 @@
#define DEVICEPLUGINWEMO_H #define DEVICEPLUGINWEMO_H
#include "plugintimer.h" #include "plugintimer.h"
#include "plugin/deviceplugin.h" #include "devices/deviceplugin.h"
#include <QNetworkReply> #include <QNetworkReply>
@ -40,9 +40,9 @@ public:
~DevicePluginWemo(); ~DevicePluginWemo();
void init() override; void init() override;
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override; Device::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList &params) override;
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; Device::DeviceSetupStatus setupDevice(Device *device) override;
DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; Device::DeviceError executeAction(Device *device, const Action &action) override;
void deviceRemoved(Device *device) override; void deviceRemoved(Device *device) override;
private: private: