Update Plugins: Set deviceId in Descriptors on discovery
This commit is contained in:
parent
a32116b56b
commit
5203f191f0
@ -82,6 +82,12 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic
|
|||||||
params.append(Param(avahiDeviceServiceParamTypeId, service.name()));
|
params.append(Param(avahiDeviceServiceParamTypeId, service.name()));
|
||||||
params.append(Param(avahiDeviceHostNameParamTypeId, service.hostName()));
|
params.append(Param(avahiDeviceHostNameParamTypeId, service.hostName()));
|
||||||
deviceDescriptor.setParams(params);
|
deviceDescriptor.setParams(params);
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(avahiDeviceServiceParamTypeId).toString() == service.name() && existingDevice->paramValue(avahiDeviceHostNameParamTypeId).toString() == service.hostName()) {
|
||||||
|
deviceDescriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
deviceDescriptors.append(deviceDescriptor);
|
deviceDescriptors.append(deviceDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -604,6 +604,12 @@ void DevicePluginElgato::onBluetoothDiscoveryFinished()
|
|||||||
params.append(Param(aveaDeviceNameParamTypeId, deviceInfo.name()));
|
params.append(Param(aveaDeviceNameParamTypeId, deviceInfo.name()));
|
||||||
params.append(Param(aveaDeviceMacAddressParamTypeId, deviceInfo.address().toString()));
|
params.append(Param(aveaDeviceMacAddressParamTypeId, deviceInfo.address().toString()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(aveaDeviceMacAddressParamTypeId).toString() == deviceInfo.address().toString()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -245,6 +245,13 @@ void DevicePluginEQ3::discoveryDone(const QList<MaxCube *> &cubeList)
|
|||||||
Param serialNumberParam(cubeDeviceSerialParamTypeId, cube->serialNumber());
|
Param serialNumberParam(cubeDeviceSerialParamTypeId, cube->serialNumber());
|
||||||
params.append(serialNumberParam);
|
params.append(serialNumberParam);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(cubeDeviceSerialParamTypeId).toString() == cube->serialNumber()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
retList.append(descriptor);
|
retList.append(descriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -172,6 +172,12 @@ void DevicePluginFlowercare::onBluetoothDiscoveryFinished()
|
|||||||
params.append(Param(flowerCareDeviceNameParamTypeId, deviceInfo.name()));
|
params.append(Param(flowerCareDeviceNameParamTypeId, deviceInfo.name()));
|
||||||
params.append(Param(flowerCareDeviceMacParamTypeId, deviceInfo.address().toString()));
|
params.append(Param(flowerCareDeviceMacParamTypeId, deviceInfo.address().toString()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(flowerCareDeviceMacParamTypeId).toString() == deviceInfo.address().toString()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -185,6 +185,13 @@ DeviceManager::DeviceError DevicePluginGpio::discoverDevices(const DeviceClassId
|
|||||||
}
|
}
|
||||||
descriptor.setParams(parameters);
|
descriptor.setParams(parameters);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(gpioOutputRpiDeviceGpioParamTypeId).toInt() == gpioDescriptor.gpio()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -340,6 +340,13 @@ void DevicePluginLgSmartTv::onUpnpDiscoveryFinished()
|
|||||||
params.append(Param(lgSmartTvDevicePortParamTypeId, upnpDeviceDescriptor.port()));
|
params.append(Param(lgSmartTvDevicePortParamTypeId, upnpDeviceDescriptor.port()));
|
||||||
params.append(Param(lgSmartTvDeviceKeyParamTypeId, QString()));
|
params.append(Param(lgSmartTvDeviceKeyParamTypeId, QString()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(lgSmartTvDeviceUuidParamTypeId).toString() == upnpDeviceDescriptor.uuid()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
emit devicesDiscovered(lgSmartTvDeviceClassId, deviceDescriptors);
|
emit devicesDiscovered(lgSmartTvDeviceClassId, deviceDescriptors);
|
||||||
|
|||||||
@ -156,6 +156,13 @@ void DevicePluginNetworkDetector::discoveryFinished(const QList<Host> &hosts)
|
|||||||
paramList.append(address);
|
paramList.append(address);
|
||||||
descriptor.setParams(paramList);
|
descriptor.setParams(paramList);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(networkDeviceDeviceMacAddressParamTypeId).toString() == host.macAddress()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
discoveredDevices.append(descriptor);
|
discoveredDevices.append(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -312,16 +312,22 @@ void DevicePluginOpenweathermap::processGeoSearchResponse(QByteArray data)
|
|||||||
void DevicePluginOpenweathermap::processSearchResults(const QList<QVariantMap> &cityList)
|
void DevicePluginOpenweathermap::processSearchResults(const QList<QVariantMap> &cityList)
|
||||||
{
|
{
|
||||||
QList<DeviceDescriptor> retList;
|
QList<DeviceDescriptor> retList;
|
||||||
foreach (QVariantMap elemant, cityList) {
|
foreach (QVariantMap element, cityList) {
|
||||||
DeviceDescriptor descriptor(openweathermapDeviceClassId, elemant.value("name").toString(), elemant.value("country").toString());
|
DeviceDescriptor descriptor(openweathermapDeviceClassId, element.value("name").toString(), element.value("country").toString());
|
||||||
ParamList params;
|
ParamList params;
|
||||||
Param nameParam(openweathermapDeviceNameParamTypeId, elemant.value("name"));
|
Param nameParam(openweathermapDeviceNameParamTypeId, element.value("name"));
|
||||||
params.append(nameParam);
|
params.append(nameParam);
|
||||||
Param countryParam(openweathermapDeviceCountryParamTypeId, elemant.value("country"));
|
Param countryParam(openweathermapDeviceCountryParamTypeId, element.value("country"));
|
||||||
params.append(countryParam);
|
params.append(countryParam);
|
||||||
Param idParam(openweathermapDeviceIdParamTypeId, elemant.value("id"));
|
Param idParam(openweathermapDeviceIdParamTypeId, element.value("id"));
|
||||||
params.append(idParam);
|
params.append(idParam);
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(openweathermapDeviceIdParamTypeId).toString() == element.value("id")) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
retList.append(descriptor);
|
retList.append(descriptor);
|
||||||
}
|
}
|
||||||
emit devicesDiscovered(openweathermapDeviceClassId, retList);
|
emit devicesDiscovered(openweathermapDeviceClassId, retList);
|
||||||
|
|||||||
@ -121,7 +121,6 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
|
|||||||
// set data which was not known during discovery
|
// set data which was not known during discovery
|
||||||
device->setParamValue(bridgeDeviceApiKeyParamTypeId, b->apiKey());
|
device->setParamValue(bridgeDeviceApiKeyParamTypeId, b->apiKey());
|
||||||
device->setParamValue(bridgeDeviceZigbeeChannelParamTypeId, b->zigbeeChannel());
|
device->setParamValue(bridgeDeviceZigbeeChannelParamTypeId, b->zigbeeChannel());
|
||||||
device->setParamValue(bridgeDeviceIdParamTypeId, b->id());
|
|
||||||
device->setParamValue(bridgeDeviceMacParamTypeId, b->macAddress());
|
device->setParamValue(bridgeDeviceMacParamTypeId, b->macAddress());
|
||||||
m_bridges.insert(b, device);
|
m_bridges.insert(b, device);
|
||||||
device->setStateValue(bridgeConnectedStateTypeId, true);
|
device->setStateValue(bridgeConnectedStateTypeId, true);
|
||||||
@ -283,6 +282,8 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::confirmPairing(const Pa
|
|||||||
{
|
{
|
||||||
Q_UNUSED(secret)
|
Q_UNUSED(secret)
|
||||||
|
|
||||||
|
qCDebug(dcPhilipsHue()) << "Confirming pairing for transactionId" << pairingTransactionId;
|
||||||
|
|
||||||
if (deviceClassId != bridgeDeviceClassId)
|
if (deviceClassId != bridgeDeviceClassId)
|
||||||
return DeviceManager::DeviceSetupStatusFailure;
|
return DeviceManager::DeviceSetupStatusFailure;
|
||||||
|
|
||||||
@ -408,7 +409,7 @@ void DevicePluginPhilipsHue::networkManagerReplyReady()
|
|||||||
|
|
||||||
// check HTTP status code
|
// check HTTP status code
|
||||||
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
||||||
if (device->stateValue(colorLightConnectedStateTypeId).toBool()) {
|
if (device->stateValue(bridgeConnectedStateTypeId).toBool()) {
|
||||||
qCWarning(dcPhilipsHue) << "Refresh Hue lights request error:" << status << reply->errorString();
|
qCWarning(dcPhilipsHue) << "Refresh Hue lights request error:" << status << reply->errorString();
|
||||||
bridgeReachableChanged(device, false);
|
bridgeReachableChanged(device, false);
|
||||||
}
|
}
|
||||||
@ -421,7 +422,7 @@ void DevicePluginPhilipsHue::networkManagerReplyReady()
|
|||||||
|
|
||||||
// check HTTP status code
|
// check HTTP status code
|
||||||
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
if (status != 200 || reply->error() != QNetworkReply::NoError) {
|
||||||
if (device->stateValue(remoteConnectedStateTypeId).toBool() || device->stateValue(tapConnectedStateTypeId).toBool()) {
|
if (device->stateValue(bridgeConnectedStateTypeId).toBool()) {
|
||||||
qCWarning(dcPhilipsHue) << "Refresh Hue sensors request error:" << status << reply->errorString();
|
qCWarning(dcPhilipsHue) << "Refresh Hue sensors request error:" << status << reply->errorString();
|
||||||
bridgeReachableChanged(device, false);
|
bridgeReachableChanged(device, false);
|
||||||
}
|
}
|
||||||
@ -764,11 +765,20 @@ void DevicePluginPhilipsHue::onUpnpDiscoveryFinished()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
params.append(Param(bridgeDeviceHostParamTypeId, upnpDevice.hostAddress().toString()));
|
params.append(Param(bridgeDeviceHostParamTypeId, upnpDevice.hostAddress().toString()));
|
||||||
|
params.append(Param(bridgeDeviceIdParamTypeId, upnpDevice.serialNumber().toLower()));
|
||||||
|
// Not known yet...
|
||||||
params.append(Param(bridgeDeviceApiKeyParamTypeId, QString()));
|
params.append(Param(bridgeDeviceApiKeyParamTypeId, QString()));
|
||||||
params.append(Param(bridgeDeviceMacParamTypeId, QString()));
|
params.append(Param(bridgeDeviceMacParamTypeId, QString()));
|
||||||
params.append(Param(bridgeDeviceIdParamTypeId, upnpDevice.serialNumber().toLower()));
|
|
||||||
params.append(Param(bridgeDeviceZigbeeChannelParamTypeId, -1));
|
params.append(Param(bridgeDeviceZigbeeChannelParamTypeId, -1));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
|
||||||
|
Device *dev = bridgeForBridgeId(upnpDevice.serialNumber().toLower());
|
||||||
|
if (dev) {
|
||||||
|
qCDebug(dcPhilipsHue()) << "Found already added Hue bridge:" << upnpDevice.serialNumber().toLower();
|
||||||
|
descriptor.setDeviceId(dev->id());
|
||||||
|
} else {
|
||||||
|
qCDebug(dcPhilipsHue()) << "Found new Hue bridge:" << upnpDevice.serialNumber().toLower();
|
||||||
|
}
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1289,13 +1299,6 @@ void DevicePluginPhilipsHue::processInformationResponse(PairingInfo *pairingInfo
|
|||||||
bridge->setName(response.value("name").toString());
|
bridge->setName(response.value("name").toString());
|
||||||
bridge->setZigbeeChannel(response.value("zigbeechannel").toInt());
|
bridge->setZigbeeChannel(response.value("zigbeechannel").toInt());
|
||||||
|
|
||||||
if (bridgeAlreadyAdded(bridge->id())) {
|
|
||||||
qCWarning(dcPhilipsHue) << "Bridge with id" << bridge->id() << "already added.";
|
|
||||||
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusFailure);
|
|
||||||
bridge->deleteLater();
|
|
||||||
pairingInfo->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_unconfiguredBridges.append(bridge);
|
m_unconfiguredBridges.append(bridge);
|
||||||
|
|
||||||
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusSuccess);
|
emit pairingFinished(pairingInfo->pairingTransactionId(), DeviceManager::DeviceSetupStatusSuccess);
|
||||||
@ -1345,6 +1348,8 @@ void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &
|
|||||||
light->setReachable(false);
|
light->setReachable(false);
|
||||||
if (m_lights.value(light)->deviceClassId() == colorLightDeviceClassId) {
|
if (m_lights.value(light)->deviceClassId() == colorLightDeviceClassId) {
|
||||||
m_lights.value(light)->setStateValue(colorLightConnectedStateTypeId, false);
|
m_lights.value(light)->setStateValue(colorLightConnectedStateTypeId, false);
|
||||||
|
} else if (m_lights.value(light)->deviceClassId() == colorTemperatureLightDeviceClassId) {
|
||||||
|
m_lights.value(light)->setStateValue(colorTemperatureLightConnectedStateTypeId, false);
|
||||||
} else if (m_lights.value(light)->deviceClassId() == dimmableLightDeviceClassId) {
|
} else if (m_lights.value(light)->deviceClassId() == dimmableLightDeviceClassId) {
|
||||||
m_lights.value(light)->setStateValue(dimmableLightConnectedStateTypeId, false);
|
m_lights.value(light)->setStateValue(dimmableLightConnectedStateTypeId, false);
|
||||||
}
|
}
|
||||||
@ -1366,16 +1371,17 @@ void DevicePluginPhilipsHue::bridgeReachableChanged(Device *device, const bool &
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginPhilipsHue::bridgeAlreadyAdded(const QString &id)
|
Device* DevicePluginPhilipsHue::bridgeForBridgeId(const QString &id)
|
||||||
{
|
{
|
||||||
foreach (Device *device, myDevices()) {
|
foreach (Device *device, myDevices()) {
|
||||||
if (device->deviceClassId() == bridgeDeviceClassId) {
|
if (device->deviceClassId() == bridgeDeviceClassId) {
|
||||||
if (device->paramValue(bridgeDeviceIdParamTypeId).toString() == id) {
|
qCDebug(dcPhilipsHue()) << "Have bridge" << device->name() << device->paramValue(bridgeDeviceIdParamTypeId).toString().toLower() << id;
|
||||||
return true;
|
if (device->paramValue(bridgeDeviceIdParamTypeId).toString().toLower() == id) {
|
||||||
|
return device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DevicePluginPhilipsHue::lightAlreadyAdded(const QString &uuid)
|
bool DevicePluginPhilipsHue::lightAlreadyAdded(const QString &uuid)
|
||||||
|
|||||||
@ -118,7 +118,7 @@ private:
|
|||||||
|
|
||||||
void bridgeReachableChanged(Device *device, const bool &reachable);
|
void bridgeReachableChanged(Device *device, const bool &reachable);
|
||||||
|
|
||||||
bool bridgeAlreadyAdded(const QString &id);
|
Device* bridgeForBridgeId(const QString &id);
|
||||||
bool lightAlreadyAdded(const QString &uuid);
|
bool lightAlreadyAdded(const QString &uuid);
|
||||||
bool sensorAlreadyAdded(const QString &uuid);
|
bool sensorAlreadyAdded(const QString &uuid);
|
||||||
|
|
||||||
|
|||||||
@ -154,8 +154,16 @@ DeviceManager::DeviceError DevicePluginUniPi::discoverDevices(const DeviceClassI
|
|||||||
DeviceDescriptor descriptor(deviceClassId, QString("Relay %1").arg(circuit), circuit);
|
DeviceDescriptor descriptor(deviceClassId, QString("Relay %1").arg(circuit), circuit);
|
||||||
ParamList parameters;
|
ParamList parameters;
|
||||||
parameters.append(Param(relayOutputDeviceNumberParamTypeId, circuit));
|
parameters.append(Param(relayOutputDeviceNumberParamTypeId, circuit));
|
||||||
|
|
||||||
descriptor.setParams(parameters);
|
descriptor.setParams(parameters);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(relayOutputDeviceNumberParamTypeId).toString() == circuit) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
emit devicesDiscovered(deviceClassId, deviceDescriptors);
|
||||||
|
|||||||
@ -254,6 +254,13 @@ void DevicePluginWemo::onUpnpDiscoveryFinished()
|
|||||||
params.append(Param(wemoSwitchDevicePortParamTypeId, upnpDeviceDescriptor.port()));
|
params.append(Param(wemoSwitchDevicePortParamTypeId, upnpDeviceDescriptor.port()));
|
||||||
params.append(Param(wemoSwitchDeviceSerialParamTypeId, upnpDeviceDescriptor.serialNumber()));
|
params.append(Param(wemoSwitchDeviceSerialParamTypeId, upnpDeviceDescriptor.serialNumber()));
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
|
||||||
|
foreach (Device *existingDevice, myDevices()) {
|
||||||
|
if (existingDevice->paramValue(wemoSwitchDeviceSerialParamTypeId).toString() == upnpDeviceDescriptor.serialNumber()) {
|
||||||
|
descriptor.setDeviceId(existingDevice->id());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
deviceDescriptors.append(descriptor);
|
deviceDescriptors.append(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user