public ActionResult SendIr(string id, int port, string codeType, string data)
        {
            var codes = new List <IrCode>();

            foreach (var code in data.Split('|').Select(x => x.Split(':')).ToList())
            {
                var d      = Convert.ToUInt32(code[0], 16);
                var b      = uint.Parse(code[1]);
                var irCode = new IrCode {
                    Bits = b, Data = d
                };
                codes.Add(irCode);
            }


            var device = _deviceRepository.FindById(id);

            if (device == null)
            {
                return(HttpNotFound($"The device with {id} does not exist."));
            }

            var feature = device.GetFeatureByPort <IrOutFeature>(port);

            feature.Send(codeType, codes);

            return(RedirectToAction("Device", new { id }));
        }
        public async Task <IrCode> CreateIrCode(string name, string code, ExecutionCommand executionCommand)
        {
            CheckInitialized();

            var device = await GetDeviceAsync();

            var irCodes = await GetIrAsync();

            if (irCodes.Codes.Count() >= device.Capabilities.MaxIrCodes)
            {
                throw new InvalidOperationException($"the max amount of ir codes ({device.Capabilities.MaxIrCodes}) has been reached.");
            }

            var irCode = new IrCode()
            {
                ExecutionCommand = executionCommand,
                Name             = name
            };

            var client = await GetHttpClient().ConfigureAwait(false);

            var response = await client.PostAsync(new Uri($"{_apiBase}/api/v1/ir/codes/{code}"), SerializeRequest(irCode)).ConfigureAwait(false);

            return(await HandleResponseAsync <IrCode>(response));
        }
        public async Task UpdateIrCode(IrCode code)
        {
            CheckInitialized();

            var client = await GetHttpClient().ConfigureAwait(false);

            var response = await client.PutAsync(new Uri($"{_apiBase}/api/v1/ir/codes/{code.Code}"), SerializeRequest(code)).ConfigureAwait(false);

            await HandleResponseAsync(response);
        }
Пример #4
0
 void SetId()
 {
     Id = Name.GetHashCode() * 1000 + IrCode.GetHashCode();
 }