got rid of last use of Engine singleton in C++ (except the qml singleton provider)
This commit is contained in:
parent
c3dd7da60c
commit
56d30ea0ca
@ -101,10 +101,9 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
}
|
}
|
||||||
dev->setStateValue(data.value("params").toMap().value("stateTypeId").toUuid(), data.value("params").toMap().value("value"));
|
dev->setStateValue(data.value("params").toMap().value("stateTypeId").toUuid(), data.value("params").toMap().value("value"));
|
||||||
} else if (notification == "Devices.DeviceAdded") {
|
} else if (notification == "Devices.DeviceAdded") {
|
||||||
Device *dev = new Device();
|
Device *dev = JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), m_deviceClasses);
|
||||||
if (!JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), dev)) {
|
if (!dev) {
|
||||||
qWarning() << "Cannot parse json device:" << data;
|
qWarning() << "Cannot parse json device:" << data;
|
||||||
delete dev;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeviceClass *dc = deviceClasses()->getDeviceClass(dev->deviceClassId());
|
DeviceClass *dc = deviceClasses()->getDeviceClass(dev->deviceClassId());
|
||||||
@ -113,7 +112,6 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
delete dev;
|
delete dev;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dev->setDeviceClass(dc);
|
|
||||||
m_devices->addDevice(dev);
|
m_devices->addDevice(dev);
|
||||||
} else if (notification == "Devices.DeviceRemoved") {
|
} else if (notification == "Devices.DeviceRemoved") {
|
||||||
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
||||||
@ -129,7 +127,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
qWarning() << "Received a device changed notification for a device we don't know";
|
qWarning() << "Received a device changed notification for a device we don't know";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), oldDevice)) {
|
if (!JsonTypes::unpackDevice(data.value("params").toMap().value("device").toMap(), m_deviceClasses, oldDevice)) {
|
||||||
qWarning() << "Error parsing device changed notification";
|
qWarning() << "Error parsing device changed notification";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -216,25 +214,17 @@ void DeviceManager::getConfiguredDevicesResponse(const QVariantMap ¶ms)
|
|||||||
if (params.value("params").toMap().keys().contains("devices")) {
|
if (params.value("params").toMap().keys().contains("devices")) {
|
||||||
QVariantList deviceList = params.value("params").toMap().value("devices").toList();
|
QVariantList deviceList = params.value("params").toMap().value("devices").toList();
|
||||||
foreach (QVariant deviceVariant, deviceList) {
|
foreach (QVariant deviceVariant, deviceList) {
|
||||||
Device *device = new Device();
|
Device *device = JsonTypes::unpackDevice(deviceVariant.toMap(), m_deviceClasses);
|
||||||
if (!JsonTypes::unpackDevice(deviceVariant.toMap(), device)) {
|
if (!device) {
|
||||||
qWarning() << "Error parsing device json" << deviceVariant;
|
qWarning() << "Error unpacking device" << deviceVariant;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// qDebug() << QJsonDocument::fromVariant(deviceVariant).toJson();
|
|
||||||
DeviceClass *dc = m_deviceClasses->getDeviceClass(device->deviceClassId());
|
|
||||||
if (!dc) {
|
|
||||||
qWarning() << "Can't find a deviceClass for this device" << device->name();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
device->setDeviceClass(dc);
|
|
||||||
|
|
||||||
// set initial state values
|
// set initial state values
|
||||||
QVariantList stateVariantList = deviceVariant.toMap().value("states").toList();
|
QVariantList stateVariantList = deviceVariant.toMap().value("states").toList();
|
||||||
foreach (const QVariant &stateMap, stateVariantList) {
|
foreach (const QVariant &stateMap, stateVariantList) {
|
||||||
QString stateTypeId = stateMap.toMap().value("stateTypeId").toString();
|
QString stateTypeId = stateMap.toMap().value("stateTypeId").toString();
|
||||||
StateType *st = dc->stateTypes()->getStateType(stateTypeId);
|
StateType *st = device->deviceClass()->stateTypes()->getStateType(stateTypeId);
|
||||||
if (!st) {
|
if (!st) {
|
||||||
qWarning() << "Can't find a statetype for this state";
|
qWarning() << "Can't find a statetype for this state";
|
||||||
continue;
|
continue;
|
||||||
@ -262,19 +252,11 @@ void DeviceManager::addDeviceResponse(const QVariantMap ¶ms)
|
|||||||
qWarning() << "Failed to add the device:" << params.value("params").toMap().value("deviceError").toString();
|
qWarning() << "Failed to add the device:" << params.value("params").toMap().value("deviceError").toString();
|
||||||
} else if (params.value("params").toMap().keys().contains("device")) {
|
} else if (params.value("params").toMap().keys().contains("device")) {
|
||||||
QVariantMap deviceVariant = params.value("params").toMap().value("device").toMap();
|
QVariantMap deviceVariant = params.value("params").toMap().value("device").toMap();
|
||||||
Device *device = new Device();
|
Device *device = JsonTypes::unpackDevice(deviceVariant, m_deviceClasses);
|
||||||
if (!JsonTypes::unpackDevice(deviceVariant, device)) {
|
if (!device) {
|
||||||
qWarning() << "Couldn't parse json in addDeviceResponse";
|
qWarning() << "Couldn't parse json in addDeviceResponse";
|
||||||
device->deleteLater();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeviceClass *dc = deviceClasses()->getDeviceClass(device->deviceClassId());
|
|
||||||
if (!dc) {
|
|
||||||
qWarning() << "Uh.. We couldn't find a DeviceClass for the Device we just added. Skipping...";
|
|
||||||
device->deleteLater();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
device->setDeviceClass(dc);
|
|
||||||
|
|
||||||
qDebug() << "Device added" << device->id().toString();
|
qDebug() << "Device added" << device->id().toString();
|
||||||
m_devices->addDevice(device);
|
m_devices->addDevice(device);
|
||||||
|
|||||||
@ -46,7 +46,7 @@ class Engine : public QObject
|
|||||||
Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
|
Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// static Engine *instance();
|
static Engine *instance();
|
||||||
|
|
||||||
bool connected() const;
|
bool connected() const;
|
||||||
QString connectedHost() const;
|
QString connectedHost() const;
|
||||||
|
|||||||
@ -196,11 +196,23 @@ ActionType *JsonTypes::unpackActionType(const QVariantMap &actionTypeMap, QObjec
|
|||||||
return actionType;
|
return actionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonTypes::unpackDevice(const QVariantMap &deviceMap, Device *device)
|
Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice)
|
||||||
{
|
{
|
||||||
|
QUuid deviceClassId = deviceMap.value("deviceClassId").toUuid();
|
||||||
|
DeviceClass *deviceClass = deviceClasses->getDeviceClass(deviceClassId);
|
||||||
|
if (!deviceClass) {
|
||||||
|
qWarning() << "Cannot find a device class for this device";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Device *device = nullptr;
|
||||||
|
if (oldDevice) {
|
||||||
|
device = oldDevice;
|
||||||
|
} else {
|
||||||
|
device = new Device(deviceClass);
|
||||||
|
}
|
||||||
device->setName(deviceMap.value("name").toString());
|
device->setName(deviceMap.value("name").toString());
|
||||||
device->setId(deviceMap.value("id").toUuid());
|
device->setId(deviceMap.value("id").toUuid());
|
||||||
device->setDeviceClassId(deviceMap.value("deviceClassId").toUuid());
|
|
||||||
device->setSetupComplete(deviceMap.value("setupComplete").toBool());
|
device->setSetupComplete(deviceMap.value("setupComplete").toBool());
|
||||||
|
|
||||||
Params *params = device->params();
|
Params *params = device->params();
|
||||||
@ -218,11 +230,6 @@ bool JsonTypes::unpackDevice(const QVariantMap &deviceMap, Device *device)
|
|||||||
}
|
}
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
|
|
||||||
DeviceClass *deviceClass = Engine::instance()->deviceManager()->deviceClasses()->getDeviceClass(device->deviceClassId());
|
|
||||||
if (!deviceClass) {
|
|
||||||
qWarning() << "Cannot find a device class for this device..." << device->deviceClassId() << "Skipping...";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
States *states = new States(device);
|
States *states = new States(device);
|
||||||
foreach (StateType *stateType, deviceClass->stateTypes()->stateTypes()) {
|
foreach (StateType *stateType, deviceClass->stateTypes()->stateTypes()) {
|
||||||
State *state = new State(device->id(), stateType->id(), stateType->defaultValue(), states);
|
State *state = new State(device->id(), stateType->id(), stateType->defaultValue(), states);
|
||||||
@ -230,7 +237,7 @@ bool JsonTypes::unpackDevice(const QVariantMap &deviceMap, Device *device)
|
|||||||
}
|
}
|
||||||
device->setStates(states);
|
device->setStates(states);
|
||||||
|
|
||||||
return true;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap JsonTypes::packRule(Rule *rule)
|
QVariantMap JsonTypes::packRule(Rule *rule)
|
||||||
|
|||||||
@ -38,6 +38,7 @@ class ActionType;
|
|||||||
class ParamType;
|
class ParamType;
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
|
class DeviceClasses;
|
||||||
class Param;
|
class Param;
|
||||||
class Rule;
|
class Rule;
|
||||||
class StateEvaluator;
|
class StateEvaluator;
|
||||||
@ -52,7 +53,7 @@ class JsonTypes : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JsonTypes(QObject *parent = 0);
|
explicit JsonTypes(QObject *parent = nullptr);
|
||||||
|
|
||||||
static Vendor *unpackVendor(const QVariantMap &vendorMap);
|
static Vendor *unpackVendor(const QVariantMap &vendorMap);
|
||||||
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent);
|
static Plugin *unpackPlugin(const QVariantMap &pluginMap, QObject *parent);
|
||||||
@ -62,7 +63,7 @@ public:
|
|||||||
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);
|
static StateType *unpackStateType(const QVariantMap &stateTypeMap, QObject *parent);
|
||||||
static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent);
|
static EventType *unpackEventType(const QVariantMap &eventTypeMap, QObject *parent);
|
||||||
static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent);
|
static ActionType *unpackActionType(const QVariantMap &actionTypeMap, QObject *parent);
|
||||||
static bool unpackDevice(const QVariantMap &deviceMap, Device *device);
|
static Device *unpackDevice(const QVariantMap &deviceMap, DeviceClasses *deviceClasses, Device *oldDevice = nullptr);
|
||||||
|
|
||||||
static QVariantMap packRule(Rule* rule);
|
static QVariantMap packRule(Rule* rule);
|
||||||
static QVariantList packRuleActions(RuleActions* ruleActions);
|
static QVariantList packRuleActions(RuleActions* ruleActions);
|
||||||
|
|||||||
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Device::Device(QObject *parent) :
|
Device::Device(DeviceClass *deviceClass, QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent),
|
||||||
|
m_deviceClass(deviceClass)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,12 +54,7 @@ void Device::setId(const QUuid &id)
|
|||||||
|
|
||||||
QUuid Device::deviceClassId() const
|
QUuid Device::deviceClassId() const
|
||||||
{
|
{
|
||||||
return m_deviceClassId;
|
return m_deviceClass->id();
|
||||||
}
|
|
||||||
|
|
||||||
void Device::setDeviceClassId(const QUuid &deviceClassId)
|
|
||||||
{
|
|
||||||
m_deviceClassId = deviceClassId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::setupComplete()
|
bool Device::setupComplete()
|
||||||
@ -99,11 +95,6 @@ DeviceClass *Device::deviceClass() const
|
|||||||
return m_deviceClass;
|
return m_deviceClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::setDeviceClass(DeviceClass *deviceClass)
|
|
||||||
{
|
|
||||||
m_deviceClass = deviceClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Device::hasState(const QUuid &stateTypeId)
|
bool Device::hasState(const QUuid &stateTypeId)
|
||||||
{
|
{
|
||||||
foreach (State *state, states()->states()) {
|
foreach (State *state, states()->states()) {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ class Device : public QObject
|
|||||||
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Device(QObject *parent = nullptr);
|
explicit Device(DeviceClass *deviceClass, QObject *parent = nullptr);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
@ -53,7 +53,6 @@ public:
|
|||||||
void setId(const QUuid &id);
|
void setId(const QUuid &id);
|
||||||
|
|
||||||
QUuid deviceClassId() const;
|
QUuid deviceClassId() const;
|
||||||
void setDeviceClassId(const QUuid &deviceClassId);
|
|
||||||
|
|
||||||
bool setupComplete();
|
bool setupComplete();
|
||||||
void setSetupComplete(const bool &setupComplete);
|
void setSetupComplete(const bool &setupComplete);
|
||||||
@ -71,15 +70,9 @@ public:
|
|||||||
Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId);
|
Q_INVOKABLE QVariant stateValue(const QUuid &stateTypeId);
|
||||||
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
void setStateValue(const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
private:
|
|
||||||
void setDeviceClass(DeviceClass *deviceClass);
|
|
||||||
|
|
||||||
friend class DeviceManager;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
QUuid m_deviceClassId;
|
|
||||||
bool m_setupComplete;
|
bool m_setupComplete;
|
||||||
Params *m_params = nullptr;
|
Params *m_params = nullptr;
|
||||||
States *m_states = nullptr;
|
States *m_states = nullptr;
|
||||||
|
|||||||
@ -25,6 +25,7 @@ CustomViewBase {
|
|||||||
|
|
||||||
ValueLogsProxyModel {
|
ValueLogsProxyModel {
|
||||||
id: logsModel
|
id: logsModel
|
||||||
|
engine: Engine
|
||||||
deviceId: root.device.id
|
deviceId: root.device.id
|
||||||
typeIds: [stateType.id]
|
typeIds: [stateType.id]
|
||||||
average: zoomTabBar.currentItem.avg
|
average: zoomTabBar.currentItem.avg
|
||||||
|
|||||||
Reference in New Issue
Block a user