private static async Task <bool> SetDevicesEnabled(string devs, bool enabled) { bool allDevices = devs == "*"; // get device with uuid if it exists, devs can be single device uuid var deviceWithUUID = AvailableDevices.GetDeviceWithUuidOrB64Uuid(devs); // Check if RPC should execute // check if redundant rpc if (allDevices && enabled && AvailableDevices.IsEnableAllDevicesRedundantOperation()) { throw new RpcException("All devices are already enabled.", ErrorCode.RedundantRpc); } // all disable if (allDevices && !enabled && AvailableDevices.IsDisableAllDevicesRedundantOperation()) { throw new RpcException("All devices are already disabled.", ErrorCode.RedundantRpc); } // if single and doesn't exist if (!allDevices && deviceWithUUID == null) { throw new RpcException("Device not found", ErrorCode.NonExistentDevice); } // if we have the device but it is redundant if (!allDevices && deviceWithUUID.IsDisabled == !enabled) { var stateStr = enabled ? "enabled" : "disabled"; throw new RpcException($"Devices with uuid {devs} is already {stateStr}.", ErrorCode.RedundantRpc); } // if got here than we can execute the call await ApplicationStateManager.SetDeviceEnabledState(null, (devs, enabled)); // TODO invoke the event for controls that use it //OnDeviceUpdate?.Invoke(null, new DeviceUpdateEventArgs(AvailableDevices.Devices.ToList())); return(true); }