Merge PR #214: Allow the "All lights off" button to also turn all lights on
This commit is contained in:
commit
099c505977
@ -32,7 +32,7 @@ NymeaConnection::NymeaConnection(QObject *parent) : QObject(parent)
|
|||||||
|
|
||||||
QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance());
|
QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance());
|
||||||
QObject::connect(app, &QGuiApplication::applicationStateChanged, this, [this](Qt::ApplicationState state) {
|
QObject::connect(app, &QGuiApplication::applicationStateChanged, this, [this](Qt::ApplicationState state) {
|
||||||
qDebug() << "Application state changed to:" << state;
|
// qDebug() << "Application state changed to:" << state;
|
||||||
updateActiveBearers();
|
updateActiveBearers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ void DeviceManager::notificationReceived(const QVariantMap &data)
|
|||||||
{
|
{
|
||||||
QString notification = data.value("notification").toString();
|
QString notification = data.value("notification").toString();
|
||||||
if (notification == "Devices.StateChanged") {
|
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());
|
Device *dev = m_devices->getDevice(data.value("params").toMap().value("deviceId").toUuid());
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
qWarning() << "Device state change notification received for an unknown device";
|
qWarning() << "Device state change notification received for an unknown device";
|
||||||
|
|||||||
@ -15,6 +15,15 @@ DeviceListPageBase {
|
|||||||
HeaderButton {
|
HeaderButton {
|
||||||
imageSource: "../images/system-shutdown.svg"
|
imageSource: "../images/system-shutdown.svg"
|
||||||
onClicked: {
|
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++) {
|
for (var i = 0; i < devicesProxy.count; i++) {
|
||||||
var device = devicesProxy.get(i);
|
var device = devicesProxy.get(i);
|
||||||
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
var deviceClass = engine.deviceManager.deviceClasses.getDeviceClass(device.deviceClassId);
|
||||||
@ -23,7 +32,7 @@ DeviceListPageBase {
|
|||||||
var params = [];
|
var params = [];
|
||||||
var param1 = {};
|
var param1 = {};
|
||||||
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
param1["value"] = false;
|
param1["value"] = allOff ? true : false;
|
||||||
params.push(param1)
|
params.push(param1)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params)
|
engine.deviceManager.executeAction(device.id, actionType.id, params)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -320,30 +320,26 @@ MainPageTile {
|
|||||||
switch (model.name) {
|
switch (model.name) {
|
||||||
case "light":
|
case "light":
|
||||||
case "powersocket":
|
case "powersocket":
|
||||||
if (devicesProxy.count == 1) {
|
var allOff = true;
|
||||||
var device = devicesProxy.get(0);
|
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 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 params = [];
|
||||||
var param1 = {};
|
var param1 = {};
|
||||||
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
param1["paramTypeId"] = actionType.paramTypes.get(0).id;
|
||||||
param1["value"] = !device.states.getState(stateType.id).value;
|
param1["value"] = allOff ? true : false;
|
||||||
params.push(param1)
|
params.push(param1)
|
||||||
engine.deviceManager.executeAction(device.id, actionType.id, params)
|
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;
|
break;
|
||||||
case "media":
|
case "media":
|
||||||
|
|||||||
Reference in New Issue
Block a user