Change group behavior a bit
This commit is contained in:
parent
b5eab4d8b9
commit
c4c7bc9108
@ -161,6 +161,10 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
||||
QUuid deviceId = data.value("params").toMap().value("deviceId").toUuid();
|
||||
qDebug() << "JsonRpc: Notification: Device removed" << deviceId.toString();
|
||||
Device *device = m_devices->getDevice(deviceId);
|
||||
if (!device) {
|
||||
qWarning() << "Received a DeviceRemoved notification for a device we don't know!";
|
||||
return;
|
||||
}
|
||||
m_devices->removeDevice(device);
|
||||
device->deleteLater();
|
||||
} else if (notification == "Devices.DeviceChanged") {
|
||||
@ -399,9 +403,8 @@ void DeviceManager::savePluginConfig(const QUuid &pluginId)
|
||||
|
||||
ThingGroup *DeviceManager::createGroup(Interface *interface, DevicesProxy *things)
|
||||
{
|
||||
|
||||
ThingGroup* group = new ThingGroup(this, interface->createDeviceClass(), things, this);
|
||||
|
||||
group->setSetupStatus(Device::DeviceSetupStatusComplete, QString());
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
@ -242,9 +242,17 @@ Device* JsonTypes::unpackDevice(DeviceManager *deviceManager, const QVariantMap
|
||||
device->setId(deviceMap.value("id").toUuid());
|
||||
// As of JSONRPC 4.2 setupComplete is deprecated and setupStatus is new
|
||||
if (deviceMap.contains("setupStatus")) {
|
||||
QMetaEnum setupStatusEnum = QMetaEnum::fromType<Device::DeviceSetupStatus>();
|
||||
device->setSetupStatus(static_cast<Device::DeviceSetupStatus>(setupStatusEnum.keyToValue(deviceMap.value("setupStatus").toByteArray().data())),
|
||||
deviceMap.value("setupDisplayMessage").toString());
|
||||
QString setupStatus = deviceMap.value("setupStatus").toString();
|
||||
QString setupDisplayMessage = deviceMap.value("setupDisplayMessage").toString();
|
||||
if (setupStatus == "DeviceSetupStatusNone" || setupStatus == "ThingSetupStatusNone") {
|
||||
device->setSetupStatus(Device::DeviceSetupStatusNone, setupDisplayMessage);
|
||||
} else if (setupStatus == "DeviceSetupStatusInProgress" || setupStatus == "ThingSetupStatusInProgress") {
|
||||
device->setSetupStatus(Device::DeviceSetupStatusInProgress, setupDisplayMessage);
|
||||
} else if (setupStatus == "DeviceSetupStatusComplete" || setupStatus == "ThingSetupStatusComplete") {
|
||||
device->setSetupStatus(Device::DeviceSetupStatusComplete, setupDisplayMessage);
|
||||
} else if (setupStatus == "DeviceSetupStatusFailed" || setupStatus == "ThingSetupStatusFailed") {
|
||||
device->setSetupStatus(Device::DeviceSetupStatusFailed, setupDisplayMessage);
|
||||
}
|
||||
} else {
|
||||
device->setSetupStatus(deviceMap.value("setupComplete").toBool() ? Device::DeviceSetupStatusComplete : Device::DeviceSetupStatusNone, QString());
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ int ThingGroup::executeAction(const QString &actionName, const QVariantList &par
|
||||
{
|
||||
QList<int> pendingIds;
|
||||
|
||||
qDebug() << "Execute action for group:" << this;
|
||||
for (int i = 0; i < m_devices->rowCount(); i++) {
|
||||
Device *device = m_devices->get(i);
|
||||
if (device->setupStatus() != Device::DeviceSetupStatusComplete) {
|
||||
@ -119,11 +120,20 @@ void ThingGroup::syncStates()
|
||||
int count = 0;
|
||||
for (int j = 0; j < m_devices->rowCount(); j++) {
|
||||
Device *d = m_devices->get(j);
|
||||
// Skip things that don't have the required state
|
||||
StateType *ds = d->deviceClass()->stateTypes()->findByName(stateType->name());
|
||||
if (!ds) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip disconnected things
|
||||
StateType *connectedStateType = d->deviceClass()->stateTypes()->findByName("connected");
|
||||
if (connectedStateType) {
|
||||
if (!d->stateValue(connectedStateType->id()).toBool()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (stateType->type().toLower() == "bool") {
|
||||
if (d->stateValue(ds->id()).toBool()) {
|
||||
value = true;
|
||||
|
||||
@ -114,7 +114,7 @@ protected:
|
||||
QString m_name;
|
||||
QUuid m_id;
|
||||
QUuid m_parentDeviceId;
|
||||
DeviceSetupStatus m_setupStatus;
|
||||
DeviceSetupStatus m_setupStatus = DeviceSetupStatusNone;
|
||||
QString m_setupDisplayMessage;
|
||||
Params *m_params = nullptr;
|
||||
Params *m_settings = nullptr;
|
||||
|
||||
@ -75,6 +75,8 @@ DeviceClass *Interface::createDeviceClass()
|
||||
{
|
||||
DeviceClass* dc = new DeviceClass();
|
||||
dc->setName(m_name);
|
||||
dc->setParamTypes(new ParamTypes(dc));
|
||||
dc->setSettingsTypes(new ParamTypes(dc));
|
||||
dc->setDisplayName(m_displayName);
|
||||
dc->setEventTypes(m_eventTypes);
|
||||
dc->setStateTypes(m_stateTypes);
|
||||
|
||||
@ -161,8 +161,9 @@ MainPageTile {
|
||||
onClicked: {
|
||||
switch (iface.name) {
|
||||
case "light":
|
||||
|
||||
pageStack.push("../devicepages/LightDevicePage.qml", {device: engine.deviceManager.createGroup(Interfaces.findByName("colorlight"), devicesProxy)})
|
||||
var group = engine.deviceManager.createGroup(Interfaces.findByName("colorlight"), devicesProxy);
|
||||
print("opening lights page for group", group)
|
||||
pageStack.push("../devicepages/LightDevicePage.qml", {device: group})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user