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() }); } }
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); }