コード例 #1
0
        private void DeviceDiscovered(object?sender, ServiceInstanceDiscoveryEventArgs e)
        {
            var foo = e.Message;

            if (!foo.ToString().Contains("_wled"))
            {
                return;
            }

            var name = e.ServiceInstanceName.ToString();

            if (name.Contains(".local"))
            {
                name = name.Split(".")[0];
            }

            if (_ids.Contains(name))
            {
                return;
            }

            try {
                var rr = e.Message.AdditionalRecords;
                var ip = string.Empty;
                var id = string.Empty;


                foreach (var msg in rr)
                {
                    switch (msg.Type)
                    {
                    // Extract IP
                    case DnsType.A:
                        ip = msg.ToString().Split(" ").Last();
                        break;

                    // Extract Mac
                    case DnsType.TXT:
                        id = msg.ToString().Split("=")[1];
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(ip))
                {
                    var nData = new WledData(id, ip)
                    {
                        Name = name
                    };
                    ControlService.AddDevice(nData).ConfigureAwait(false);
                    _ids.Add(id);
                }
                else
                {
                    Log.Warning("Unable to get data for wled.");
                }
            } catch (Exception p) {
                Log.Warning("WLED Discovery Exception: " + p.Message);
            }
        }
コード例 #2
0
ファイル: WledDevice.cs プロジェクト: d8ahazard/glimmr
 public WledDevice(WledData wd, ColorService cs) : base(cs)
 {
     _segments = Array.Empty <WledSegment>();
     cs.ControlService.RefreshSystemEvent += RefreshSystem;
     _udpClient  = cs.ControlService.UdpClient;
     _httpClient = cs.ControlService.HttpSender;
     _data       = wd ?? throw new ArgumentException("Invalid WLED data.");
     Id          = _data.Id;
     IpAddress   = _data.IpAddress;
     _brightness = _data.Brightness;
     _multiplier = _data.LedMultiplier;
     ReloadData();
     cs.ColorSendEventAsync += SetColors;
 }