From b39c05b1616dc68a3ca4c2f535cf72ad9fb455fc Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 28 Jun 2019 01:35:13 +0200 Subject: [PATCH] Allow the "All lights off" button to also turn all lights on --- .../connection/nymeaconnection.cpp | 6 ++-- libnymea-app-core/devicemanager.cpp | 2 +- .../devicelistpages/LightsDeviceListPage.qml | 11 ++++++- .../ui/mainviews/DevicesPageDelegate.qml | 32 ++++++++----------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/libnymea-app-core/connection/nymeaconnection.cpp b/libnymea-app-core/connection/nymeaconnection.cpp index 17a0ca73..f8f251b5 100644 --- a/libnymea-app-core/connection/nymeaconnection.cpp +++ b/libnymea-app-core/connection/nymeaconnection.cpp @@ -32,7 +32,7 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent) QGuiApplication *app = static_cast(QGuiApplication::instance()); QObject::connect(app, &QGuiApplication::applicationStateChanged, this, [this](Qt::ApplicationState state) { - qDebug() << "Application state changed to:" << state; +// qDebug() << "Application state changed to:" << state; updateActiveBearers(); }); @@ -388,9 +388,9 @@ void NymeaConnection::updateActiveBearers() { NymeaConnection::BearerTypes availableBearerTypes; QList configs = m_networkConfigManager->allConfigurations(QNetworkConfiguration::Active); - qDebug() << "Network configuations:" << configs.count(); +// qDebug() << "Network configuations:" << configs.count(); foreach (const QNetworkConfiguration &config, configs) { - qDebug() << "Active network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName(); +// qDebug() << "Active network config:" << config.name() << config.bearerTypeFamily() << config.bearerTypeName(); // NOTE: iOS doesn't correctly report bearer types. It'll be Unknown all the time. Let's hardcode it to WiFi for that... #if defined(Q_OS_IOS) diff --git a/libnymea-app-core/devicemanager.cpp b/libnymea-app-core/devicemanager.cpp index 07dcb704..4332f3e9 100644 --- a/libnymea-app-core/devicemanager.cpp +++ b/libnymea-app-core/devicemanager.cpp @@ -93,7 +93,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data) { QString notification = data.value("notification").toString(); 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()); if (!dev) { qWarning() << "Device state change notification received for an unknown device"; diff --git a/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml b/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml index facc4476..367e5648 100644 --- a/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml +++ b/nymea-app/ui/devicelistpages/LightsDeviceListPage.qml @@ -15,6 +15,15 @@ DeviceListPageBase { HeaderButton { imageSource: "../images/system-shutdown.svg" onClicked: { + var allOff = true; + for (var i = 0; i < devicesProxy.count; i++) { + var device = devicesProxy.get(i); + if (device.states.getState(device.deviceClass.stateTypes.findByName("power").id).value === true) { + allOff = false; + break; + } + } + for (var i = 0; i < devicesProxy.count; i++) { var device = devicesProxy.get(i); var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); @@ -23,7 +32,7 @@ DeviceListPageBase { var params = []; var param1 = {}; param1["paramTypeId"] = actionType.paramTypes.get(0).id; - param1["value"] = false; + param1["value"] = allOff ? true : false; params.push(param1) engine.deviceManager.executeAction(device.id, actionType.id, params) } diff --git a/nymea-app/ui/mainviews/DevicesPageDelegate.qml b/nymea-app/ui/mainviews/DevicesPageDelegate.qml index 88df04e2..da93c081 100644 --- a/nymea-app/ui/mainviews/DevicesPageDelegate.qml +++ b/nymea-app/ui/mainviews/DevicesPageDelegate.qml @@ -320,30 +320,26 @@ MainPageTile { switch (model.name) { case "light": case "powersocket": - if (devicesProxy.count == 1) { - var device = devicesProxy.get(0); + var allOff = true; + for (var i = 0; i < devicesProxy.count; i++) { + var device = devicesProxy.get(i); + if (device.states.getState(device.deviceClass.stateTypes.findByName("power").id).value === true) { + allOff = false; + break; + } + } + + for (var i = 0; i < devicesProxy.count; i++) { + var device = devicesProxy.get(i); var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var stateType = deviceClass.stateTypes.findByName("power") - var actionType = deviceClass.actionTypes.findByName("power") + var actionType = deviceClass.actionTypes.findByName("power"); + var params = []; var param1 = {}; param1["paramTypeId"] = actionType.paramTypes.get(0).id; - param1["value"] = !device.states.getState(stateType.id).value; + param1["value"] = allOff ? true : false; params.push(param1) engine.deviceManager.executeAction(device.id, actionType.id, params) - } else { - for (var i = 0; i < devicesProxy.count; i++) { - var device = devicesProxy.get(i); - var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId); - var actionType = deviceClass.actionTypes.findByName("power"); - - var params = []; - var param1 = {}; - param1["paramTypeId"] = actionType.paramTypes.get(0).id; - param1["value"] = false; - params.push(param1) - engine.deviceManager.executeAction(device.id, actionType.id, params) - } } break; case "media":