fix removing hue devices when there's still a request going on

master
Michael Zanetti 2018-07-02 23:19:34 +02:00
parent 0b05a72d46
commit 18bb1a4cfd
2 changed files with 19 additions and 0 deletions

View File

@ -240,6 +240,15 @@ DeviceManager::DeviceSetupStatus DevicePluginPhilipsHue::setupDevice(Device *dev
void DevicePluginPhilipsHue::deviceRemoved(Device *device)
{
abortRequests(m_lightRefreshRequests, device);
abortRequests(m_lightSetNameRequests, device);
abortRequests(m_bridgeRefreshRequests, device);
abortRequests(m_lightsRefreshRequests, device);
abortRequests(m_sensorsRefreshRequests, device);
abortRequests(m_bridgeLightsDiscoveryRequests, device);
abortRequests(m_bridgeSensorsDiscoveryRequests, device);
abortRequests(m_bridgeSearchDevicesRequests, device);
if (device->deviceClassId() == hueBridgeDeviceClassId) {
HueBridge *bridge = m_bridges.key(device);
m_bridges.remove(bridge);
@ -1335,3 +1344,12 @@ int DevicePluginPhilipsHue::percentageToBrightness(int percentage)
{
return qRound((255.0 * percentage) / 100.0);
}
void DevicePluginPhilipsHue::abortRequests(QHash<QNetworkReply *, Device *> requestList, Device *device)
{
foreach (QNetworkReply* reply, requestList.keys()) {
if (requestList.value(reply) == device) {
reply->abort();
}
}
}

View File

@ -123,6 +123,7 @@ private:
int brightnessToPercentage(int brightness);
int percentageToBrightness(int percentage);
void abortRequests(QHash<QNetworkReply *, Device *> requestList, Device* device);
};
#endif // DEVICEPLUGINBOBLIGHT_H