mirror of https://github.com/nymea/nymea.git
fix hue plugin and improve network detector shutdown mechanism
parent
7a4c0ab454
commit
dd495719b1
|
|
@ -54,11 +54,30 @@
|
|||
|
||||
DevicePluginNetworkDetector::DevicePluginNetworkDetector():
|
||||
m_discoveryProcess(0),
|
||||
m_scanProcess(0)
|
||||
m_scanProcess(0),
|
||||
m_aboutToQuit(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DevicePluginNetworkDetector::~DevicePluginNetworkDetector()
|
||||
{
|
||||
// Stop running processes
|
||||
m_aboutToQuit = true;
|
||||
|
||||
if (m_scanProcess && m_scanProcess->state() == QProcess::Running) {
|
||||
qCDebug(dcNetworkDetector()) << "Kill running scan process";
|
||||
m_scanProcess->kill();
|
||||
m_scanProcess->waitForFinished(5000);
|
||||
}
|
||||
|
||||
if (m_discoveryProcess && m_discoveryProcess->state() == QProcess::Running) {
|
||||
qCDebug(dcNetworkDetector()) << "Kill running discovery process";
|
||||
m_discoveryProcess->terminate();
|
||||
m_discoveryProcess->waitForFinished(5000);
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device *device)
|
||||
{
|
||||
qCDebug(dcNetworkDetector()) << "Setup" << device->name() << device->params();
|
||||
|
|
@ -183,6 +202,10 @@ void DevicePluginNetworkDetector::processFinished(int exitCode, QProcess::ExitSt
|
|||
{
|
||||
QProcess *process = static_cast<QProcess*>(sender());
|
||||
|
||||
// If the process was killed because guhd is shutting down...we dont't care any more about the result
|
||||
if (m_aboutToQuit)
|
||||
return;
|
||||
|
||||
// Discovery
|
||||
if (process == m_discoveryProcess) {
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class DevicePluginNetworkDetector : public DevicePlugin
|
|||
|
||||
public:
|
||||
explicit DevicePluginNetworkDetector();
|
||||
~DevicePluginNetworkDetector();
|
||||
|
||||
DeviceManager::DeviceSetupStatus setupDevice(Device *device) override;
|
||||
DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override;
|
||||
|
|
@ -50,6 +51,8 @@ private:
|
|||
|
||||
QXmlStreamReader m_reader;
|
||||
|
||||
bool m_aboutToQuit;
|
||||
|
||||
QStringList getDefaultTargets();
|
||||
QProcess *startScanProcesses();
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ DevicePluginPhilipsHue::DevicePluginPhilipsHue()
|
|||
{
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setSingleShot(false);
|
||||
m_timer->setInterval(2000);
|
||||
m_timer->setInterval(5000);
|
||||
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout()));
|
||||
}
|
||||
|
|
@ -490,11 +490,11 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
|
|||
m_asyncActions.insert(networkManagerPut(request.first, request.second),QPair<Device *, ActionId>(device, action.id()));
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
} else if (action.actionTypeId() == hueAlertActionTypeId) {
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(hueEffectStateParamTypeId).value().toString());
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(alertParamTypeId).value().toString());
|
||||
m_asyncActions.insert(networkManagerPut(request.first, request.second),QPair<Device *, ActionId>(device, action.id()));
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
} else if (action.actionTypeId() == hueTemperatureActionTypeId) {
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(hueColorStateParamTypeId).value().toInt());
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createSetTemperatureRequest(action.param(hueTemperatureStateParamTypeId).value().toInt());
|
||||
m_asyncActions.insert(networkManagerPut(request.first, request.second),QPair<Device *, ActionId>(device, action.id()));
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
|
@ -519,7 +519,7 @@ DeviceManager::DeviceError DevicePluginPhilipsHue::executeAction(Device *device,
|
|||
m_asyncActions.insert(networkManagerPut(request.first, request.second),QPair<Device *, ActionId>(device, action.id()));
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
} else if (action.actionTypeId() == hueAlertActionTypeId) {
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(hueEffectStateParamTypeId).value().toString());
|
||||
QPair<QNetworkRequest, QByteArray> request = light->createFlashRequest(action.param(alertParamTypeId).value().toString());
|
||||
m_asyncActions.insert(networkManagerPut(request.first, request.second),QPair<Device *, ActionId>(device, action.id()));
|
||||
return DeviceManager::DeviceErrorAsync;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,8 +334,8 @@
|
|||
"type": "QString",
|
||||
"index": 0,
|
||||
"allowedValues": [
|
||||
"flash once",
|
||||
"flash 30 seconds"
|
||||
"flash",
|
||||
"flash 15 [s]"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -476,8 +476,8 @@
|
|||
"type": "QString",
|
||||
"index": 0,
|
||||
"allowedValues": [
|
||||
"flash once",
|
||||
"flash 30 seconds"
|
||||
"flash",
|
||||
"flash 15 [s]"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -144,7 +144,10 @@ QPair<QNetworkRequest, QByteArray> HueBridge::createCheckUpdatesRequest()
|
|||
updateMap.insert("checkforupdate", true);
|
||||
|
||||
QVariantMap requestMap;
|
||||
requestMap.insert("portalservices", true);
|
||||
|
||||
// TODO: check if portalservice is true, cannot be done in one step
|
||||
//requestMap.insert("portalservices", true);
|
||||
|
||||
requestMap.insert("swupdate", updateMap);
|
||||
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(requestMap);
|
||||
|
|
|
|||
|
|
@ -201,6 +201,8 @@ void HueLight::processActionResponse(const QVariantList &responseList)
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createSetPowerRequest(const bool &power)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create power request" << power;
|
||||
|
||||
QVariantMap requestMap;
|
||||
requestMap.insert("on", power);
|
||||
|
||||
|
|
@ -214,6 +216,8 @@ QPair<QNetworkRequest, QByteArray> HueLight::createSetPowerRequest(const bool &p
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createSetColorRequest(const QColor &color)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create color request" << color.toRgb();
|
||||
|
||||
QVariantMap requestMap;
|
||||
requestMap.insert("hue", color.hue() * 65535 / 360);
|
||||
requestMap.insert("sat", color.saturation());
|
||||
|
|
@ -229,6 +233,8 @@ QPair<QNetworkRequest, QByteArray> HueLight::createSetColorRequest(const QColor
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createSetBrightnessRequest(const int &brightness)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create brightness request" << brightness;
|
||||
|
||||
QVariantMap requestMap;
|
||||
requestMap.insert("bri", brightness);
|
||||
if (brightness == 0) {
|
||||
|
|
@ -247,6 +253,8 @@ QPair<QNetworkRequest, QByteArray> HueLight::createSetBrightnessRequest(const in
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createSetEffectRequest(const QString &effect)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create effect request" << effect;
|
||||
|
||||
QVariantMap requestMap;
|
||||
if (effect == "none") {
|
||||
requestMap.insert("effect", "none");
|
||||
|
|
@ -264,6 +272,8 @@ QPair<QNetworkRequest, QByteArray> HueLight::createSetEffectRequest(const QStrin
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createSetTemperatureRequest(const int &colorTemp)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create color temperature request" << colorTemp;
|
||||
|
||||
QVariantMap requestMap;
|
||||
requestMap.insert("ct", colorTemp);
|
||||
requestMap.insert("on", true);
|
||||
|
|
@ -278,10 +288,12 @@ QPair<QNetworkRequest, QByteArray> HueLight::createSetTemperatureRequest(const i
|
|||
|
||||
QPair<QNetworkRequest, QByteArray> HueLight::createFlashRequest(const QString &alert)
|
||||
{
|
||||
qCDebug(dcPhilipsHue()) << "Create flash request" << alert;
|
||||
|
||||
QVariantMap requestMap;
|
||||
if (alert == "flash once") {
|
||||
if (alert == "flash") {
|
||||
requestMap.insert("alert", "select");
|
||||
} else if (alert == "flash 30 seconds") {
|
||||
} else if (alert == "flash 15 [s]") {
|
||||
requestMap.insert("alert", "lselect");
|
||||
}
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromVariant(requestMap);
|
||||
|
|
|
|||
Loading…
Reference in New Issue