Esempio n. 1
0
        private void DeviceFound(Device dev)
        {
            var ip       = IpUtil.GetIpFromHost(dev.Hostname);
            var ipString = ip == null ? "" : ip.ToString();
            var yd       = new YeelightData {
                Id = dev.Id, IpAddress = ipString, Name = dev.Name
            };

            _controlService.AddDevice(yd).ConfigureAwait(false);
        }
Esempio n. 2
0
 public LifxData(LightBulb b)
 {
     if (b == null)
     {
         throw new ArgumentException("Invalid bulb data.");
     }
     HostName         = b.HostName;
     IpAddress        = IpUtil.GetIpFromHost(HostName).ToString();
     Id               = b.MacAddressName;
     Service          = b.Service;
     Port             = (int)b.Port;
     MacAddress       = b.MacAddress;
     MacAddressString = b.MacAddressName;
 }
Esempio n. 3
0
        /// <summary>
        ///     Use this for sending color data to the panel
        /// </summary>
        /// <param name="n"></param>
        /// <param name="cs"></param>
        public NanoleafDevice(NanoleafData n, ColorService cs) : base(cs)
        {
            _brightness = -1;
            _targets    = new Dictionary <int, int>();
            _data       = n;
            Id          = _data.Id;
            var streamMode     = n.Type is "NL29" or "NL42" ? 2 : 1;
            var controlService = cs.ControlService;
            var host           = n.IpAddress;

            try {
                var ip = IpUtil.GetIpFromHost(n.IpAddress);
                if (ip != null)
                {
                    host = ip.ToString();
                }
                else
                {
                    if (host.Contains(".local"))
                    {
                        host = host.Replace(".local", "");
                        ip   = IpUtil.GetIpFromHost(host);
                    }
                }

                if (ip != null)
                {
                    host = ip.ToString();
                }
            } catch (Exception) {
                //ignored
            }

            try {
                Log.Debug("Creating nano client: " + host);
                _nanoleafClient = new NanoleafClient(host, n.Token);
                Log.Debug("Nano client created.");
                _streamingClient = new NanoleafStreamingClient(host, streamMode, controlService.UdpClient);
            } catch (Exception e) {
                Log.Debug("Exception creating client..." + e.Message);
            }

            _frameWatch = new Stopwatch();
            SetData();
            controlService.RefreshSystemEvent += SetData;
            _disposed = false;
            cs.ColorSendEventAsync += SetColors;
        }