重建我的代码。我只能关闭阵列中的设备,但我想做相反的事情,关闭阵列中所有设备(但设备除外)。 如何交换?我正在使用!=(不等于),但它对此并不在意。
let devices = await Homey.devices.getDevices();
var DeviceNames = [
"Kitchentable - Right",
"Kitchentable - Middle",
"Kitchentable - Left"
];
DeviceNames.forEach(function(element) {
_.forEach(devices, device => {
if(device.class != 'light') return;
if(!device.state.onoff) return;
if(device.name != element) return;
device.setCapabilityValue('onoff', false);
console.log(device.name);
}
});
return true;
控制台输出
Kitchentable - Right
Kitchentable - Middle
Kitchentable - Left
----------------
Script returned:
true