Allow the "All lights off" button to also turn all lights on

This commit is contained in:
Michael Zanetti 2019-06-28 01:35:13 +02:00
parent 58d4be66f5
commit b39c05b161
4 changed files with 28 additions and 23 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();
});
@ -388,9 +388,9 @@ void NymeaConnection::updateActiveBearers()
{
NymeaConnection::BearerTypes availableBearerTypes;
QList<QNetworkConfiguration> 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)

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