public Device AddDevice(Device parentDevice, Driver driver, int intAddress)
		{
			var device = new Device()
			{
				DriverUID = driver.UID,
				Driver = driver,
				IntAddress = intAddress,
				Parent = parentDevice
			};
			if (parentDevice.Driver.DriverType == DriverType.MPT)
			{
				device.ZoneUID = parentDevice.ZoneUID;
			}
            if (driver.DriverType == DriverType.Valve)
            {
                device.Properties.Add(new Property() { Name = "Action", Value = "1" });
            }
			parentDevice.Children.Add(device);
			AddAutoCreateChildren(device);
			AddAutoChildren(device);

			parentDevice.OnChanged();
			DeviceConfiguration.Update();
			return device;
		}
		public void RemoveOneDevice(Device device)
		{
			DeviceConfiguration.Devices.Remove(device);

			var dependentDevices = new List<Device>(device.DependentDevices);
			foreach (var dependentDevice in dependentDevices)
			{
				if (!device.AllParents.Contains(deletingDevice))
				{
					DeviceConfiguration.InvalidateOneDevice(dependentDevice);
					DeviceConfiguration.UpdateOneDeviceCrossReferences(dependentDevice);
					dependentDevice.OnChanged();
				}
			}

			var children = new List<Device>(device.Children);
			foreach (var child in children)
			{
				RemoveOneDevice(child);
			}
			var parentDevice = device.Parent;
			parentDevice.Children.Remove(device);
			parentDevice.OnChanged();
			device.OnChanged();
		}
		public void ChangeDriver(Device device, Driver driver)
		{
			var changeZone = !(device.Driver.IsZoneDevice && driver.IsZoneDevice);
			device.Driver = driver;
			device.DriverUID = driver.UID;
            if (driver.IsRangeEnabled)
                device.IntAddress = driver.MinAddress;
			if (changeZone)
			{
				RemoveDeviceFromZone(device, null);
				SetDeviceZoneLogic(device, new ZoneLogic());
			}
			device.Properties = new List<Property>();
			device.SystemAUProperties = new List<Property>();
			device.DeviceAUProperties = new List<Property>();
			device.OnChanged();
		}
		public void SetIsNotUsed(Device device, bool isUsed)
		{
			device.IsNotUsed = isUsed;
			device.OnChanged();
			if (isUsed)
			{
				SetDeviceZoneLogic(device, new ZoneLogic());
			}
		}
        public void SetPDUGroupLogic(Device device, PDUGroupLogic pduGroupLogic)
        {
            foreach (var pduGroupDevice in device.PDUGroupLogic.Devices)
            {
                pduGroupDevice.Device = null;
                if (pduGroupDevice.DeviceUID != Guid.Empty)
                {
                    var pduDevice = DeviceConfiguration.Devices.FirstOrDefault(x => x.UID == pduGroupDevice.DeviceUID);
                    if (pduDevice != null)
                    {
                        pduGroupDevice.Device = pduDevice;
                        pduDevice.DependentDevices.Remove(device);
                    }
                }
            }

            device.PDUGroupLogic = pduGroupLogic;
            DeviceConfiguration.InvalidatePDUDirection(device);
            DeviceConfiguration.UpdateOneDeviceCrossReferences(device);
            device.OnChanged();
        }
 public void SetIndicatorLogic(Device device, IndicatorLogic indicatorLogic)
 {
     foreach (var zone in device.IndicatorLogic.Zones)
         zone.IndicatorsInZone.Remove(device);
     device.IndicatorLogic = indicatorLogic;
     DeviceConfiguration.InvalidateIndicator(device);
     DeviceConfiguration.UpdateOneDeviceCrossReferences(device);
     device.OnChanged();
 }