public Task <bool> SendCommand(int id, TelldusDeviceMethods command)
        {
            lock (queueLock)
            {
                // if same device is already in queue, remove it
                if (sendQueue.Any(i => i.DeviceID == id))
                {
                    sendQueue = sendQueue.Where(i => i.DeviceID != id).ToQueue();
                }

                string[] telldusControllers = configuration.GetSection("Telldus:APIURL").Get <string[]>();
                for (int i = 0; i < telldusControllers.Length; i++)
                {
                    QueueItem item = new QueueItem {
                        DeviceID = id, Command = command, ControllerUrl = telldusControllers[i]
                    };

                    // add one first to queue, so it will be executed next
                    var list = sendQueue.ToList();
                    list.Insert(i, item);
                    sendQueue = list.ToQueue();

                    // and then the other last in the queue, so total 2 tries per controller
                    sendQueue.Enqueue(item);
                }

                if (!isQueueProcessing)
                {
                    isQueueProcessing = true;
                    Task.Run(ExecuteSendCommand);
                }
            }

            return(Task.FromResult(true));
        }
        public DeviceEvent ConvertCommandToEvent(TelldusDeviceMethods command)
        {
            switch (command)
            {
            case TelldusDeviceMethods.TurnOn: return(DeviceEvent.On);

            case TelldusDeviceMethods.TurnOff: return(DeviceEvent.Off);

            default: return(DeviceEvent.Unknown);
            }
        }
        private bool IsDuplicateRequest(int deviceId, TelldusDeviceMethods command, string parameter)
        {
            string requestKey = $"{deviceId}|{command}";

            if (command == TelldusDeviceMethods.Dim)
            {
                requestKey = $"{deviceId}|{command}|{parameter}";
            }

            return(IsDuplicateRequest(requestKey));
        }
        public async Task <IActionResult> SendCommand(int deviceId, TelldusDeviceMethods command)
        {
            var result = await telldusAPIService.SendCommand(deviceId, command);

            return(Ok(result));
        }