Ejemplo n.º 1
0
        public async Task UpdateExistingBridges()
        {
            IBridgeLocator       locator = new HttpBridgeLocator();
            List <LocatedBridge> bridges = (await locator.LocateBridgesAsync(TimeSpan.FromSeconds(5))).ToList();

            // Lets try to find some more
            locator = new SsdpBridgeLocator();
            IEnumerable <LocatedBridge> extraBridges = await locator.LocateBridgesAsync(TimeSpan.FromSeconds(5));

            foreach (LocatedBridge extraBridge in extraBridges)
            {
                if (bridges.All(b => b.BridgeId != extraBridge.BridgeId))
                {
                    bridges.Add(extraBridge);
                }
            }

            int updatedBridges = 0;

            foreach (LocatedBridge locatedBridge in bridges)
            {
                PhilipsHueBridge storedBridge = _storedBridgesSetting.Value.FirstOrDefault(s => s.BridgeId == locatedBridge.BridgeId);
                if (storedBridge != null && storedBridge.IpAddress != locatedBridge.IpAddress)
                {
                    storedBridge.IpAddress = locatedBridge.IpAddress;
                    updatedBridges++;
                }
            }

            if (updatedBridges > 0)
            {
                _storedBridgesSetting.Save();
                _logger.Information("Updated IP addresses of {updatedBridges} Hue Bridge(s)", updatedBridges);
            }
        }
Ejemplo n.º 2
0
        public static LocatedBridge[] FindBridges(int time = 2)
        {
            Console.WriteLine(@"Hue: Looking for bridges...");
            IBridgeLocator locator = new SsdpBridgeLocator();
            var            res     = locator.LocateBridgesAsync(TimeSpan.FromSeconds(time)).Result;

            Console.WriteLine($@"Result: {JsonConvert.SerializeObject(res)}");
            return(res.ToArray());
        }