class DeviceAddedListener extends BaseChangeListener {

	@OnMessage(from="DRIV:dev:*", types=Capability.EVENT_ADDED)
	public void onDeviceAdded(PlatformMessage message) {
		Device device = deviceDao.findById((UUID) message.getSource().getId());
		if(device == null) {
			logger.warn("Unable to load device with address [{}], can't create associated PairingDevice", message.getSource());
			return;
		}
		UUID placeId = device.getPlace();
		DeviceProtocolAddress protocolAddress = (DeviceProtocolAddress) Address.fromString(device.getProtocolAddress());
		Map<String, Object> original;
		PairingDevice model = pairingDeviceDao.findByProtocolAddress(placeId, protocolAddress);
		if(model == null) {
			model = new PairingDevice();
			model.setPlaceId(placeId);
			model.setProtocolAddress(protocolAddress);
			PairingDeviceModel.setCustomizations(model, ImmutableSet.of());
			original = null;
		}
		else {
			original = model.toMap();
		}
		PairingDeviceModel.setDeviceAddress(model, message.getSource().getRepresentation());
		if(!StringUtils.isEmpty(device.getProductId())) {
			PairingDeviceModel.setProductAddress(model, Address.platformService(device.getProductId(), ProductCapability.NAMESPACE).getRepresentation());
		}
		updatePairingStatus(model, message.getValue(), original);
	}

	@Inject public  DeviceAddedListener(
			PlatformMessageBus messageBus,
			DeviceDAO deviceDao,
			PairingDeviceDao pairingDeviceDao
	);

}