Merge PR #214: Allow the "All lights off" button to also turn all lights on

This commit is contained in:
Jenkins 2019-07-05 01:25:33 +02:00
commit 099c505977
4 changed files with 26 additions and 21 deletions

View File

@ -32,7 +32,7 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
QGuiApplication *app = static_cast<QGuiApplication*>(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();
});

View File

@ -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";

View File

@ -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)
}

View File

@ -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":