also make PluginId typesafe and add some initial discovery code
This commit is contained in:
parent
a5eb0ef759
commit
38d4faedeb
@ -146,6 +146,20 @@ QList<DeviceClass> DeviceManager::supportedDevices(const VendorId &vendorId) con
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<DeviceDescription> DeviceManager::discoveredDevices(const DeviceClassId &deviceClassId) const
|
||||||
|
{
|
||||||
|
QList<DeviceDescription> ret;
|
||||||
|
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||||
|
if (!deviceClass.isValid()) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||||
|
if (!plugin) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = plugin->discoveredDevices(deviceClassId);
|
||||||
|
}
|
||||||
|
|
||||||
/*! Add a new configured device for the given \l{DeviceClass} and the given parameters.
|
/*! Add a new configured device for the given \l{DeviceClass} and the given parameters.
|
||||||
\a deviceClassId must refer to an existing \{DeviceClass} and \a params must match the parameter description in the \l{DeviceClass}.
|
\a deviceClassId must refer to an existing \{DeviceClass} and \a params must match the parameter description in the \l{DeviceClass}.
|
||||||
Optionally you can supply an id yourself if you must keep track of the added device. If you don't supply it, a new one will
|
Optionally you can supply an id yourself if you must keep track of the added device. If you don't supply it, a new one will
|
||||||
@ -154,7 +168,7 @@ QList<DeviceClass> DeviceManager::supportedDevices(const VendorId &vendorId) con
|
|||||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id)
|
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id)
|
||||||
{
|
{
|
||||||
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
DeviceClass deviceClass = findDeviceClass(deviceClassId);
|
||||||
if (deviceClass.id().isNull()) {
|
if (!deviceClass.isValid()) {
|
||||||
qWarning() << "cannot find a device class with id" << deviceClassId;
|
qWarning() << "cannot find a device class with id" << deviceClassId;
|
||||||
return DeviceErrorDeviceClassNotFound;
|
return DeviceErrorDeviceClassNotFound;
|
||||||
}
|
}
|
||||||
@ -362,7 +376,7 @@ void DeviceManager::loadConfiguredDevices()
|
|||||||
qDebug() << "loading devices from" << settings.fileName();
|
qDebug() << "loading devices from" << settings.fileName();
|
||||||
foreach (const QString &idString, settings.childGroups()) {
|
foreach (const QString &idString, settings.childGroups()) {
|
||||||
settings.beginGroup(idString);
|
settings.beginGroup(idString);
|
||||||
Device *device = new Device(settings.value("pluginid").toUuid(), DeviceId(idString), DeviceClassId(settings.value("deviceClassId").toString()), this);
|
Device *device = new Device(PluginId(settings.value("pluginid").toString()), DeviceId(idString), DeviceClassId(settings.value("deviceClassId").toString()), this);
|
||||||
device->setName(settings.value("devicename").toString());
|
device->setName(settings.value("devicename").toString());
|
||||||
device->setParams(settings.value("params").toMap());
|
device->setParams(settings.value("params").toMap());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "plugin/deviceclass.h"
|
#include "plugin/deviceclass.h"
|
||||||
#include "plugin/device.h"
|
#include "plugin/device.h"
|
||||||
|
#include "plugin/devicedescription.h"
|
||||||
|
|
||||||
#include "types/event.h"
|
#include "types/event.h"
|
||||||
#include "types/action.h"
|
#include "types/action.h"
|
||||||
@ -67,6 +68,7 @@ public:
|
|||||||
|
|
||||||
QList<Vendor> supportedVendors() const;
|
QList<Vendor> supportedVendors() const;
|
||||||
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
|
QList<DeviceClass> supportedDevices(const VendorId &vendorId = VendorId()) const;
|
||||||
|
QList<DeviceDescription> discoveredDevices(const DeviceClassId &deviceClassId) const;
|
||||||
|
|
||||||
QList<Device*> configuredDevices() const;
|
QList<Device*> configuredDevices() const;
|
||||||
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
DeviceError addConfiguredDevice(const DeviceClassId &deviceClassId, const QVariantMap ¶ms, const DeviceId id = DeviceId::createDeviceId());
|
||||||
@ -105,7 +107,7 @@ private:
|
|||||||
QHash<DeviceClassId, DeviceClass> m_supportedDevices;
|
QHash<DeviceClassId, DeviceClass> m_supportedDevices;
|
||||||
QList<Device*> m_configuredDevices;
|
QList<Device*> m_configuredDevices;
|
||||||
|
|
||||||
QHash<QUuid, DevicePlugin*> m_devicePlugins;
|
QHash<PluginId, DevicePlugin*> m_devicePlugins;
|
||||||
|
|
||||||
// Hardware Resources
|
// Hardware Resources
|
||||||
Radio433* m_radio433;
|
Radio433* m_radio433;
|
||||||
|
|||||||
@ -18,7 +18,8 @@ SOURCES += plugin/device.cpp \
|
|||||||
types/statetype.cpp \
|
types/statetype.cpp \
|
||||||
types/eventtype.cpp \
|
types/eventtype.cpp \
|
||||||
types/event.cpp \
|
types/event.cpp \
|
||||||
types/vendor.cpp
|
types/vendor.cpp \
|
||||||
|
plugin/devicedescription.cpp
|
||||||
|
|
||||||
HEADERS += plugin/device.h \
|
HEADERS += plugin/device.h \
|
||||||
plugin/deviceclass.h \
|
plugin/deviceclass.h \
|
||||||
@ -33,5 +34,6 @@ HEADERS += plugin/device.h \
|
|||||||
types/eventtype.h \
|
types/eventtype.h \
|
||||||
types/event.h \
|
types/event.h \
|
||||||
types/vendor.h \
|
types/vendor.h \
|
||||||
types/typeutils.h
|
types/typeutils.h \
|
||||||
|
plugin/devicedescription.h
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Device::Device(const QUuid &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent):
|
Device::Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_deviceClassId(deviceClassId),
|
m_deviceClassId(deviceClassId),
|
||||||
@ -42,7 +42,7 @@ Device::Device(const QUuid &pluginId, const DeviceId &id, const DeviceClassId &d
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Device(const QUuid &pluginId, const DeviceClassId &deviceClassId, QObject *parent):
|
Device::Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_id(DeviceId::createDeviceId()),
|
m_id(DeviceId::createDeviceId()),
|
||||||
m_deviceClassId(deviceClassId),
|
m_deviceClassId(deviceClassId),
|
||||||
@ -64,7 +64,7 @@ DeviceClassId Device::deviceClassId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the id of the \l{DevicePlugin} this Device is managed by. */
|
/*! Returns the id of the \l{DevicePlugin} this Device is managed by. */
|
||||||
QUuid Device::pluginId() const
|
PluginId Device::pluginId() const
|
||||||
{
|
{
|
||||||
return m_pluginId;
|
return m_pluginId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class Device: public QObject
|
|||||||
public:
|
public:
|
||||||
DeviceId id() const;
|
DeviceId id() const;
|
||||||
DeviceClassId deviceClassId() const;
|
DeviceClassId deviceClassId() const;
|
||||||
QUuid pluginId() const;
|
PluginId pluginId() const;
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
@ -57,13 +57,13 @@ signals:
|
|||||||
void stateValueChanged(const QUuid &stateTypeId, const QVariant &value);
|
void stateValueChanged(const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Device(const QUuid &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent = 0);
|
Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent = 0);
|
||||||
Device(const QUuid &pluginId, const DeviceClassId &deviceClassId, QObject *parent = 0);
|
Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceId m_id;
|
DeviceId m_id;
|
||||||
DeviceClassId m_deviceClassId;
|
DeviceClassId m_deviceClassId;
|
||||||
QUuid m_pluginId;
|
PluginId m_pluginId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QVariantMap m_params;
|
QVariantMap m_params;
|
||||||
QList<State> m_states;
|
QList<State> m_states;
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
Generate a new uuid (e.g. uuidgen) and hardode it into the plugin. The id
|
Generate a new uuid (e.g. uuidgen) and hardode it into the plugin. The id
|
||||||
should never change or it will appear as a new DeviceClass in the system.
|
should never change or it will appear as a new DeviceClass in the system.
|
||||||
*/
|
*/
|
||||||
DeviceClass::DeviceClass(const QUuid &pluginId, const VendorId &vendorId, const DeviceClassId &id):
|
DeviceClass::DeviceClass(const PluginId &pluginId, const VendorId &vendorId, const DeviceClassId &id):
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_vendorId(vendorId),
|
m_vendorId(vendorId),
|
||||||
m_pluginId(pluginId),
|
m_pluginId(pluginId),
|
||||||
@ -62,7 +62,7 @@ VendorId DeviceClass::vendorId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns the pluginId this DeviceClass is managed by. */
|
/*! Returns the pluginId this DeviceClass is managed by. */
|
||||||
QUuid DeviceClass::pluginId() const
|
PluginId DeviceClass::pluginId() const
|
||||||
{
|
{
|
||||||
return m_pluginId;
|
return m_pluginId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,11 +43,11 @@ public:
|
|||||||
SetupMethodPushButton
|
SetupMethodPushButton
|
||||||
};
|
};
|
||||||
|
|
||||||
DeviceClass(const QUuid &pluginId = QUuid(), const VendorId &vendorId = VendorId(), const DeviceClassId &id = DeviceClassId());
|
DeviceClass(const PluginId &pluginId = PluginId(), const VendorId &vendorId = VendorId(), const DeviceClassId &id = DeviceClassId());
|
||||||
|
|
||||||
DeviceClassId id() const;
|
DeviceClassId id() const;
|
||||||
VendorId vendorId() const;
|
VendorId vendorId() const;
|
||||||
QUuid pluginId() const;
|
PluginId pluginId() const;
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
@ -75,7 +75,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
DeviceClassId m_id;
|
DeviceClassId m_id;
|
||||||
VendorId m_vendorId;
|
VendorId m_vendorId;
|
||||||
QUuid m_pluginId;
|
PluginId m_pluginId;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QList<StateType> m_states;
|
QList<StateType> m_states;
|
||||||
QList<EventType> m_events;
|
QList<EventType> m_events;
|
||||||
|
|||||||
5
libguh/plugin/devicedescription.cpp
Normal file
5
libguh/plugin/devicedescription.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "devicedescription.h"
|
||||||
|
|
||||||
|
DeviceDescription::DeviceDescription()
|
||||||
|
{
|
||||||
|
}
|
||||||
10
libguh/plugin/devicedescription.h
Normal file
10
libguh/plugin/devicedescription.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef DEVICEDESCRIPTION_H
|
||||||
|
#define DEVICEDESCRIPTION_H
|
||||||
|
|
||||||
|
class DeviceDescription
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeviceDescription();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEDESCRIPTION_H
|
||||||
@ -126,6 +126,11 @@ bool DevicePlugin::configureAutoDevice(QList<Device*> loadedDevices, Device *dev
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<DeviceDescription> DevicePlugin::discoveredDevices(const DeviceClassId &deviceClassId) const
|
||||||
|
{
|
||||||
|
return QList<DeviceDescription>();
|
||||||
|
}
|
||||||
|
|
||||||
/*! This will be called when a new device is created. The plugin has the chance to do some setup.
|
/*! This will be called when a new device is created. The plugin has the chance to do some setup.
|
||||||
Return false if something bad happened during the setup. The device will be disabled.
|
Return false if something bad happened during the setup. The device will be disabled.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -42,13 +42,14 @@ public:
|
|||||||
virtual void init() {}
|
virtual void init() {}
|
||||||
|
|
||||||
virtual QString pluginName() const = 0;
|
virtual QString pluginName() const = 0;
|
||||||
virtual QUuid pluginId() const = 0;
|
virtual PluginId pluginId() const = 0;
|
||||||
|
|
||||||
virtual QList<Vendor> supportedVendors() const = 0;
|
virtual QList<Vendor> supportedVendors() const = 0;
|
||||||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||||
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
|
virtual DeviceManager::HardwareResources requiredHardware() const = 0;
|
||||||
|
|
||||||
virtual bool configureAutoDevice(QList<Device *> loadedDevices, Device *device) const;
|
virtual bool configureAutoDevice(QList<Device *> loadedDevices, Device *device) const;
|
||||||
|
virtual QList<DeviceDescription> discoveredDevices(const DeviceClassId &deviceClassId) const;
|
||||||
|
|
||||||
virtual bool deviceCreated(Device *device);
|
virtual bool deviceCreated(Device *device);
|
||||||
virtual void deviceRemoved(Device *device);
|
virtual void deviceRemoved(Device *device);
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
VendorId boblightVendorId = VendorId("8c5e8d4c-b5ed-4bfe-b30d-35c2790ec100");
|
VendorId boblightVendorId = VendorId("8c5e8d4c-b5ed-4bfe-b30d-35c2790ec100");
|
||||||
|
|
||||||
QUuid boblightPluginUuid = QUuid("e1647872-c0f5-4680-b49b-3924e5b54dcd");
|
PluginId boblightPluginUuid = PluginId("e1647872-c0f5-4680-b49b-3924e5b54dcd");
|
||||||
DeviceClassId boblightDeviceClassId = DeviceClassId("1647c61c-db14-461e-8060-8a3533d5d92f");
|
DeviceClassId boblightDeviceClassId = DeviceClassId("1647c61c-db14-461e-8060-8a3533d5d92f");
|
||||||
StateTypeId colorStateTypeId = StateTypeId("97ec80cd-43a9-40fa-93b7-d1580043d981");
|
StateTypeId colorStateTypeId = StateTypeId("97ec80cd-43a9-40fa-93b7-d1580043d981");
|
||||||
ActionTypeId setColorActionTypeId = ActionTypeId("668e1aa3-fa13-49ce-8630-17a5c0a7c34b");
|
ActionTypeId setColorActionTypeId = ActionTypeId("668e1aa3-fa13-49ce-8630-17a5c0a7c34b");
|
||||||
@ -99,7 +99,7 @@ QString DevicePluginBoblight::pluginName() const
|
|||||||
return "Boblight client";
|
return "Boblight client";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginBoblight::pluginId() const
|
PluginId DevicePluginBoblight::pluginId() const
|
||||||
{
|
{
|
||||||
return boblightPluginUuid;
|
return boblightPluginUuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ public:
|
|||||||
bool configureAutoDevice(QList<Device *> loadedDevices, Device *device) const override;
|
bool configureAutoDevice(QList<Device *> loadedDevices, Device *device) const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
QVariantMap configuration() const override;
|
QVariantMap configuration() const override;
|
||||||
void setConfiguration(const QVariantMap &configuration) override;
|
void setConfiguration(const QVariantMap &configuration) override;
|
||||||
|
|||||||
@ -119,9 +119,9 @@ QString DevicePluginConrad::pluginName() const
|
|||||||
return "Conrad";
|
return "Conrad";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginConrad::pluginId() const
|
PluginId DevicePluginConrad::pluginId() const
|
||||||
{
|
{
|
||||||
return QUuid("1fd1a076-f229-4ec6-b501-48ddd15935e4");
|
return PluginId("1fd1a076-f229-4ec6-b501-48ddd15935e4");
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, const Action &action)
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public:
|
|||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
void radioData(QList<int> rawData) override;
|
void radioData(QList<int> rawData) override;
|
||||||
|
|
||||||
|
|||||||
@ -216,9 +216,9 @@ QString DevicePluginElro::pluginName() const
|
|||||||
return QStringLiteral("Elro");
|
return QStringLiteral("Elro");
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginElro::pluginId() const
|
PluginId DevicePluginElro::pluginId() const
|
||||||
{
|
{
|
||||||
return QUuid("2b267f81-d9ae-4f4f-89a0-7386b547cfd3");
|
return PluginId("2b267f81-d9ae-4f4f-89a0-7386b547cfd3");
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginElro::executeAction(Device *device, const Action &action)
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public:
|
|||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
void radioData(QList<int> rawData) override;
|
void radioData(QList<int> rawData) override;
|
||||||
|
|
||||||
|
|||||||
@ -352,9 +352,9 @@ QString DevicePluginIntertechno::pluginName() const
|
|||||||
return "Intertechno";
|
return "Intertechno";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginIntertechno::pluginId() const
|
PluginId DevicePluginIntertechno::pluginId() const
|
||||||
{
|
{
|
||||||
return QUuid("e998d934-0397-42c1-ad63-9141bcac8563");
|
return PluginId("e998d934-0397-42c1-ad63-9141bcac8563");
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action)
|
DeviceManager::DeviceError DevicePluginIntertechno::executeAction(Device *device, const Action &action)
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public:
|
|||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
void radioData(QList<int> rawData) override;
|
void radioData(QList<int> rawData) override;
|
||||||
|
|
||||||
|
|||||||
@ -130,9 +130,9 @@ QString DevicePluginMock::pluginName() const
|
|||||||
return "Mock Devices";
|
return "Mock Devices";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginMock::pluginId() const
|
PluginId DevicePluginMock::pluginId() const
|
||||||
{
|
{
|
||||||
return QUuid("727a4a9a-c187-446f-aadf-f1b2220607d1");
|
return PluginId("727a4a9a-c187-446f-aadf-f1b2220607d1");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginMock::deviceCreated(Device *device)
|
bool DevicePluginMock::deviceCreated(Device *device)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public:
|
|||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
bool deviceCreated(Device *device) override;
|
bool deviceCreated(Device *device) override;
|
||||||
void deviceRemoved(Device *device) override;
|
void deviceRemoved(Device *device) override;
|
||||||
|
|||||||
@ -171,6 +171,15 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||||||
|
|
||||||
DeviceClass deviceClassOpenweathermap(pluginId(), openweathermapVendorId, DeviceClassId("985195aa-17ad-4530-88a4-cdd753d747d7"));
|
DeviceClass deviceClassOpenweathermap(pluginId(), openweathermapVendorId, DeviceClassId("985195aa-17ad-4530-88a4-cdd753d747d7"));
|
||||||
deviceClassOpenweathermap.setName("Weather from openweathermap");
|
deviceClassOpenweathermap.setName("Weather from openweathermap");
|
||||||
|
deviceClassOpenweathermap.setCreateMethod(DeviceClass::CreateMethodDiscovery);
|
||||||
|
|
||||||
|
// Params
|
||||||
|
QVariantList params;
|
||||||
|
QVariantMap locationParam;
|
||||||
|
locationParam.insert("name", "location");
|
||||||
|
locationParam.insert("type", "string");
|
||||||
|
params.append(locationParam);
|
||||||
|
deviceClassOpenweathermap.setParams(params);
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
QList<ActionType> weatherActions;
|
QList<ActionType> weatherActions;
|
||||||
@ -280,6 +289,11 @@ QList<DeviceClass> DevicePluginOpenweathermap::supportedDevices() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<DeviceDescription> DevicePluginOpenweathermap::discoveredDevices(const DeviceClassId &deviceClassId) const
|
||||||
|
{
|
||||||
|
m_openweaher->
|
||||||
|
}
|
||||||
|
|
||||||
DeviceManager::HardwareResources DevicePluginOpenweathermap::requiredHardware() const
|
DeviceManager::HardwareResources DevicePluginOpenweathermap::requiredHardware() const
|
||||||
{
|
{
|
||||||
return DeviceManager::HardwareResourceTimer;
|
return DeviceManager::HardwareResourceTimer;
|
||||||
@ -290,9 +304,9 @@ QString DevicePluginOpenweathermap::pluginName() const
|
|||||||
return "Openweathermap";
|
return "Openweathermap";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginOpenweathermap::pluginId() const
|
PluginId DevicePluginOpenweathermap::pluginId() const
|
||||||
{
|
{
|
||||||
return QUuid("bc6af567-2338-41d5-aac1-462dec6e4783");
|
return PluginId("bc6af567-2338-41d5-aac1-462dec6e4783");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginOpenweathermap::guhTimer()
|
void DevicePluginOpenweathermap::guhTimer()
|
||||||
|
|||||||
@ -37,10 +37,13 @@ public:
|
|||||||
|
|
||||||
QList<Vendor> supportedVendors() const override;
|
QList<Vendor> supportedVendors() const override;
|
||||||
QList<DeviceClass> supportedDevices() const override;
|
QList<DeviceClass> supportedDevices() const override;
|
||||||
|
|
||||||
|
QList<DeviceDescription> discoveredDevices(const DeviceClassId &deviceClassId) const;
|
||||||
|
|
||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
void guhTimer() override;
|
void guhTimer() override;
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ void OpenWeatherMap::updateLocationData()
|
|||||||
QNetworkRequest locationRequest;
|
QNetworkRequest locationRequest;
|
||||||
locationRequest.setUrl(QUrl(urlString));
|
locationRequest.setUrl(QUrl(urlString));
|
||||||
|
|
||||||
m_locationReplay = m_manager->get(locationRequest);
|
m_locationReply = m_manager->get(locationRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenWeatherMap::updateSearchData()
|
void OpenWeatherMap::updateSearchData()
|
||||||
@ -42,7 +42,7 @@ void OpenWeatherMap::updateSearchData()
|
|||||||
QNetworkRequest searchRequest;
|
QNetworkRequest searchRequest;
|
||||||
searchRequest.setUrl(QUrl(urlString));
|
searchRequest.setUrl(QUrl(urlString));
|
||||||
|
|
||||||
m_searchReplay = m_manager->get(searchRequest);
|
m_searchReply = m_manager->get(searchRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenWeatherMap::updateWeatherData()
|
void OpenWeatherMap::updateWeatherData()
|
||||||
@ -51,7 +51,7 @@ void OpenWeatherMap::updateWeatherData()
|
|||||||
QNetworkRequest weatherRequest;
|
QNetworkRequest weatherRequest;
|
||||||
weatherRequest.setUrl(QUrl(urlString));
|
weatherRequest.setUrl(QUrl(urlString));
|
||||||
|
|
||||||
m_weatherReplay = m_manager->get(weatherRequest);
|
m_weatherReply = m_manager->get(weatherRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenWeatherMap::processLocationResponse(QByteArray data)
|
void OpenWeatherMap::processLocationResponse(QByteArray data)
|
||||||
@ -222,19 +222,19 @@ void OpenWeatherMap::replyFinished(QNetworkReply *reply)
|
|||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
|
||||||
if(reply == m_locationReplay && status == 200){
|
if(reply == m_locationReply && status == 200){
|
||||||
data = reply->readAll();
|
data = reply->readAll();
|
||||||
processLocationResponse(data);
|
processLocationResponse(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reply == m_searchReplay && status == 200){
|
if(reply == m_searchReply && status == 200){
|
||||||
data = reply->readAll();
|
data = reply->readAll();
|
||||||
processSearchResponse(data);
|
processSearchResponse(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reply == m_weatherReplay && status == 200){
|
if(reply == m_weatherReply && status == 200){
|
||||||
data = reply->readAll();
|
data = reply->readAll();
|
||||||
processWeatherResponse(data);
|
processWeatherResponse(data);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -38,9 +38,9 @@ private:
|
|||||||
QString m_cityName;
|
QString m_cityName;
|
||||||
QString m_cityId;
|
QString m_cityId;
|
||||||
|
|
||||||
QNetworkReply *m_locationReplay;
|
QNetworkReply *m_locationReply;
|
||||||
QNetworkReply *m_searchReplay;
|
QNetworkReply *m_searchReply;
|
||||||
QNetworkReply *m_weatherReplay;
|
QNetworkReply *m_weatherReply;
|
||||||
|
|
||||||
QString m_country;
|
QString m_country;
|
||||||
QString m_weatherDescription;
|
QString m_weatherDescription;
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
extern VendorId guhVendorId;
|
extern VendorId guhVendorId;
|
||||||
QUuid pluginUuid = QUuid("8e0f791e-b273-4267-8605-b7c2f55a68ab");
|
PluginId pluginUuid = PluginId("8e0f791e-b273-4267-8605-b7c2f55a68ab");
|
||||||
DeviceClassId detectorId = DeviceClassId("bd216356-f1ec-4324-9785-6982d2174e17");
|
DeviceClassId detectorId = DeviceClassId("bd216356-f1ec-4324-9785-6982d2174e17");
|
||||||
StateTypeId inRangeStateTypeId = StateTypeId("cb43e1b5-4f61-4538-bfa2-c33055c542cf");
|
StateTypeId inRangeStateTypeId = StateTypeId("cb43e1b5-4f61-4538-bfa2-c33055c542cf");
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ QString DevicePluginWifiDetector::pluginName() const
|
|||||||
return "WiFi Detector";
|
return "WiFi Detector";
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid DevicePluginWifiDetector::pluginId() const
|
PluginId DevicePluginWifiDetector::pluginId() const
|
||||||
{
|
{
|
||||||
return pluginUuid;
|
return pluginUuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public:
|
|||||||
DeviceManager::HardwareResources requiredHardware() const override;
|
DeviceManager::HardwareResources requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const override;
|
QString pluginName() const override;
|
||||||
QUuid pluginId() const override;
|
PluginId pluginId() const override;
|
||||||
|
|
||||||
void guhTimer() override;
|
void guhTimer() override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user