Exemplo n.º 1
0
        public async Task <dynamic> CheckAuthAsync(dynamic deviceData)
        {
            var nanoleaf = new NanoleafClient(deviceData.IpAddress, "");

            try {
                var result = await nanoleaf.CreateTokenAsync();

                Log.Debug("Authorized.");
                if (!string.IsNullOrEmpty(result.Token))
                {
                    deviceData.Token = result.Token;
                    nanoleaf.Dispose();
                    nanoleaf = new NanoleafClient(deviceData.IpAddress, result.Token);
                    var layout = await nanoleaf.GetLayoutAsync();

                    deviceData.Layout = new TileLayout(layout);
                    Log.Debug("New nano info: " + JsonConvert.SerializeObject(deviceData));
                }
            } catch (Exception e) {
                Log.Debug("Nanoleaf Discovery Exception: " + e.Message);
            }

            nanoleaf.Dispose();
            return(deviceData);
        }
Exemplo n.º 2
0
        public async Task <UserToken> CheckAuth()
        {
            var       nanoleaf = new NanoleafClient(IpAddress);
            UserToken result   = null;

            try {
                result = await nanoleaf.CreateTokenAsync().ConfigureAwait(false);

                LogUtil.Write("Authorized.");
            } catch (AggregateException e) {
                LogUtil.Write("Unauthorized Exception: " + e.Message);
            }

            nanoleaf.Dispose();
            return(result);
        }