Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void DevFound(object?sender, DreamScreenClient.DeviceDiscoveryEventArgs e)
        {
            Log.Debug("Dream Device found??");
            var dd = new DreamScreenData(e.Device);

            Log.Debug("Got one: " + JsonConvert.SerializeObject(dd));
            _cs.AddDevice(dd).ConfigureAwait(false);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private async void Client_DeviceDiscovered(object?sender, LifxClient.DeviceDiscoveryEventArgs e)
        {
            var bulb = e.Device;

            if (bulb == null)
            {
                return;
            }

            //Log.Debug("Device found: " + JsonConvert.SerializeObject(bulb));
            var ld = await GetBulbInfo(bulb);

            if (ld == null)
            {
                return;
            }

            Log.Debug("Adding device: " + JsonConvert.SerializeObject(ld));
            await _controlService.AddDevice(ld);
        }
Exemplo n.º 5
0
        public async Task Discover(CancellationToken ct, int timeout)
        {
            DataUtil.DeleteDevice("2");

            if (!SystemUtil.IsRaspberryPi())
            {
                DataUtil.DeleteDevice("0");
                DataUtil.DeleteDevice("1");
                Log.Debug("No, really, this is not a pi, we shouldn't be creating GPIO stuff here.");
                return;
            }

            var ld0 = new LedData {
                Id = "0", Brightness = 255, GpioNumber = 18, Enable = true
            };
            var ld1 = new LedData {
                Id = "1", Brightness = 255, GpioNumber = 19
            };

            await ControlService.AddDevice(ld0);

            await ControlService.AddDevice(ld1);
        }
Exemplo n.º 6
0
        public async Task Discover(CancellationToken ct, int timeout)
        {
            var sd   = DataUtil.GetSystemData();
            var baud = sd.BaudRate;

            Log.Debug("Adalight: Discovery started.");
            var discoTask = Task.Run(() => {
                var devs = new Dictionary <string, KeyValuePair <int, int> >();
                try {
                    devs = FindDevices(baud);
                } catch (Exception e) {
                    Log.Debug("Exception: " + e.Message);
                }

                Log.Debug("Found" + devs.Count + " devices.");

                foreach (var(key, value) in devs)
                {
                    var count = value.Key;
                    var bri   = value.Value;
                    try {
                        Log.Debug("Trying: " + key);
                        var ac = new AdalightNet.Adalight(key, 20, baud);
                        ac.Connect();
                        if (ac.Connected)
                        {
                            Log.Debug("Connected.");
                            var foo = ac.GetState();
                            count   = foo[0];
                            bri     = foo[0];
                            ac.Disconnect();
                            ac.Dispose();
                            Log.Debug("State got, done.");
                        }
                        else
                        {
                            Log.Debug("Not connected...");
                        }
                    } catch (Exception e) {
                        Log.Debug("Discovery exception: " + e.Message + " at " + e.StackTrace);
                    }


                    var data = new AdalightData(key, count)
                    {
                        Speed = baud
                    };
                    Log.Debug("Creating device.");
                    if (bri != 0)
                    {
                        data.Brightness = bri;
                    }

                    ControlService.AddDevice(data).ConfigureAwait(false);
                    Log.Debug("And added...");
                }
            }, ct);
            await discoTask;

            Log.Debug("Adalight: Discovery complete.");
        }