Exemple #1
0
        public void UpdateDeviceTest()
        {
            var manager = new InsteonDataManager(true);
            var device  = new InsteonDeviceModel()
            {
                Address     = "34.55.66",
                Category    = 0x01,
                SubCategory = 0x02,
                DisplayName = "Test Device",
                Firmware    = 0x45
            };

            var id = manager.Add(device);

            id.Should().Be(1);

            device.Id = 1;

            var d = manager.GetByAddress(device.Address);

            d.Should().NotBeNull();
            d.Address.Should().Be(device.Address);
            d.Category.Should().Be(device.Category);

            device.Category = 0x04;
            manager.Update(device);

            device.Category.Should().Be(0x04);
            d = manager.GetByAddress(device.Address);
            d.Address.Should().Be(device.Address);
            d.Category.Should().Be(device.Category);
        }
Exemple #2
0
        private void DevicesOnDeviceAdded(object sender, InsteonDeviceEventArgs data)
        {
            logger.Debug("Device added.");

            var dataManager = new InsteonDataManager(false);
            var found       = dataManager.GetByAddress(data.Device.Address.ToString());

            if (found != null)
            {
                // update
                found.Category    = data.Device.Identity.DevCat;
                found.SubCategory = data.Device.Identity.SubCat;
                found.Firmware    = data.Device.Identity.FirmwareVersion;
                found.ProductKey  = data.Device.Identity.ProductKey?.StringKey();
                dataManager.Update(found);
            }
            else
            {
                // insert
                dataManager.Add(new InsteonDeviceModel()
                {
                    Address     = data.Device.Address.ToString(),
                    Category    = data.Device.Identity.DevCat,
                    SubCategory = data.Device.Identity.SubCat,
                    Firmware    = data.Device.Identity.FirmwareVersion,
                    ProductKey  = data.Device.Identity.ProductKey?.StringKey()
                });
            }
        }
Exemple #3
0
        public void RefreshDeviceDatabase()
        {
            var dataManager = new InsteonDataManager(false);

            Network.Devices.DeviceAdded -= DevicesOnDeviceAdded;

            var allLinks         = Network.Controller.GetDeviceLinkRecords(true);
            var insteonAddresses = allLinks.Select(l => l.Address).Distinct();

            // TODO: modify this so that we can call refresh when devices exist, and update netowrk items and db as necessary

            foreach (var insteonAddress in insteonAddresses)
            {
                if (Network.Devices.ContainsKey(insteonAddress))
                {
                    continue;
                }

                if (dataManager.GetByAddress(insteonAddress.ToString()) != null)
                {
                    continue;
                }

                InsteonIdentity?id;
                if (Network.Controller.TryGetLinkIdentity(insteonAddress, out id))
                {
                    if (id != null)
                    {
                        var d = Network.Devices.Add(insteonAddress, id.Value);

                        dataManager.Add(new InsteonDeviceModel()
                        {
                            Address     = d.Address.ToString(),
                            Category    = id.Value.DevCat,
                            SubCategory = id.Value.SubCat,
                            Firmware    = id.Value.FirmwareVersion,
                            ProductKey  = id.Value.ProductKey?.ToString(),
                        });

                        logger.DebugFormat("New device identified and added to device list. ({0})", d);
                    }
                    else
                    {
                        logger.Debug("What does this mean?");
                    }
                }
                else
                {
                    dataManager.Add(new InsteonDeviceModel()
                    {
                        Address     = insteonAddress.ToString(),
                        Category    = 0,
                        SubCategory = 0,
                        Firmware    = 0
                    });

                    logger.Warn("device didn't respond. Battery powered?");
                }
            }

            Network.Devices.DeviceAdded += DevicesOnDeviceAdded;
        }