Merge PR #198: Add support for device settings
This commit is contained in:
commit
4dabffb770
@ -27,7 +27,7 @@ void NetworkManager::init()
|
|||||||
{
|
{
|
||||||
m_jsonClient->sendCommand("NetworkManager.GetNetworkStatus", QVariantMap(), this, "getStatusReply");
|
m_jsonClient->sendCommand("NetworkManager.GetNetworkStatus", QVariantMap(), this, "getStatusReply");
|
||||||
m_jsonClient->sendCommand("NetworkManager.GetNetworkDevices", QVariantMap(), this, "getDevicesReply");
|
m_jsonClient->sendCommand("NetworkManager.GetNetworkDevices", QVariantMap(), this, "getDevicesReply");
|
||||||
m_jsonClient->sendCommand("NetworkManager.GetWirelessAccessPoints", QVariantMap(), this, "getAccessPointsReply");
|
// m_jsonClient->sendCommand("NetworkManager.GetWirelessAccessPoints", QVariantMap(), this, "getAccessPointsReply");
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkManager::NetworkManagerState NetworkManager::state() const
|
NetworkManager::NetworkManagerState NetworkManager::state() const
|
||||||
@ -95,7 +95,7 @@ void NetworkManager::disconnectInterface(const QString &interface)
|
|||||||
|
|
||||||
void NetworkManager::getStatusReply(const QVariantMap ¶ms)
|
void NetworkManager::getStatusReply(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
qDebug() << "NetworkManager reply" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
// qDebug() << "NetworkManager reply" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
QVariantMap statusMap = params.value("params").toMap().value("status").toMap();
|
QVariantMap statusMap = params.value("params").toMap().value("status").toMap();
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ void NetworkManager::getStatusReply(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void NetworkManager::getDevicesReply(const QVariantMap ¶ms)
|
void NetworkManager::getDevicesReply(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
qDebug() << "Dwvices reply" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
// qDebug() << "Devices reply" << qUtf8Printable(QJsonDocument::fromVariant(params).toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
foreach (const QVariant &deviceVariant, params.value("params").toMap().value("wiredNetworkDevices").toList()) {
|
foreach (const QVariant &deviceVariant, params.value("params").toMap().value("wiredNetworkDevices").toList()) {
|
||||||
QVariantMap deviceMap = deviceVariant.toMap();
|
QVariantMap deviceMap = deviceVariant.toMap();
|
||||||
|
|||||||
@ -93,7 +93,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
{
|
{
|
||||||
QString notification = data.value("notification").toString();
|
QString notification = data.value("notification").toString();
|
||||||
if (notification == "Devices.StateChanged") {
|
if (notification == "Devices.StateChanged") {
|
||||||
// qDebug() << "Device state changed" << data.value("params");
|
qDebug() << "Device state changed" << data.value("params");
|
||||||
Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid());
|
Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid());
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
qWarning() << "Device state change notification received for an unknown device";
|
qWarning() << "Device state change notification received for an unknown device";
|
||||||
@ -132,6 +132,22 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "*** device unpacked" << oldDevice->stateValue("98e4476f-e745-4a7f-b795-19269cb70c40");
|
qDebug() << "*** device unpacked" << oldDevice->stateValue("98e4476f-e745-4a7f-b795-19269cb70c40");
|
||||||
|
} else if (notification == "Devices.DeviceSettingChanged") {
|
||||||
|
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
||||||
|
QString paramTypeId = data.value("params").toMap().value("paramTypeId").toString();
|
||||||
|
QVariant value = data.value("params").toMap().value("value");
|
||||||
|
qDebug() << "Device settings changed notification for device" << deviceId << data.value("params").toMap().value("settings").toList();
|
||||||
|
Device *dev = m_devices->getDevice(deviceId);
|
||||||
|
if (!dev) {
|
||||||
|
qWarning() << "Device settings changed notification for a device we don't know" << deviceId.toString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Param *p = dev->settings()->getParam(paramTypeId);
|
||||||
|
if (!p) {
|
||||||
|
qWarning() << "Device" << dev->name() << dev->id().toString() << "does not have a setting of id" << paramTypeId;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p->setValue(value);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
qWarning() << "DeviceManager unhandled device notification received" << notification;
|
||||||
}
|
}
|
||||||
@ -239,9 +255,9 @@ void DeviceManager::getConfiguredDevicesResponse(const QVariantMap ¶ms)
|
|||||||
device->setStateValue(stateTypeId, value);
|
device->setStateValue(stateTypeId, value);
|
||||||
// qDebug() << "Set device state value:" << device->stateValue(stateTypeId) << value;
|
// qDebug() << "Set device state value:" << device->stateValue(stateTypeId) << value;
|
||||||
}
|
}
|
||||||
// qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
qDebug() << "Configured Device JSON:" << qUtf8Printable(QJsonDocument::fromVariant(deviceVariant).toJson(QJsonDocument::Indented));
|
||||||
devices()->addDevice(device);
|
devices()->addDevice(device);
|
||||||
// qDebug() << "*** Added device:" << endl << device;
|
qDebug() << "*** Added device:" << endl << device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_fetchingData = false;
|
m_fetchingData = false;
|
||||||
@ -373,6 +389,14 @@ void DeviceManager::editDevice(const QUuid &deviceId, const QString &name)
|
|||||||
m_jsonClient->sendCommand("Devices.EditDevice", params, this, "editDeviceResponse");
|
m_jsonClient->sendCommand("Devices.EditDevice", params, this, "editDeviceResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceManager::setDeviceSettings(const QUuid &deviceId, const QVariantList &settings)
|
||||||
|
{
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("deviceId", deviceId);
|
||||||
|
params.insert("settings", settings);
|
||||||
|
m_jsonClient->sendCommand("Devices.SetDeviceSettings", params);
|
||||||
|
}
|
||||||
|
|
||||||
void DeviceManager::reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams)
|
void DeviceManager::reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams)
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
|
|||||||
@ -69,6 +69,7 @@ public:
|
|||||||
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString());
|
||||||
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
||||||
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
||||||
|
Q_INVOKABLE void setDeviceSettings(const QUuid &deviceId, const QVariantList &settings);
|
||||||
Q_INVOKABLE void reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams);
|
Q_INVOKABLE void reconfigureDevice(const QUuid &deviceId, const QVariantList &deviceParams);
|
||||||
Q_INVOKABLE void reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId);
|
Q_INVOKABLE void reconfigureDiscoveredDevice(const QUuid &deviceId, const QUuid &deviceDescriptorId);
|
||||||
Q_INVOKABLE int executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
Q_INVOKABLE int executeAction(const QUuid &deviceId, const QUuid &actionTypeId, const QVariantList ¶ms = QVariantList());
|
||||||
|
|||||||
@ -91,6 +91,13 @@ DeviceClass *JsonTypes::unpackDeviceClass(const QVariantMap &deviceClassMap, QOb
|
|||||||
}
|
}
|
||||||
deviceClass->setParamTypes(paramTypes);
|
deviceClass->setParamTypes(paramTypes);
|
||||||
|
|
||||||
|
// SettingsTypes
|
||||||
|
ParamTypes *settingsTypes = new ParamTypes(deviceClass);
|
||||||
|
foreach (QVariant settingsType, deviceClassMap.value("settingsTypes").toList()) {
|
||||||
|
settingsTypes->addParamType(JsonTypes::unpackParamType(settingsType.toMap(), settingsTypes));
|
||||||
|
}
|
||||||
|
deviceClass->setSettingsTypes(settingsTypes);
|
||||||
|
|
||||||
// discovery ParamTypes
|
// discovery ParamTypes
|
||||||
ParamTypes *discoveryParamTypes = new ParamTypes(deviceClass);
|
ParamTypes *discoveryParamTypes = new ParamTypes(deviceClass);
|
||||||
foreach (QVariant paramType, deviceClassMap.value("discoveryParamTypes").toList()) {
|
foreach (QVariant paramType, deviceClassMap.value("discoveryParamTypes").toList()) {
|
||||||
@ -219,7 +226,6 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev
|
|||||||
Params *params = device->params();
|
Params *params = device->params();
|
||||||
if (!params) {
|
if (!params) {
|
||||||
params = new Params(device);
|
params = new Params(device);
|
||||||
device->setParams(params);
|
|
||||||
}
|
}
|
||||||
foreach (QVariant param, deviceMap.value("params").toList()) {
|
foreach (QVariant param, deviceMap.value("params").toList()) {
|
||||||
Param *p = params->getParam(param.toMap().value("paramTypeId").toString());
|
Param *p = params->getParam(param.toMap().value("paramTypeId").toString());
|
||||||
@ -231,6 +237,20 @@ Device* JsonTypes::unpackDevice(const QVariantMap &deviceMap, DeviceClasses *dev
|
|||||||
}
|
}
|
||||||
device->setParams(params);
|
device->setParams(params);
|
||||||
|
|
||||||
|
Params *settings = device->settings();
|
||||||
|
if (!settings) {
|
||||||
|
settings = new Params(device);
|
||||||
|
}
|
||||||
|
foreach (QVariant setting, deviceMap.value("settings").toList()) {
|
||||||
|
Param *p = settings->getParam(setting.toMap().value("paramTypeId").toString());
|
||||||
|
if (!p) {
|
||||||
|
p = new Param();
|
||||||
|
settings->addParam(p);
|
||||||
|
}
|
||||||
|
JsonTypes::unpackParam(setting.toMap(), p);
|
||||||
|
}
|
||||||
|
device->setSettings(settings);
|
||||||
|
|
||||||
States *states = device->states();
|
States *states = device->states();
|
||||||
if (!states) {
|
if (!states) {
|
||||||
states = new States(device);
|
states = new States(device);
|
||||||
|
|||||||
@ -79,11 +79,29 @@ void Device::setParams(Params *params)
|
|||||||
if (m_params) {
|
if (m_params) {
|
||||||
m_params->deleteLater();
|
m_params->deleteLater();
|
||||||
}
|
}
|
||||||
|
params->setParent(this);
|
||||||
m_params = params;
|
m_params = params;
|
||||||
emit paramsChanged();
|
emit paramsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Params *Device::settings() const
|
||||||
|
{
|
||||||
|
return m_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::setSettings(Params *settings)
|
||||||
|
{
|
||||||
|
if (m_settings != settings) {
|
||||||
|
if (m_settings) {
|
||||||
|
m_settings->deleteLater();
|
||||||
|
}
|
||||||
|
settings->setParent(this);
|
||||||
|
m_settings = settings;
|
||||||
|
emit settingsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
States *Device::states() const
|
States *Device::states() const
|
||||||
{
|
{
|
||||||
return m_states;
|
return m_states;
|
||||||
@ -95,6 +113,7 @@ void Device::setStates(States *states)
|
|||||||
if (m_states) {
|
if (m_states) {
|
||||||
m_states->deleteLater();
|
m_states->deleteLater();
|
||||||
}
|
}
|
||||||
|
states->setParent(this);
|
||||||
m_states = states;
|
m_states = states;
|
||||||
emit statesChanged();
|
emit statesChanged();
|
||||||
}
|
}
|
||||||
@ -147,6 +166,15 @@ QDebug operator<<(QDebug &dbg, Device *device)
|
|||||||
dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << endl;
|
dbg << " Param " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < device->deviceClass()->settingsTypes()->rowCount(); i++) {
|
||||||
|
ParamType *pt = device->deviceClass()->settingsTypes()->get(i);
|
||||||
|
Param *p = device->settings()->getParam(pt->id().toString());
|
||||||
|
if (p) {
|
||||||
|
dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << p->value() << endl;
|
||||||
|
} else {
|
||||||
|
dbg << " Setting " << i << ": " << pt->id().toString() << ": " << pt->name() << " = " << "*** Unknown value ***" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (int i = 0; i < device->deviceClass()->stateTypes()->rowCount(); i++) {
|
for (int i = 0; i < device->deviceClass()->stateTypes()->rowCount(); i++) {
|
||||||
StateType *st = device->deviceClass()->stateTypes()->get(i);
|
StateType *st = device->deviceClass()->stateTypes()->get(i);
|
||||||
State *s = device->states()->getState(st->id());
|
State *s = device->states()->getState(st->id());
|
||||||
|
|||||||
@ -40,6 +40,7 @@ class Device : public QObject
|
|||||||
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
|
||||||
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)
|
Q_PROPERTY(bool setupComplete READ setupComplete NOTIFY setupCompleteChanged)
|
||||||
Q_PROPERTY(Params *params READ params NOTIFY paramsChanged)
|
Q_PROPERTY(Params *params READ params NOTIFY paramsChanged)
|
||||||
|
Q_PROPERTY(Params *settings READ settings NOTIFY settingsChanged)
|
||||||
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
Q_PROPERTY(States *states READ states NOTIFY statesChanged)
|
||||||
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
Q_PROPERTY(DeviceClass *deviceClass READ deviceClass CONSTANT)
|
||||||
|
|
||||||
@ -60,6 +61,9 @@ public:
|
|||||||
Params *params() const;
|
Params *params() const;
|
||||||
void setParams(Params *params);
|
void setParams(Params *params);
|
||||||
|
|
||||||
|
Params *settings() const;
|
||||||
|
void setSettings(Params *settings);
|
||||||
|
|
||||||
States *states() const;
|
States *states() const;
|
||||||
void setStates(States *states);
|
void setStates(States *states);
|
||||||
|
|
||||||
@ -75,6 +79,7 @@ private:
|
|||||||
QUuid m_id;
|
QUuid m_id;
|
||||||
bool m_setupComplete;
|
bool m_setupComplete;
|
||||||
Params *m_params = nullptr;
|
Params *m_params = nullptr;
|
||||||
|
Params *m_settings = nullptr;
|
||||||
States *m_states = nullptr;
|
States *m_states = nullptr;
|
||||||
DeviceClass *m_deviceClass = nullptr;
|
DeviceClass *m_deviceClass = nullptr;
|
||||||
|
|
||||||
@ -83,6 +88,7 @@ signals:
|
|||||||
void nameChanged();
|
void nameChanged();
|
||||||
void setupCompleteChanged();
|
void setupCompleteChanged();
|
||||||
void paramsChanged();
|
void paramsChanged();
|
||||||
|
void settingsChanged();
|
||||||
void statesChanged();
|
void statesChanged();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -174,10 +174,27 @@ ParamTypes *DeviceClass::paramTypes() const
|
|||||||
|
|
||||||
void DeviceClass::setParamTypes(ParamTypes *paramTypes)
|
void DeviceClass::setParamTypes(ParamTypes *paramTypes)
|
||||||
{
|
{
|
||||||
|
if (m_paramTypes) {
|
||||||
|
m_paramTypes->deleteLater();
|
||||||
|
}
|
||||||
m_paramTypes = paramTypes;
|
m_paramTypes = paramTypes;
|
||||||
emit paramTypesChanged();
|
emit paramTypesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ParamTypes *DeviceClass::settingsTypes() const
|
||||||
|
{
|
||||||
|
return m_settingsTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceClass::setSettingsTypes(ParamTypes *settingsTypes)
|
||||||
|
{
|
||||||
|
if (m_settingsTypes) {
|
||||||
|
m_settingsTypes->deleteLater();
|
||||||
|
}
|
||||||
|
m_settingsTypes = settingsTypes;
|
||||||
|
emit settingsTypesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
ParamTypes *DeviceClass::discoveryParamTypes() const
|
ParamTypes *DeviceClass::discoveryParamTypes() const
|
||||||
{
|
{
|
||||||
return m_discoveryParamTypes;
|
return m_discoveryParamTypes;
|
||||||
@ -185,6 +202,9 @@ ParamTypes *DeviceClass::discoveryParamTypes() const
|
|||||||
|
|
||||||
void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
void DeviceClass::setDiscoveryParamTypes(ParamTypes *paramTypes)
|
||||||
{
|
{
|
||||||
|
if (m_discoveryParamTypes) {
|
||||||
|
m_discoveryParamTypes->deleteLater();
|
||||||
|
}
|
||||||
m_discoveryParamTypes = paramTypes;
|
m_discoveryParamTypes = paramTypes;
|
||||||
emit discoveryParamTypesChanged();
|
emit discoveryParamTypesChanged();
|
||||||
}
|
}
|
||||||
@ -196,6 +216,9 @@ StateTypes *DeviceClass::stateTypes() const
|
|||||||
|
|
||||||
void DeviceClass::setStateTypes(StateTypes *stateTypes)
|
void DeviceClass::setStateTypes(StateTypes *stateTypes)
|
||||||
{
|
{
|
||||||
|
if (m_stateTypes) {
|
||||||
|
m_stateTypes->deleteLater();
|
||||||
|
}
|
||||||
m_stateTypes = stateTypes;
|
m_stateTypes = stateTypes;
|
||||||
emit stateTypesChanged();
|
emit stateTypesChanged();
|
||||||
}
|
}
|
||||||
@ -207,6 +230,9 @@ EventTypes *DeviceClass::eventTypes() const
|
|||||||
|
|
||||||
void DeviceClass::setEventTypes(EventTypes *eventTypes)
|
void DeviceClass::setEventTypes(EventTypes *eventTypes)
|
||||||
{
|
{
|
||||||
|
if (m_eventTypes) {
|
||||||
|
m_eventTypes->deleteLater();
|
||||||
|
}
|
||||||
m_eventTypes = eventTypes;
|
m_eventTypes = eventTypes;
|
||||||
emit eventTypesChanged();
|
emit eventTypesChanged();
|
||||||
}
|
}
|
||||||
@ -218,6 +244,9 @@ ActionTypes *DeviceClass::actionTypes() const
|
|||||||
|
|
||||||
void DeviceClass::setActionTypes(ActionTypes *actionTypes)
|
void DeviceClass::setActionTypes(ActionTypes *actionTypes)
|
||||||
{
|
{
|
||||||
|
if (m_actionTypes) {
|
||||||
|
m_actionTypes->deleteLater();
|
||||||
|
}
|
||||||
m_actionTypes = actionTypes;
|
m_actionTypes = actionTypes;
|
||||||
emit actionTypesChanged();
|
emit actionTypesChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ class DeviceClass : public QObject
|
|||||||
Q_PROPERTY(QStringList interfaces READ interfaces CONSTANT)
|
Q_PROPERTY(QStringList interfaces READ interfaces CONSTANT)
|
||||||
Q_PROPERTY(QString baseInterface READ baseInterface CONSTANT)
|
Q_PROPERTY(QString baseInterface READ baseInterface CONSTANT)
|
||||||
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
|
Q_PROPERTY(ParamTypes *paramTypes READ paramTypes NOTIFY paramTypesChanged)
|
||||||
|
Q_PROPERTY(ParamTypes *settingsTypes READ settingsTypes NOTIFY settingsTypesChanged)
|
||||||
Q_PROPERTY(ParamTypes *discoveryParamTypes READ discoveryParamTypes NOTIFY discoveryParamTypesChanged)
|
Q_PROPERTY(ParamTypes *discoveryParamTypes READ discoveryParamTypes NOTIFY discoveryParamTypesChanged)
|
||||||
Q_PROPERTY(StateTypes *stateTypes READ stateTypes NOTIFY stateTypesChanged)
|
Q_PROPERTY(StateTypes *stateTypes READ stateTypes NOTIFY stateTypesChanged)
|
||||||
Q_PROPERTY(EventTypes *eventTypes READ eventTypes NOTIFY eventTypesChanged)
|
Q_PROPERTY(EventTypes *eventTypes READ eventTypes NOTIFY eventTypesChanged)
|
||||||
@ -93,6 +94,9 @@ public:
|
|||||||
ParamTypes *paramTypes() const;
|
ParamTypes *paramTypes() const;
|
||||||
void setParamTypes(ParamTypes *paramTypes);
|
void setParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
|
ParamTypes *settingsTypes() const;
|
||||||
|
void setSettingsTypes(ParamTypes *settingsTypes);
|
||||||
|
|
||||||
ParamTypes *discoveryParamTypes() const;
|
ParamTypes *discoveryParamTypes() const;
|
||||||
void setDiscoveryParamTypes(ParamTypes *paramTypes);
|
void setDiscoveryParamTypes(ParamTypes *paramTypes);
|
||||||
|
|
||||||
@ -117,14 +121,16 @@ private:
|
|||||||
SetupMethod m_setupMethod;
|
SetupMethod m_setupMethod;
|
||||||
QStringList m_interfaces;
|
QStringList m_interfaces;
|
||||||
|
|
||||||
ParamTypes *m_paramTypes;
|
ParamTypes *m_paramTypes = nullptr;
|
||||||
ParamTypes *m_discoveryParamTypes;
|
ParamTypes *m_settingsTypes = nullptr;
|
||||||
StateTypes *m_stateTypes;
|
ParamTypes *m_discoveryParamTypes = nullptr;
|
||||||
EventTypes *m_eventTypes;
|
StateTypes *m_stateTypes = nullptr;
|
||||||
ActionTypes *m_actionTypes;
|
EventTypes *m_eventTypes = nullptr;
|
||||||
|
ActionTypes *m_actionTypes = nullptr;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void paramTypesChanged();
|
void paramTypesChanged();
|
||||||
|
void settingsTypesChanged();
|
||||||
void discoveryParamTypesChanged();
|
void discoveryParamTypesChanged();
|
||||||
void stateTypesChanged();
|
void stateTypesChanged();
|
||||||
void eventTypesChanged();
|
void eventTypesChanged();
|
||||||
|
|||||||
@ -41,6 +41,9 @@ int Params::count() const
|
|||||||
|
|
||||||
Param *Params::get(int index) const
|
Param *Params::get(int index) const
|
||||||
{
|
{
|
||||||
|
if (index < 0 || index >= m_params.count()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
return m_params.at(index);
|
return m_params.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ Param *Params::getParam(QString paramTypeId) const
|
|||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Params::paramCount() const
|
int Params::paramCount() const
|
||||||
|
|||||||
@ -19,13 +19,13 @@ Item {
|
|||||||
if (d.delegateCache.indexOf(thisItem) < 0) {
|
if (d.delegateCache.indexOf(thisItem) < 0) {
|
||||||
d.delegateCache.push(thisItem);
|
d.delegateCache.push(thisItem);
|
||||||
|
|
||||||
print("cache is now", d.delegateCache.length)
|
// print("cache is now", d.delegateCache.length)
|
||||||
|
|
||||||
thisItem.Component.destruction.connect(function() {
|
thisItem.Component.destruction.connect(function() {
|
||||||
print("item destroyed", thisItem)
|
// print("item destroyed", thisItem)
|
||||||
var idx = d.delegateCache.indexOf(thisItem)
|
var idx = d.delegateCache.indexOf(thisItem)
|
||||||
d.delegateCache.splice(idx, 1)
|
d.delegateCache.splice(idx, 1)
|
||||||
print("cache is now", d.delegateCache.length)
|
// print("cache is now", d.delegateCache.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
thisItem.swipe.opened.connect(function() {
|
thisItem.swipe.opened.connect(function() {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ ItemDelegate {
|
|||||||
}
|
}
|
||||||
Loader {
|
Loader {
|
||||||
id: loader
|
id: loader
|
||||||
Layout.fillWidth: sourceComponent === textFieldComponent
|
Layout.fillWidth: true// sourceComponent === textFieldComponent || sourceComponent === stringComponent
|
||||||
sourceComponent: {
|
sourceComponent: {
|
||||||
print("loading paramdelegate:", root.writable, root.paramType.type)
|
print("loading paramdelegate:", root.writable, root.paramType.type)
|
||||||
if (!root.writable) {
|
if (!root.writable) {
|
||||||
@ -93,6 +93,8 @@ ItemDelegate {
|
|||||||
}
|
}
|
||||||
return root.param.value;
|
return root.param.value;
|
||||||
}
|
}
|
||||||
|
horizontalAlignment: Text.AlignRight
|
||||||
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
@ -150,26 +152,34 @@ ItemDelegate {
|
|||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: spinnerComponent
|
id: spinnerComponent
|
||||||
SpinBox {
|
RowLayout {
|
||||||
value: root.param.value ? root.param.value : 0
|
spacing: app.margins
|
||||||
from: root.paramType.minValue
|
|
||||||
? root.paramType.minValue
|
SpinBox {
|
||||||
: root.paramType.type.toLowerCase() === "uint"
|
value: root.param.value ? root.param.value : 0
|
||||||
? 0
|
from: root.paramType.minValue
|
||||||
: -2000000000
|
? root.paramType.minValue
|
||||||
to: root.paramType.maxValue
|
: root.paramType.type.toLowerCase() === "uint"
|
||||||
? root.paramType.maxValue
|
? 0
|
||||||
: 2000000000
|
: -2000000000
|
||||||
editable: true
|
to: root.paramType.maxValue
|
||||||
width: 150
|
? root.paramType.maxValue
|
||||||
onValueModified: root.param.value = value
|
: 2000000000
|
||||||
textFromValue: function(value) {
|
editable: true
|
||||||
return value
|
width: 150
|
||||||
}
|
onValueModified: root.param.value = value
|
||||||
Component.onCompleted: {
|
textFromValue: function(value) {
|
||||||
if (root.value === undefined) {
|
return value
|
||||||
root.value = value
|
|
||||||
}
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
if (root.value === undefined) {
|
||||||
|
root.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Label {
|
||||||
|
text: root.paramType.unitString
|
||||||
|
visible: text.length > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,8 +68,10 @@ Page {
|
|||||||
|
|
||||||
Flickable {
|
Flickable {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
contentHeight: contentColumn.implicitHeight
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
id: contentColumn
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
@ -119,6 +121,62 @@ Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: app.margins
|
||||||
|
Layout.rightMargin: app.margins
|
||||||
|
Layout.topMargin: app.margins
|
||||||
|
text: qsTr("Thing settings")
|
||||||
|
color: app.accentColor
|
||||||
|
visible: root.deviceClass.settingsTypes.count > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
Repeater {
|
||||||
|
id: settingsRepeater
|
||||||
|
model: root.device.settings
|
||||||
|
delegate: ParamDelegate {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
paramType: root.deviceClass.settingsTypes.getParamType(model.id)
|
||||||
|
value: root.device.settings.get(index).value
|
||||||
|
writable: true
|
||||||
|
property bool dirty: root.device.settings.get(index).value !== value
|
||||||
|
onDirtyChanged: settingsRepeater.checkDirty()
|
||||||
|
}
|
||||||
|
function checkDirty() {
|
||||||
|
for (var i = 0; i < settingsRepeater.count; i++) {
|
||||||
|
if (settingsRepeater.itemAt(i).dirty) {
|
||||||
|
dirty = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dirty = false;
|
||||||
|
}
|
||||||
|
property bool dirty: false
|
||||||
|
}
|
||||||
|
Button {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.leftMargin: app.margins
|
||||||
|
Layout.rightMargin: app.margins
|
||||||
|
text: qsTr("Apply")
|
||||||
|
enabled: settingsRepeater.dirty
|
||||||
|
visible: settingsRepeater.count > 0
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
var params = []
|
||||||
|
for (var i = 0; i < settingsRepeater.count; i++) {
|
||||||
|
if (!settingsRepeater.itemAt(i).dirty) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var setting = {}
|
||||||
|
setting["paramTypeId"] = settingsRepeater.itemAt(i).param.paramTypeId
|
||||||
|
setting["value"] = settingsRepeater.itemAt(i).param.value
|
||||||
|
params.push(setting)
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.deviceManager.setDeviceSettings(root.device.id, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ThinDivider {}
|
// ThinDivider {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@
|
|||||||
application still try to draw after
|
application still try to draw after
|
||||||
"applicationStateChanged(Qt::ApplicationSuspended)"
|
"applicationStateChanged(Qt::ApplicationSuspended)"
|
||||||
signal is sent! -->
|
signal is sent! -->
|
||||||
<meta-data android:name="android.app.background_running" android:value="false"/>
|
<meta-data android:name="android.app.background_running" android:value="true"/>
|
||||||
<!-- Background running -->
|
<!-- Background running -->
|
||||||
|
|
||||||
<!-- auto screen scale factor -->
|
<!-- auto screen scale factor -->
|
||||||
|
|||||||
Reference in New Issue
Block a user